aboutsummaryrefslogtreecommitdiff
path: root/ncurses/base
diff options
context:
space:
mode:
Diffstat (limited to 'ncurses/base')
-rw-r--r--ncurses/base/MKkeyname.awk156
-rwxr-xr-xncurses/base/MKlib_gen.sh426
-rw-r--r--ncurses/base/MKunctrl.awk185
-rw-r--r--ncurses/base/README35
-rw-r--r--ncurses/base/define_key.c70
-rw-r--r--ncurses/base/key_defined.c78
-rw-r--r--ncurses/base/keybound.c51
-rw-r--r--ncurses/base/keyok.c78
-rw-r--r--ncurses/base/legacy_coding.c48
-rw-r--r--ncurses/base/lib_addch.c545
-rw-r--r--ncurses/base/lib_addstr.c245
-rw-r--r--ncurses/base/lib_beep.c76
-rw-r--r--ncurses/base/lib_bkgd.c156
-rw-r--r--ncurses/base/lib_box.c128
-rw-r--r--ncurses/base/lib_chgat.c68
-rw-r--r--ncurses/base/lib_clear.c56
-rw-r--r--ncurses/base/lib_clearok.c55
-rw-r--r--ncurses/base/lib_clrbot.c76
-rw-r--r--ncurses/base/lib_clreol.c91
-rw-r--r--ncurses/base/lib_color.c593
-rw-r--r--ncurses/base/lib_colorset.c60
-rw-r--r--ncurses/base/lib_delch.c69
-rw-r--r--ncurses/base/lib_delwin.c89
-rw-r--r--ncurses/base/lib_dft_fgbg.c75
-rw-r--r--ncurses/base/lib_echo.c61
-rw-r--r--ncurses/base/lib_endwin.c60
-rw-r--r--ncurses/base/lib_erase.c92
-rw-r--r--ncurses/base/lib_flash.c73
-rw-r--r--ncurses/base/lib_freeall.c146
-rw-r--r--ncurses/base/lib_getch.c611
-rw-r--r--ncurses/base/lib_getstr.c224
-rw-r--r--ncurses/base/lib_hline.c80
-rw-r--r--ncurses/base/lib_immedok.c54
-rw-r--r--ncurses/base/lib_inchstr.c64
-rw-r--r--ncurses/base/lib_initscr.c97
-rw-r--r--ncurses/base/lib_insch.c155
-rw-r--r--ncurses/base/lib_insdel.c63
-rw-r--r--ncurses/base/lib_insnstr.c68
-rw-r--r--ncurses/base/lib_instr.c112
-rw-r--r--ncurses/base/lib_isendwin.c51
-rw-r--r--ncurses/base/lib_leaveok.c55
-rw-r--r--ncurses/base/lib_mouse.c1367
-rw-r--r--ncurses/base/lib_move.c60
-rw-r--r--ncurses/base/lib_mvwin.c114
-rw-r--r--ncurses/base/lib_newterm.c217
-rw-r--r--ncurses/base/lib_newwin.c322
-rw-r--r--ncurses/base/lib_nl.c79
-rw-r--r--ncurses/base/lib_overlay.c211
-rw-r--r--ncurses/base/lib_pad.c322
-rw-r--r--ncurses/base/lib_printw.c138
-rw-r--r--ncurses/base/lib_redrawln.c84
-rw-r--r--ncurses/base/lib_refresh.c288
-rw-r--r--ncurses/base/lib_restart.c99
-rw-r--r--ncurses/base/lib_scanw.c106
-rw-r--r--ncurses/base/lib_screen.c214
-rw-r--r--ncurses/base/lib_scroll.c150
-rw-r--r--ncurses/base/lib_scrollok.c55
-rw-r--r--ncurses/base/lib_scrreg.c60
-rw-r--r--ncurses/base/lib_set_term.c655
-rw-r--r--ncurses/base/lib_slk.c219
-rw-r--r--ncurses/base/lib_slkatr_set.c59
-rw-r--r--ncurses/base/lib_slkatrof.c58
-rw-r--r--ncurses/base/lib_slkatron.c58
-rw-r--r--ncurses/base/lib_slkatrset.c53
-rw-r--r--ncurses/base/lib_slkattr.c56
-rw-r--r--ncurses/base/lib_slkclear.c66
-rw-r--r--ncurses/base/lib_slkcolor.c56
-rw-r--r--ncurses/base/lib_slkinit.c55
-rw-r--r--ncurses/base/lib_slklab.c51
-rw-r--r--ncurses/base/lib_slkrefr.c122
-rw-r--r--ncurses/base/lib_slkset.c149
-rw-r--r--ncurses/base/lib_slktouch.c53
-rw-r--r--ncurses/base/lib_touch.c91
-rw-r--r--ncurses/base/lib_ungetch.c90
-rw-r--r--ncurses/base/lib_vline.c79
-rw-r--r--ncurses/base/lib_wattroff.c64
-rw-r--r--ncurses/base/lib_wattron.c64
-rw-r--r--ncurses/base/lib_winch.c54
-rw-r--r--ncurses/base/lib_window.c250
-rw-r--r--ncurses/base/memmove.c69
-rw-r--r--ncurses/base/nc_panel.c41
-rw-r--r--ncurses/base/resizeterm.c455
-rw-r--r--ncurses/base/safe_sprintf.c264
-rw-r--r--ncurses/base/sigaction.c99
-rw-r--r--ncurses/base/tries.c143
-rw-r--r--ncurses/base/use_window.c78
-rw-r--r--ncurses/base/version.c42
-rw-r--r--ncurses/base/vsscanf.c356
-rw-r--r--ncurses/base/wresize.c246
89 files changed, 13656 insertions, 0 deletions
diff --git a/ncurses/base/MKkeyname.awk b/ncurses/base/MKkeyname.awk
new file mode 100644
index 000000000000..c1d9475045d0
--- /dev/null
+++ b/ncurses/base/MKkeyname.awk
@@ -0,0 +1,156 @@
+# $Id: MKkeyname.awk,v 1.38 2007/08/18 18:41:18 tom Exp $
+##############################################################################
+# Copyright (c) 1999-2006,2007 Free Software Foundation, Inc. #
+# #
+# Permission is hereby granted, free of charge, to any person obtaining a #
+# copy of this software and associated documentation files (the "Software"), #
+# to deal in the Software without restriction, including without limitation #
+# the rights to use, copy, modify, merge, publish, distribute, distribute #
+# with modifications, sublicense, and/or sell copies of the Software, and to #
+# permit persons to whom the Software is furnished to do so, subject to the #
+# following conditions: #
+# #
+# The above copyright notice and this permission notice shall be included in #
+# all copies or substantial portions of the Software. #
+# #
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
+# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
+# DEALINGS IN THE SOFTWARE. #
+# #
+# Except as contained in this notice, the name(s) of the above copyright #
+# holders shall not be used in advertising or otherwise to promote the sale, #
+# use or other dealings in this Software without prior written #
+# authorization. #
+##############################################################################
+BEGIN {
+ print "/* generated by MKkeyname.awk */"
+ print ""
+ print "#include <curses.priv.h>"
+ print "#include <tic.h>"
+ print "#include <term_entry.h>"
+ print ""
+ first = 1;
+}
+
+/^[^#]/ {
+ if (bigstrings) {
+ if (first) {
+ print "struct kn { short offset; int code; };"
+ print "static const struct kn _nc_key_names[] = {"
+ }
+ printf "\t{ %d, %s },\n", offset, $1
+ offset += length($1) + 1
+ names = names"\n\t\""$1"\\0\""
+ } else {
+ if (first) {
+ print "struct kn { const char *name; int code; };"
+ print "static const struct kn _nc_key_names[] = {"
+ }
+ printf "\t{ \"%s\", %s },\n", $1, $1;
+ }
+ first = 0;
+ }
+
+END {
+ if (bigstrings) {
+ printf "\t{ -1, 0 }};\n"
+ print ""
+ print "static const char key_names[] = "names";"
+ } else {
+ printf "\t{ 0, 0 }};\n"
+ }
+ print ""
+ print "#define SIZEOF_TABLE 256"
+ print "#define MyTable _nc_globals.keyname_table"
+ print ""
+ print "NCURSES_EXPORT(NCURSES_CONST char *) keyname (int c)"
+ print "{"
+ print " int i;"
+ print " char name[20];"
+ print " char *p;"
+ print " NCURSES_CONST char *result = 0;"
+ print ""
+ print " if (c == -1) {"
+ print " result = \"-1\";"
+ print " } else {"
+ if (bigstrings) {
+ print " for (i = 0; _nc_key_names[i].offset != -1; i++) {"
+ print " if (_nc_key_names[i].code == c) {"
+ print " result = (NCURSES_CONST char *)key_names + _nc_key_names[i].offset;"
+ print " break;"
+ print " }"
+ print " }"
+ } else {
+ print " for (i = 0; _nc_key_names[i].name != 0; i++) {"
+ print " if (_nc_key_names[i].code == c) {"
+ print " result = (NCURSES_CONST char *)_nc_key_names[i].name;"
+ print " break;"
+ print " }"
+ print " }"
+ }
+ print ""
+ print " if (result == 0 && (c >= 0 && c < SIZEOF_TABLE)) {"
+ print " if (MyTable == 0)"
+ print " MyTable = typeCalloc(char *, SIZEOF_TABLE);"
+ print " if (MyTable != 0) {"
+ print " if (MyTable[c] == 0) {"
+ print " int cc = c;"
+ print " p = name;"
+ print " if (cc >= 128 && (SP == 0 || SP->_use_meta)) {"
+ print " strcpy(p, \"M-\");"
+ print " p += 2;"
+ print " cc -= 128;"
+ print " }"
+ print " if (cc < 32)"
+ print " sprintf(p, \"^%c\", cc + '@');"
+ print " else if (cc == 127)"
+ print " strcpy(p, \"^?\");"
+ print " else"
+ print " sprintf(p, \"%c\", cc);"
+ print " MyTable[c] = strdup(name);"
+ print " }"
+ print " result = MyTable[c];"
+ print " }"
+ print "#if NCURSES_EXT_FUNCS && NCURSES_XNAMES"
+ print " } else if (result == 0 && cur_term != 0) {"
+ print " int j, k;"
+ print " char * bound;"
+ print " TERMTYPE *tp = &(cur_term->type);"
+ print " int save_trace = _nc_tracing;"
+ print ""
+ print " _nc_tracing = 0; /* prevent recursion via keybound() */"
+ print " for (j = 0; (bound = keybound(c, j)) != 0; ++j) {"
+ print " for(k = STRCOUNT; k < NUM_STRINGS(tp); k++) {"
+ print " if (tp->Strings[k] != 0 && !strcmp(bound, tp->Strings[k])) {"
+ print " result = ExtStrname(tp, k, strnames);"
+ print " break;"
+ print " }"
+ print " }"
+ print " free(bound);"
+ print " if (result != 0)"
+ print " break;"
+ print " }"
+ print " _nc_tracing = save_trace;"
+ print "#endif"
+ print " }"
+ print " }"
+ print " return result;"
+ print "}"
+ print ""
+ print "#if NO_LEAKS"
+ print "void _nc_keyname_leaks(void)"
+ print "{"
+ print " int j;"
+ print " if (MyTable != 0) {"
+ print " for (j = 0; j < SIZEOF_TABLE; ++j) {"
+ print " FreeIfNeeded(MyTable[j]);"
+ print " }"
+ print " FreeAndNull(MyTable);"
+ print " }"
+ print "}"
+ print "#endif /* NO_LEAKS */"
+}
diff --git a/ncurses/base/MKlib_gen.sh b/ncurses/base/MKlib_gen.sh
new file mode 100755
index 000000000000..09857834e7e0
--- /dev/null
+++ b/ncurses/base/MKlib_gen.sh
@@ -0,0 +1,426 @@
+#!/bin/sh
+#
+# MKlib_gen.sh -- generate sources from curses.h macro definitions
+#
+# ($Id: MKlib_gen.sh,v 1.30 2008/01/05 23:21:10 tom Exp $)
+#
+##############################################################################
+# Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. #
+# #
+# Permission is hereby granted, free of charge, to any person obtaining a #
+# copy of this software and associated documentation files (the "Software"), #
+# to deal in the Software without restriction, including without limitation #
+# the rights to use, copy, modify, merge, publish, distribute, distribute #
+# with modifications, sublicense, and/or sell copies of the Software, and to #
+# permit persons to whom the Software is furnished to do so, subject to the #
+# following conditions: #
+# #
+# The above copyright notice and this permission notice shall be included in #
+# all copies or substantial portions of the Software. #
+# #
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
+# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
+# DEALINGS IN THE SOFTWARE. #
+# #
+# Except as contained in this notice, the name(s) of the above copyright #
+# holders shall not be used in advertising or otherwise to promote the sale, #
+# use or other dealings in this Software without prior written #
+# authorization. #
+##############################################################################
+#
+# The XSI Curses standard requires all curses entry points to exist as
+# functions, even though many definitions would normally be shadowed
+# by macros. Rather than hand-hack all that code, we actually
+# generate functions from the macros.
+#
+# This script accepts a file of prototypes on standard input. It discards
+# any that don't have a `generated' comment attached. It then parses each
+# prototype (relying on the fact that none of the macros take function
+# pointer or array arguments) and generates C source from it.
+#
+# Here is what the pipeline stages are doing:
+#
+# 1. sed: extract prototypes of generated functions
+# 2. sed: decorate prototypes with generated arguments a1. a2,...z
+# 3. awk: generate the calls with args matching the formals
+# 4. sed: prefix function names in prototypes so the preprocessor won't expand
+# them.
+# 5. cpp: macro-expand the file so the macro calls turn into C calls
+# 6. awk: strip the expansion junk off the front and add the new header
+# 7. sed: squeeze spaces, strip off gen_ prefix, create needed #undef
+#
+
+# keep the editing independent of locale:
+if test "${LANGUAGE+set}" = set; then LANGUAGE=C; export LANGUAGE; fi
+if test "${LANG+set}" = set; then LANG=C; export LANG; fi
+if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
+if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
+if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
+if test "${LC_COLLATE+set}" = set; then LC_COLLATE=C; export LC_COLLATE; fi
+
+preprocessor="$1 -DNCURSES_INTERNALS -I../include"
+AWK="$2"
+USE="$3"
+
+PID=$$
+ED1=sed1_${PID}.sed
+ED2=sed2_${PID}.sed
+ED3=sed3_${PID}.sed
+ED4=sed4_${PID}.sed
+AW1=awk1_${PID}.awk
+AW2=awk2_${PID}.awk
+TMP=gen__${PID}.c
+trap "rm -f $ED1 $ED2 $ED3 $ED4 $AW1 $AW2 $TMP" 0 1 2 5 15
+
+ALL=$USE
+if test "$USE" = implemented ; then
+ CALL="call_"
+ cat >$ED1 <<EOF1
+/^extern.*implemented/{
+ h
+ s/^.*implemented:\([^ *]*\).*/P_POUNDCif_USE_\1_SUPPORT/p
+ g
+ s/^extern \([^;]*\);.*/\1/p
+ g
+ s/^.*implemented:\([^ *]*\).*/P_POUNDCendif/p
+}
+/^extern.*generated/{
+ h
+ s/^.*generated:\([^ *]*\).*/P_POUNDCif_USE_\1_SUPPORT/p
+ g
+ s/^extern \([^;]*\);.*/\1/p
+ g
+ s/^.*generated:\([^ *]*\).*/P_POUNDCendif/p
+}
+EOF1
+else
+ CALL=""
+ cat >$ED1 <<EOF1
+/^extern.*${ALL}/{
+ h
+ s/^.*${ALL}:\([^ *]*\).*/P_POUNDCif_USE_\1_SUPPORT/p
+ g
+ s/^extern \([^;]*\);.*/\1/p
+ g
+ s/^.*${ALL}:\([^ *]*\).*/P_POUNDCendif/p
+}
+EOF1
+fi
+
+cat >$ED2 <<EOF2
+/^P_/b nc
+/(void)/b nc
+ s/,/ a1% /
+ s/,/ a2% /
+ s/,/ a3% /
+ s/,/ a4% /
+ s/,/ a5% /
+ s/,/ a6% /
+ s/,/ a7% /
+ s/,/ a8% /
+ s/,/ a9% /
+ s/,/ a10% /
+ s/,/ a11% /
+ s/,/ a12% /
+ s/,/ a13% /
+ s/,/ a14% /
+ s/,/ a15% /
+ s/*/ * /g
+ s/%/ , /g
+ s/)/ z)/
+ s/\.\.\. z)/...)/
+:nc
+ s/(/ ( /
+ s/)/ )/
+EOF2
+
+cat >$ED3 <<EOF3
+/^P_/{
+ s/^P_POUNDCif_/#if /
+ s/^P_POUNDCendif/#endif/
+ s/^P_//
+ b done
+}
+ s/ */ /g
+ s/ */ /g
+ s/ ,/,/g
+ s/( /(/g
+ s/ )/)/g
+ s/ gen_/ /
+ s/^M_/#undef /
+ s/^[ ]*%[ ]*%[ ]*/ /
+:done
+EOF3
+
+if test "$USE" = generated ; then
+cat >$ED4 <<EOF
+ s/^\(.*\) \(.*\) (\(.*\))\$/NCURSES_EXPORT(\1) \2 (\3)/
+EOF
+else
+cat >$ED4 <<EOF
+/^\(.*\) \(.*\) (\(.*\))\$/ {
+ h
+ s/^\(.*\) \(.*\) (\(.*\))\$/extern \1 call_\2 (\3);/
+ p
+ g
+ s/^\(.*\) \(.*\) (\(.*\))\$/\1 call_\2 (\3)/
+ }
+EOF
+fi
+
+cat >$AW1 <<\EOF1
+BEGIN {
+ skip=0;
+ }
+/^P_POUNDCif/ {
+ print "\n"
+ print $0
+ skip=0;
+}
+/^P_POUNDCendif/ {
+ print $0
+ skip=1;
+}
+$0 !~ /^P_/ {
+ if (skip)
+ print "\n"
+ skip=1;
+
+ first=$1
+ for (i = 1; i <= NF; i++) {
+ if ( $i != "NCURSES_CONST" ) {
+ first = i;
+ break;
+ }
+ }
+ second = first + 1;
+ if ( $first == "chtype" ) {
+ returnType = "Char";
+ } else if ( $first == "SCREEN" ) {
+ returnType = "SP";
+ } else if ( $first == "WINDOW" ) {
+ returnType = "Win";
+ } else if ( $first == "attr_t" || $second == "attrset" || $second == "standout" || $second == "standend" || $second == "wattrset" || $second == "wstandout" || $second == "wstandend" ) {
+ returnType = "Attr";
+ } else if ( $first == "bool" || $first == "NCURSES_BOOL" ) {
+ returnType = "Bool";
+ } else if ( $second == "*" ) {
+ returnType = "Ptr";
+ } else {
+ returnType = "Code";
+ }
+ myfunc = second;
+ for (i = second; i <= NF; i++) {
+ if ($i != "*") {
+ myfunc = i;
+ break;
+ }
+ }
+ if (using == "generated") {
+ print "M_" $myfunc
+ }
+ print $0;
+ print "{";
+ argcount = 1;
+ check = NF - 1;
+ if ($check == "void")
+ argcount = 0;
+ if (argcount != 0) {
+ for (i = 1; i <= NF; i++)
+ if ($i == ",")
+ argcount++;
+ }
+
+ # suppress trace-code for functions that we cannot do properly here,
+ # since they return data.
+ dotrace = 1;
+ if ($myfunc ~ /innstr/)
+ dotrace = 0;
+ if ($myfunc ~ /innwstr/)
+ dotrace = 0;
+
+ # workaround functions that we do not parse properly
+ if ($myfunc ~ /ripoffline/) {
+ dotrace = 0;
+ argcount = 2;
+ }
+ if ($myfunc ~ /wunctrl/) {
+ dotrace = 0;
+ }
+
+ call = "%%T((T_CALLED(\""
+ args = ""
+ comma = ""
+ num = 0;
+ pointer = 0;
+ va_list = 0;
+ varargs = 0;
+ argtype = ""
+ for (i = myfunc; i <= NF; i++) {
+ ch = $i;
+ if ( ch == "*" )
+ pointer = 1;
+ else if ( ch == "va_list" )
+ va_list = 1;
+ else if ( ch == "..." )
+ varargs = 1;
+ else if ( ch == "char" )
+ argtype = "char";
+ else if ( ch == "int" )
+ argtype = "int";
+ else if ( ch == "short" )
+ argtype = "short";
+ else if ( ch == "chtype" )
+ argtype = "chtype";
+ else if ( ch == "attr_t" || ch == "NCURSES_ATTR_T" )
+ argtype = "attr";
+
+ if ( ch == "," || ch == ")" ) {
+ if (va_list) {
+ call = call "%s"
+ } else if (varargs) {
+ call = call "%s"
+ } else if (pointer) {
+ if ( argtype == "char" ) {
+ call = call "%s"
+ comma = comma "_nc_visbuf2(" num ","
+ pointer = 0;
+ } else
+ call = call "%p"
+ } else if (argcount != 0) {
+ if ( argtype == "int" || argtype == "short" ) {
+ call = call "%d"
+ argtype = ""
+ } else if ( argtype != "" ) {
+ call = call "%s"
+ comma = comma "_trace" argtype "2(" num ","
+ } else {
+ call = call "%#lx"
+ comma = comma "(long)"
+ }
+ }
+ if (ch == ",") {
+ args = args comma "a" ++num;
+ } else if ( argcount != 0 ) {
+ if ( va_list ) {
+ args = args comma "\"va_list\""
+ } else if ( varargs ) {
+ args = args comma "\"...\""
+ } else {
+ args = args comma "z"
+ }
+ }
+ call = call ch
+ if (pointer == 0 && argcount != 0 && argtype != "" )
+ args = args ")"
+ if (args != "")
+ comma = ", "
+ pointer = 0;
+ argtype = ""
+ }
+ if ( i == 2 || ch == "(" )
+ call = call ch
+ }
+ call = call "\")"
+ if (args != "")
+ call = call ", " args
+ call = call ")); "
+
+ if (dotrace)
+ printf "%s", call
+
+ if (match($0, "^void"))
+ call = ""
+ else if (dotrace)
+ call = sprintf("return%s( ", returnType);
+ else
+ call = "%%return ";
+
+ call = call $myfunc "(";
+ for (i = 1; i < argcount; i++) {
+ if (i != 1)
+ call = call ", ";
+ call = call "a" i;
+ }
+ if ( argcount != 0 && $check != "..." ) {
+ if (argcount != 1)
+ call = call ", ";
+ call = call "z";
+ }
+ if (!match($0, "^void"))
+ call = call ") ";
+ if (dotrace)
+ call = call ")";
+ print call ";"
+
+ if (match($0, "^void"))
+ print "%%returnVoid;"
+ print "}";
+}
+EOF1
+
+cat >$AW2 <<EOF1
+BEGIN {
+ print "/*"
+ print " * DO NOT EDIT THIS FILE BY HAND!"
+ printf " * It is generated by $0 %s.\n", "$USE"
+ if ( "$USE" == "generated" ) {
+ print " *"
+ print " * This is a file of trivial functions generated from macro"
+ print " * definitions in curses.h to satisfy the XSI Curses requirement"
+ print " * that every macro also exist as a callable function."
+ print " *"
+ print " * It will never be linked unless you call one of the entry"
+ print " * points with its normal macro definition disabled. In that"
+ print " * case, if you have no shared libraries, it will indirectly"
+ print " * pull most of the rest of the library into your link image."
+ }
+ print " */"
+ print "#define NCURSES_ATTR_T int"
+ print "#include <curses.priv.h>"
+ print ""
+ }
+/^DECLARATIONS/ {start = 1; next;}
+ {if (start) print \$0;}
+END {
+ if ( "$USE" != "generated" ) {
+ print "int main(void) { return 0; }"
+ }
+ }
+EOF1
+
+cat >$TMP <<EOF
+#include <ncurses_cfg.h>
+#undef NCURSES_NOMACROS
+#include <curses.h>
+
+DECLARATIONS
+
+EOF
+
+sed -n -f $ED1 \
+| sed -e 's/NCURSES_EXPORT(\(.*\)) \(.*\) (\(.*\))/\1 \2(\3)/' \
+| sed -f $ED2 \
+| $AWK -f $AW1 using=$USE \
+| sed \
+ -e 's/ [ ]*$//g' \
+ -e 's/^\([a-zA-Z_][a-zA-Z_]*[ *]*\)/\1 gen_/' \
+ -e 's/gen_$//' \
+ -e 's/ / /g' >>$TMP
+
+$preprocessor $TMP 2>/dev/null \
+| sed \
+ -e 's/ / /g' \
+ -e 's/^ //' \
+ -e 's/^_Bool/bool/' \
+| $AWK -f $AW2 \
+| sed -f $ED3 \
+| sed \
+ -e 's/^.*T_CALLED.*returnCode( \([a-z].*) \));/ return \1;/' \
+ -e 's/^.*T_CALLED.*returnCode( \((wmove.*) \));/ return \1;/' \
+ -e 's/gen_//' \
+| sed -f $ED4
diff --git a/ncurses/base/MKunctrl.awk b/ncurses/base/MKunctrl.awk
new file mode 100644
index 000000000000..1ba511d72323
--- /dev/null
+++ b/ncurses/base/MKunctrl.awk
@@ -0,0 +1,185 @@
+# $Id: MKunctrl.awk,v 1.21 2008/02/03 20:24:30 tom Exp $
+##############################################################################
+# Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. #
+# #
+# Permission is hereby granted, free of charge, to any person obtaining a #
+# copy of this software and associated documentation files (the "Software"), #
+# to deal in the Software without restriction, including without limitation #
+# the rights to use, copy, modify, merge, publish, distribute, distribute #
+# with modifications, sublicense, and/or sell copies of the Software, and to #
+# permit persons to whom the Software is furnished to do so, subject to the #
+# following conditions: #
+# #
+# The above copyright notice and this permission notice shall be included in #
+# all copies or substantial portions of the Software. #
+# #
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
+# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
+# DEALINGS IN THE SOFTWARE. #
+# #
+# Except as contained in this notice, the name(s) of the above copyright #
+# holders shall not be used in advertising or otherwise to promote the sale, #
+# use or other dealings in this Software without prior written #
+# authorization. #
+##############################################################################
+#
+# Author: Thomas E. Dickey (1997-on)
+#
+
+BEGIN {
+ print "/* generated by MKunctrl.awk */"
+ print ""
+ print "#include <curses.priv.h>"
+ print "#include <ctype.h>"
+ print ""
+ print "#if USE_WIDEC_SUPPORT"
+ print "#if HAVE_WCTYPE_H"
+ print "#include <wctype.h>"
+ print "#endif"
+ print "#endif"
+ print ""
+ print "#undef unctrl"
+ print ""
+ }
+END {
+ print "NCURSES_EXPORT(NCURSES_CONST char *) unctrl (register chtype ch)"
+ print "{"
+
+ blob=""
+ offset=0
+ if (bigstrings) {
+ printf "static const short unctrl_table[] = {"
+ } else {
+ printf "static const char* const unctrl_table[] = {"
+ }
+ for ( ch = 0; ch < 256; ch++ ) {
+ gap = ","
+ part=""
+ if ((ch % 8) == 0) {
+ printf "\n "
+ if (ch != 0)
+ blob = blob "\""
+ blob = blob "\n \""
+ }
+ if (bigstrings)
+ printf "%4d%s", offset, gap;
+ if (ch < 32) {
+ part = sprintf ("^\\%03o", ch + 64);
+ offset = offset + 3;
+ } else if (ch == 127) {
+ part = "^?";
+ offset = offset + 3;
+ } else if (ch >= 128 && ch < 160) {
+ part = sprintf("~\\%03o", ch - 64);
+ offset = offset + 3;
+ } else if (ch == 255) {
+ part = "~?";
+ offset = offset + 3;
+ } else if (ch >= 160) {
+ part = sprintf("M-\\%03o", ch - 128);
+ offset = offset + 4;
+ } else {
+ gap = gap " "
+ part = sprintf("\\%03o", ch);
+ offset = offset + 2;
+ }
+ if (ch == 255)
+ gap = "\n"
+ else if (((ch + 1) % 8) != 0)
+ gap = gap " "
+ if (bigstrings) {
+ blob = blob part "\\0";
+ } else {
+ printf "\"%s\"%s", part, gap
+ }
+ }
+ print "};"
+ blob = blob "\"";
+
+ print ""
+ if (bigstrings) {
+ blob = blob "\n/* printable values in 128-255 range */"
+ printf "static const short unctrl_c1[] = {"
+ } else {
+ printf "static const char* const unctrl_c1[] = {"
+ }
+ for ( ch = 128; ch < 256; ch++ ) {
+ gap = ","
+ if ((ch % 8) == 0) {
+ if (ch != 128)
+ blob = blob "\""
+ printf "\n "
+ blob = blob "\n \""
+ }
+ if (bigstrings) {
+ printf "%4d%s", offset, gap;
+ part = sprintf("\\%03o\\0", ch);
+ blob = blob part
+ offset = offset + 2;
+ if (((ch + 1) % 8) != 0)
+ gap = gap " "
+ } else {
+ if (ch >= 128) {
+ printf "\"\\%03o\"", ch
+ gap = gap " "
+ }
+ if (ch == 255)
+ gap = "\n"
+ else if (((ch + 1) % 8) != 0)
+ gap = gap " "
+ printf "%s", gap
+ }
+ }
+ print "};"
+ blob = blob "\"\n"
+
+ print ""
+ if (bigstrings) {
+ print "static const char unctrl_blob[] = "blob";"
+ print ""
+ stringname = "unctrl_blob + unctrl"
+ } else {
+ stringname = "unctrl"
+ }
+ print "\tint check = ChCharOf(ch);"
+ print "\tconst char *result;"
+ print ""
+ print "\tif (check >= 0 && check < (int)SIZEOF(unctrl_table)) {"
+ print "#if NCURSES_EXT_FUNCS"
+ print "\t\tif ((SP != 0)"
+ print "\t\t && (SP->_legacy_coding > 1)"
+ print "\t\t && (check >= 128)"
+ print "\t\t && (check < 160))"
+ printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
+ print "\t\telse"
+ print "#if USE_WIDEC_SUPPORT"
+ print "\t\tif ((check >= 160)"
+ print "\t\t && (check < 256)"
+ print "\t\t && ((SP != 0)"
+ print "\t\t && ((SP->_legacy_coding > 0)"
+ print "\t\t || (SP->_legacy_coding == 0"
+ print "\t\t && (isprint(check) || iswprint(check))))))"
+ printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
+ print "\t\telse"
+ print "#else"
+ print "\t\tif ((check >= 160)"
+ print "\t\t && (check < 256)"
+ print "\t\t && ((SP != 0)"
+ print "\t\t && ((SP->_legacy_coding > 0)"
+ print "\t\t || (SP->_legacy_coding == 0"
+ print "\t\t && isprint(check)))))"
+ printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
+ print "\t\telse"
+ print "#endif /* USE_WIDEC_SUPPORT */"
+ print "#endif /* NCURSES_EXT_FUNCS */"
+ printf "\t\t\tresult = %s_table[check];\n", stringname;
+ print "\t} else {"
+ print "\t\tresult = 0;"
+ print "\t}"
+ print "\treturn (NCURSES_CONST char *)result;"
+ print "}"
+ }
diff --git a/ncurses/base/README b/ncurses/base/README
new file mode 100644
index 000000000000..4677e42e6176
--- /dev/null
+++ b/ncurses/base/README
@@ -0,0 +1,35 @@
+-------------------------------------------------------------------------------
+-- Copyright (c) 1998,2006 Free Software Foundation, Inc. --
+-- --
+-- Permission is hereby granted, free of charge, to any person obtaining a --
+-- copy of this software and associated documentation files (the --
+-- "Software"), to deal in the Software without restriction, including --
+-- without limitation the rights to use, copy, modify, merge, publish, --
+-- distribute, distribute with modifications, sublicense, and/or sell copies --
+-- of the Software, and to permit persons to whom the Software is furnished --
+-- to do so, subject to the following conditions: --
+-- --
+-- The above copyright notice and this permission notice shall be included --
+-- in all copies or substantial portions of the Software. --
+-- --
+-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
+-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
+-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN --
+-- NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
+-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
+-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE --
+-- USE OR OTHER DEALINGS IN THE SOFTWARE. --
+-- --
+-- Except as contained in this notice, the name(s) of the above copyright --
+-- holders shall not be used in advertising or otherwise to promote the --
+-- sale, use or other dealings in this Software without prior written --
+-- authorization. --
+-------------------------------------------------------------------------------
+-- $Id: README,v 1.2 2006/04/22 22:19:37 tom Exp $
+-------------------------------------------------------------------------------
+
+The functions in this directory are the generic (not device-specific) modules
+of ncurses.
+
+As a rule, these modules should not depend directly on term.h references and
+associated terminfo function and variables.
diff --git a/ncurses/base/define_key.c b/ncurses/base/define_key.c
new file mode 100644
index 000000000000..3d5815f906d6
--- /dev/null
+++ b/ncurses/base/define_key.c
@@ -0,0 +1,70 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey 1997-on *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: define_key.c,v 1.13 2006/12/30 23:23:31 tom Exp $")
+
+NCURSES_EXPORT(int)
+define_key(const char *str, int keycode)
+{
+ int code = ERR;
+
+ T((T_CALLED("define_key(%s,%d)"), _nc_visbuf(str), keycode));
+ if (SP == 0) {
+ code = ERR;
+ } else if (keycode > 0) {
+ unsigned ukey = (unsigned) keycode;
+
+ if (str != 0) {
+ define_key(str, 0);
+ } else if (has_key(keycode)) {
+ while (_nc_remove_key(&(SP->_keytry), ukey))
+ code = OK;
+ }
+ if (str != 0) {
+ if (key_defined(str) == 0) {
+ if (_nc_add_to_try(&(SP->_keytry), str, ukey) == OK) {
+ code = OK;
+ } else {
+ code = ERR;
+ }
+ } else {
+ code = ERR;
+ }
+ }
+ } else {
+ while (_nc_remove_string(&(SP->_keytry), str))
+ code = OK;
+ }
+ returnCode(code);
+}
diff --git a/ncurses/base/key_defined.c b/ncurses/base/key_defined.c
new file mode 100644
index 000000000000..759ad824318d
--- /dev/null
+++ b/ncurses/base/key_defined.c
@@ -0,0 +1,78 @@
+/****************************************************************************
+ * Copyright (c) 2003,2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey, 2003 *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: key_defined.c,v 1.6 2006/12/30 23:22:55 tom Exp $")
+
+static int
+find_definition(TRIES * tree, const char *str)
+{
+ TRIES *ptr;
+ int result = OK;
+
+ if (str != 0 && *str != '\0') {
+ for (ptr = tree; ptr != 0; ptr = ptr->sibling) {
+ if (UChar(*str) == UChar(ptr->ch)) {
+ if (str[1] == '\0' && ptr->child != 0) {
+ result = ERR;
+ } else if ((result = find_definition(ptr->child, str + 1))
+ == OK) {
+ result = ptr->value;
+ } else if (str[1] == '\0') {
+ result = ERR;
+ }
+ }
+ if (result != OK)
+ break;
+ }
+ }
+ return (result);
+}
+
+/*
+ * Returns the keycode associated with the given string. If none is found,
+ * return OK. If the string is only a prefix to other strings, return ERR.
+ * Otherwise, return the keycode's value (neither OK/ERR).
+ */
+NCURSES_EXPORT(int)
+key_defined(const char *str)
+{
+ int code = ERR;
+
+ T((T_CALLED("key_defined(%s)"), _nc_visbuf(str)));
+ if (SP != 0 && str != 0) {
+ code = find_definition(SP->_keytry, str);
+ }
+
+ returnCode(code);
+}
diff --git a/ncurses/base/keybound.c b/ncurses/base/keybound.c
new file mode 100644
index 000000000000..2995714ba936
--- /dev/null
+++ b/ncurses/base/keybound.c
@@ -0,0 +1,51 @@
+/****************************************************************************
+ * Copyright (c) 1999-2005,2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey 1999-on *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: keybound.c,v 1.7 2006/06/17 18:19:24 tom Exp $")
+
+/*
+ * Returns the count'th string definition which is associated with the
+ * given keycode. The result is malloc'd, must be freed by the caller.
+ */
+NCURSES_EXPORT(char *)
+keybound(int code, int count)
+{
+ char *result = 0;
+
+ T((T_CALLED("keybound(%d,%d)"), code, count));
+ if (SP != 0 && code >= 0) {
+ result = _nc_expand_try(SP->_keytry, (unsigned) code, &count, 0);
+ }
+ returnPtr(result);
+}
diff --git a/ncurses/base/keyok.c b/ncurses/base/keyok.c
new file mode 100644
index 000000000000..ad8988cded3b
--- /dev/null
+++ b/ncurses/base/keyok.c
@@ -0,0 +1,78 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey 1997-on *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: keyok.c,v 1.7 2006/12/30 16:22:33 tom Exp $")
+
+/*
+ * Enable (or disable) ncurses' interpretation of a keycode by adding (or
+ * removing) the corresponding 'tries' entry.
+ *
+ * Do this by storing a second tree of tries, which records the disabled keys.
+ * The simplest way to copy is to make a function that returns the string (with
+ * nulls set to 0200), then use that to reinsert the string into the
+ * corresponding tree.
+ */
+
+NCURSES_EXPORT(int)
+keyok(int c, bool flag)
+{
+ int code = ERR;
+ int count = 0;
+ char *s;
+
+ T((T_CALLED("keyok(%d,%d)"), c, flag));
+ if (c >= 0) {
+ unsigned ch = (unsigned) c;
+ if (flag) {
+ while ((s = _nc_expand_try(SP->_key_ok, ch, &count, 0)) != 0
+ && _nc_remove_key(&(SP->_key_ok), ch)) {
+ code = _nc_add_to_try(&(SP->_keytry), s, ch);
+ free(s);
+ count = 0;
+ if (code != OK)
+ break;
+ }
+ } else {
+ while ((s = _nc_expand_try(SP->_keytry, ch, &count, 0)) != 0
+ && _nc_remove_key(&(SP->_keytry), ch)) {
+ code = _nc_add_to_try(&(SP->_key_ok), s, ch);
+ free(s);
+ count = 0;
+ if (code != OK)
+ break;
+ }
+ }
+ }
+ returnCode(code);
+}
diff --git a/ncurses/base/legacy_coding.c b/ncurses/base/legacy_coding.c
new file mode 100644
index 000000000000..1c2f160a605d
--- /dev/null
+++ b/ncurses/base/legacy_coding.c
@@ -0,0 +1,48 @@
+/****************************************************************************
+ * Copyright (c) 2005 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: legacy_coding.c,v 1.2 2005/12/17 23:38:17 tom Exp $")
+
+NCURSES_EXPORT(int)
+use_legacy_coding(int level)
+{
+ int result = ERR;
+
+ T((T_CALLED("use_legacy_coding(%d)"), level));
+ if (level >= 0 && level <= 2 && SP != 0) {
+ result = SP->_legacy_coding;
+ SP->_legacy_coding = level;
+ }
+ returnCode(result);
+}
diff --git a/ncurses/base/lib_addch.c b/ncurses/base/lib_addch.c
new file mode 100644
index 000000000000..17ba6e2bcd6c
--- /dev/null
+++ b/ncurses/base/lib_addch.c
@@ -0,0 +1,545 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/*
+** lib_addch.c
+**
+** The routine waddch().
+**
+*/
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_addch.c,v 1.111 2008/03/29 18:48:02 tom Exp $")
+
+static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
+
+/*
+ * Ugly microtweaking alert. Everything from here to end of module is
+ * likely to be speed-critical -- profiling data sure says it is!
+ * Most of the important screen-painting functions are shells around
+ * waddch(). So we make every effort to reduce function-call overhead
+ * by inlining stuff, even at the cost of making wrapped copies for
+ * export. Also we supply some internal versions that don't call the
+ * window sync hook, for use by string-put functions.
+ */
+
+/* Return bit mask for clearing color pair number if given ch has color */
+#define COLOR_MASK(ch) (~(attr_t)((ch) & A_COLOR ? A_COLOR : 0))
+
+static NCURSES_INLINE NCURSES_CH_T
+render_char(WINDOW *win, NCURSES_CH_T ch)
+/* compute a rendition of the given char correct for the current context */
+{
+ attr_t a = WINDOW_ATTRS(win);
+ int pair = GetPair(ch);
+
+ if (ISBLANK(ch)
+ && AttrOf(ch) == A_NORMAL
+ && pair == 0) {
+ /* color/pair in attrs has precedence over bkgrnd */
+ ch = win->_nc_bkgd;
+ SetAttr(ch, a | AttrOf(win->_nc_bkgd));
+ if ((pair = GET_WINDOW_PAIR(win)) == 0)
+ pair = GetPair(win->_nc_bkgd);
+ SetPair(ch, pair);
+ } else {
+ /* color in attrs has precedence over bkgrnd */
+ a |= AttrOf(win->_nc_bkgd) & COLOR_MASK(a);
+ /* color in ch has precedence */
+ if (pair == 0) {
+ if ((pair = GET_WINDOW_PAIR(win)) == 0)
+ pair = GetPair(win->_nc_bkgd);
+ }
+#if 0
+ if (pair > 255) {
+ NCURSES_CH_T fixme = ch;
+ SetPair(fixme, pair);
+ }
+#endif
+ AddAttr(ch, (a & COLOR_MASK(AttrOf(ch))));
+ SetPair(ch, pair);
+ }
+
+ TR(TRACE_VIRTPUT,
+ ("render_char bkg %s (%d), attrs %s (%d) -> ch %s (%d)",
+ _tracech_t2(1, CHREF(win->_nc_bkgd)),
+ GetPair(win->_nc_bkgd),
+ _traceattr(WINDOW_ATTRS(win)),
+ GET_WINDOW_PAIR(win),
+ _tracech_t2(3, CHREF(ch)),
+ GetPair(ch)));
+
+ return (ch);
+}
+
+NCURSES_EXPORT(NCURSES_CH_T)
+_nc_render(WINDOW *win, NCURSES_CH_T ch)
+/* make render_char() visible while still allowing us to inline it below */
+{
+ return render_char(win, ch);
+}
+
+/* check if position is legal; if not, return error */
+#ifndef NDEBUG /* treat this like an assertion */
+#define CHECK_POSITION(win, x, y) \
+ if (y > win->_maxy \
+ || x > win->_maxx \
+ || y < 0 \
+ || x < 0) { \
+ TR(TRACE_VIRTPUT, ("Alert! Win=%p _curx = %d, _cury = %d " \
+ "(_maxx = %d, _maxy = %d)", win, x, y, \
+ win->_maxx, win->_maxy)); \
+ return(ERR); \
+ }
+#else
+#define CHECK_POSITION(win, x, y) /* nothing */
+#endif
+
+static bool
+newline_forces_scroll(WINDOW *win, NCURSES_SIZE_T * ypos)
+{
+ bool result = FALSE;
+
+ if (*ypos >= win->_regtop && *ypos == win->_regbottom) {
+ *ypos = win->_regbottom;
+ result = TRUE;
+ } else {
+ *ypos += 1;
+ }
+ return result;
+}
+
+/*
+ * The _WRAPPED flag is useful only for telling an application that we've just
+ * wrapped the cursor. We don't do anything with this flag except set it when
+ * wrapping, and clear it whenever we move the cursor. If we try to wrap at
+ * the lower-right corner of a window, we cannot move the cursor (since that
+ * wouldn't be legal). So we return an error (which is what SVr4 does).
+ * Unlike SVr4, we can successfully add a character to the lower-right corner
+ * (Solaris 2.6 does this also, however).
+ */
+static int
+wrap_to_next_line(WINDOW *win)
+{
+ win->_flags |= _WRAPPED;
+ if (newline_forces_scroll(win, &(win->_cury))) {
+ win->_curx = win->_maxx;
+ if (!win->_scroll)
+ return (ERR);
+ scroll(win);
+ }
+ win->_curx = 0;
+ return (OK);
+}
+
+#if USE_WIDEC_SUPPORT
+static int waddch_literal(WINDOW *, NCURSES_CH_T);
+/*
+ * Fill the given number of cells with blanks using the current background
+ * rendition. This saves/restores the current x-position.
+ */
+static void
+fill_cells(WINDOW *win, int count)
+{
+ NCURSES_CH_T blank = blankchar;
+ int save_x = win->_curx;
+ int save_y = win->_cury;
+
+ while (count-- > 0) {
+ if (waddch_literal(win, blank) == ERR)
+ break;
+ }
+ win->_curx = save_x;
+ win->_cury = save_y;
+}
+#endif
+
+/*
+ * Build up the bytes for a multibyte character, returning the length when
+ * complete (a positive number), -1 for error and -2 for incomplete.
+ */
+#if USE_WIDEC_SUPPORT
+NCURSES_EXPORT(int)
+_nc_build_wch(WINDOW *win, ARG_CH_T ch)
+{
+ char *buffer = WINDOW_EXT(win, addch_work);
+ int len;
+ int x = win->_curx;
+ int y = win->_cury;
+ mbstate_t state;
+ wchar_t result;
+
+ if ((WINDOW_EXT(win, addch_used) != 0) &&
+ (WINDOW_EXT(win, addch_x) != x ||
+ WINDOW_EXT(win, addch_y) != y)) {
+ /* discard the incomplete multibyte character */
+ WINDOW_EXT(win, addch_used) = 0;
+ TR(TRACE_VIRTPUT,
+ ("Alert discarded multibyte on move (%d,%d) -> (%d,%d)",
+ WINDOW_EXT(win, addch_y), WINDOW_EXT(win, addch_x),
+ y, x));
+ }
+ WINDOW_EXT(win, addch_x) = x;
+ WINDOW_EXT(win, addch_y) = y;
+
+ init_mb(state);
+ buffer[WINDOW_EXT(win, addch_used)] = CharOf(CHDEREF(ch));
+ WINDOW_EXT(win, addch_used) += 1;
+ buffer[WINDOW_EXT(win, addch_used)] = '\0';
+ if ((len = mbrtowc(&result,
+ buffer,
+ WINDOW_EXT(win, addch_used), &state)) > 0) {
+ attr_t attrs = AttrOf(CHDEREF(ch));
+ if_EXT_COLORS(int pair = GetPair(CHDEREF(ch)));
+ SetChar(CHDEREF(ch), result, attrs);
+ if_EXT_COLORS(SetPair(CHDEREF(ch), pair));
+ WINDOW_EXT(win, addch_used) = 0;
+ } else if (len == -1) {
+ /*
+ * An error occurred. We could either discard everything,
+ * or assume that the error was in the previous input.
+ * Try the latter.
+ */
+ TR(TRACE_VIRTPUT, ("Alert! mbrtowc returns error"));
+ /* handle this with unctrl() */
+ WINDOW_EXT(win, addch_used) = 0;
+ }
+ return len;
+}
+#endif /* USE_WIDEC_SUPPORT */
+
+static
+#if !USE_WIDEC_SUPPORT /* cannot be inline if it is recursive */
+NCURSES_INLINE
+#endif
+int
+waddch_literal(WINDOW *win, NCURSES_CH_T ch)
+{
+ int x;
+ int y;
+ struct ldat *line;
+
+ x = win->_curx;
+ y = win->_cury;
+
+ CHECK_POSITION(win, x, y);
+
+ ch = render_char(win, ch);
+
+ line = win->_line + y;
+
+ CHANGED_CELL(line, x);
+
+ /*
+ * Build up multibyte characters until we have a wide-character.
+ */
+ if_WIDEC({
+ if (WINDOW_EXT(win, addch_used) != 0 || !Charable(ch)) {
+ int len = _nc_build_wch(win, CHREF(ch));
+
+ if (len >= -1) {
+ /* handle EILSEQ */
+ if (is8bits(CharOf(ch))) {
+ const char *s = unctrl((chtype) CharOf(ch));
+ if (s[1] != 0) {
+ return waddstr(win, s);
+ }
+ }
+ if (len == -1)
+ return waddch(win, ' ');
+ } else {
+ return OK;
+ }
+ }
+ });
+
+ /*
+ * Non-spacing characters are added to the current cell.
+ *
+ * Spacing characters that are wider than one column require some display
+ * adjustments.
+ */
+ if_WIDEC({
+ int len = wcwidth(CharOf(ch));
+ int i;
+ int j;
+
+ if (len == 0) { /* non-spacing */
+ if ((x > 0 && y >= 0)
+ || ((y = win->_cury - 1) >= 0 &&
+ (x = win->_maxx) > 0)) {
+ wchar_t *chars = (win->_line[y].text[x - 1].chars);
+ for (i = 0; i < CCHARW_MAX; ++i) {
+ if (chars[i] == 0) {
+ TR(TRACE_VIRTPUT,
+ ("added non-spacing %d: %x",
+ x, (int) CharOf(ch)));
+ chars[i] = CharOf(ch);
+ break;
+ }
+ }
+ }
+ goto testwrapping;
+ } else if (len > 1) { /* multi-column characters */
+ /*
+ * Check if the character will fit on the current line. If it does
+ * not fit, fill in the remainder of the line with blanks. and
+ * move to the next line.
+ */
+ if (len > win->_maxx + 1) {
+ TR(TRACE_VIRTPUT, ("character will not fit"));
+ return ERR;
+ } else if (x + len > win->_maxx + 1) {
+ int count = win->_maxx + 1 - x;
+ TR(TRACE_VIRTPUT, ("fill %d remaining cells", count));
+ fill_cells(win, count);
+ if (wrap_to_next_line(win) == ERR)
+ return ERR;
+ x = win->_curx;
+ y = win->_cury;
+ }
+ /*
+ * Check for cells which are orphaned by adding this character, set
+ * those to blanks.
+ *
+ * FIXME: this actually could fill j-i cells, more complicated to
+ * setup though.
+ */
+ for (i = 0; i < len; ++i) {
+ if (isWidecBase(win->_line[y].text[x + i])) {
+ break;
+ } else if (isWidecExt(win->_line[y].text[x + i])) {
+ for (j = i; x + j <= win->_maxx; ++j) {
+ if (!isWidecExt(win->_line[y].text[x + j])) {
+ TR(TRACE_VIRTPUT, ("fill %d orphan cells", j));
+ fill_cells(win, j);
+ break;
+ }
+ }
+ break;
+ }
+ }
+ /*
+ * Finally, add the cells for this character.
+ */
+ for (i = 0; i < len; ++i) {
+ NCURSES_CH_T value = ch;
+ SetWidecExt(value, i);
+ TR(TRACE_VIRTPUT, ("multicolumn %d:%d (%d,%d)",
+ i + 1, len,
+ win->_begy + y, win->_begx + x));
+ line->text[x] = value;
+ CHANGED_CELL(line, x);
+ ++x;
+ }
+ goto testwrapping;
+ }
+ });
+
+ /*
+ * Single-column characters.
+ */
+ line->text[x++] = ch;
+ /*
+ * This label is used only for wide-characters.
+ */
+ if_WIDEC(
+ testwrapping:
+ );
+
+ TR(TRACE_VIRTPUT, ("cell (%ld, %ld..%d) = %s",
+ (long) win->_cury, (long) win->_curx, x - 1,
+ _tracech_t(CHREF(ch))));
+
+ if (x > win->_maxx) {
+ return wrap_to_next_line(win);
+ }
+ win->_curx = x;
+ return OK;
+}
+
+static NCURSES_INLINE int
+waddch_nosync(WINDOW *win, const NCURSES_CH_T ch)
+/* the workhorse function -- add a character to the given window */
+{
+ NCURSES_SIZE_T x, y;
+ chtype t = CharOf(ch);
+ const char *s = unctrl(t);
+
+ /*
+ * If we are using the alternate character set, forget about locale.
+ * Otherwise, if unctrl() returns a single-character or the locale
+ * claims the code is printable, treat it that way.
+ */
+ if ((AttrOf(ch) & A_ALTCHARSET)
+ || (
+#if USE_WIDEC_SUPPORT
+ (SP != 0 && SP->_legacy_coding) &&
+#endif
+ s[1] == 0
+ )
+ || (
+ isprint(t)
+#if USE_WIDEC_SUPPORT
+ || ((SP == 0 || !SP->_legacy_coding) &&
+ (WINDOW_EXT(win, addch_used)
+ || !_nc_is_charable(CharOf(ch))))
+#endif
+ ))
+ return waddch_literal(win, ch);
+
+ /*
+ * Handle carriage control and other codes that are not printable, or are
+ * known to expand to more than one character according to unctrl().
+ */
+ x = win->_curx;
+ y = win->_cury;
+
+ switch (t) {
+ case '\t':
+ x += (TABSIZE - (x % TABSIZE));
+
+ /*
+ * Space-fill the tab on the bottom line so that we'll get the
+ * "correct" cursor position.
+ */
+ if ((!win->_scroll && (y == win->_regbottom))
+ || (x <= win->_maxx)) {
+ NCURSES_CH_T blank = blankchar;
+ AddAttr(blank, AttrOf(ch));
+ while (win->_curx < x) {
+ if (waddch_literal(win, blank) == ERR)
+ return (ERR);
+ }
+ break;
+ } else {
+ wclrtoeol(win);
+ win->_flags |= _WRAPPED;
+ if (newline_forces_scroll(win, &y)) {
+ x = win->_maxx;
+ if (win->_scroll) {
+ scroll(win);
+ x = 0;
+ }
+ } else {
+ x = 0;
+ }
+ }
+ break;
+ case '\n':
+ wclrtoeol(win);
+ if (newline_forces_scroll(win, &y)) {
+ if (win->_scroll)
+ scroll(win);
+ else
+ return (ERR);
+ }
+ /* FALLTHRU */
+ case '\r':
+ x = 0;
+ win->_flags &= ~_WRAPPED;
+ break;
+ case '\b':
+ if (x == 0)
+ return (OK);
+ x--;
+ win->_flags &= ~_WRAPPED;
+ break;
+ default:
+ while (*s) {
+ NCURSES_CH_T sch;
+ SetChar(sch, *s++, AttrOf(ch));
+ if_EXT_COLORS(SetPair(sch, GetPair(ch)));
+ if (waddch_literal(win, sch) == ERR)
+ return ERR;
+ }
+ return (OK);
+ }
+
+ win->_curx = x;
+ win->_cury = y;
+
+ return (OK);
+}
+
+NCURSES_EXPORT(int)
+_nc_waddch_nosync(WINDOW *win, const NCURSES_CH_T c)
+/* export copy of waddch_nosync() so the string-put functions can use it */
+{
+ return (waddch_nosync(win, c));
+}
+
+/*
+ * The versions below call _nc_synchook(). We wanted to avoid this in the
+ * version exported for string puts; they'll call _nc_synchook once at end
+ * of run.
+ */
+
+/* These are actual entry points */
+
+NCURSES_EXPORT(int)
+waddch(WINDOW *win, const chtype ch)
+{
+ int code = ERR;
+ NCURSES_CH_T wch;
+ SetChar2(wch, ch);
+
+ TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("waddch(%p, %s)"), win,
+ _tracechtype(ch)));
+
+ if (win && (waddch_nosync(win, wch) != ERR)) {
+ _nc_synchook(win);
+ code = OK;
+ }
+
+ TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
+ return (code);
+}
+
+NCURSES_EXPORT(int)
+wechochar(WINDOW *win, const chtype ch)
+{
+ int code = ERR;
+ NCURSES_CH_T wch;
+ SetChar2(wch, ch);
+
+ TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"), win,
+ _tracechtype(ch)));
+
+ if (win && (waddch_nosync(win, wch) != ERR)) {
+ bool save_immed = win->_immed;
+ win->_immed = TRUE;
+ _nc_synchook(win);
+ win->_immed = save_immed;
+ code = OK;
+ }
+ TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
+ return (code);
+}
diff --git a/ncurses/base/lib_addstr.c b/ncurses/base/lib_addstr.c
new file mode 100644
index 000000000000..4e3a040cf032
--- /dev/null
+++ b/ncurses/base/lib_addstr.c
@@ -0,0 +1,245 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * *
+ * Rewritten 2001-2004 to support wide-characters by *
+ * Sven Verdoolaege *
+ * Thomas Dickey *
+ ****************************************************************************/
+
+/*
+** lib_addstr.c
+*
+** The routines waddnstr(), waddchnstr().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_addstr.c,v 1.48 2007/10/13 19:56:57 tom Exp $")
+
+NCURSES_EXPORT(int)
+waddnstr(WINDOW *win, const char *astr, int n)
+{
+ const char *str = astr;
+ int code = ERR;
+
+ T((T_CALLED("waddnstr(%p,%s,%d)"), win, _nc_visbufn(astr, n), n));
+
+ if (win && (str != 0)) {
+ TR(TRACE_VIRTPUT | TRACE_ATTRS,
+ ("... current %s", _traceattr(WINDOW_ATTRS(win))));
+ code = OK;
+ if (n < 0)
+ n = (int) strlen(astr);
+
+ TR(TRACE_VIRTPUT, ("str is not null, length = %d", n));
+ while ((n-- > 0) && (*str != '\0')) {
+ NCURSES_CH_T ch;
+ TR(TRACE_VIRTPUT, ("*str = %#o", UChar(*str)));
+ SetChar(ch, UChar(*str++), A_NORMAL);
+ if (_nc_waddch_nosync(win, ch) == ERR) {
+ code = ERR;
+ break;
+ }
+ }
+ _nc_synchook(win);
+ }
+ TR(TRACE_VIRTPUT, ("waddnstr returns %d", code));
+ returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+waddchnstr(WINDOW *win, const chtype *astr, int n)
+{
+ NCURSES_SIZE_T y, x;
+ int code = OK;
+ int i;
+ struct ldat *line;
+
+ T((T_CALLED("waddchnstr(%p,%p,%d)"), win, astr, n));
+
+ if (!win)
+ returnCode(ERR);
+
+ y = win->_cury;
+ x = win->_curx;
+ if (n < 0) {
+ const chtype *str;
+ n = 0;
+ for (str = (const chtype *) astr; *str != 0; str++)
+ n++;
+ }
+ if (n > win->_maxx - x + 1)
+ n = win->_maxx - x + 1;
+ if (n == 0)
+ returnCode(code);
+
+ line = &(win->_line[y]);
+ for (i = 0; i < n && ChCharOf(astr[i]) != '\0'; ++i) {
+ SetChar2(line->text[i + x], astr[i]);
+ }
+ CHANGED_RANGE(line, x, x + n - 1);
+
+ _nc_synchook(win);
+ returnCode(code);
+}
+
+#if USE_WIDEC_SUPPORT
+
+NCURSES_EXPORT(int)
+_nc_wchstrlen(const cchar_t *s)
+{
+ int result = 0;
+ while (CharOf(s[result]) != L'\0') {
+ result++;
+ }
+ return result;
+}
+
+NCURSES_EXPORT(int)
+wadd_wchnstr(WINDOW *win, const cchar_t *astr, int n)
+{
+ static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
+ NCURSES_SIZE_T y;
+ NCURSES_SIZE_T x;
+ int code = OK;
+ struct ldat *line;
+ int i, j, start, len, end;
+
+ T((T_CALLED("wadd_wchnstr(%p,%s,%d)"), win, _nc_viscbuf(astr, n), n));
+
+ if (!win)
+ returnCode(ERR);
+
+ y = win->_cury;
+ x = win->_curx;
+ if (n < 0) {
+ n = _nc_wchstrlen(astr);
+ }
+ if (n > win->_maxx - x + 1)
+ n = win->_maxx - x + 1;
+ if (n == 0)
+ returnCode(code);
+
+ line = &(win->_line[y]);
+ start = x;
+ end = x + n - 1;
+
+ /*
+ * Reset orphaned cells of multi-column characters that extend up to the
+ * new string's location to blanks.
+ */
+ if (x > 0 && isWidecExt(line->text[x])) {
+ for (i = 0; i <= x; ++i) {
+ if (!isWidecExt(line->text[x - i])) {
+ /* must be isWidecBase() */
+ start -= i;
+ while (i > 0) {
+ line->text[x - i--] = _nc_render(win, blank);
+ }
+ break;
+ }
+ }
+ }
+
+ /*
+ * Copy the new string to the window.
+ */
+ for (i = 0; i < n && CharOf(astr[i]) != L'\0' && x <= win->_maxx; ++i) {
+ if (isWidecExt(astr[i]))
+ continue;
+
+ len = wcwidth(CharOf(astr[i]));
+
+ if (x + len - 1 <= win->_maxx) {
+ line->text[x] = _nc_render(win, astr[i]);
+ if (len > 1) {
+ for (j = 0; j < len; ++j) {
+ if (j != 0) {
+ line->text[x + j] = line->text[x];
+ }
+ SetWidecExt(line->text[x + j], j);
+ }
+ }
+ x += len;
+ end += len - 1;
+ } else {
+ break;
+ }
+ }
+
+ /*
+ * Set orphaned cells of multi-column characters which lie after the new
+ * string to blanks.
+ */
+ while (x <= win->_maxx && isWidecExt(line->text[x])) {
+ line->text[x] = _nc_render(win, blank);
+ ++end;
+ ++x;
+ }
+ CHANGED_RANGE(line, start, end);
+
+ _nc_synchook(win);
+ returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+waddnwstr(WINDOW *win, const wchar_t *str, int n)
+{
+ int code = ERR;
+
+ T((T_CALLED("waddnwstr(%p,%s,%d)"), win, _nc_viswbufn(str, n), n));
+
+ if (win && (str != 0)) {
+ TR(TRACE_VIRTPUT | TRACE_ATTRS,
+ ("... current %s", _traceattr(WINDOW_ATTRS(win))));
+ code = OK;
+ if (n < 0)
+ n = (int) wcslen(str);
+
+ TR(TRACE_VIRTPUT, ("str is not null, length = %d", n));
+ while ((n-- > 0) && (*str != L('\0'))) {
+ NCURSES_CH_T ch;
+ TR(TRACE_VIRTPUT, ("*str[0] = %#lx", (unsigned long) *str));
+ SetChar(ch, *str++, A_NORMAL);
+ if (wadd_wch(win, &ch) == ERR) {
+ code = ERR;
+ break;
+ }
+ }
+ _nc_synchook(win);
+ }
+ TR(TRACE_VIRTPUT, ("waddnwstr returns %d", code));
+ returnCode(code);
+}
+
+#endif
diff --git a/ncurses/base/lib_beep.c b/ncurses/base/lib_beep.c
new file mode 100644
index 000000000000..b478f251a1bb
--- /dev/null
+++ b/ncurses/base/lib_beep.c
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+ * beep.c
+ *
+ * The routine beep().
+ *
+ */
+
+#include <curses.priv.h>
+#include <term.h> /* beep, flash */
+
+MODULE_ID("$Id: lib_beep.c,v 1.10 2005/04/09 15:20:04 tom Exp $")
+
+/*
+ * beep()
+ *
+ * Sound the current terminal's audible bell if it has one. If not,
+ * flash the screen if possible.
+ *
+ */
+
+NCURSES_EXPORT(int)
+beep(void)
+{
+ int res = ERR;
+
+ T((T_CALLED("beep()")));
+
+ /* FIXME: should make sure that we are not in altchar mode */
+ if (cur_term == 0) {
+ res = ERR;
+ } else if (bell) {
+ TPUTS_TRACE("bell");
+ res = putp(bell);
+ _nc_flush();
+ } else if (flash_screen) {
+ TPUTS_TRACE("flash_screen");
+ res = putp(flash_screen);
+ _nc_flush();
+ }
+
+ returnCode(res);
+}
diff --git a/ncurses/base/lib_bkgd.c b/ncurses/base/lib_bkgd.c
new file mode 100644
index 000000000000..c99e0c5fc3a8
--- /dev/null
+++ b/ncurses/base/lib_bkgd.c
@@ -0,0 +1,156 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Juergen Pfeifer 1997 *
+ * and: Sven Verdoolaege 2000 *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_bkgd.c,v 1.36 2008/03/23 00:09:14 tom Exp $")
+
+/*
+ * Set the window's background information.
+ */
+#if USE_WIDEC_SUPPORT
+NCURSES_EXPORT(void)
+#else
+static NCURSES_INLINE void
+#endif
+wbkgrndset(WINDOW *win, const ARG_CH_T ch)
+{
+ T((T_CALLED("wbkgdset(%p,%s)"), win, _tracech_t(ch)));
+
+ if (win) {
+ attr_t off = AttrOf(win->_nc_bkgd);
+ attr_t on = AttrOf(CHDEREF(ch));
+
+ toggle_attr_off(WINDOW_ATTRS(win), off);
+ toggle_attr_on(WINDOW_ATTRS(win), on);
+
+#if NCURSES_EXT_COLORS
+ {
+ int pair;
+
+ if ((pair = GetPair(win->_nc_bkgd)) != 0)
+ SET_WINDOW_PAIR(win, 0);
+ if ((pair = GetPair(CHDEREF(ch))) != 0)
+ SET_WINDOW_PAIR(win, pair);
+ }
+#endif
+
+ if (CharOf(CHDEREF(ch)) == L('\0')) {
+ SetChar(win->_nc_bkgd, BLANK_TEXT, AttrOf(CHDEREF(ch)));
+ if_EXT_COLORS(SetPair(win->_nc_bkgd, GetPair(CHDEREF(ch))));
+ } else {
+ win->_nc_bkgd = CHDEREF(ch);
+ }
+#if USE_WIDEC_SUPPORT
+ /*
+ * If we're compiled for wide-character support, _bkgrnd is the
+ * preferred location for the background information since it stores
+ * more than _bkgd. Update _bkgd each time we modify _bkgrnd, so the
+ * macro getbkgd() will work.
+ */
+ {
+ cchar_t wch;
+ int tmp;
+
+ wgetbkgrnd(win, &wch);
+ tmp = _nc_to_char((wint_t) CharOf(wch));
+
+ win->_bkgd = (((tmp == EOF) ? ' ' : (chtype) tmp)
+ | (AttrOf(wch) & ALL_BUT_COLOR)
+ | COLOR_PAIR(GET_WINDOW_PAIR(win)));
+ }
+#endif
+ }
+ returnVoid;
+}
+
+NCURSES_EXPORT(void)
+wbkgdset(WINDOW *win, chtype ch)
+{
+ NCURSES_CH_T wch;
+ SetChar2(wch, ch);
+ wbkgrndset(win, CHREF(wch));
+}
+
+/*
+ * Set the window's background information and apply it to each cell.
+ */
+#if USE_WIDEC_SUPPORT
+NCURSES_EXPORT(int)
+#else
+static NCURSES_INLINE int
+#undef wbkgrnd
+#endif
+wbkgrnd(WINDOW *win, const ARG_CH_T ch)
+{
+ int code = ERR;
+ int x, y;
+ NCURSES_CH_T new_bkgd = CHDEREF(ch);
+
+ T((T_CALLED("wbkgd(%p,%s)"), win, _tracech_t(ch)));
+
+ if (win) {
+ NCURSES_CH_T old_bkgrnd;
+ wgetbkgrnd(win, &old_bkgrnd);
+
+ wbkgrndset(win, CHREF(new_bkgd));
+ wattrset(win, AttrOf(win->_nc_bkgd));
+
+ for (y = 0; y <= win->_maxy; y++) {
+ for (x = 0; x <= win->_maxx; x++) {
+ if (CharEq(win->_line[y].text[x], old_bkgrnd)) {
+ win->_line[y].text[x] = win->_nc_bkgd;
+ } else {
+ NCURSES_CH_T wch = win->_line[y].text[x];
+ RemAttr(wch, (~(A_ALTCHARSET | A_CHARTEXT)));
+ win->_line[y].text[x] = _nc_render(win, wch);
+ }
+ }
+ }
+ touchwin(win);
+ _nc_synchook(win);
+ code = OK;
+ }
+ returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+wbkgd(WINDOW *win, chtype ch)
+{
+ NCURSES_CH_T wch;
+ SetChar2(wch, ch);
+ return wbkgrnd(win, CHREF(wch));
+}
diff --git a/ncurses/base/lib_box.c b/ncurses/base/lib_box.c
new file mode 100644
index 000000000000..d6cfc6cfe09c
--- /dev/null
+++ b/ncurses/base/lib_box.c
@@ -0,0 +1,128 @@
+/****************************************************************************
+ * Copyright (c) 1998-2002,2005 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ * and: Sven Verdoolaege 2001 *
+ ****************************************************************************/
+
+/*
+** lib_box.c
+**
+** The routine wborder().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_box.c,v 1.22 2005/11/26 15:39:42 tom Exp $")
+
+#if USE_WIDEC_SUPPORT
+static NCURSES_INLINE chtype
+_my_render(WINDOW *win, chtype ch)
+{
+ NCURSES_CH_T wch;
+ SetChar2(wch, ch);
+ wch = _nc_render(win, wch);
+ return CharOf(wch) | AttrOf(wch);
+}
+#define RENDER_WITH_DEFAULT(ch,def) w ## ch = _my_render(win, (ch == 0) ? def : ch)
+#else
+#define RENDER_WITH_DEFAULT(ch,def) w ## ch = _nc_render(win, (ch == 0) ? def : ch)
+#endif
+
+NCURSES_EXPORT(int)
+wborder(WINDOW *win,
+ chtype ls, chtype rs,
+ chtype ts, chtype bs,
+ chtype tl, chtype tr,
+ chtype bl, chtype br)
+{
+ NCURSES_SIZE_T i;
+ NCURSES_SIZE_T endx, endy;
+ chtype wls, wrs, wts, wbs, wtl, wtr, wbl, wbr;
+
+ T((T_CALLED("wborder(%p,%s,%s,%s,%s,%s,%s,%s,%s)"),
+ win,
+ _tracechtype2(1, ls),
+ _tracechtype2(2, rs),
+ _tracechtype2(3, ts),
+ _tracechtype2(4, bs),
+ _tracechtype2(5, tl),
+ _tracechtype2(6, tr),
+ _tracechtype2(7, bl),
+ _tracechtype2(8, br)));
+
+ if (!win)
+ returnCode(ERR);
+
+ RENDER_WITH_DEFAULT(ls, ACS_VLINE);
+ RENDER_WITH_DEFAULT(rs, ACS_VLINE);
+ RENDER_WITH_DEFAULT(ts, ACS_HLINE);
+ RENDER_WITH_DEFAULT(bs, ACS_HLINE);
+ RENDER_WITH_DEFAULT(tl, ACS_ULCORNER);
+ RENDER_WITH_DEFAULT(tr, ACS_URCORNER);
+ RENDER_WITH_DEFAULT(bl, ACS_LLCORNER);
+ RENDER_WITH_DEFAULT(br, ACS_LRCORNER);
+
+ T(("using %s, %s, %s, %s, %s, %s, %s, %s",
+ _tracechtype2(1, wls),
+ _tracechtype2(2, wrs),
+ _tracechtype2(3, wts),
+ _tracechtype2(4, wbs),
+ _tracechtype2(5, wtl),
+ _tracechtype2(6, wtr),
+ _tracechtype2(7, wbl),
+ _tracechtype2(8, wbr)));
+
+ endx = win->_maxx;
+ endy = win->_maxy;
+
+ for (i = 0; i <= endx; i++) {
+ SetChar2(win->_line[0].text[i], wts);
+ SetChar2(win->_line[endy].text[i], wbs);
+ }
+ win->_line[endy].firstchar = win->_line[0].firstchar = 0;
+ win->_line[endy].lastchar = win->_line[0].lastchar = endx;
+
+ for (i = 0; i <= endy; i++) {
+ SetChar2(win->_line[i].text[0], wls);
+ SetChar2(win->_line[i].text[endx], wrs);
+ win->_line[i].firstchar = 0;
+ win->_line[i].lastchar = endx;
+ }
+ SetChar2(win->_line[0].text[0], wtl);
+ SetChar2(win->_line[0].text[endx], wtr);
+ SetChar2(win->_line[endy].text[0], wbl);
+ SetChar2(win->_line[endy].text[endx], wbr);
+
+ _nc_synchook(win);
+ returnCode(OK);
+}
diff --git a/ncurses/base/lib_chgat.c b/ncurses/base/lib_chgat.c
new file mode 100644
index 000000000000..89eefa7e82fe
--- /dev/null
+++ b/ncurses/base/lib_chgat.c
@@ -0,0 +1,68 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Sven Verdoolaege 2001 *
+ * and: Thomas E. Dickey 2005 *
+ ****************************************************************************/
+
+/*
+** lib_chgat.c
+**
+** The routine wchgat().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_chgat.c,v 1.7 2006/07/15 22:07:11 tom Exp $")
+
+NCURSES_EXPORT(int)
+wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts GCC_UNUSED)
+{
+ int i;
+
+ T((T_CALLED("wchgat(%p,%d,%s,%d)"), win, n, _traceattr(attr), color));
+
+ if (win) {
+ struct ldat *line = &(win->_line[win->_cury]);
+
+ toggle_attr_on(attr, COLOR_PAIR(color));
+
+ for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++) {
+ SetAttr(line->text[i], attr);
+ SetPair(line->text[i], color);
+ CHANGED_CELL(line, i);
+ }
+
+ returnCode(OK);
+ } else
+ returnCode(ERR);
+}
diff --git a/ncurses/base/lib_clear.c b/ncurses/base/lib_clear.c
new file mode 100644
index 000000000000..e0b4edf9e224
--- /dev/null
+++ b/ncurses/base/lib_clear.c
@@ -0,0 +1,56 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_clear.c
+**
+** The routine wclear().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_clear.c,v 1.7 2000/12/10 02:43:26 tom Exp $")
+
+NCURSES_EXPORT(int)
+wclear(WINDOW *win)
+{
+ int code = ERR;
+
+ T((T_CALLED("wclear(%p)"), win));
+
+ if ((code = werase(win)) != ERR)
+ win->_clear = TRUE;
+
+ returnCode(code);
+}
diff --git a/ncurses/base/lib_clearok.c b/ncurses/base/lib_clearok.c
new file mode 100644
index 000000000000..9b56bd1ec63a
--- /dev/null
+++ b/ncurses/base/lib_clearok.c
@@ -0,0 +1,55 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_clearok.c
+**
+** The routine clearok.
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_clearok.c,v 1.4 2000/12/10 02:43:26 tom Exp $")
+
+NCURSES_EXPORT(int)
+clearok(WINDOW *win, bool flag)
+{
+ T((T_CALLED("clearok(%p,%d)"), win, flag));
+
+ if (win) {
+ win->_clear = flag;
+ returnCode(OK);
+ } else
+ returnCode(ERR);
+}
diff --git a/ncurses/base/lib_clrbot.c b/ncurses/base/lib_clrbot.c
new file mode 100644
index 000000000000..df196e815f82
--- /dev/null
+++ b/ncurses/base/lib_clrbot.c
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_clrbot.c
+**
+** The routine wclrtobot().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_clrbot.c,v 1.20 2006/10/14 20:43:31 tom Exp $")
+
+NCURSES_EXPORT(int)
+wclrtobot(WINDOW *win)
+{
+ int code = ERR;
+
+ T((T_CALLED("wclrtobot(%p)"), win));
+
+ if (win) {
+ NCURSES_SIZE_T y;
+ NCURSES_SIZE_T startx = win->_curx;
+ NCURSES_CH_T blank = win->_nc_bkgd;
+
+ T(("clearing from y = %ld to y = %ld with maxx = %ld",
+ (long) win->_cury, (long) win->_maxy, (long) win->_maxx));
+
+ for (y = win->_cury; y <= win->_maxy; y++) {
+ struct ldat *line = &(win->_line[y]);
+ NCURSES_CH_T *ptr = &(line->text[startx]);
+ NCURSES_CH_T *end = &(line->text[win->_maxx]);
+
+ CHANGED_TO_EOL(line, startx, win->_maxx);
+
+ while (ptr <= end)
+ *ptr++ = blank;
+
+ startx = 0;
+ }
+ _nc_synchook(win);
+ code = OK;
+ }
+ returnCode(code);
+}
diff --git a/ncurses/base/lib_clreol.c b/ncurses/base/lib_clreol.c
new file mode 100644
index 000000000000..c46ebd93a332
--- /dev/null
+++ b/ncurses/base/lib_clreol.c
@@ -0,0 +1,91 @@
+/****************************************************************************
+ * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_clreol.c
+**
+** The routine wclrtoeol().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_clreol.c,v 1.21 2001/12/19 01:06:04 tom Exp $")
+
+NCURSES_EXPORT(int)
+wclrtoeol(WINDOW *win)
+{
+ int code = ERR;
+
+ T((T_CALLED("wclrtoeol(%p)"), win));
+
+ if (win) {
+ NCURSES_CH_T blank;
+ NCURSES_CH_T *ptr, *end;
+ struct ldat *line;
+ NCURSES_SIZE_T y = win->_cury;
+ NCURSES_SIZE_T x = win->_curx;
+
+ /*
+ * If we have just wrapped the cursor, the clear applies to the
+ * new line, unless we are at the lower right corner.
+ */
+ if ((win->_flags & _WRAPPED) != 0
+ && y < win->_maxy) {
+ win->_flags &= ~_WRAPPED;
+ }
+
+ /*
+ * There's no point in clearing if we're not on a legal
+ * position, either.
+ */
+ if ((win->_flags & _WRAPPED) != 0
+ || y > win->_maxy
+ || x > win->_maxx)
+ returnCode(ERR);
+
+ blank = win->_nc_bkgd;
+ line = &win->_line[y];
+ CHANGED_TO_EOL(line, x, win->_maxx);
+
+ ptr = &(line->text[x]);
+ end = &(line->text[win->_maxx]);
+
+ while (ptr <= end)
+ *ptr++ = blank;
+
+ _nc_synchook(win);
+ code = OK;
+ }
+ returnCode(code);
+}
diff --git a/ncurses/base/lib_color.c b/ncurses/base/lib_color.c
new file mode 100644
index 000000000000..9cae495436fe
--- /dev/null
+++ b/ncurses/base/lib_color.c
@@ -0,0 +1,593 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/* lib_color.c
+ *
+ * Handles color emulation of SYS V curses
+ */
+
+#include <curses.priv.h>
+
+#include <term.h>
+#include <tic.h>
+
+MODULE_ID("$Id: lib_color.c,v 1.85 2007/04/07 17:07:28 tom Exp $")
+
+/*
+ * These should be screen structure members. They need to be globals for
+ * historical reasons. So we assign them in start_color() and also in
+ * set_term()'s screen-switching logic.
+ */
+#if USE_REENTRANT
+NCURSES_EXPORT(int)
+NCURSES_PUBLIC_VAR(COLOR_PAIRS) (void)
+{
+ return SP ? SP->_pair_count : -1;
+}
+NCURSES_EXPORT(int)
+NCURSES_PUBLIC_VAR(COLORS) (void)
+{
+ return SP ? SP->_color_count : -1;
+}
+#else
+NCURSES_EXPORT_VAR(int) COLOR_PAIRS = 0;
+NCURSES_EXPORT_VAR(int) COLORS = 0;
+#endif
+
+#define DATA(r,g,b) {r,g,b, 0,0,0, 0}
+
+#define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts))
+
+#define MAX_PALETTE 8
+
+#define OkColorHi(n) (((n) < COLORS) && ((n) < max_colors))
+#define InPalette(n) ((n) >= 0 && (n) < MAX_PALETTE)
+
+/*
+ * Given a RGB range of 0..1000, we'll normally set the individual values
+ * to about 2/3 of the maximum, leaving full-range for bold/bright colors.
+ */
+#define RGB_ON 680
+#define RGB_OFF 0
+/* *INDENT-OFF* */
+static const color_t cga_palette[] =
+{
+ /* R G B */
+ DATA(RGB_OFF, RGB_OFF, RGB_OFF), /* COLOR_BLACK */
+ DATA(RGB_ON, RGB_OFF, RGB_OFF), /* COLOR_RED */
+ DATA(RGB_OFF, RGB_ON, RGB_OFF), /* COLOR_GREEN */
+ DATA(RGB_ON, RGB_ON, RGB_OFF), /* COLOR_YELLOW */
+ DATA(RGB_OFF, RGB_OFF, RGB_ON), /* COLOR_BLUE */
+ DATA(RGB_ON, RGB_OFF, RGB_ON), /* COLOR_MAGENTA */
+ DATA(RGB_OFF, RGB_ON, RGB_ON), /* COLOR_CYAN */
+ DATA(RGB_ON, RGB_ON, RGB_ON), /* COLOR_WHITE */
+};
+
+static const color_t hls_palette[] =
+{
+ /* H L S */
+ DATA( 0, 0, 0), /* COLOR_BLACK */
+ DATA( 120, 50, 100), /* COLOR_RED */
+ DATA( 240, 50, 100), /* COLOR_GREEN */
+ DATA( 180, 50, 100), /* COLOR_YELLOW */
+ DATA( 330, 50, 100), /* COLOR_BLUE */
+ DATA( 60, 50, 100), /* COLOR_MAGENTA */
+ DATA( 300, 50, 100), /* COLOR_CYAN */
+ DATA( 0, 50, 100), /* COLOR_WHITE */
+};
+/* *INDENT-ON* */
+
+#if NCURSES_EXT_FUNCS
+/*
+ * These are called from _nc_do_color(), which in turn is called from
+ * vidattr - so we have to assume that SP may be null.
+ */
+static int
+default_fg(void)
+{
+ return (SP != 0) ? SP->_default_fg : COLOR_WHITE;
+}
+
+static int
+default_bg(void)
+{
+ return SP != 0 ? SP->_default_bg : COLOR_BLACK;
+}
+#else
+#define default_fg() COLOR_WHITE
+#define default_bg() COLOR_BLACK
+#endif
+
+/*
+ * SVr4 curses is known to interchange color codes (1,4) and (3,6), possibly
+ * to maintain compatibility with a pre-ANSI scheme. The same scheme is
+ * also used in the FreeBSD syscons.
+ */
+static int
+toggled_colors(int c)
+{
+ if (c < 16) {
+ static const int table[] =
+ {0, 4, 2, 6, 1, 5, 3, 7,
+ 8, 12, 10, 14, 9, 13, 11, 15};
+ c = table[c];
+ }
+ return c;
+}
+
+static void
+set_background_color(int bg, int (*outc) (int))
+{
+ if (set_a_background) {
+ TPUTS_TRACE("set_a_background");
+ tputs(TPARM_1(set_a_background, bg), 1, outc);
+ } else {
+ TPUTS_TRACE("set_background");
+ tputs(TPARM_1(set_background, toggled_colors(bg)), 1, outc);
+ }
+}
+
+static void
+set_foreground_color(int fg, int (*outc) (int))
+{
+ if (set_a_foreground) {
+ TPUTS_TRACE("set_a_foreground");
+ tputs(TPARM_1(set_a_foreground, fg), 1, outc);
+ } else {
+ TPUTS_TRACE("set_foreground");
+ tputs(TPARM_1(set_foreground, toggled_colors(fg)), 1, outc);
+ }
+}
+
+static void
+init_color_table(void)
+{
+ const color_t *tp;
+ int n;
+
+ tp = (hue_lightness_saturation) ? hls_palette : cga_palette;
+ for (n = 0; n < COLORS; n++) {
+ if (InPalette(n)) {
+ SP->_color_table[n] = tp[n];
+ } else {
+ SP->_color_table[n] = tp[n % MAX_PALETTE];
+ if (hue_lightness_saturation) {
+ SP->_color_table[n].green = 100;
+ } else {
+ if (SP->_color_table[n].red)
+ SP->_color_table[n].red = 1000;
+ if (SP->_color_table[n].green)
+ SP->_color_table[n].green = 1000;
+ if (SP->_color_table[n].blue)
+ SP->_color_table[n].blue = 1000;
+ }
+ }
+ }
+}
+
+/*
+ * Reset the color pair, e.g., to whatever color pair 0 is.
+ */
+static bool
+reset_color_pair(void)
+{
+ bool result = FALSE;
+
+ if (orig_pair != 0) {
+ TPUTS_TRACE("orig_pair");
+ putp(orig_pair);
+ result = TRUE;
+ }
+ return result;
+}
+
+/*
+ * Reset color pairs and definitions. Actually we do both more to accommodate
+ * badly-written terminal descriptions than for the relatively rare case where
+ * someone has changed the color definitions.
+ */
+bool
+_nc_reset_colors(void)
+{
+ int result = FALSE;
+
+ T((T_CALLED("_nc_reset_colors()")));
+ if (SP->_color_defs > 0)
+ SP->_color_defs = -(SP->_color_defs);
+
+ if (reset_color_pair())
+ result = TRUE;
+ if (orig_colors != 0) {
+ TPUTS_TRACE("orig_colors");
+ putp(orig_colors);
+ result = TRUE;
+ }
+ returnBool(result);
+}
+
+NCURSES_EXPORT(int)
+start_color(void)
+{
+ int result = ERR;
+
+ T((T_CALLED("start_color()")));
+
+ if (SP == 0) {
+ result = ERR;
+ } else if (SP->_coloron) {
+ result = OK;
+ } else {
+
+ if (reset_color_pair() != TRUE) {
+ set_foreground_color(default_fg(), _nc_outch);
+ set_background_color(default_bg(), _nc_outch);
+ }
+
+ if (max_pairs > 0 && max_colors > 0) {
+ SP->_pair_count = max_pairs;
+ SP->_color_count = max_colors;
+#if !USE_REENTRANT
+ COLOR_PAIRS = max_pairs;
+ COLORS = max_colors;
+#endif
+
+ if ((SP->_color_pairs = TYPE_CALLOC(colorpair_t,
+ max_pairs)) != 0) {
+ if ((SP->_color_table = TYPE_CALLOC(color_t,
+ max_colors)) != 0) {
+ SP->_color_pairs[0] = PAIR_OF(default_fg(), default_bg());
+ init_color_table();
+
+ T(("started color: COLORS = %d, COLOR_PAIRS = %d",
+ COLORS, COLOR_PAIRS));
+
+ SP->_coloron = 1;
+ result = OK;
+ } else if (SP->_color_pairs != 0) {
+ FreeAndNull(SP->_color_pairs);
+ }
+ }
+ } else {
+ result = OK;
+ }
+ }
+ returnCode(result);
+}
+
+/* This function was originally written by Daniel Weaver <danw@znyx.com> */
+static void
+rgb2hls(short r, short g, short b, short *h, short *l, short *s)
+/* convert RGB to HLS system */
+{
+ short min, max, t;
+
+ if ((min = g < r ? g : r) > b)
+ min = b;
+ if ((max = g > r ? g : r) < b)
+ max = b;
+
+ /* calculate lightness */
+ *l = (min + max) / 20;
+
+ if (min == max) { /* black, white and all shades of gray */
+ *h = 0;
+ *s = 0;
+ return;
+ }
+
+ /* calculate saturation */
+ if (*l < 50)
+ *s = ((max - min) * 100) / (max + min);
+ else
+ *s = ((max - min) * 100) / (2000 - max - min);
+
+ /* calculate hue */
+ if (r == max)
+ t = 120 + ((g - b) * 60) / (max - min);
+ else if (g == max)
+ t = 240 + ((b - r) * 60) / (max - min);
+ else
+ t = 360 + ((r - g) * 60) / (max - min);
+
+ *h = t % 360;
+}
+
+/*
+ * Extension (1997/1/18) - Allow negative f/b values to set default color
+ * values.
+ */
+NCURSES_EXPORT(int)
+init_pair(short pair, short f, short b)
+{
+ colorpair_t result;
+
+ T((T_CALLED("init_pair(%d,%d,%d)"), pair, f, b));
+
+ if ((pair < 0) || (pair >= COLOR_PAIRS) || SP == 0 || !SP->_coloron)
+ returnCode(ERR);
+#if NCURSES_EXT_FUNCS
+ if (SP->_default_color) {
+ if (f < 0)
+ f = COLOR_DEFAULT;
+ if (b < 0)
+ b = COLOR_DEFAULT;
+ if (!OkColorHi(f) && !isDefaultColor(f))
+ returnCode(ERR);
+ if (!OkColorHi(b) && !isDefaultColor(b))
+ returnCode(ERR);
+ } else
+#endif
+ {
+ if ((f < 0) || !OkColorHi(f)
+ || (b < 0) || !OkColorHi(b)
+ || (pair < 1))
+ returnCode(ERR);
+ }
+
+ /*
+ * When a pair's content is changed, replace its colors (if pair was
+ * initialized before a screen update is performed replacing original
+ * pair colors with the new ones).
+ */
+ result = PAIR_OF(f, b);
+ if (SP->_color_pairs[pair] != 0
+ && SP->_color_pairs[pair] != result) {
+ int y, x;
+
+ for (y = 0; y <= curscr->_maxy; y++) {
+ struct ldat *ptr = &(curscr->_line[y]);
+ bool changed = FALSE;
+ for (x = 0; x <= curscr->_maxx; x++) {
+ if (GetPair(ptr->text[x]) == pair) {
+ /* Set the old cell to zero to ensure it will be
+ updated on the next doupdate() */
+ SetChar(ptr->text[x], 0, 0);
+ CHANGED_CELL(ptr, x);
+ changed = TRUE;
+ }
+ }
+ if (changed)
+ _nc_make_oldhash(y);
+ }
+ }
+ SP->_color_pairs[pair] = result;
+ if (GET_SCREEN_PAIR(SP) == pair)
+ SET_SCREEN_PAIR(SP, (chtype) (~0)); /* force attribute update */
+
+ if (initialize_pair && InPalette(f) && InPalette(b)) {
+ const color_t *tp = hue_lightness_saturation ? hls_palette : cga_palette;
+
+ TR(TRACE_ATTRS,
+ ("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)",
+ pair,
+ tp[f].red, tp[f].green, tp[f].blue,
+ tp[b].red, tp[b].green, tp[b].blue));
+
+ TPUTS_TRACE("initialize_pair");
+ putp(TPARM_7(initialize_pair,
+ pair,
+ tp[f].red, tp[f].green, tp[f].blue,
+ tp[b].red, tp[b].green, tp[b].blue));
+ }
+
+ returnCode(OK);
+}
+
+#define okRGB(n) ((n) >= 0 && (n) <= 1000)
+
+NCURSES_EXPORT(int)
+init_color(short color, short r, short g, short b)
+{
+ int result = ERR;
+
+ T((T_CALLED("init_color(%d,%d,%d,%d)"), color, r, g, b));
+
+ if (initialize_color != NULL
+ && SP != 0
+ && SP->_coloron
+ && (color >= 0 && OkColorHi(color))
+ && (okRGB(r) && okRGB(g) && okRGB(b))) {
+
+ SP->_color_table[color].init = 1;
+ SP->_color_table[color].r = r;
+ SP->_color_table[color].g = g;
+ SP->_color_table[color].b = b;
+
+ if (hue_lightness_saturation) {
+ rgb2hls(r, g, b,
+ &SP->_color_table[color].red,
+ &SP->_color_table[color].green,
+ &SP->_color_table[color].blue);
+ } else {
+ SP->_color_table[color].red = r;
+ SP->_color_table[color].green = g;
+ SP->_color_table[color].blue = b;
+ }
+
+ TPUTS_TRACE("initialize_color");
+ putp(TPARM_4(initialize_color, color, r, g, b));
+ SP->_color_defs = max(color + 1, SP->_color_defs);
+ result = OK;
+ }
+ returnCode(result);
+}
+
+NCURSES_EXPORT(bool)
+can_change_color(void)
+{
+ T((T_CALLED("can_change_color()")));
+ returnCode((can_change != 0) ? TRUE : FALSE);
+}
+
+NCURSES_EXPORT(bool)
+has_colors(void)
+{
+ T((T_CALLED("has_colors()")));
+ returnCode((VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs)
+ && (((set_foreground != NULL)
+ && (set_background != NULL))
+ || ((set_a_foreground != NULL)
+ && (set_a_background != NULL))
+ || set_color_pair)) ? TRUE : FALSE);
+}
+
+NCURSES_EXPORT(int)
+color_content(short color, short *r, short *g, short *b)
+{
+ int result;
+
+ T((T_CALLED("color_content(%d,%p,%p,%p)"), color, r, g, b));
+ if (color < 0 || !OkColorHi(color) || SP == 0 || !SP->_coloron) {
+ result = ERR;
+ } else {
+ NCURSES_COLOR_T c_r = SP->_color_table[color].red;
+ NCURSES_COLOR_T c_g = SP->_color_table[color].green;
+ NCURSES_COLOR_T c_b = SP->_color_table[color].blue;
+
+ if (r)
+ *r = c_r;
+ if (g)
+ *g = c_g;
+ if (b)
+ *b = c_b;
+
+ TR(TRACE_ATTRS, ("...color_content(%d,%d,%d,%d)",
+ color, c_r, c_g, c_b));
+ result = OK;
+ }
+ returnCode(result);
+}
+
+NCURSES_EXPORT(int)
+pair_content(short pair, short *f, short *b)
+{
+ int result;
+
+ T((T_CALLED("pair_content(%d,%p,%p)"), pair, f, b));
+
+ if ((pair < 0) || (pair >= COLOR_PAIRS) || SP == 0 || !SP->_coloron) {
+ result = ERR;
+ } else {
+ NCURSES_COLOR_T fg = ((SP->_color_pairs[pair] >> C_SHIFT) & C_MASK);
+ NCURSES_COLOR_T bg = (SP->_color_pairs[pair] & C_MASK);
+
+#if NCURSES_EXT_FUNCS
+ if (fg == COLOR_DEFAULT)
+ fg = -1;
+ if (bg == COLOR_DEFAULT)
+ bg = -1;
+#endif
+
+ if (f)
+ *f = fg;
+ if (b)
+ *b = bg;
+
+ TR(TRACE_ATTRS, ("...pair_content(%d,%d,%d)", pair, fg, bg));
+ result = OK;
+ }
+ returnCode(result);
+}
+
+NCURSES_EXPORT(void)
+_nc_do_color(short old_pair, short pair, bool reverse, int (*outc) (int))
+{
+ NCURSES_COLOR_T fg = COLOR_DEFAULT;
+ NCURSES_COLOR_T bg = COLOR_DEFAULT;
+ NCURSES_COLOR_T old_fg, old_bg;
+
+ if (pair < 0 || pair >= COLOR_PAIRS) {
+ return;
+ } else if (pair != 0) {
+ if (set_color_pair) {
+ TPUTS_TRACE("set_color_pair");
+ tputs(TPARM_1(set_color_pair, pair), 1, outc);
+ return;
+ } else if (SP != 0) {
+ pair_content((short) pair, &fg, &bg);
+ }
+ }
+
+ if (old_pair >= 0
+ && SP != 0
+ && pair_content(old_pair, &old_fg, &old_bg) != ERR) {
+ if ((isDefaultColor(fg) && !isDefaultColor(old_fg))
+ || (isDefaultColor(bg) && !isDefaultColor(old_bg))) {
+#if NCURSES_EXT_FUNCS
+ /*
+ * A minor optimization - but extension. If "AX" is specified in
+ * the terminal description, treat it as screen's indicator of ECMA
+ * SGR 39 and SGR 49, and assume the two sequences are independent.
+ */
+ if (SP->_has_sgr_39_49
+ && isDefaultColor(old_bg)
+ && !isDefaultColor(old_fg)) {
+ tputs("\033[39m", 1, outc);
+ } else if (SP->_has_sgr_39_49
+ && isDefaultColor(old_fg)
+ && !isDefaultColor(old_bg)) {
+ tputs("\033[49m", 1, outc);
+ } else
+#endif
+ reset_color_pair();
+ }
+ } else {
+ reset_color_pair();
+ if (old_pair < 0)
+ return;
+ }
+
+#if NCURSES_EXT_FUNCS
+ if (isDefaultColor(fg))
+ fg = default_fg();
+ if (isDefaultColor(bg))
+ bg = default_bg();
+#endif
+
+ if (reverse) {
+ NCURSES_COLOR_T xx = fg;
+ fg = bg;
+ bg = xx;
+ }
+
+ TR(TRACE_ATTRS, ("setting colors: pair = %d, fg = %d, bg = %d", pair,
+ fg, bg));
+
+ if (!isDefaultColor(fg)) {
+ set_foreground_color(fg, outc);
+ }
+ if (!isDefaultColor(bg)) {
+ set_background_color(bg, outc);
+ }
+}
diff --git a/ncurses/base/lib_colorset.c b/ncurses/base/lib_colorset.c
new file mode 100644
index 000000000000..a973c5350c8f
--- /dev/null
+++ b/ncurses/base/lib_colorset.c
@@ -0,0 +1,60 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer, 1998 *
+ * and: Thomas E. Dickey, 2005 *
+ ****************************************************************************/
+
+/*
+** lib_colorset.c
+**
+** The routine wcolor_set().
+**
+*/
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_colorset.c,v 1.11 2005/01/29 21:40:51 tom Exp $")
+
+NCURSES_EXPORT(int)
+wcolor_set(WINDOW *win, short color_pair_number, void *opts)
+{
+ T((T_CALLED("wcolor_set(%p,%d)"), win, color_pair_number));
+ if (win
+ && !opts
+ && (color_pair_number >= 0)
+ && (color_pair_number < COLOR_PAIRS)) {
+ TR(TRACE_ATTRS, ("... current %ld", (long) GET_WINDOW_PAIR(win)));
+ SET_WINDOW_PAIR(win, color_pair_number);
+ if_EXT_COLORS(win->_color = color_pair_number);
+ returnCode(OK);
+ } else
+ returnCode(ERR);
+}
diff --git a/ncurses/base/lib_delch.c b/ncurses/base/lib_delch.c
new file mode 100644
index 000000000000..0c30f2d93c1b
--- /dev/null
+++ b/ncurses/base/lib_delch.c
@@ -0,0 +1,69 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_delch.c
+**
+** The routine wdelch().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_delch.c,v 1.12 2001/12/19 01:06:09 tom Exp $")
+
+NCURSES_EXPORT(int)
+wdelch(WINDOW *win)
+{
+ int code = ERR;
+
+ T((T_CALLED("wdelch(%p)"), win));
+
+ if (win) {
+ NCURSES_CH_T blank = win->_nc_bkgd;
+ struct ldat *line = &(win->_line[win->_cury]);
+ NCURSES_CH_T *end = &(line->text[win->_maxx]);
+ NCURSES_CH_T *temp2 = &(line->text[win->_curx + 1]);
+ NCURSES_CH_T *temp1 = temp2 - 1;
+
+ CHANGED_TO_EOL(line, win->_curx, win->_maxx);
+ while (temp1 < end)
+ *temp1++ = *temp2++;
+
+ *temp1 = blank;
+
+ _nc_synchook(win);
+ code = OK;
+ }
+ returnCode(code);
+}
diff --git a/ncurses/base/lib_delwin.c b/ncurses/base/lib_delwin.c
new file mode 100644
index 000000000000..ba5f180d5f3c
--- /dev/null
+++ b/ncurses/base/lib_delwin.c
@@ -0,0 +1,89 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_delwin.c
+**
+** The routine delwin().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_delwin.c,v 1.16 2008/05/03 14:13:51 tom Exp $")
+
+static bool
+cannot_delete(WINDOW *win)
+{
+ WINDOWLIST *p;
+ bool result = TRUE;
+
+ for (each_window(p)) {
+ if (&(p->win) == win) {
+ result = FALSE;
+ } else if ((p->win._flags & _SUBWIN) != 0
+ && p->win._parent == win) {
+ result = TRUE;
+ break;
+ }
+ }
+ return result;
+}
+
+NCURSES_EXPORT(int)
+delwin(WINDOW *win)
+{
+ int result = ERR;
+
+ T((T_CALLED("delwin(%p)"), win));
+
+ if (_nc_try_global(windowlist) == 0) {
+ _nc_lock_window(win);
+ if (win == 0
+ || cannot_delete(win)) {
+ result = ERR;
+ _nc_unlock_window(win);
+ } else {
+
+ if (win->_flags & _SUBWIN)
+ touchwin(win->_parent);
+ else if (curscr != 0)
+ touchwin(curscr);
+
+ _nc_unlock_window(win);
+ result = _nc_freewin(win);
+ }
+ _nc_unlock_global(windowlist);
+ }
+ returnCode(result);
+}
diff --git a/ncurses/base/lib_dft_fgbg.c b/ncurses/base/lib_dft_fgbg.c
new file mode 100644
index 000000000000..8953c148b09e
--- /dev/null
+++ b/ncurses/base/lib_dft_fgbg.c
@@ -0,0 +1,75 @@
+/****************************************************************************
+ * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#include <term.h>
+
+MODULE_ID("$Id: lib_dft_fgbg.c,v 1.18 2005/11/26 20:03:38 tom Exp $")
+
+/*
+ * Modify the behavior of color-pair 0 so that the library doesn't assume that
+ * it is white on black. This is an extension to XSI curses.
+ */
+NCURSES_EXPORT(int)
+use_default_colors(void)
+{
+ T((T_CALLED("use_default_colors()")));
+ returnCode(assume_default_colors(-1, -1));
+}
+
+/*
+ * Modify the behavior of color-pair 0 so that the library assumes that it
+ * is something specific, possibly not white on black.
+ */
+NCURSES_EXPORT(int)
+assume_default_colors(int fg, int bg)
+{
+ T((T_CALLED("assume_default_colors(%d,%d)"), fg, bg));
+
+ if (!orig_pair && !orig_colors)
+ returnCode(ERR);
+
+ if (initialize_pair) /* don't know how to handle this */
+ returnCode(ERR);
+
+ SP->_default_color = isDefaultColor(fg) || isDefaultColor(bg);
+ SP->_has_sgr_39_49 = (tigetflag("AX") == TRUE);
+ SP->_default_fg = isDefaultColor(fg) ? COLOR_DEFAULT : (fg & C_MASK);
+ SP->_default_bg = isDefaultColor(bg) ? COLOR_DEFAULT : (bg & C_MASK);
+ if (SP->_color_pairs != 0) {
+ bool save = SP->_default_color;
+ SP->_default_color = TRUE;
+ init_pair(0, (short) fg, (short) bg);
+ SP->_default_color = save;
+ }
+ returnCode(OK);
+}
diff --git a/ncurses/base/lib_echo.c b/ncurses/base/lib_echo.c
new file mode 100644
index 000000000000..df44713d1a11
--- /dev/null
+++ b/ncurses/base/lib_echo.c
@@ -0,0 +1,61 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+ * echo.c
+ *
+ * Routines:
+ * echo()
+ * noecho()
+ *
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_echo.c,v 1.5 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(int)
+echo(void)
+{
+ T((T_CALLED("echo()")));
+ SP->_echo = TRUE;
+ returnCode(OK);
+}
+
+NCURSES_EXPORT(int)
+noecho(void)
+{
+ T((T_CALLED("noecho()")));
+ SP->_echo = FALSE;
+ returnCode(OK);
+}
diff --git a/ncurses/base/lib_endwin.c b/ncurses/base/lib_endwin.c
new file mode 100644
index 000000000000..66662871962b
--- /dev/null
+++ b/ncurses/base/lib_endwin.c
@@ -0,0 +1,60 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_endwin.c
+**
+** The routine endwin().
+**
+*/
+
+#include <curses.priv.h>
+#include <term.h>
+
+MODULE_ID("$Id: lib_endwin.c,v 1.19 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(int)
+endwin(void)
+{
+ T((T_CALLED("endwin()")));
+
+ if (SP) {
+ SP->_endwin = TRUE;
+ SP->_mouse_wrap(SP);
+ _nc_screen_wrap();
+ _nc_mvcur_wrap(); /* wrap up cursor addressing */
+ returnCode(reset_shell_mode());
+ }
+
+ returnCode(ERR);
+}
diff --git a/ncurses/base/lib_erase.c b/ncurses/base/lib_erase.c
new file mode 100644
index 000000000000..2566e8b39820
--- /dev/null
+++ b/ncurses/base/lib_erase.c
@@ -0,0 +1,92 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+** lib_erase.c
+**
+** The routine werase().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_erase.c,v 1.16 2005/10/30 00:36:36 tom Exp $")
+
+NCURSES_EXPORT(int)
+werase(WINDOW *win)
+{
+ int code = ERR;
+ int y;
+ NCURSES_CH_T blank;
+ NCURSES_CH_T *sp, *end, *start;
+
+ T((T_CALLED("werase(%p)"), win));
+
+ if (win) {
+ blank = win->_nc_bkgd;
+ for (y = 0; y <= win->_maxy; y++) {
+ start = win->_line[y].text;
+ end = &start[win->_maxx];
+
+ /*
+ * If this is a derived window, we have to handle the case where
+ * a multicolumn character extends into the window that we are
+ * erasing.
+ */
+ if_WIDEC({
+ if (isWidecExt(start[0])) {
+ int x = (win->_parent != 0) ? (win->_begx) : 0;
+ while (x-- > 0) {
+ if (isWidecBase(start[-1])) {
+ --start;
+ break;
+ }
+ --start;
+ }
+ }
+ });
+
+ for (sp = start; sp <= end; sp++)
+ *sp = blank;
+
+ win->_line[y].firstchar = 0;
+ win->_line[y].lastchar = win->_maxx;
+ }
+ win->_curx = win->_cury = 0;
+ win->_flags &= ~_WRAPPED;
+ _nc_synchook(win);
+ code = OK;
+ }
+ returnCode(code);
+}
diff --git a/ncurses/base/lib_flash.c b/ncurses/base/lib_flash.c
new file mode 100644
index 000000000000..a6b022a8e816
--- /dev/null
+++ b/ncurses/base/lib_flash.c
@@ -0,0 +1,73 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+ * flash.c
+ *
+ * The routine flash().
+ *
+ */
+
+#include <curses.priv.h>
+#include <term.h> /* beep, flash */
+
+MODULE_ID("$Id: lib_flash.c,v 1.6 2000/12/10 02:43:27 tom Exp $")
+
+/*
+ * flash()
+ *
+ * Flash the current terminal's screen if possible. If not,
+ * sound the audible bell if one exists.
+ *
+ */
+
+NCURSES_EXPORT(int)
+flash(void)
+{
+ int res = ERR;
+
+ T((T_CALLED("flash()")));
+
+ /* FIXME: should make sure that we are not in altchar mode */
+ if (flash_screen) {
+ TPUTS_TRACE("flash_screen");
+ res = putp(flash_screen);
+ _nc_flush();
+ } else if (bell) {
+ TPUTS_TRACE("bell");
+ res = putp(bell);
+ _nc_flush();
+ }
+
+ returnCode(res);
+}
diff --git a/ncurses/base/lib_freeall.c b/ncurses/base/lib_freeall.c
new file mode 100644
index 000000000000..4bb7ccc79995
--- /dev/null
+++ b/ncurses/base/lib_freeall.c
@@ -0,0 +1,146 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#include <term_entry.h>
+#include <tic.h>
+
+#if HAVE_NC_FREEALL
+
+#if HAVE_LIBDBMALLOC
+extern int malloc_errfd; /* FIXME */
+#endif
+
+MODULE_ID("$Id: lib_freeall.c,v 1.46 2008/05/03 14:13:51 tom Exp $")
+
+/*
+ * Free all ncurses data. This is used for testing only (there's no practical
+ * use for it as an extension).
+ */
+NCURSES_EXPORT(void)
+_nc_freeall(void)
+{
+ WINDOWLIST *p, *q;
+ static va_list empty_va;
+
+ T((T_CALLED("_nc_freeall()")));
+#if NO_LEAKS
+ if (SP != 0) {
+ if (SP->_oldnum_list != 0) {
+ FreeAndNull(SP->_oldnum_list);
+ }
+ }
+#endif
+ if (SP != 0) {
+ _nc_lock_global(windowlist);
+
+ while (_nc_windows != 0) {
+ bool deleted = FALSE;
+
+ /* Delete only windows that're not a parent */
+ for (each_window(p)) {
+ bool found = FALSE;
+
+ for (each_window(q)) {
+ if ((p != q)
+ && (q->win._flags & _SUBWIN)
+ && (&(p->win) == q->win._parent)) {
+ found = TRUE;
+ break;
+ }
+ }
+
+ if (!found) {
+ if (delwin(&(p->win)) != ERR)
+ deleted = TRUE;
+ break;
+ }
+ }
+
+ /*
+ * Don't continue to loop if the list is trashed.
+ */
+ if (!deleted)
+ break;
+ }
+ delscreen(SP);
+ _nc_unlock_global(windowlist);
+ }
+ if (cur_term != 0)
+ del_curterm(cur_term);
+
+#if USE_WIDEC_SUPPORT
+ FreeIfNeeded(_nc_wacs);
+#endif
+ (void) _nc_printf_string(0, empty_va);
+#ifdef TRACE
+ (void) _nc_trace_buf(-1, 0);
+#endif
+
+#if BROKEN_LINKER || USE_REENTRANT
+ FreeIfNeeded(_nc_prescreen.real_acs_map);
+#endif
+
+ _nc_leaks_tinfo();
+
+#if HAVE_LIBDBMALLOC
+ malloc_dump(malloc_errfd);
+#elif HAVE_LIBDMALLOC
+#elif HAVE_LIBMPATROL
+ __mp_summary();
+#elif HAVE_PURIFY
+ purify_all_inuse();
+#endif
+ returnVoid;
+}
+
+NCURSES_EXPORT(void)
+_nc_free_and_exit(int code)
+{
+ char *last_setbuf = (SP != 0) ? SP->_setbuf : 0;
+
+ _nc_freeall();
+#ifdef TRACE
+ trace(0); /* close trace file, freeing its setbuf */
+ free(_nc_varargs("?", 0));
+#endif
+ fclose(stdout);
+ FreeIfNeeded(last_setbuf);
+ exit(code);
+}
+
+#else
+NCURSES_EXPORT(void)
+_nc_freeall(void)
+{
+}
+#endif
diff --git a/ncurses/base/lib_getch.c b/ncurses/base/lib_getch.c
new file mode 100644
index 000000000000..d9f6b1795c77
--- /dev/null
+++ b/ncurses/base/lib_getch.c
@@ -0,0 +1,611 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+** lib_getch.c
+**
+** The routine getch().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_getch.c,v 1.87 2008/05/03 22:42:10 tom Exp $")
+
+#include <fifo_defs.h>
+
+#if USE_REENTRANT
+#define GetEscdelay(sp) (sp)->_ESCDELAY
+NCURSES_EXPORT(int)
+NCURSES_PUBLIC_VAR(ESCDELAY) (void)
+{
+ return SP ? GetEscdelay(SP) : 1000;
+}
+#else
+#define GetEscdelay(sp) ESCDELAY
+NCURSES_EXPORT_VAR(int)
+ESCDELAY = 1000; /* max interval betw. chars in funkeys, in millisecs */
+#endif
+
+#if NCURSES_EXT_FUNCS
+NCURSES_EXPORT(int)
+set_escdelay(int value)
+{
+ int code = OK;
+#if USE_REENTRANT
+ if (SP) {
+ SP->_ESCDELAY = value;
+ } else {
+ code = ERR;
+ }
+#else
+ ESCDELAY = value;
+#endif
+ return code;
+}
+#endif
+
+#ifdef NCURSES_WGETCH_EVENTS
+#define TWAIT_MASK 7
+#else
+#define TWAIT_MASK 3
+#endif
+
+/*
+ * Check for mouse activity, returning nonzero if we find any.
+ */
+static int
+check_mouse_activity(SCREEN *sp, int delay EVENTLIST_2nd(_nc_eventlist * evl))
+{
+ int rc;
+
+#if USE_SYSMOUSE
+ if ((sp->_mouse_type == M_SYSMOUSE)
+ && (sp->_sysmouse_head < sp->_sysmouse_tail)) {
+ return 2;
+ }
+#endif
+ rc = _nc_timed_wait(sp, TWAIT_MASK, delay, (int *) 0 EVENTLIST_2nd(evl));
+#if USE_SYSMOUSE
+ if ((sp->_mouse_type == M_SYSMOUSE)
+ && (sp->_sysmouse_head < sp->_sysmouse_tail)
+ && (rc == 0)
+ && (errno == EINTR)) {
+ rc |= 2;
+ }
+#endif
+ return rc;
+}
+
+static NCURSES_INLINE int
+fifo_peek(SCREEN *sp)
+{
+ int ch = sp->_fifo[peek];
+ TR(TRACE_IEVENT, ("peeking at %d", peek));
+
+ p_inc();
+ return ch;
+}
+
+static NCURSES_INLINE int
+fifo_pull(SCREEN *sp)
+{
+ int ch;
+ ch = sp->_fifo[head];
+ TR(TRACE_IEVENT, ("pulling %s from %d", _tracechar(ch), head));
+
+ if (peek == head) {
+ h_inc();
+ peek = head;
+ } else
+ h_inc();
+
+#ifdef TRACE
+ if (USE_TRACEF(TRACE_IEVENT)) {
+ _nc_fifo_dump(sp);
+ _nc_unlock_global(tracef);
+ }
+#endif
+ return ch;
+}
+
+static NCURSES_INLINE int
+fifo_push(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
+{
+ int n;
+ int ch = 0;
+ int mask = 0;
+
+ (void) mask;
+ if (tail == -1)
+ return ERR;
+
+#ifdef HIDE_EINTR
+ again:
+ errno = 0;
+#endif
+
+#ifdef NCURSES_WGETCH_EVENTS
+ if (evl
+#if USE_GPM_SUPPORT || USE_EMX_MOUSE || USE_SYSMOUSE
+ || (sp->_mouse_fd >= 0)
+#endif
+ ) {
+ mask = check_mouse_activity(sp, -1 EVENTLIST_2nd(evl));
+ } else
+ mask = 0;
+
+ if (mask & 4) {
+ T(("fifo_push: ungetch KEY_EVENT"));
+ _nc_ungetch(sp, KEY_EVENT);
+ return KEY_EVENT;
+ }
+#elif USE_GPM_SUPPORT || USE_EMX_MOUSE || USE_SYSMOUSE
+ if (sp->_mouse_fd >= 0) {
+ mask = check_mouse_activity(sp, -1 EVENTLIST_2nd(evl));
+ }
+#endif
+
+#if USE_GPM_SUPPORT || USE_EMX_MOUSE
+ if ((sp->_mouse_fd >= 0) && (mask & 2)) {
+ sp->_mouse_event(sp);
+ ch = KEY_MOUSE;
+ n = 1;
+ } else
+#endif
+#if USE_SYSMOUSE
+ if ((sp->_mouse_type == M_SYSMOUSE)
+ && (sp->_sysmouse_head < sp->_sysmouse_tail)) {
+ sp->_mouse_event(sp);
+ ch = KEY_MOUSE;
+ n = 1;
+ } else if ((sp->_mouse_type == M_SYSMOUSE)
+ && (mask <= 0) && errno == EINTR) {
+ sp->_mouse_event(sp);
+ ch = KEY_MOUSE;
+ n = 1;
+ } else
+#endif
+ { /* Can block... */
+ unsigned char c2 = 0;
+ n = read(sp->_ifd, &c2, 1);
+ ch = c2;
+ }
+
+#ifdef HIDE_EINTR
+ /*
+ * Under System V curses with non-restarting signals, getch() returns
+ * with value ERR when a handled signal keeps it from completing.
+ * If signals restart system calls, OTOH, the signal is invisible
+ * except to its handler.
+ *
+ * We don't want this difference to show. This piece of code
+ * tries to make it look like we always have restarting signals.
+ */
+ if (n <= 0 && errno == EINTR)
+ goto again;
+#endif
+
+ if ((n == -1) || (n == 0)) {
+ TR(TRACE_IEVENT, ("read(%d,&ch,1)=%d, errno=%d", sp->_ifd, n, errno));
+ ch = ERR;
+ }
+ TR(TRACE_IEVENT, ("read %d characters", n));
+
+ sp->_fifo[tail] = ch;
+ sp->_fifohold = 0;
+ if (head == -1)
+ head = peek = tail;
+ t_inc();
+ TR(TRACE_IEVENT, ("pushed %s at %d", _tracechar(ch), tail));
+#ifdef TRACE
+ if (USE_TRACEF(TRACE_IEVENT)) {
+ _nc_fifo_dump(sp);
+ _nc_unlock_global(tracef);
+ }
+#endif
+ return ch;
+}
+
+static NCURSES_INLINE void
+fifo_clear(SCREEN *sp)
+{
+ memset(sp->_fifo, 0, sizeof(sp->_fifo));
+ head = -1;
+ tail = peek = 0;
+}
+
+static int kgetch(SCREEN *EVENTLIST_2nd(_nc_eventlist * evl));
+
+#define wgetch_should_refresh(win) (\
+ (is_wintouched(win) || (win->_flags & _HASMOVED)) \
+ && !(win->_flags & _ISPAD))
+
+NCURSES_EXPORT(int)
+_nc_wgetch(WINDOW *win,
+ unsigned long *result,
+ int use_meta
+ EVENTLIST_2nd(_nc_eventlist * evl))
+{
+ SCREEN *sp = SP;
+ int ch;
+#ifdef NCURSES_WGETCH_EVENTS
+ long event_delay = -1;
+#endif
+
+ T((T_CALLED("_nc_wgetch(%p)"), win));
+
+ *result = 0;
+ if (win == 0 || sp == 0) {
+ returnCode(ERR);
+ }
+
+ if (cooked_key_in_fifo()) {
+ if (wgetch_should_refresh(win))
+ wrefresh(win);
+
+ *result = fifo_pull(sp);
+ returnCode(*result >= KEY_MIN ? KEY_CODE_YES : OK);
+ }
+#ifdef NCURSES_WGETCH_EVENTS
+ if (evl && (evl->count == 0))
+ evl = NULL;
+ event_delay = _nc_eventlist_timeout(evl);
+#endif
+
+ /*
+ * Handle cooked mode. Grab a string from the screen,
+ * stuff its contents in the FIFO queue, and pop off
+ * the first character to return it.
+ */
+ if (head == -1 &&
+ !sp->_notty &&
+ !sp->_raw &&
+ !sp->_cbreak &&
+ !sp->_called_wgetch) {
+ char buf[MAXCOLUMNS], *bufp;
+ int rc;
+
+ TR(TRACE_IEVENT, ("filling queue in cooked mode"));
+
+ sp->_called_wgetch = TRUE;
+ rc = wgetnstr(win, buf, MAXCOLUMNS);
+ sp->_called_wgetch = FALSE;
+
+ /* ungetch in reverse order */
+#ifdef NCURSES_WGETCH_EVENTS
+ if (rc != KEY_EVENT)
+#endif
+ _nc_ungetch(sp, '\n');
+ for (bufp = buf + strlen(buf); bufp > buf; bufp--)
+ _nc_ungetch(sp, bufp[-1]);
+
+#ifdef NCURSES_WGETCH_EVENTS
+ /* Return it first */
+ if (rc == KEY_EVENT) {
+ *result = rc;
+ } else
+#endif
+ *result = fifo_pull(sp);
+ returnCode(*result >= KEY_MIN ? KEY_CODE_YES : OK);
+ }
+
+ if (win->_use_keypad != sp->_keypad_on)
+ _nc_keypad(sp, win->_use_keypad);
+
+ if (wgetch_should_refresh(win))
+ wrefresh(win);
+
+ if (!win->_notimeout && (win->_delay >= 0 || sp->_cbreak > 1)) {
+ if (head == -1) { /* fifo is empty */
+ int delay;
+ int rc;
+
+ TR(TRACE_IEVENT, ("timed delay in wgetch()"));
+ if (sp->_cbreak > 1)
+ delay = (sp->_cbreak - 1) * 100;
+ else
+ delay = win->_delay;
+
+#ifdef NCURSES_WGETCH_EVENTS
+ if (event_delay >= 0 && delay > event_delay)
+ delay = event_delay;
+#endif
+
+ TR(TRACE_IEVENT, ("delay is %d milliseconds", delay));
+
+ rc = check_mouse_activity(sp, delay EVENTLIST_2nd(evl));
+
+#ifdef NCURSES_WGETCH_EVENTS
+ if (rc & 4) {
+ *result = KEY_EVENT;
+ returnCode(KEY_CODE_YES);
+ }
+#endif
+ if (!rc)
+ returnCode(ERR);
+ }
+ /* else go on to read data available */
+ }
+
+ if (win->_use_keypad) {
+ /*
+ * This is tricky. We only want to get special-key
+ * events one at a time. But we want to accumulate
+ * mouse events until either (a) the mouse logic tells
+ * us it's picked up a complete gesture, or (b)
+ * there's a detectable time lapse after one.
+ *
+ * Note: if the mouse code starts failing to compose
+ * press/release events into clicks, you should probably
+ * increase the wait with mouseinterval().
+ */
+ int runcount = 0;
+ int rc;
+
+ do {
+ ch = kgetch(sp EVENTLIST_2nd(evl));
+ if (ch == KEY_MOUSE) {
+ ++runcount;
+ if (sp->_mouse_inline(sp))
+ break;
+ }
+ if (sp->_maxclick < 0)
+ break;
+ } while
+ (ch == KEY_MOUSE
+ && (((rc = check_mouse_activity(sp, sp->_maxclick
+ EVENTLIST_2nd(evl))) != 0
+ && !(rc & 4))
+ || !sp->_mouse_parse(runcount)));
+#ifdef NCURSES_WGETCH_EVENTS
+ if ((rc & 4) && !ch == KEY_EVENT) {
+ _nc_ungetch(sp, ch);
+ ch = KEY_EVENT;
+ }
+#endif
+ if (runcount > 0 && ch != KEY_MOUSE) {
+#ifdef NCURSES_WGETCH_EVENTS
+ /* mouse event sequence ended by an event, report event */
+ if (ch == KEY_EVENT) {
+ _nc_ungetch(sp, KEY_MOUSE); /* FIXME This interrupts a gesture... */
+ } else
+#endif
+ {
+ /* mouse event sequence ended by keystroke, store keystroke */
+ _nc_ungetch(sp, ch);
+ ch = KEY_MOUSE;
+ }
+ }
+ } else {
+ if (head == -1)
+ fifo_push(sp EVENTLIST_2nd(evl));
+ ch = fifo_pull(sp);
+ }
+
+ if (ch == ERR) {
+#if USE_SIZECHANGE
+ if (_nc_handle_sigwinch(sp)) {
+ _nc_update_screensize(sp);
+ /* resizeterm can push KEY_RESIZE */
+ if (cooked_key_in_fifo()) {
+ *result = fifo_pull(sp);
+ returnCode(*result >= KEY_MIN ? KEY_CODE_YES : OK);
+ }
+ }
+#endif
+ returnCode(ERR);
+ }
+
+ /*
+ * If echo() is in effect, display the printable version of the
+ * key on the screen. Carriage return and backspace are treated
+ * specially by Solaris curses:
+ *
+ * If carriage return is defined as a function key in the
+ * terminfo, e.g., kent, then Solaris may return either ^J (or ^M
+ * if nonl() is set) or KEY_ENTER depending on the echo() mode.
+ * We echo before translating carriage return based on nonl(),
+ * since the visual result simply moves the cursor to column 0.
+ *
+ * Backspace is a different matter. Solaris curses does not
+ * translate it to KEY_BACKSPACE if kbs=^H. This does not depend
+ * on the stty modes, but appears to be a hardcoded special case.
+ * This is a difference from ncurses, which uses the terminfo entry.
+ * However, we provide the same visual result as Solaris, moving the
+ * cursor to the left.
+ */
+ if (sp->_echo && !(win->_flags & _ISPAD)) {
+ chtype backup = (ch == KEY_BACKSPACE) ? '\b' : ch;
+ if (backup < KEY_MIN)
+ wechochar(win, backup);
+ }
+
+ /*
+ * Simulate ICRNL mode
+ */
+ if ((ch == '\r') && sp->_nl)
+ ch = '\n';
+
+ /* Strip 8th-bit if so desired. We do this only for characters that
+ * are in the range 128-255, to provide compatibility with terminals
+ * that display only 7-bit characters. Note that 'ch' may be a
+ * function key at this point, so we mustn't strip _those_.
+ */
+ if (!use_meta)
+ if ((ch < KEY_MIN) && (ch & 0x80))
+ ch &= 0x7f;
+
+ T(("wgetch returning : %s", _tracechar(ch)));
+
+ *result = ch;
+ returnCode(ch >= KEY_MIN ? KEY_CODE_YES : OK);
+}
+
+#ifdef NCURSES_WGETCH_EVENTS
+NCURSES_EXPORT(int)
+wgetch_events(WINDOW *win, _nc_eventlist * evl)
+{
+ SCREEN *sp = SP;
+ int code;
+ unsigned long value;
+
+ T((T_CALLED("wgetch_events(%p,%p)"), win, evl));
+ code = _nc_wgetch(win,
+ &value,
+ sp->_use_meta
+ EVENTLIST_2nd(evl));
+ if (code != ERR)
+ code = value;
+ returnCode(code);
+}
+#endif
+
+NCURSES_EXPORT(int)
+wgetch(WINDOW *win)
+{
+ SCREEN *sp = SP;
+ int code;
+ unsigned long value;
+
+ T((T_CALLED("wgetch(%p)"), win));
+ code = _nc_wgetch(win,
+ &value,
+ (sp ? sp->_use_meta : 0)
+ EVENTLIST_2nd((_nc_eventlist *) 0));
+ if (code != ERR)
+ code = value;
+ returnCode(code);
+}
+
+/*
+** int
+** kgetch()
+**
+** Get an input character, but take care of keypad sequences, returning
+** an appropriate code when one matches the input. After each character
+** is received, set an alarm call based on ESCDELAY. If no more of the
+** sequence is received by the time the alarm goes off, pass through
+** the sequence gotten so far.
+**
+** This function must be called when there are no cooked keys in queue.
+** (that is head==-1 || peek==head)
+**
+*/
+
+static int
+kgetch(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
+{
+ TRIES *ptr;
+ int ch = 0;
+ int timeleft = GetEscdelay(sp);
+
+ TR(TRACE_IEVENT, ("kgetch() called"));
+
+ ptr = sp->_keytry;
+
+ for (;;) {
+ if (cooked_key_in_fifo() && sp->_fifo[head] >= KEY_MIN) {
+ break;
+ } else if (!raw_key_in_fifo()) {
+ ch = fifo_push(sp EVENTLIST_2nd(evl));
+ if (ch == ERR) {
+ peek = head; /* the keys stay uninterpreted */
+ return ERR;
+ }
+#ifdef NCURSES_WGETCH_EVENTS
+ else if (ch == KEY_EVENT) {
+ peek = head; /* the keys stay uninterpreted */
+ return fifo_pull(sp); /* Remove KEY_EVENT from the queue */
+ }
+#endif
+ }
+
+ ch = fifo_peek(sp);
+ if (ch >= KEY_MIN) {
+ /* If not first in queue, somebody put this key there on purpose in
+ * emergency. Consider it higher priority than the unfinished
+ * keysequence we are parsing.
+ */
+ peek = head;
+ /* assume the key is the last in fifo */
+ t_dec(); /* remove the key */
+ return ch;
+ }
+
+ TR(TRACE_IEVENT, ("ch: %s", _tracechar((unsigned char) ch)));
+ while ((ptr != NULL) && (ptr->ch != (unsigned char) ch))
+ ptr = ptr->sibling;
+
+ if (ptr == NULL) {
+ TR(TRACE_IEVENT, ("ptr is null"));
+ break;
+ }
+ TR(TRACE_IEVENT, ("ptr=%p, ch=%d, value=%d",
+ ptr, ptr->ch, ptr->value));
+
+ if (ptr->value != 0) { /* sequence terminated */
+ TR(TRACE_IEVENT, ("end of sequence"));
+ if (peek == tail)
+ fifo_clear(sp);
+ else
+ head = peek;
+ return (ptr->value);
+ }
+
+ ptr = ptr->child;
+
+ if (!raw_key_in_fifo()) {
+ int rc;
+
+ TR(TRACE_IEVENT, ("waiting for rest of sequence"));
+ rc = check_mouse_activity(sp, timeleft EVENTLIST_2nd(evl));
+#ifdef NCURSES_WGETCH_EVENTS
+ if (rc & 4) {
+ TR(TRACE_IEVENT, ("interrupted by a user event"));
+ /* FIXME Should have preserved remainder timeleft for reuse... */
+ peek = head; /* Restart interpreting later */
+ return KEY_EVENT;
+ }
+#endif
+ if (!rc) {
+ TR(TRACE_IEVENT, ("ran out of time"));
+ break;
+ }
+ }
+ }
+ ch = fifo_pull(sp);
+ peek = head;
+ return ch;
+}
diff --git a/ncurses/base/lib_getstr.c b/ncurses/base/lib_getstr.c
new file mode 100644
index 000000000000..274e87887371
--- /dev/null
+++ b/ncurses/base/lib_getstr.c
@@ -0,0 +1,224 @@
+/****************************************************************************
+ * Copyright (c) 1998-2002,2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_getstr.c
+**
+** The routine wgetstr().
+**
+*/
+
+#include <curses.priv.h>
+#include <term.h>
+
+MODULE_ID("$Id: lib_getstr.c,v 1.25 2006/01/12 00:33:52 tom Exp $")
+
+/*
+ * This wipes out the last character, no matter whether it was a tab, control
+ * or other character, and handles reverse wraparound.
+ */
+static char *
+WipeOut(WINDOW *win, int y, int x, char *first, char *last, bool echoed)
+{
+ if (last > first) {
+ *--last = '\0';
+ if (echoed) {
+ int y1 = win->_cury;
+ int x1 = win->_curx;
+
+ wmove(win, y, x);
+ waddstr(win, first);
+ getyx(win, y, x);
+ while (win->_cury < y1
+ || (win->_cury == y1 && win->_curx < x1))
+ waddch(win, (chtype) ' ');
+
+ wmove(win, y, x);
+ }
+ }
+ return last;
+}
+
+NCURSES_EXPORT(int)
+wgetnstr_events(WINDOW *win,
+ char *str,
+ int maxlen,
+ EVENTLIST_1st(_nc_eventlist * evl))
+{
+ TTY buf;
+ bool oldnl, oldecho, oldraw, oldcbreak;
+ char erasec;
+ char killc;
+ char *oldstr;
+ int ch;
+ int y, x;
+
+ T((T_CALLED("wgetnstr(%p,%p, %d)"), win, str, maxlen));
+
+ if (!win)
+ returnCode(ERR);
+
+ _nc_get_tty_mode(&buf);
+
+ oldnl = SP->_nl;
+ oldecho = SP->_echo;
+ oldraw = SP->_raw;
+ oldcbreak = SP->_cbreak;
+ nl();
+ noecho();
+ noraw();
+ cbreak();
+
+ erasec = erasechar();
+ killc = killchar();
+
+ oldstr = str;
+ getyx(win, y, x);
+
+ if (is_wintouched(win) || (win->_flags & _HASMOVED))
+ wrefresh(win);
+
+ while ((ch = wgetch_events(win, evl)) != ERR) {
+ /*
+ * Some terminals (the Wyse-50 is the most common) generate
+ * a \n from the down-arrow key. With this logic, it's the
+ * user's choice whether to set kcud=\n for wgetch();
+ * terminating *getstr() with \n should work either way.
+ */
+ if (ch == '\n'
+ || ch == '\r'
+ || ch == KEY_DOWN
+ || ch == KEY_ENTER) {
+ if (oldecho == TRUE
+ && win->_cury == win->_maxy
+ && win->_scroll)
+ wechochar(win, (chtype) '\n');
+ break;
+ }
+#ifdef KEY_EVENT
+ if (ch == KEY_EVENT)
+ break;
+#endif
+#ifdef KEY_RESIZE
+ if (ch == KEY_RESIZE)
+ break;
+#endif
+ if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) {
+ if (str > oldstr) {
+ str = WipeOut(win, y, x, oldstr, str, oldecho);
+ }
+ } else if (ch == killc) {
+ while (str > oldstr) {
+ str = WipeOut(win, y, x, oldstr, str, oldecho);
+ }
+ } else if (ch >= KEY_MIN
+ || (maxlen >= 0 && str - oldstr >= maxlen)) {
+ beep();
+ } else {
+ *str++ = ch;
+ if (oldecho == TRUE) {
+ int oldy = win->_cury;
+ if (waddch(win, (chtype) ch) == ERR) {
+ /*
+ * We can't really use the lower-right
+ * corner for input, since it'll mess
+ * up bookkeeping for erases.
+ */
+ win->_flags &= ~_WRAPPED;
+ waddch(win, (chtype) ' ');
+ str = WipeOut(win, y, x, oldstr, str, oldecho);
+ continue;
+ } else if (win->_flags & _WRAPPED) {
+ /*
+ * If the last waddch forced a wrap &
+ * scroll, adjust our reference point
+ * for erasures.
+ */
+ if (win->_scroll
+ && oldy == win->_maxy
+ && win->_cury == win->_maxy) {
+ if (--y <= 0) {
+ y = 0;
+ }
+ }
+ win->_flags &= ~_WRAPPED;
+ }
+ wrefresh(win);
+ }
+ }
+ }
+
+ win->_curx = 0;
+ win->_flags &= ~_WRAPPED;
+ if (win->_cury < win->_maxy)
+ win->_cury++;
+ wrefresh(win);
+
+ /* Restore with a single I/O call, to fix minor asymmetry between
+ * raw/noraw, etc.
+ */
+ SP->_nl = oldnl;
+ SP->_echo = oldecho;
+ SP->_raw = oldraw;
+ SP->_cbreak = oldcbreak;
+
+ _nc_set_tty_mode(&buf);
+
+ *str = '\0';
+ if (ch == ERR)
+ returnCode(ch);
+
+ T(("wgetnstr returns %s", _nc_visbuf(oldstr)));
+
+#ifdef KEY_EVENT
+ if (ch == KEY_EVENT)
+ returnCode(ch);
+#endif
+#ifdef KEY_RESIZE
+ if (ch == KEY_RESIZE)
+ returnCode(ch);
+#endif
+
+ returnCode(OK);
+}
+
+#ifdef NCURSES_WGETCH_EVENTS
+NCURSES_EXPORT(int)
+wgetnstr(WINDOW *win, char *str, int maxlen)
+{
+ returnCode(wgetnstr_events(win,
+ str,
+ maxlen,
+ EVENTLIST_1st((_nc_eventlist *) 0)));
+}
+#endif
diff --git a/ncurses/base/lib_hline.c b/ncurses/base/lib_hline.c
new file mode 100644
index 000000000000..2ef2cc585e10
--- /dev/null
+++ b/ncurses/base/lib_hline.c
@@ -0,0 +1,80 @@
+/****************************************************************************
+ * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_hline.c
+**
+** The routine whline().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_hline.c,v 1.11 2006/03/11 21:52:27 tom Exp $")
+
+NCURSES_EXPORT(int)
+whline(WINDOW *win, chtype ch, int n)
+{
+ int code = ERR;
+ NCURSES_SIZE_T start;
+ NCURSES_SIZE_T end;
+
+ T((T_CALLED("whline(%p,%s,%d)"), win, _tracechtype(ch), n));
+
+ if (win) {
+ struct ldat *line = &(win->_line[win->_cury]);
+ NCURSES_CH_T wch;
+
+ start = win->_curx;
+ end = start + n - 1;
+ if (end > win->_maxx)
+ end = win->_maxx;
+
+ CHANGED_RANGE(line, start, end);
+
+ if (ch == 0)
+ SetChar2(wch, ACS_HLINE);
+ else
+ SetChar2(wch, ch);
+ wch = _nc_render(win, wch);
+
+ while (end >= start) {
+ line->text[end] = wch;
+ end--;
+ }
+
+ _nc_synchook(win);
+ code = OK;
+ }
+ returnCode(code);
+}
diff --git a/ncurses/base/lib_immedok.c b/ncurses/base/lib_immedok.c
new file mode 100644
index 000000000000..87988b66f1a3
--- /dev/null
+++ b/ncurses/base/lib_immedok.c
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_immedok.c
+**
+** The routine immedok.
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_immedok.c,v 1.4 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(void)
+immedok(WINDOW *win, bool flag)
+{
+ T((T_CALLED("immedok(%p,%d)"), win, flag));
+
+ if (win)
+ win->_immed = flag;
+
+ returnVoid;
+}
diff --git a/ncurses/base/lib_inchstr.c b/ncurses/base/lib_inchstr.c
new file mode 100644
index 000000000000..6ff01687826e
--- /dev/null
+++ b/ncurses/base/lib_inchstr.c
@@ -0,0 +1,64 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_inchstr.c
+**
+** The routine winchnstr().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_inchstr.c,v 1.10 2001/06/02 23:37:58 skimo Exp $")
+
+NCURSES_EXPORT(int)
+winchnstr(WINDOW *win, chtype * str, int n)
+{
+ int i = 0;
+
+ T((T_CALLED("winchnstr(%p,%p,%d)"), win, str, n));
+
+ if (!str)
+ returnCode(0);
+
+ if (win) {
+ for (; (n < 0 || (i < n)) && (win->_curx + i <= win->_maxx); i++)
+ str[i] =
+ CharOf(win->_line[win->_cury].text[win->_curx + i]) |
+ AttrOf(win->_line[win->_cury].text[win->_curx + i]);
+ }
+ str[i] = (chtype) 0;
+
+ returnCode(i);
+}
diff --git a/ncurses/base/lib_initscr.c b/ncurses/base/lib_initscr.c
new file mode 100644
index 000000000000..ef360c03b642
--- /dev/null
+++ b/ncurses/base/lib_initscr.c
@@ -0,0 +1,97 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-2003 *
+ ****************************************************************************/
+
+/*
+** lib_initscr.c
+**
+** The routines initscr(), and termname().
+**
+*/
+
+#include <curses.priv.h>
+
+#if HAVE_SYS_TERMIO_H
+#include <sys/termio.h> /* needed for ISC */
+#endif
+
+MODULE_ID("$Id: lib_initscr.c,v 1.36 2008/04/12 18:11:36 tom Exp $")
+
+NCURSES_EXPORT(WINDOW *)
+initscr(void)
+{
+ WINDOW *result;
+
+ NCURSES_CONST char *name;
+
+ START_TRACE();
+ T((T_CALLED("initscr()")));
+
+ _nc_lock_global(set_SP);
+ /* Portable applications must not call initscr() more than once */
+ if (!_nc_globals.init_screen) {
+ _nc_globals.init_screen = TRUE;
+
+ if ((name = getenv("TERM")) == 0
+ || *name == '\0')
+ name = "unknown";
+#ifdef __CYGWIN__
+ /*
+ * 2002/9/21
+ * Work around a bug in Cygwin. Full-screen subprocesses run from
+ * bash, in turn spawned from another full-screen process, will dump
+ * core when attempting to write to stdout. Opening /dev/tty
+ * explicitly seems to fix the problem.
+ */
+ if (isatty(fileno(stdout))) {
+ FILE *fp = fopen("/dev/tty", "w");
+ if (fp != 0 && isatty(fileno(fp))) {
+ fclose(stdout);
+ dup2(fileno(fp), STDOUT_FILENO);
+ stdout = fdopen(STDOUT_FILENO, "w");
+ }
+ }
+#endif
+ if (newterm(name, stdout, stdin) == 0) {
+ fprintf(stderr, "Error opening terminal: %s.\n", name);
+ exit(EXIT_FAILURE);
+ }
+
+ /* def_shell_mode - done in newterm/_nc_setupscreen */
+ def_prog_mode();
+ }
+ result = stdscr;
+ _nc_unlock_global(set_SP);
+
+ returnWin(result);
+}
diff --git a/ncurses/base/lib_insch.c b/ncurses/base/lib_insch.c
new file mode 100644
index 000000000000..9166ea5240e7
--- /dev/null
+++ b/ncurses/base/lib_insch.c
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Sven Verdoolaege *
+ * and: Thomas E. Dickey *
+ ****************************************************************************/
+
+/*
+** lib_insch.c
+**
+** The routine winsch().
+**
+*/
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_insch.c,v 1.25 2008/02/03 00:14:37 tom Exp $")
+
+/*
+ * Insert the given character, updating the current location to simplify
+ * inserting a string.
+ */
+NCURSES_EXPORT(int)
+_nc_insert_ch(WINDOW *win, chtype ch)
+{
+ int code = OK;
+ NCURSES_CH_T wch;
+ int count;
+ NCURSES_CONST char *s;
+
+ switch (ch) {
+ case '\t':
+ for (count = (TABSIZE - (win->_curx % TABSIZE)); count > 0; count--) {
+ if ((code = _nc_insert_ch(win, ' ')) != OK)
+ break;
+ }
+ break;
+ case '\n':
+ case '\r':
+ case '\b':
+ SetChar2(wch, ch);
+ _nc_waddch_nosync(win, wch);
+ break;
+ default:
+ if (
+#if USE_WIDEC_SUPPORT
+ WINDOW_EXT(win, addch_used) == 0 &&
+#endif
+ is8bits(ChCharOf(ch)) &&
+ isprint(ChCharOf(ch))) {
+ if (win->_curx <= win->_maxx) {
+ struct ldat *line = &(win->_line[win->_cury]);
+ NCURSES_CH_T *end = &(line->text[win->_curx]);
+ NCURSES_CH_T *temp1 = &(line->text[win->_maxx]);
+ NCURSES_CH_T *temp2 = temp1 - 1;
+
+ SetChar2(wch, ch);
+
+ CHANGED_TO_EOL(line, win->_curx, win->_maxx);
+ while (temp1 > end)
+ *temp1-- = *temp2--;
+
+ *temp1 = _nc_render(win, wch);
+ win->_curx++;
+ }
+ } else if (is8bits(ChCharOf(ch)) && iscntrl(ChCharOf(ch))) {
+ s = unctrl(ChCharOf(ch));
+ while (*s != '\0') {
+ code = _nc_insert_ch(win, ChAttrOf(ch) | UChar(*s));
+ if (code != OK)
+ break;
+ ++s;
+ }
+ }
+#if USE_WIDEC_SUPPORT
+ else {
+ /*
+ * Handle multibyte characters here
+ */
+ SetChar2(wch, ch);
+ wch = _nc_render(win, wch);
+ count = _nc_build_wch(win, &wch);
+ if (count > 0) {
+ code = wins_wch(win, &wch);
+ } else if (count == -1) {
+ /* handle EILSEQ */
+ if (is8bits(ch)) {
+ s = unctrl(ChCharOf(ch));
+ while (*s != '\0') {
+ code = _nc_insert_ch(win, ChAttrOf(ch) | UChar(*s));
+ if (code != OK)
+ break;
+ ++s;
+ }
+ } else {
+ code = ERR;
+ }
+ }
+ }
+#endif
+ break;
+ }
+ return code;
+}
+
+NCURSES_EXPORT(int)
+winsch(WINDOW *win, chtype c)
+{
+ NCURSES_SIZE_T oy;
+ NCURSES_SIZE_T ox;
+ int code = ERR;
+
+ T((T_CALLED("winsch(%p, %s)"), win, _tracechtype(c)));
+
+ if (win != 0) {
+ oy = win->_cury;
+ ox = win->_curx;
+
+ code = _nc_insert_ch(win, c);
+
+ win->_curx = ox;
+ win->_cury = oy;
+ _nc_synchook(win);
+ }
+ returnCode(code);
+}
diff --git a/ncurses/base/lib_insdel.c b/ncurses/base/lib_insdel.c
new file mode 100644
index 000000000000..342c6541f95f
--- /dev/null
+++ b/ncurses/base/lib_insdel.c
@@ -0,0 +1,63 @@
+/****************************************************************************
+ * Copyright (c) 1998-2001,2003 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_insdel.c
+**
+** The routine winsdelln(win, n).
+** positive n insert n lines above current line
+** negative n delete n lines starting from current line
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_insdel.c,v 1.12 2003/07/26 22:40:06 tom Exp $")
+
+NCURSES_EXPORT(int)
+winsdelln(WINDOW *win, int n)
+{
+ int code = ERR;
+
+ T((T_CALLED("winsdelln(%p,%d)"), win, n));
+
+ if (win) {
+ if (n != 0) {
+ _nc_scroll_window(win, -n, win->_cury, win->_maxy,
+ win->_nc_bkgd);
+ _nc_synchook(win);
+ }
+ code = OK;
+ }
+ returnCode(code);
+}
diff --git a/ncurses/base/lib_insnstr.c b/ncurses/base/lib_insnstr.c
new file mode 100644
index 000000000000..b6ddfde3c52b
--- /dev/null
+++ b/ncurses/base/lib_insnstr.c
@@ -0,0 +1,68 @@
+/****************************************************************************
+ * Copyright (c) 2004 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey *
+ ****************************************************************************/
+
+/*
+** lib_insnstr.c
+**
+** The routine winsnstr().
+**
+*/
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_insnstr.c,v 1.1 2004/02/28 23:44:56 tom Exp $")
+
+NCURSES_EXPORT(int)
+winsnstr(WINDOW *win, const char *s, int n)
+{
+ int code = ERR;
+ NCURSES_SIZE_T oy;
+ NCURSES_SIZE_T ox;
+ const unsigned char *str = (const unsigned char *) s;
+ const unsigned char *cp;
+
+ T((T_CALLED("winsnstr(%p,%s,%d)"), win, _nc_visbufn(s, n), n));
+
+ if (win != 0 && str != 0) {
+ oy = win->_cury;
+ ox = win->_curx;
+ for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) {
+ _nc_insert_ch(win, (chtype) UChar(*cp));
+ }
+ win->_curx = ox;
+ win->_cury = oy;
+ _nc_synchook(win);
+ code = OK;
+ }
+ returnCode(code);
+}
diff --git a/ncurses/base/lib_instr.c b/ncurses/base/lib_instr.c
new file mode 100644
index 000000000000..3fb29490ad06
--- /dev/null
+++ b/ncurses/base/lib_instr.c
@@ -0,0 +1,112 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+** lib_instr.c
+**
+** The routine winnstr().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_instr.c,v 1.16 2007/07/21 20:18:10 tom Exp $")
+
+NCURSES_EXPORT(int)
+winnstr(WINDOW *win, char *str, int n)
+{
+ int i = 0, row, col;
+
+ T((T_CALLED("winnstr(%p,%p,%d)"), win, str, n));
+
+ if (!str)
+ returnCode(0);
+
+ if (win) {
+ getyx(win, row, col);
+
+ if (n < 0)
+ n = win->_maxx - win->_curx + 1;
+
+ for (; i < n;) {
+#if USE_WIDEC_SUPPORT
+ cchar_t *cell = &(win->_line[row].text[col]);
+ wchar_t *wch;
+ attr_t attrs;
+ short pair;
+ int n2;
+ bool done = FALSE;
+ mbstate_t state;
+ size_t i3, n3;
+ char *tmp;
+
+ if (!isWidecExt(*cell)) {
+ n2 = getcchar(cell, 0, 0, 0, 0);
+ if (n2 > 0
+ && (wch = typeCalloc(wchar_t, (unsigned) n2 + 1)) != 0) {
+ if (getcchar(cell, wch, &attrs, &pair, 0) == OK) {
+
+ init_mb(state);
+ n3 = wcstombs(0, wch, 0);
+ if (isEILSEQ(n3) || (n3 == 0)) {
+ ;
+ } else if ((int) (n3 + i) > n) {
+ done = TRUE;
+ } else if ((tmp = typeCalloc(char, n3 + 10)) == 0) {
+ done = TRUE;
+ } else {
+ init_mb(state);
+ wcstombs(tmp, wch, n3);
+ for (i3 = 0; i3 < n3; ++i3)
+ str[i++] = tmp[i3];
+ free(tmp);
+ }
+ }
+ free(wch);
+ if (done)
+ break;
+ }
+ }
+#else
+ str[i++] = (char) CharOf(win->_line[row].text[col]);
+#endif
+ if (++col > win->_maxx) {
+ break;
+ }
+ }
+ }
+ str[i] = '\0'; /* SVr4 does not seem to count the null */
+ T(("winnstr returns %s", _nc_visbuf(str)));
+ returnCode(i);
+}
diff --git a/ncurses/base/lib_isendwin.c b/ncurses/base/lib_isendwin.c
new file mode 100644
index 000000000000..b337d97a94c3
--- /dev/null
+++ b/ncurses/base/lib_isendwin.c
@@ -0,0 +1,51 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_endwin.c
+**
+** The routine endwin().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_isendwin.c,v 1.6 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(bool)
+isendwin(void)
+{
+ if (SP == NULL)
+ return FALSE;
+ return SP->_endwin;
+}
diff --git a/ncurses/base/lib_leaveok.c b/ncurses/base/lib_leaveok.c
new file mode 100644
index 000000000000..17d095d0f8c8
--- /dev/null
+++ b/ncurses/base/lib_leaveok.c
@@ -0,0 +1,55 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_leaveok.c
+**
+** The routine leaveok.
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_leaveok.c,v 1.5 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(int)
+leaveok(WINDOW *win, bool flag)
+{
+ T((T_CALLED("leaveok(%p,%d)"), win, flag));
+
+ if (win) {
+ win->_leaveok = flag;
+ returnCode(OK);
+ } else
+ returnCode(ERR);
+}
diff --git a/ncurses/base/lib_mouse.c b/ncurses/base/lib_mouse.c
new file mode 100644
index 000000000000..aace7deb4c7f
--- /dev/null
+++ b/ncurses/base/lib_mouse.c
@@ -0,0 +1,1367 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+ * This module is intended to encapsulate ncurses's interface to pointing
+ * devices.
+ *
+ * The primary method used is xterm's internal mouse-tracking facility.
+ * Additional methods depend on the platform:
+ * Alessandro Rubini's GPM server (Linux)
+ * sysmouse (FreeBSD)
+ * special-purpose mouse interface for OS/2 EMX.
+ *
+ * Notes for implementors of new mouse-interface methods:
+ *
+ * The code is logically split into a lower level that accepts event reports
+ * in a device-dependent format and an upper level that parses mouse gestures
+ * and filters events. The mediating data structure is a circular queue of
+ * MEVENT structures.
+ *
+ * Functionally, the lower level's job is to pick up primitive events and
+ * put them on the circular queue. This can happen in one of two ways:
+ * either (a) _nc_mouse_event() detects a series of incoming mouse reports
+ * and queues them, or (b) code in lib_getch.c detects the kmous prefix in
+ * the keyboard input stream and calls _nc_mouse_inline to queue up a series
+ * of adjacent mouse reports.
+ *
+ * In either case, _nc_mouse_parse() should be called after the series is
+ * accepted to parse the digested mouse reports (low-level MEVENTs) into
+ * a gesture (a high-level or composite MEVENT).
+ *
+ * Don't be too shy about adding new event types or modifiers, if you can find
+ * room for them in the 32-bit mask. The API is written so that users get
+ * feedback on which theoretical event types they won't see when they call
+ * mousemask. There's one bit per button (the RESERVED_EVENT bit) not being
+ * used yet, and a couple of bits open at the high end.
+ */
+
+#ifdef __EMX__
+# include <io.h>
+# define INCL_DOS
+# define INCL_VIO
+# define INCL_KBD
+# define INCL_MOU
+# define INCL_DOSPROCESS
+# include <os2.h> /* Need to include before the others */
+#endif
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_mouse.c,v 1.88 2007/09/29 21:50:04 tom Exp $")
+
+#include <term.h>
+#include <tic.h>
+
+#if USE_GPM_SUPPORT
+#include <linux/keyboard.h> /* defines KG_* macros */
+
+#ifdef HAVE_LIBDL
+/* use dynamic loader to avoid linkage dependency */
+#include <dlfcn.h>
+
+#ifdef RTLD_NOW
+#define my_RTLD RTLD_NOW
+#else
+#ifdef RTLD_LAZY
+#define my_RTLD RTLD_LAZY
+#else
+make an error
+#endif
+#endif /* RTLD_NOW */
+#endif /* HAVE_LIBDL */
+
+#endif /* USE_GPM_SUPPORT */
+
+#if USE_SYSMOUSE
+#undef buttons /* symbol conflict in consio.h */
+#undef mouse_info /* symbol conflict in consio.h */
+#include <osreldate.h>
+#if (__FreeBSD_version >= 400017)
+#include <sys/consio.h>
+#include <sys/fbio.h>
+#else
+#include <machine/console.h>
+#endif
+#endif /* use_SYSMOUSE */
+
+#define MY_TRACE TRACE_ICALLS|TRACE_IEVENT
+
+#define MASK_RELEASE(x) NCURSES_MOUSE_MASK(x, 001)
+#define MASK_PRESS(x) NCURSES_MOUSE_MASK(x, 002)
+#define MASK_CLICK(x) NCURSES_MOUSE_MASK(x, 004)
+#define MASK_DOUBLE_CLICK(x) NCURSES_MOUSE_MASK(x, 010)
+#define MASK_TRIPLE_CLICK(x) NCURSES_MOUSE_MASK(x, 020)
+#define MASK_RESERVED_EVENT(x) NCURSES_MOUSE_MASK(x, 040)
+
+#if NCURSES_MOUSE_VERSION == 1
+#define BUTTON_CLICKED (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED | BUTTON4_CLICKED)
+#define BUTTON_PRESSED (BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED)
+#define BUTTON_RELEASED (BUTTON1_RELEASED | BUTTON2_RELEASED | BUTTON3_RELEASED | BUTTON4_RELEASED)
+#define BUTTON_DOUBLE_CLICKED (BUTTON1_DOUBLE_CLICKED | BUTTON2_DOUBLE_CLICKED | BUTTON3_DOUBLE_CLICKED | BUTTON4_DOUBLE_CLICKED)
+#define BUTTON_TRIPLE_CLICKED (BUTTON1_TRIPLE_CLICKED | BUTTON2_TRIPLE_CLICKED | BUTTON3_TRIPLE_CLICKED | BUTTON4_TRIPLE_CLICKED)
+#define MAX_BUTTONS 4
+#else
+#define BUTTON_CLICKED (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED | BUTTON4_CLICKED | BUTTON5_CLICKED)
+#define BUTTON_PRESSED (BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED | BUTTON5_PRESSED)
+#define BUTTON_RELEASED (BUTTON1_RELEASED | BUTTON2_RELEASED | BUTTON3_RELEASED | BUTTON4_RELEASED | BUTTON5_RELEASED)
+#define BUTTON_DOUBLE_CLICKED (BUTTON1_DOUBLE_CLICKED | BUTTON2_DOUBLE_CLICKED | BUTTON3_DOUBLE_CLICKED | BUTTON4_DOUBLE_CLICKED | BUTTON5_DOUBLE_CLICKED)
+#define BUTTON_TRIPLE_CLICKED (BUTTON1_TRIPLE_CLICKED | BUTTON2_TRIPLE_CLICKED | BUTTON3_TRIPLE_CLICKED | BUTTON4_TRIPLE_CLICKED | BUTTON5_TRIPLE_CLICKED)
+#define MAX_BUTTONS 5
+#endif
+
+#define INVALID_EVENT -1
+#define NORMAL_EVENT 0
+
+#if USE_GPM_SUPPORT
+
+#ifndef LIBGPM_SONAME
+#define LIBGPM_SONAME "libgpm.so"
+#endif
+
+#define GET_DLSYM(name) (my_##name = (TYPE_##name) dlsym(obj, #name))
+
+#endif /* USE_GPM_SUPPORT */
+
+static bool _nc_mouse_parse(int);
+static void _nc_mouse_resume(SCREEN *);
+static void _nc_mouse_wrap(SCREEN *);
+
+/* maintain a circular list of mouse events */
+
+#undef NEXT
+#define NEXT(ep) ((ep == SP->_mouse_events + EV_MAX - 1) \
+ ? SP->_mouse_events \
+ : ep + 1)
+
+#undef PREV
+#define PREV(ep) ((ep == SP->_mouse_events) \
+ ? SP->_mouse_events + EV_MAX - 1 \
+ : ep - 1)
+
+#ifdef TRACE
+static void
+_trace_slot(const char *tag)
+{
+ MEVENT *ep;
+
+ _tracef(tag);
+
+ for (ep = SP->_mouse_events; ep < SP->_mouse_events + EV_MAX; ep++)
+ _tracef("mouse event queue slot %ld = %s",
+ (long) (ep - SP->_mouse_events),
+ _tracemouse(ep));
+}
+#endif
+
+#if USE_EMX_MOUSE
+
+# define TOP_ROW 0
+# define LEFT_COL 0
+
+# define M_FD(sp) sp->_mouse_fd
+
+static void
+write_event(int down, int button, int x, int y)
+{
+ char buf[6];
+ unsigned long ignore;
+
+ strncpy(buf, key_mouse, 3); /* should be "\033[M" */
+ buf[3] = ' ' + (button - 1) + (down ? 0 : 0x40);
+ buf[4] = ' ' + x - LEFT_COL + 1;
+ buf[5] = ' ' + y - TOP_ROW + 1;
+ DosWrite(SP->_emxmouse_wfd, buf, 6, &ignore);
+}
+
+static void
+mouse_server(unsigned long ignored GCC_UNUSED)
+{
+ unsigned short fWait = MOU_WAIT;
+ /* NOPTRRECT mourt = { 0,0,24,79 }; */
+ MOUEVENTINFO mouev;
+ HMOU hmou;
+ unsigned short mask = MOUSE_BN1_DOWN | MOUSE_BN2_DOWN | MOUSE_BN3_DOWN;
+ int nbuttons = 3;
+ int oldstate = 0;
+ char err[80];
+ unsigned long rc;
+
+ /* open the handle for the mouse */
+ if (MouOpen(NULL, &hmou) == 0) {
+ rc = MouSetEventMask(&mask, hmou);
+ if (rc) { /* retry with 2 buttons */
+ mask = MOUSE_BN1_DOWN | MOUSE_BN2_DOWN;
+ rc = MouSetEventMask(&mask, hmou);
+ nbuttons = 2;
+ }
+ if (rc == 0 && MouDrawPtr(hmou) == 0) {
+ for (;;) {
+ /* sit and wait on the event queue */
+ rc = MouReadEventQue(&mouev, &fWait, hmou);
+ if (rc) {
+ sprintf(err, "Error reading mouse queue, rc=%lu.\r\n", rc);
+ break;
+ }
+ if (!SP->_emxmouse_activated)
+ goto finish;
+
+ /*
+ * OS/2 numbers a 3-button mouse inconsistently from other
+ * platforms:
+ * 1 = left
+ * 2 = right
+ * 3 = middle.
+ */
+ if ((mouev.fs ^ oldstate) & MOUSE_BN1_DOWN)
+ write_event(mouev.fs & MOUSE_BN1_DOWN,
+ SP->_emxmouse_buttons[1], mouev.col, mouev.row);
+ if ((mouev.fs ^ oldstate) & MOUSE_BN2_DOWN)
+ write_event(mouev.fs & MOUSE_BN2_DOWN,
+ SP->_emxmouse_buttons[3], mouev.col, mouev.row);
+ if ((mouev.fs ^ oldstate) & MOUSE_BN3_DOWN)
+ write_event(mouev.fs & MOUSE_BN3_DOWN,
+ SP->_emxmouse_buttons[2], mouev.col, mouev.row);
+
+ finish:
+ oldstate = mouev.fs;
+ }
+ } else
+ sprintf(err, "Error setting event mask, buttons=%d, rc=%lu.\r\n",
+ nbuttons, rc);
+
+ DosWrite(2, err, strlen(err), &rc);
+ MouClose(hmou);
+ }
+ DosExit(EXIT_THREAD, 0L);
+}
+
+#endif /* USE_EMX_MOUSE */
+
+#if USE_SYSMOUSE
+static void
+handle_sysmouse(int sig GCC_UNUSED)
+{
+ struct mouse_info the_mouse;
+ MEVENT *work;
+
+ the_mouse.operation = MOUSE_GETINFO;
+ if (SP != 0
+ && SP->_mouse_fd >= 0
+ && SP->_sysmouse_tail < FIFO_SIZE
+ && ioctl(SP->_mouse_fd, CONS_MOUSECTL, &the_mouse) != -1) {
+
+ if (SP->_sysmouse_head > SP->_sysmouse_tail) {
+ SP->_sysmouse_tail = 0;
+ SP->_sysmouse_head = 0;
+ }
+ work = &(SP->_sysmouse_fifo[SP->_sysmouse_tail]);
+ memset(work, 0, sizeof(*work));
+ work->id = NORMAL_EVENT; /* there's only one mouse... */
+
+ SP->_sysmouse_old_buttons = SP->_sysmouse_new_buttons;
+ SP->_sysmouse_new_buttons = the_mouse.u.data.buttons & 0x7;
+
+ if (SP->_sysmouse_new_buttons) {
+ if (SP->_sysmouse_new_buttons & 1)
+ work->bstate |= BUTTON1_PRESSED;
+ if (SP->_sysmouse_new_buttons & 2)
+ work->bstate |= BUTTON2_PRESSED;
+ if (SP->_sysmouse_new_buttons & 4)
+ work->bstate |= BUTTON3_PRESSED;
+ } else {
+ if (SP->_sysmouse_old_buttons & 1)
+ work->bstate |= BUTTON1_RELEASED;
+ if (SP->_sysmouse_old_buttons & 2)
+ work->bstate |= BUTTON2_RELEASED;
+ if (SP->_sysmouse_old_buttons & 4)
+ work->bstate |= BUTTON3_RELEASED;
+ }
+
+ /* for cosmetic bug in syscons.c on FreeBSD 3.[34] */
+ the_mouse.operation = MOUSE_HIDE;
+ ioctl(SP->_mouse_fd, CONS_MOUSECTL, &the_mouse);
+ the_mouse.operation = MOUSE_SHOW;
+ ioctl(SP->_mouse_fd, CONS_MOUSECTL, &the_mouse);
+
+ /*
+ * We're only interested if the button is pressed or released.
+ * FIXME: implement continuous event-tracking.
+ */
+ if (SP->_sysmouse_new_buttons != SP->_sysmouse_old_buttons) {
+ SP->_sysmouse_tail += 1;
+ }
+ work->x = the_mouse.u.data.x / SP->_sysmouse_char_width;
+ work->y = the_mouse.u.data.y / SP->_sysmouse_char_height;
+ }
+}
+#endif /* USE_SYSMOUSE */
+
+static void
+init_xterm_mouse(void)
+{
+ SP->_mouse_type = M_XTERM;
+ SP->_mouse_xtermcap = tigetstr("XM");
+ if (!VALID_STRING(SP->_mouse_xtermcap))
+ SP->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";
+}
+
+static void
+enable_xterm_mouse(int enable)
+{
+#if USE_EMX_MOUSE
+ SP->_emxmouse_activated = enable;
+#else
+ putp(TPARM_1(SP->_mouse_xtermcap, enable));
+#endif
+ SP->_mouse_active = enable;
+}
+
+#if USE_GPM_SUPPORT
+static int
+allow_gpm_mouse(void)
+{
+ /* GPM does printf's without checking if stdout is a terminal */
+ if (isatty(fileno(stdout))) {
+ char *env = getenv("TERM");
+ /* GPM checks the beginning of the $TERM variable to decide if
+ * it should pass xterm events through. There is no real advantage
+ * in allowing GPM to do this.
+ */
+ if (env == 0 || strncmp(env, "xterm", 5))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static bool
+enable_gpm_mouse(int enable)
+{
+ bool result;
+
+ T((T_CALLED("enable_gpm_mouse(%d)"), enable));
+
+ if (enable && !SP->_mouse_active) {
+ /* GPM: initialize connection to gpm server */
+ SP->_mouse_gpm_connect.eventMask = GPM_DOWN | GPM_UP;
+ SP->_mouse_gpm_connect.defaultMask =
+ ~(SP->_mouse_gpm_connect.eventMask | GPM_HARD);
+ SP->_mouse_gpm_connect.minMod = 0;
+ SP->_mouse_gpm_connect.maxMod =
+ (unsigned short) (~((1 << KG_SHIFT) |
+ (1 << KG_SHIFTL) |
+ (1 << KG_SHIFTR)));
+ /*
+ * Note: GPM hardcodes \E[?1001s and \E[?1000h during its open.
+ * The former is recognized by wscons (SunOS), and the latter by
+ * xterm. Those will not show up in ncurses' traces.
+ */
+ result = (my_Gpm_Open(&SP->_mouse_gpm_connect, 0) >= 0);
+ SP->_mouse_active = result;
+ T(("GPM open %s", result ? "succeeded" : "failed"));
+ } else {
+ if (!enable && SP->_mouse_active) {
+ /* GPM: close connection to gpm server */
+ my_Gpm_Close();
+ SP->_mouse_active = FALSE;
+ T(("GPM closed"));
+ }
+ result = FALSE;
+ }
+ returnBool(result);
+}
+#endif /* USE_GPM_SUPPORT */
+
+#define xterm_kmous "\033[M"
+
+static void
+initialize_mousetype(void)
+{
+ T((T_CALLED("initialize_mousetype()")));
+
+ /* Try gpm first, because gpm may be configured to run in xterm */
+#if USE_GPM_SUPPORT
+ if (allow_gpm_mouse()) {
+ if (!SP->_mouse_gpm_loaded) {
+#ifdef HAVE_LIBDL
+ void *obj;
+
+ if ((obj = dlopen(LIBGPM_SONAME, my_RTLD)) != 0) {
+ if (GET_DLSYM(gpm_fd) == 0 ||
+ GET_DLSYM(Gpm_Open) == 0 ||
+ GET_DLSYM(Gpm_Close) == 0 ||
+ GET_DLSYM(Gpm_GetEvent) == 0) {
+ T(("GPM initialization failed: %s", dlerror()));
+ dlclose(obj);
+ } else {
+ SP->_mouse_gpm_found = TRUE;
+ }
+ }
+#else /* !HAVE_LIBDL */
+ SP->_mouse_gpm_found = TRUE;
+#endif
+ SP->_mouse_gpm_loaded = TRUE;
+ }
+
+ /*
+ * The gpm_fd file-descriptor may be negative (xterm). So we have to
+ * maintain our notion of whether the mouse connection is active
+ * without testing the file-descriptor.
+ */
+ if (SP->_mouse_gpm_found && enable_gpm_mouse(TRUE)) {
+ SP->_mouse_type = M_GPM;
+ SP->_mouse_fd = *(my_gpm_fd);
+ T(("GPM mouse_fd %d", SP->_mouse_fd));
+ returnVoid;
+ }
+ }
+#endif /* USE_GPM_SUPPORT */
+
+ /* OS/2 VIO */
+#if USE_EMX_MOUSE
+ if (!SP->_emxmouse_thread
+ && strstr(cur_term->type.term_names, "xterm") == 0
+ && key_mouse) {
+ int handles[2];
+
+ if (pipe(handles) < 0) {
+ perror("mouse pipe error");
+ returnVoid;
+ } else {
+ int rc;
+
+ if (!SP->_emxmouse_buttons[0]) {
+ char *s = getenv("MOUSE_BUTTONS_123");
+
+ SP->_emxmouse_buttons[0] = 1;
+ if (s && strlen(s) >= 3) {
+ SP->_emxmouse_buttons[1] = s[0] - '0';
+ SP->_emxmouse_buttons[2] = s[1] - '0';
+ SP->_emxmouse_buttons[3] = s[2] - '0';
+ } else {
+ SP->_emxmouse_buttons[1] = 1;
+ SP->_emxmouse_buttons[2] = 3;
+ SP->_emxmouse_buttons[3] = 2;
+ }
+ }
+ SP->_emxmouse_wfd = handles[1];
+ M_FD(SP) = handles[0];
+ /* Needed? */
+ setmode(handles[0], O_BINARY);
+ setmode(handles[1], O_BINARY);
+ /* Do not use CRT functions, we may single-threaded. */
+ rc = DosCreateThread((unsigned long *) &SP->_emxmouse_thread,
+ mouse_server, 0, 0, 8192);
+ if (rc) {
+ printf("mouse thread error %d=%#x", rc, rc);
+ } else {
+ SP->_mouse_type = M_XTERM;
+ }
+ returnVoid;
+ }
+ }
+#endif /* USE_EMX_MOUSE */
+
+#if USE_SYSMOUSE
+ {
+ struct mouse_info the_mouse;
+ char *the_device = 0;
+
+ if (isatty(SP->_ifd))
+ the_device = ttyname(SP->_ifd);
+ if (the_device == 0)
+ the_device = "/dev/tty";
+
+ SP->_mouse_fd = open(the_device, O_RDWR);
+
+ if (SP->_mouse_fd >= 0) {
+ /*
+ * sysmouse does not have a usable user interface for obtaining
+ * mouse events. The logical way to proceed (reading data on a
+ * stream) only works if one opens the device as root. Even in
+ * that mode, careful examination shows we lose events
+ * occasionally. The interface provided for user programs is to
+ * establish a signal handler. really.
+ *
+ * Take over SIGUSR2 for this purpose since SIGUSR1 is more
+ * likely to be used by an application. getch() will have to
+ * handle the misleading EINTR's.
+ */
+ signal(SIGUSR2, SIG_IGN);
+ the_mouse.operation = MOUSE_MODE;
+ the_mouse.u.mode.mode = 0;
+ the_mouse.u.mode.signal = SIGUSR2;
+ if (ioctl(SP->_mouse_fd, CONS_MOUSECTL, &the_mouse) != -1) {
+ signal(SIGUSR2, handle_sysmouse);
+ the_mouse.operation = MOUSE_SHOW;
+ ioctl(SP->_mouse_fd, CONS_MOUSECTL, &the_mouse);
+
+#if defined(FBIO_MODEINFO) || defined(CONS_MODEINFO) /* FreeBSD > 2.x */
+ {
+#ifndef FBIO_GETMODE /* FreeBSD 3.x */
+#define FBIO_GETMODE CONS_GET
+#define FBIO_MODEINFO CONS_MODEINFO
+#endif /* FBIO_GETMODE */
+ video_info_t the_video;
+
+ if (ioctl(SP->_mouse_fd,
+ FBIO_GETMODE,
+ &the_video.vi_mode) != -1
+ && ioctl(SP->_mouse_fd,
+ FBIO_MODEINFO,
+ &the_video) != -1) {
+ SP->_sysmouse_char_width = the_video.vi_cwidth;
+ SP->_sysmouse_char_height = the_video.vi_cheight;
+ }
+ }
+#endif /* defined(FBIO_MODEINFO) || defined(CONS_MODEINFO) */
+
+ if (SP->_sysmouse_char_width <= 0)
+ SP->_sysmouse_char_width = 8;
+ if (SP->_sysmouse_char_height <= 0)
+ SP->_sysmouse_char_height = 16;
+ SP->_mouse_type = M_SYSMOUSE;
+ returnVoid;
+ }
+ }
+ }
+#endif /* USE_SYSMOUSE */
+
+ /* we know how to recognize mouse events under "xterm" */
+ if (key_mouse != 0) {
+ if (!strcmp(key_mouse, xterm_kmous)
+ || strstr(cur_term->type.term_names, "xterm") != 0) {
+ init_xterm_mouse();
+ }
+ } else if (strstr(cur_term->type.term_names, "xterm") != 0) {
+ if (_nc_add_to_try(&(SP->_keytry), xterm_kmous, KEY_MOUSE) == OK)
+ init_xterm_mouse();
+ }
+ returnVoid;
+}
+
+static bool
+_nc_mouse_init(void)
+/* initialize the mouse */
+{
+ bool result = FALSE;
+ int i;
+
+ if (SP != 0) {
+ if (!SP->_mouse_initialized) {
+ SP->_mouse_initialized = TRUE;
+
+ TR(MY_TRACE, ("_nc_mouse_init() called"));
+
+ SP->_mouse_eventp = SP->_mouse_events;
+ for (i = 0; i < EV_MAX; i++)
+ SP->_mouse_events[i].id = INVALID_EVENT;
+
+ initialize_mousetype();
+
+ T(("_nc_mouse_init() set mousetype to %d", SP->_mouse_type));
+ }
+ result = SP->_mouse_initialized;
+ }
+ return result;
+}
+
+/*
+ * Query to see if there is a pending mouse event. This is called from
+ * fifo_push() in lib_getch.c
+ */
+static bool
+_nc_mouse_event(SCREEN *sp GCC_UNUSED)
+{
+ MEVENT *eventp = SP->_mouse_eventp;
+ bool result = FALSE;
+
+ (void) eventp;
+
+ switch (SP->_mouse_type) {
+ case M_XTERM:
+ /* xterm: never have to query, mouse events are in the keyboard stream */
+#if USE_EMX_MOUSE
+ {
+ char kbuf[3];
+
+ int i, res = read(M_FD(sp), &kbuf, 3); /* Eat the prefix */
+ if (res != 3)
+ printf("Got %d chars instead of 3 for prefix.\n", res);
+ for (i = 0; i < res; i++) {
+ if (kbuf[i] != key_mouse[i])
+ printf("Got char %d instead of %d for prefix.\n",
+ (int) kbuf[i], (int) key_mouse[i]);
+ }
+ result = TRUE;
+ }
+#endif /* USE_EMX_MOUSE */
+ break;
+
+#if USE_GPM_SUPPORT
+ case M_GPM:
+ {
+ /* query server for event, return TRUE if we find one */
+ Gpm_Event ev;
+
+ if (my_Gpm_GetEvent(&ev) == 1) {
+ /* there's only one mouse... */
+ eventp->id = NORMAL_EVENT;
+
+ eventp->bstate = 0;
+ switch (ev.type & 0x0f) {
+ case (GPM_DOWN):
+ if (ev.buttons & GPM_B_LEFT)
+ eventp->bstate |= BUTTON1_PRESSED;
+ if (ev.buttons & GPM_B_MIDDLE)
+ eventp->bstate |= BUTTON2_PRESSED;
+ if (ev.buttons & GPM_B_RIGHT)
+ eventp->bstate |= BUTTON3_PRESSED;
+ break;
+ case (GPM_UP):
+ if (ev.buttons & GPM_B_LEFT)
+ eventp->bstate |= BUTTON1_RELEASED;
+ if (ev.buttons & GPM_B_MIDDLE)
+ eventp->bstate |= BUTTON2_RELEASED;
+ if (ev.buttons & GPM_B_RIGHT)
+ eventp->bstate |= BUTTON3_RELEASED;
+ break;
+ default:
+ break;
+ }
+
+ eventp->x = ev.x - 1;
+ eventp->y = ev.y - 1;
+ eventp->z = 0;
+
+ /* bump the next-free pointer into the circular list */
+ SP->_mouse_eventp = eventp = NEXT(eventp);
+ result = TRUE;
+ }
+ }
+ break;
+#endif
+
+#if USE_SYSMOUSE
+ case M_SYSMOUSE:
+ if (SP->_sysmouse_head < SP->_sysmouse_tail) {
+ *eventp = SP->_sysmouse_fifo[SP->_sysmouse_head];
+
+ /*
+ * Point the fifo-head to the next possible location. If there
+ * are none, reset the indices. This may be interrupted by the
+ * signal handler, doing essentially the same reset.
+ */
+ SP->_sysmouse_head += 1;
+ if (SP->_sysmouse_head == SP->_sysmouse_tail) {
+ SP->_sysmouse_tail = 0;
+ SP->_sysmouse_head = 0;
+ }
+
+ /* bump the next-free pointer into the circular list */
+ SP->_mouse_eventp = eventp = NEXT(eventp);
+ result = TRUE;
+ }
+ break;
+#endif /* USE_SYSMOUSE */
+
+ case M_NONE:
+ break;
+ }
+
+ return result; /* true if we found an event */
+}
+
+static bool
+_nc_mouse_inline(SCREEN *sp)
+/* mouse report received in the keyboard stream -- parse its info */
+{
+ int b;
+ bool result = FALSE;
+ MEVENT *eventp = SP->_mouse_eventp;
+
+ TR(MY_TRACE, ("_nc_mouse_inline() called"));
+
+ if (SP->_mouse_type == M_XTERM) {
+ unsigned char kbuf[4];
+ mmask_t prev;
+ size_t grabbed;
+ int res;
+
+ /* This code requires that your xterm entry contain the kmous
+ * capability and that it be set to the \E[M documented in the
+ * Xterm Control Sequences reference. This is how we
+ * arrange for mouse events to be reported via a KEY_MOUSE
+ * return value from wgetch(). After this value is received,
+ * _nc_mouse_inline() gets called and is immediately
+ * responsible for parsing the mouse status information
+ * following the prefix.
+ *
+ * The following quotes from the ctrlseqs.ms document in the
+ * X distribution, describing the X mouse tracking feature:
+ *
+ * Parameters for all mouse tracking escape sequences
+ * generated by xterm encode numeric parameters in a single
+ * character as value+040. For example, ! is 1.
+ *
+ * On button press or release, xterm sends ESC [ M CbCxCy.
+ * The low two bits of Cb encode button information: 0=MB1
+ * pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release. The
+ * upper bits encode what modifiers were down when the
+ * button was pressed and are added together. 4=Shift,
+ * 8=Meta, 16=Control. Cx and Cy are the x and y coordinates
+ * of the mouse event. The upper left corner is (1,1).
+ *
+ * (End quote) By the time we get here, we've eaten the
+ * key prefix. FYI, the loop below is necessary because
+ * mouse click info isn't guaranteed to present as a
+ * single clist item.
+ *
+ * Wheel mice may return buttons 4 and 5 when the wheel is turned.
+ * We encode those as button presses.
+ */
+ for (grabbed = 0; grabbed < 3; grabbed += res) {
+
+ /* For VIO mouse we add extra bit 64 to disambiguate button-up. */
+#if USE_EMX_MOUSE
+ res = read(M_FD(sp) >= 0 ? M_FD(sp) : sp->_ifd, &kbuf, 3);
+#else
+ res = read(sp->_ifd, kbuf + grabbed, 3 - grabbed);
+#endif
+ if (res == -1)
+ break;
+ }
+ kbuf[3] = '\0';
+
+ TR(TRACE_IEVENT,
+ ("_nc_mouse_inline sees the following xterm data: '%s'", kbuf));
+
+ /* there's only one mouse... */
+ eventp->id = NORMAL_EVENT;
+
+ /* processing code goes here */
+ eventp->bstate = 0;
+ prev = PREV(eventp)->bstate;
+
+#if USE_EMX_MOUSE
+#define PRESS_POSITION(n) \
+ eventp->bstate = MASK_PRESS(n); \
+ if (kbuf[0] & 0x40) \
+ eventp->bstate = MASK_RELEASE(n)
+#else
+#define PRESS_POSITION(n) \
+ eventp->bstate = (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",
+ _tracemouse(eventp),
+ (long) (eventp - SP->_mouse_events)));
+
+ /* bump the next-free pointer into the circular list */
+ SP->_mouse_eventp = NEXT(eventp);
+#if 0 /* this return would be needed for QNX's mods to lib_getch.c */
+ return (TRUE);
+#endif
+ }
+
+ return (result);
+}
+
+static void
+mouse_activate(bool on)
+{
+ if (!on && !SP->_mouse_initialized)
+ return;
+
+ if (!_nc_mouse_init())
+ return;
+
+ if (on) {
+
+ switch (SP->_mouse_type) {
+ case M_XTERM:
+#if NCURSES_EXT_FUNCS
+ keyok(KEY_MOUSE, on);
+#endif
+ TPUTS_TRACE("xterm mouse initialization");
+ enable_xterm_mouse(1);
+ break;
+#if USE_GPM_SUPPORT
+ case M_GPM:
+ if (enable_gpm_mouse(1)) {
+ SP->_mouse_fd = *(my_gpm_fd);
+ T(("GPM mouse_fd %d", SP->_mouse_fd));
+ }
+ break;
+#endif
+#if USE_SYSMOUSE
+ case M_SYSMOUSE:
+ signal(SIGUSR2, handle_sysmouse);
+ SP->_mouse_active = TRUE;
+ break;
+#endif
+ case M_NONE:
+ return;
+ }
+ /* Make runtime binding to cut down on object size of applications that
+ * do not use the mouse (e.g., 'clear').
+ */
+ SP->_mouse_event = _nc_mouse_event;
+ SP->_mouse_inline = _nc_mouse_inline;
+ SP->_mouse_parse = _nc_mouse_parse;
+ SP->_mouse_resume = _nc_mouse_resume;
+ SP->_mouse_wrap = _nc_mouse_wrap;
+ } else {
+
+ switch (SP->_mouse_type) {
+ case M_XTERM:
+ TPUTS_TRACE("xterm mouse deinitialization");
+ enable_xterm_mouse(0);
+ break;
+#if USE_GPM_SUPPORT
+ case M_GPM:
+ enable_gpm_mouse(0);
+ break;
+#endif
+#if USE_SYSMOUSE
+ case M_SYSMOUSE:
+ signal(SIGUSR2, SIG_IGN);
+ SP->_mouse_active = FALSE;
+ break;
+#endif
+ case M_NONE:
+ return;
+ }
+ }
+ _nc_flush();
+}
+
+/**************************************************************************
+ *
+ * Device-independent code
+ *
+ **************************************************************************/
+
+static bool
+_nc_mouse_parse(int runcount)
+/* parse a run of atomic mouse events into a gesture */
+{
+ MEVENT *eventp = SP->_mouse_eventp;
+ MEVENT *ep, *runp, *next, *prev = PREV(eventp);
+ int n;
+ int b;
+ bool merge;
+
+ TR(MY_TRACE, ("_nc_mouse_parse(%d) called", runcount));
+
+ /*
+ * When we enter this routine, the event list next-free pointer
+ * points just past a run of mouse events that we know were separated
+ * in time by less than the critical click interval. The job of this
+ * routine is to collapse this run into a single higher-level event
+ * or gesture.
+ *
+ * We accomplish this in two passes. The first pass merges press/release
+ * pairs into click events. The second merges runs of click events into
+ * double or triple-click events.
+ *
+ * It's possible that the run may not resolve to a single event (for
+ * example, if the user quadruple-clicks). If so, leading events
+ * in the run are ignored.
+ *
+ * Note that this routine is independent of the format of the specific
+ * format of the pointing-device's reports. We can use it to parse
+ * gestures on anything that reports press/release events on a per-
+ * button basis, as long as the device-dependent mouse code puts stuff
+ * on the queue in MEVENT format.
+ */
+ if (runcount == 1) {
+ TR(MY_TRACE,
+ ("_nc_mouse_parse: returning simple mouse event %s at slot %ld",
+ _tracemouse(prev),
+ (long) (prev - SP->_mouse_events)));
+ return (prev->id >= NORMAL_EVENT)
+ ? ((prev->bstate & SP->_mouse_mask) ? TRUE : FALSE)
+ : FALSE;
+ }
+
+ /* find the start of the run */
+ runp = eventp;
+ for (n = runcount; n > 0; n--) {
+ runp = PREV(runp);
+ }
+
+#ifdef TRACE
+ if (USE_TRACEF(TRACE_IEVENT)) {
+ _trace_slot("before mouse press/release merge:");
+ _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
+ (long) (runp - SP->_mouse_events),
+ (long) ((eventp - SP->_mouse_events) + (EV_MAX - 1)) % EV_MAX,
+ runcount);
+ _nc_unlock_global(tracef);
+ }
+#endif /* TRACE */
+
+ /* first pass; merge press/release pairs */
+ do {
+ merge = FALSE;
+ for (ep = runp; (next = NEXT(ep)) != eventp; ep = next) {
+
+#define MASK_CHANGED(x) (!(ep->bstate & MASK_PRESS(x)) \
+ == !(next->bstate & MASK_RELEASE(x)))
+
+ if (ep->x == next->x && ep->y == next->y
+ && (ep->bstate & BUTTON_PRESSED)
+ && MASK_CHANGED(1)
+ && MASK_CHANGED(2)
+ && MASK_CHANGED(3)
+ && MASK_CHANGED(4)
+#if NCURSES_MOUSE_VERSION == 2
+ && MASK_CHANGED(5)
+#endif
+ ) {
+ for (b = 1; b <= MAX_BUTTONS; ++b) {
+ if ((SP->_mouse_mask & MASK_CLICK(b))
+ && (ep->bstate & MASK_PRESS(b))) {
+ ep->bstate &= ~MASK_PRESS(b);
+ ep->bstate |= MASK_CLICK(b);
+ merge = TRUE;
+ }
+ }
+ if (merge)
+ next->id = INVALID_EVENT;
+ }
+ }
+ } while
+ (merge);
+
+#ifdef TRACE
+ if (USE_TRACEF(TRACE_IEVENT)) {
+ _trace_slot("before mouse click merge:");
+ _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
+ (long) (runp - SP->_mouse_events),
+ (long) ((eventp - SP->_mouse_events) + (EV_MAX - 1)) % EV_MAX,
+ runcount);
+ _nc_unlock_global(tracef);
+ }
+#endif /* TRACE */
+
+ /*
+ * Second pass; merge click runs. At this point, click events are
+ * each followed by one invalid event. We merge click events
+ * forward in the queue.
+ *
+ * NOTE: There is a problem with this design! If the application
+ * allows enough click events to pile up in the circular queue so
+ * they wrap around, it will cheerfully merge the newest forward
+ * into the oldest, creating a bogus doubleclick and confusing
+ * the queue-traversal logic rather badly. Generally this won't
+ * happen, because calling getmouse() marks old events invalid and
+ * ineligible for merges. The true solution to this problem would
+ * be to timestamp each MEVENT and perform the obvious sanity check,
+ * but the timer element would have to have sub-second resolution,
+ * which would get us into portability trouble.
+ */
+ do {
+ MEVENT *follower;
+
+ merge = FALSE;
+ for (ep = runp; (next = NEXT(ep)) != eventp; ep = next)
+ if (ep->id != INVALID_EVENT) {
+ if (next->id != INVALID_EVENT)
+ continue;
+ follower = NEXT(next);
+ if (follower->id == INVALID_EVENT)
+ continue;
+
+ /* merge click events forward */
+ if ((ep->bstate & BUTTON_CLICKED)
+ && (follower->bstate & BUTTON_CLICKED)) {
+ for (b = 1; b <= MAX_BUTTONS; ++b) {
+ if ((SP->_mouse_mask & MASK_DOUBLE_CLICK(b))
+ && (follower->bstate & MASK_CLICK(b))) {
+ follower->bstate &= ~MASK_CLICK(b);
+ follower->bstate |= MASK_DOUBLE_CLICK(b);
+ merge = TRUE;
+ }
+ }
+ if (merge)
+ ep->id = INVALID_EVENT;
+ }
+
+ /* merge double-click events forward */
+ if ((ep->bstate & BUTTON_DOUBLE_CLICKED)
+ && (follower->bstate & BUTTON_CLICKED)) {
+ for (b = 1; b <= MAX_BUTTONS; ++b) {
+ if ((SP->_mouse_mask & MASK_TRIPLE_CLICK(b))
+ && (follower->bstate & MASK_CLICK(b))) {
+ follower->bstate &= ~MASK_CLICK(b);
+ follower->bstate |= MASK_TRIPLE_CLICK(b);
+ merge = TRUE;
+ }
+ }
+ if (merge)
+ ep->id = INVALID_EVENT;
+ }
+ }
+ } while
+ (merge);
+
+#ifdef TRACE
+ if (USE_TRACEF(TRACE_IEVENT)) {
+ _trace_slot("before mouse event queue compaction:");
+ _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
+ (long) (runp - SP->_mouse_events),
+ (long) ((eventp - SP->_mouse_events) + (EV_MAX - 1)) % EV_MAX,
+ runcount);
+ _nc_unlock_global(tracef);
+ }
+#endif /* TRACE */
+
+ /*
+ * Now try to throw away trailing events flagged invalid, or that
+ * don't match the current event mask.
+ */
+ for (; runcount; prev = PREV(eventp), runcount--)
+ if (prev->id == INVALID_EVENT || !(prev->bstate & SP->_mouse_mask)) {
+ SP->_mouse_eventp = eventp = prev;
+ }
+#ifdef TRACE
+ if (USE_TRACEF(TRACE_IEVENT)) {
+ _trace_slot("after mouse event queue compaction:");
+ _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
+ (long) (runp - SP->_mouse_events),
+ (long) ((eventp - SP->_mouse_events) + (EV_MAX - 1)) % EV_MAX,
+ runcount);
+ _nc_unlock_global(tracef);
+ }
+ for (ep = runp; ep != eventp; ep = NEXT(ep))
+ if (ep->id != INVALID_EVENT)
+ TR(MY_TRACE,
+ ("_nc_mouse_parse: returning composite mouse event %s at slot %ld",
+ _tracemouse(ep),
+ (long) (ep - SP->_mouse_events)));
+#endif /* TRACE */
+
+ /* after all this, do we have a valid event? */
+ return (PREV(eventp)->id != INVALID_EVENT);
+}
+
+static void
+_nc_mouse_wrap(SCREEN *sp GCC_UNUSED)
+/* release mouse -- called by endwin() before shellout/exit */
+{
+ TR(MY_TRACE, ("_nc_mouse_wrap() called"));
+
+ switch (SP->_mouse_type) {
+ case M_XTERM:
+ if (SP->_mouse_mask)
+ mouse_activate(FALSE);
+ break;
+#if USE_GPM_SUPPORT
+ /* GPM: pass all mouse events to next client */
+ case M_GPM:
+ if (SP->_mouse_mask)
+ mouse_activate(FALSE);
+ break;
+#endif
+#if USE_SYSMOUSE
+ case M_SYSMOUSE:
+ mouse_activate(FALSE);
+ break;
+#endif
+ case M_NONE:
+ break;
+ }
+}
+
+static void
+_nc_mouse_resume(SCREEN *sp GCC_UNUSED)
+/* re-connect to mouse -- called by doupdate() after shellout */
+{
+ TR(MY_TRACE, ("_nc_mouse_resume() called"));
+
+ switch (SP->_mouse_type) {
+ case M_XTERM:
+ /* xterm: re-enable reporting */
+ if (SP->_mouse_mask)
+ mouse_activate(TRUE);
+ break;
+
+#if USE_GPM_SUPPORT
+ case M_GPM:
+ /* GPM: reclaim our event set */
+ if (SP->_mouse_mask)
+ mouse_activate(TRUE);
+ break;
+#endif
+
+#if USE_SYSMOUSE
+ case M_SYSMOUSE:
+ mouse_activate(TRUE);
+ break;
+#endif
+ case M_NONE:
+ break;
+ }
+}
+
+/**************************************************************************
+ *
+ * Mouse interface entry points for the API
+ *
+ **************************************************************************/
+
+NCURSES_EXPORT(int)
+getmouse(MEVENT * aevent)
+/* grab a copy of the current mouse event */
+{
+ T((T_CALLED("getmouse(%p)"), aevent));
+
+ if ((aevent != 0) && (SP != 0) && (SP->_mouse_type != M_NONE)) {
+ MEVENT *eventp = SP->_mouse_eventp;
+ /* compute the current-event pointer */
+ MEVENT *prev = PREV(eventp);
+
+ /* copy the event we find there */
+ *aevent = *prev;
+
+ TR(TRACE_IEVENT, ("getmouse: returning event %s from slot %ld",
+ _tracemouse(prev),
+ (long) (prev - SP->_mouse_events)));
+
+ prev->id = INVALID_EVENT; /* so the queue slot becomes free */
+ returnCode(OK);
+ }
+ returnCode(ERR);
+}
+
+NCURSES_EXPORT(int)
+ungetmouse(MEVENT * aevent)
+/* enqueue a synthesized mouse event to be seen by the next wgetch() */
+{
+ int result = ERR;
+
+ T((T_CALLED("ungetmouse(%p)"), aevent));
+
+ if (aevent != 0 && SP != 0) {
+ MEVENT *eventp = SP->_mouse_eventp;
+
+ /* stick the given event in the next-free slot */
+ *eventp = *aevent;
+
+ /* bump the next-free pointer into the circular list */
+ SP->_mouse_eventp = NEXT(eventp);
+
+ /* push back the notification event on the keyboard queue */
+ result = ungetch(KEY_MOUSE);
+ }
+ returnCode(result);
+}
+
+NCURSES_EXPORT(mmask_t)
+mousemask(mmask_t newmask, mmask_t * oldmask)
+/* set the mouse event mask */
+{
+ mmask_t result = 0;
+
+ T((T_CALLED("mousemask(%#lx,%p)"), (unsigned long) newmask, oldmask));
+
+ if (SP != 0) {
+ if (oldmask)
+ *oldmask = SP->_mouse_mask;
+
+ if (newmask || SP->_mouse_initialized) {
+ _nc_mouse_init();
+ if (SP->_mouse_type != M_NONE) {
+ result = newmask &
+ (REPORT_MOUSE_POSITION
+ | BUTTON_ALT
+ | BUTTON_CTRL
+ | BUTTON_SHIFT
+ | BUTTON_PRESSED
+ | BUTTON_RELEASED
+ | BUTTON_CLICKED
+ | BUTTON_DOUBLE_CLICKED
+ | BUTTON_TRIPLE_CLICKED);
+
+ mouse_activate((bool) (result != 0));
+
+ SP->_mouse_mask = result;
+ }
+ }
+ } else {
+ if (oldmask)
+ *oldmask = SP->_mouse_mask;
+ }
+ returnBits(result);
+}
+
+NCURSES_EXPORT(bool)
+wenclose(const WINDOW *win, int y, int x)
+/* check to see if given window encloses given screen location */
+{
+ bool result = FALSE;
+
+ T((T_CALLED("wenclose(%p,%d,%d)"), win, y, x));
+
+ if (win != 0) {
+ y -= win->_yoffset;
+ result = ((win->_begy <= y &&
+ win->_begx <= x &&
+ (win->_begx + win->_maxx) >= x &&
+ (win->_begy + win->_maxy) >= y) ? TRUE : FALSE);
+ }
+ returnBool(result);
+}
+
+NCURSES_EXPORT(int)
+mouseinterval(int maxclick)
+/* set the maximum mouse interval within which to recognize a click */
+{
+ int oldval;
+
+ T((T_CALLED("mouseinterval(%d)"), maxclick));
+
+ if (SP != 0) {
+ oldval = SP->_maxclick;
+ if (maxclick >= 0)
+ SP->_maxclick = maxclick;
+ } else {
+ oldval = DEFAULT_MAXCLICK;
+ }
+
+ returnCode(oldval);
+}
+
+/* This may be used by other routines to ask for the existence of mouse
+ support */
+NCURSES_EXPORT(int)
+_nc_has_mouse(void)
+{
+ return (SP->_mouse_type == M_NONE ? 0 : 1);
+}
+
+NCURSES_EXPORT(bool)
+wmouse_trafo(const WINDOW *win, int *pY, int *pX, bool to_screen)
+{
+ bool result = FALSE;
+
+ T((T_CALLED("wmouse_trafo(%p,%p,%p,%d)"), win, pY, pX, to_screen));
+
+ if (win && pY && pX) {
+ int y = *pY;
+ int x = *pX;
+
+ if (to_screen) {
+ y += win->_begy + win->_yoffset;
+ x += win->_begx;
+ if (wenclose(win, y, x))
+ result = TRUE;
+ } else {
+ if (wenclose(win, y, x)) {
+ y -= (win->_begy + win->_yoffset);
+ x -= win->_begx;
+ result = TRUE;
+ }
+ }
+ if (result) {
+ *pX = x;
+ *pY = y;
+ }
+ }
+ returnBool(result);
+}
diff --git a/ncurses/base/lib_move.c b/ncurses/base/lib_move.c
new file mode 100644
index 000000000000..652c44d7b718
--- /dev/null
+++ b/ncurses/base/lib_move.c
@@ -0,0 +1,60 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2004 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+** lib_move.c
+**
+** The routine wmove().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_move.c,v 1.12 2004/12/04 21:50:07 tom Exp $")
+
+NCURSES_EXPORT(int)
+wmove(WINDOW *win, int y, int x)
+{
+ T((T_CALLED("wmove(%p,%d,%d)"), win, y, x));
+
+ if (LEGALYX(win, y, x)) {
+ win->_curx = (NCURSES_SIZE_T) x;
+ win->_cury = (NCURSES_SIZE_T) y;
+
+ win->_flags &= ~_WRAPPED;
+ win->_flags |= _HASMOVED;
+ returnCode(OK);
+ } else
+ returnCode(ERR);
+}
diff --git a/ncurses/base/lib_mvwin.c b/ncurses/base/lib_mvwin.c
new file mode 100644
index 000000000000..e4dad4a746f0
--- /dev/null
+++ b/ncurses/base/lib_mvwin.c
@@ -0,0 +1,114 @@
+/****************************************************************************
+ * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_mvwin.c
+**
+** The routine mvwin().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_mvwin.c,v 1.14 2006/02/25 22:53:46 tom Exp $")
+
+NCURSES_EXPORT(int)
+mvwin(WINDOW *win, int by, int bx)
+{
+ T((T_CALLED("mvwin(%p,%d,%d)"), win, by, bx));
+
+ if (!win || (win->_flags & _ISPAD))
+ returnCode(ERR);
+
+ /*
+ * mvwin() should only modify the indices. See test/demo_menus.c and
+ * test/movewindow.c for examples.
+ */
+#if 0
+ /* Copying subwindows is allowed, but it is expensive... */
+ if (win->_flags & _SUBWIN) {
+ int err = ERR;
+ WINDOW *parent = win->_parent;
+ if (parent) { /* Now comes the complicated and costly part, you should really
+ * try to avoid to move subwindows. Because a subwindow shares
+ * the text buffers with its parent, one can't do a simple
+ * memmove of the text buffers. One has to create a copy, then
+ * to relocate the subwindow and then to do a copy.
+ */
+ if ((by - parent->_begy == win->_pary) &&
+ (bx - parent->_begx == win->_parx))
+ err = OK; /* we don't actually move */
+ else {
+ WINDOW *clone = dupwin(win);
+ if (clone) {
+ /* now we have the clone, so relocate win */
+
+ werase(win); /* Erase the original place */
+ /* fill with parents background */
+ wbkgrnd(win, CHREF(parent->_nc_bkgd));
+ wsyncup(win); /* Tell the parent(s) */
+
+ err = mvderwin(win,
+ by - parent->_begy,
+ bx - parent->_begx);
+ if (err != ERR) {
+ err = copywin(clone, win,
+ 0, 0, 0, 0, win->_maxy, win->_maxx, 0);
+ if (ERR != err)
+ wsyncup(win);
+ }
+ if (ERR == delwin(clone))
+ err = ERR;
+ }
+ }
+ }
+ returnCode(err);
+ }
+#endif
+
+ if (by + win->_maxy > screen_lines - 1
+ || bx + win->_maxx > screen_columns - 1
+ || by < 0
+ || bx < 0)
+ returnCode(ERR);
+
+ /*
+ * Whether or not the window is moved, touch the window's contents so
+ * that a following call to 'wrefresh()' will paint the window at the
+ * new location. This ensures that if the caller has refreshed another
+ * window at the same location, that this one will be displayed.
+ */
+ win->_begy = by;
+ win->_begx = bx;
+ returnCode(touchwin(win));
+}
diff --git a/ncurses/base/lib_newterm.c b/ncurses/base/lib_newterm.c
new file mode 100644
index 000000000000..3620a3fdbf2b
--- /dev/null
+++ b/ncurses/base/lib_newterm.c
@@ -0,0 +1,217 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+** lib_newterm.c
+**
+** The newterm() function.
+**
+*/
+
+#include <curses.priv.h>
+
+#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
+#define _POSIX_SOURCE
+#endif
+
+#include <term.h> /* clear_screen, cup & friends, cur_term */
+#include <tic.h>
+
+MODULE_ID("$Id: lib_newterm.c,v 1.69 2008/04/12 18:15:04 tom Exp $")
+
+#ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */
+#define ONLCR 0
+#endif
+
+/*
+ * SVr4/XSI Curses specify that hardware echo is turned off in initscr, and not
+ * restored during the curses session. The library simulates echo in software.
+ * (The behavior is unspecified if the application enables hardware echo).
+ *
+ * The newterm function also initializes terminal settings, and since initscr
+ * is supposed to behave as if it calls newterm, we do it here.
+ */
+static NCURSES_INLINE int
+_nc_initscr(void)
+{
+ int result = ERR;
+
+ /* for extended XPG4 conformance requires cbreak() at this point */
+ /* (SVr4 curses does this anyway) */
+ if (cbreak() == OK) {
+ TTY buf;
+
+ buf = cur_term->Nttyb;
+#ifdef TERMIOS
+ buf.c_lflag &= ~(ECHO | ECHONL);
+ buf.c_iflag &= ~(ICRNL | INLCR | IGNCR);
+ buf.c_oflag &= ~(ONLCR);
+#elif HAVE_SGTTY_H
+ buf.sg_flags &= ~(ECHO | CRMOD);
+#else
+ memset(&buf, 0, sizeof(buf));
+#endif
+ if ((result = _nc_set_tty_mode(&buf)) == OK)
+ cur_term->Nttyb = buf;
+ }
+ return result;
+}
+
+/*
+ * filter() has to be called before either initscr() or newterm(), so there is
+ * apparently no way to make this flag apply to some terminals and not others,
+ * aside from possibly delaying a filter() call until some terminals have been
+ * initialized.
+ */
+NCURSES_EXPORT(void)
+filter(void)
+{
+ START_TRACE();
+ T((T_CALLED("filter")));
+ _nc_prescreen.filter_mode = TRUE;
+ returnVoid;
+}
+
+#if NCURSES_EXT_FUNCS
+/*
+ * An extension, allowing the application to open a new screen without
+ * requiring it to also be filtered.
+ */
+NCURSES_EXPORT(void)
+nofilter(void)
+{
+ START_TRACE();
+ T((T_CALLED("nofilter")));
+ _nc_prescreen.filter_mode = FALSE;
+ returnVoid;
+}
+#endif
+
+NCURSES_EXPORT(SCREEN *)
+newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp)
+{
+ int value;
+ int errret;
+ SCREEN *current;
+ SCREEN *result = 0;
+
+ START_TRACE();
+ T((T_CALLED("newterm(\"%s\",%p,%p)"), name, ofp, ifp));
+
+ _nc_lock_global(set_SP);
+ /* this loads the capability entry, then sets LINES and COLS */
+ if (setupterm(name, fileno(ofp), &errret) != ERR) {
+ int slk_format = _nc_globals.slk_format;
+
+ /*
+ * This actually allocates the screen structure, and saves the original
+ * terminal settings.
+ */
+ current = SP;
+ _nc_set_screen(0);
+
+ /* allow user to set maximum escape delay from the environment */
+ if ((value = _nc_getenv_num("ESCDELAY")) >= 0) {
+ set_escdelay(value);
+ }
+
+ if (_nc_setupscreen(LINES,
+ COLS,
+ ofp,
+ _nc_prescreen.filter_mode,
+ slk_format) == ERR) {
+ _nc_set_screen(current);
+ result = 0;
+ } else {
+ /* if the terminal type has real soft labels, set those up */
+ if (slk_format && num_labels > 0 && SLK_STDFMT(slk_format))
+ _nc_slk_initialize(stdscr, COLS);
+
+ SP->_ifd = fileno(ifp);
+ typeahead(fileno(ifp));
+#ifdef TERMIOS
+ SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 &&
+ !(cur_term->Ottyb.c_iflag & ISTRIP));
+#else
+ SP->_use_meta = FALSE;
+#endif
+ SP->_endwin = FALSE;
+
+ /*
+ * Check whether we can optimize scrolling under dumb terminals in
+ * case we do not have any of these capabilities, scrolling
+ * optimization will be useless.
+ */
+ SP->_scrolling = ((scroll_forward && scroll_reverse) ||
+ ((parm_rindex ||
+ parm_insert_line ||
+ insert_line) &&
+ (parm_index ||
+ parm_delete_line ||
+ delete_line)));
+
+ baudrate(); /* sets a field in the SP structure */
+
+ SP->_keytry = 0;
+
+ /*
+ * Check for mismatched graphic-rendition capabilities. Most SVr4
+ * terminfo trees contain entries that have rmul or rmso equated to
+ * sgr0 (Solaris curses copes with those entries). We do this only
+ * for curses, since many termcap applications assume that
+ * smso/rmso and smul/rmul are paired, and will not function
+ * properly if we remove rmso or rmul. Curses applications
+ * shouldn't be looking at this detail.
+ */
+#define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode))
+ SP->_use_rmso = SGR0_TEST(exit_standout_mode);
+ SP->_use_rmul = SGR0_TEST(exit_underline_mode);
+
+ /* compute movement costs so we can do better move optimization */
+ _nc_mvcur_init();
+
+ /* initialize terminal to a sane state */
+ _nc_screen_init();
+
+ /* Initialize the terminal line settings. */
+ _nc_initscr();
+
+ _nc_signal_handler(TRUE);
+
+ result = SP;
+ }
+ }
+ _nc_unlock_global(set_SP);
+ returnSP(result);
+}
diff --git a/ncurses/base/lib_newwin.c b/ncurses/base/lib_newwin.c
new file mode 100644
index 000000000000..7f7aa3e04f1e
--- /dev/null
+++ b/ncurses/base/lib_newwin.c
@@ -0,0 +1,322 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+** lib_newwin.c
+**
+** The routines newwin(), subwin() and their dependent
+**
+*/
+
+#include <curses.priv.h>
+#include <stddef.h>
+
+MODULE_ID("$Id: lib_newwin.c,v 1.50 2008/05/03 16:36:39 tom Exp $")
+
+#define window_is(name) ((sp)->_##name == win)
+
+#if USE_REENTRANT
+#define remove_window(name) \
+ sp->_##name = 0
+#else
+#define remove_window(name) \
+ sp->_##name = 0; \
+ if (win == name) \
+ name = 0
+#endif
+
+static void
+remove_window_from_screen(WINDOW *win)
+{
+ SCREEN *sp;
+
+ for (each_screen(sp)) {
+ if (window_is(curscr)) {
+ remove_window(curscr);
+ break;
+ } else if (window_is(stdscr)) {
+ remove_window(stdscr);
+ break;
+ } else if (window_is(newscr)) {
+ remove_window(newscr);
+ break;
+ }
+ }
+}
+
+NCURSES_EXPORT(int)
+_nc_freewin(WINDOW *win)
+{
+ WINDOWLIST *p, *q;
+ int i;
+ int result = ERR;
+
+ T((T_CALLED("_nc_freewin(%p)"), win));
+
+ if (win != 0) {
+ if (_nc_try_global(windowlist) == 0) {
+ q = 0;
+ for (each_window(p)) {
+ if (&(p->win) == win) {
+ remove_window_from_screen(win);
+ if (q == 0)
+ _nc_windows = p->next;
+ else
+ q->next = p->next;
+
+ if (!(win->_flags & _SUBWIN)) {
+ for (i = 0; i <= win->_maxy; i++)
+ FreeIfNeeded(win->_line[i].text);
+ }
+ free(win->_line);
+ free(p);
+
+ result = OK;
+ T(("...deleted win=%p", win));
+ break;
+ }
+ q = p;
+ }
+ _nc_unlock_global(windowlist);
+ }
+ }
+ returnCode(result);
+}
+
+NCURSES_EXPORT(WINDOW *)
+newwin(int num_lines, int num_columns, int begy, int begx)
+{
+ WINDOW *win;
+ NCURSES_CH_T *ptr;
+ int i;
+
+ T((T_CALLED("newwin(%d,%d,%d,%d)"), num_lines, num_columns, begy, begx));
+
+ if (begy < 0 || begx < 0 || num_lines < 0 || num_columns < 0)
+ returnWin(0);
+
+ if (num_lines == 0)
+ num_lines = SP->_lines_avail - begy;
+ if (num_columns == 0)
+ num_columns = screen_columns - begx;
+
+ if ((win = _nc_makenew(num_lines, num_columns, begy, begx, 0)) == 0)
+ returnWin(0);
+
+ for (i = 0; i < num_lines; i++) {
+ win->_line[i].text = typeCalloc(NCURSES_CH_T, (unsigned) num_columns);
+ if (win->_line[i].text == 0) {
+ (void) _nc_freewin(win);
+ returnWin(0);
+ }
+ for (ptr = win->_line[i].text;
+ ptr < win->_line[i].text + num_columns;
+ ptr++)
+ SetChar(*ptr, BLANK_TEXT, BLANK_ATTR);
+ }
+
+ returnWin(win);
+}
+
+NCURSES_EXPORT(WINDOW *)
+derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx)
+{
+ WINDOW *win;
+ int i;
+ int flags = _SUBWIN;
+
+ T((T_CALLED("derwin(%p,%d,%d,%d,%d)"), orig, num_lines, num_columns,
+ begy, begx));
+
+ /*
+ * make sure window fits inside the original one
+ */
+ if (begy < 0 || begx < 0 || orig == 0 || num_lines < 0 || num_columns < 0)
+ returnWin(0);
+ if (begy + num_lines > orig->_maxy + 1
+ || begx + num_columns > orig->_maxx + 1)
+ returnWin(0);
+
+ if (num_lines == 0)
+ num_lines = orig->_maxy + 1 - begy;
+
+ if (num_columns == 0)
+ num_columns = orig->_maxx + 1 - begx;
+
+ if (orig->_flags & _ISPAD)
+ flags |= _ISPAD;
+
+ if ((win = _nc_makenew(num_lines, num_columns, orig->_begy + begy,
+ orig->_begx + begx, flags)) == 0)
+ returnWin(0);
+
+ win->_pary = begy;
+ win->_parx = begx;
+ WINDOW_ATTRS(win) = WINDOW_ATTRS(orig);
+ win->_nc_bkgd = orig->_nc_bkgd;
+
+ for (i = 0; i < num_lines; i++)
+ win->_line[i].text = &orig->_line[begy++].text[begx];
+
+ win->_parent = orig;
+
+ returnWin(win);
+}
+
+NCURSES_EXPORT(WINDOW *)
+subwin(WINDOW *w, int l, int c, int y, int x)
+{
+ T((T_CALLED("subwin(%p, %d, %d, %d, %d)"), w, l, c, y, x));
+ T(("parent has begy = %ld, begx = %ld", (long) w->_begy, (long) w->_begx));
+
+ returnWin(derwin(w, l, c, y - w->_begy, x - w->_begx));
+}
+
+static bool
+dimension_limit(int value)
+{
+ NCURSES_SIZE_T test = value;
+ return (test == value && value > 0);
+}
+
+NCURSES_EXPORT(WINDOW *)
+_nc_makenew(int num_lines, int num_columns, int begy, int begx, int flags)
+{
+ int i;
+ WINDOWLIST *wp;
+ WINDOW *win;
+ bool is_pad = (flags & _ISPAD);
+
+ T((T_CALLED("_nc_makenew(%d,%d,%d,%d)"), num_lines, num_columns, begy, begx));
+
+ if (SP == 0)
+ returnWin(0);
+
+ if (!dimension_limit(num_lines) || !dimension_limit(num_columns))
+ returnWin(0);
+
+ if ((wp = typeCalloc(WINDOWLIST, 1)) == 0)
+ returnWin(0);
+
+ _nc_mutex_init(&(wp->mutex_use_window));
+
+ win = &(wp->win);
+
+ if ((win->_line = typeCalloc(struct ldat, ((unsigned) num_lines))) == 0) {
+ free(win);
+ returnWin(0);
+ }
+
+ _nc_lock_global(windowlist);
+
+ win->_curx = 0;
+ win->_cury = 0;
+ win->_maxy = num_lines - 1;
+ win->_maxx = num_columns - 1;
+ win->_begy = begy;
+ win->_begx = begx;
+ win->_yoffset = SP->_topstolen;
+
+ win->_flags = flags;
+ WINDOW_ATTRS(win) = A_NORMAL;
+ SetChar(win->_nc_bkgd, BLANK_TEXT, BLANK_ATTR);
+
+ win->_clear = is_pad ? FALSE : (num_lines == screen_lines
+ && num_columns == screen_columns);
+ win->_idlok = FALSE;
+ win->_idcok = TRUE;
+ win->_scroll = FALSE;
+ win->_leaveok = FALSE;
+ win->_use_keypad = FALSE;
+ win->_delay = -1;
+ win->_immed = FALSE;
+ win->_sync = 0;
+ win->_parx = -1;
+ win->_pary = -1;
+ win->_parent = 0;
+
+ win->_regtop = 0;
+ win->_regbottom = num_lines - 1;
+
+ win->_pad._pad_y = -1;
+ win->_pad._pad_x = -1;
+ win->_pad._pad_top = -1;
+ win->_pad._pad_bottom = -1;
+ win->_pad._pad_left = -1;
+ win->_pad._pad_right = -1;
+
+ for (i = 0; i < num_lines; i++) {
+ /*
+ * This used to do
+ *
+ * win->_line[i].firstchar = win->_line[i].lastchar = _NOCHANGE;
+ *
+ * which marks the whole window unchanged. That's how
+ * SVr1 curses did it, but SVr4 curses marks the whole new
+ * window changed.
+ *
+ * With the old SVr1-like code, say you have stdscr full of
+ * characters, then create a new window with newwin(),
+ * then do a printw(win, "foo ");, the trailing spaces are
+ * completely ignored by the following refreshes. So, you
+ * get "foojunkjunk" on the screen instead of "foo " as
+ * you actually intended.
+ *
+ * SVr4 doesn't do this. Instead the spaces are actually written.
+ * So that's how we want ncurses to behave.
+ */
+ win->_line[i].firstchar = 0;
+ win->_line[i].lastchar = num_columns - 1;
+
+ if_USE_SCROLL_HINTS(win->_line[i].oldindex = i);
+ }
+
+ if (!is_pad && (begx + num_columns == screen_columns)) {
+ win->_flags |= _ENDLINE;
+
+ if (begx == 0 && num_lines == screen_lines && begy == 0)
+ win->_flags |= _FULLWIN;
+
+ if (begy + num_lines == screen_lines)
+ win->_flags |= _SCROLLWIN;
+ }
+
+ wp->next = _nc_windows;
+ _nc_windows = wp;
+
+ T((T_CREATE("window %p"), win));
+
+ _nc_unlock_global(windowlist);
+ returnWin(win);
+}
diff --git a/ncurses/base/lib_nl.c b/ncurses/base/lib_nl.c
new file mode 100644
index 000000000000..32515da0be81
--- /dev/null
+++ b/ncurses/base/lib_nl.c
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+ * nl.c
+ *
+ * Routines:
+ * nl()
+ * nonl()
+ *
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_nl.c,v 1.8 2000/12/10 02:43:27 tom Exp $")
+
+#ifdef __EMX__
+#include <io.h>
+#endif
+
+NCURSES_EXPORT(int)
+nl(void)
+{
+ T((T_CALLED("nl()")));
+
+ SP->_nl = TRUE;
+
+#ifdef __EMX__
+ _nc_flush();
+ _fsetmode(NC_OUTPUT, "t");
+#endif
+
+ returnCode(OK);
+}
+
+NCURSES_EXPORT(int)
+nonl(void)
+{
+ T((T_CALLED("nonl()")));
+
+ SP->_nl = FALSE;
+
+#ifdef __EMX__
+ _nc_flush();
+ _fsetmode(NC_OUTPUT, "b");
+#endif
+
+ returnCode(OK);
+}
diff --git a/ncurses/base/lib_overlay.c b/ncurses/base/lib_overlay.c
new file mode 100644
index 000000000000..26314de5e5fb
--- /dev/null
+++ b/ncurses/base/lib_overlay.c
@@ -0,0 +1,211 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_overlay.c
+**
+** The routines overlay(), copywin(), and overwrite().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_overlay.c,v 1.25 2008/04/12 17:21:59 tom Exp $")
+
+static int
+overlap(const WINDOW *const src, WINDOW *const dst, int const flag)
+{
+ int rc = ERR;
+ int sx1, sy1, sx2, sy2;
+ int dx1, dy1, dx2, dy2;
+ int sminrow, smincol;
+ int dminrow, dmincol;
+ int dmaxrow, dmaxcol;
+
+ T((T_CALLED("overlap(%p,%p,%d)"), src, dst, flag));
+
+ if (src != 0 && dst != 0) {
+ _nc_lock_window(src);
+ _nc_lock_window(dst);
+
+ T(("src : begy %ld, begx %ld, maxy %ld, maxx %ld",
+ (long) src->_begy,
+ (long) src->_begx,
+ (long) src->_maxy,
+ (long) src->_maxx));
+ T(("dst : begy %ld, begx %ld, maxy %ld, maxx %ld",
+ (long) dst->_begy,
+ (long) dst->_begx,
+ (long) dst->_maxy,
+ (long) dst->_maxx));
+
+ sx1 = src->_begx;
+ sy1 = src->_begy;
+ sx2 = sx1 + src->_maxx;
+ sy2 = sy1 + src->_maxy;
+
+ dx1 = dst->_begx;
+ dy1 = dst->_begy;
+ dx2 = dx1 + dst->_maxx;
+ dy2 = dy1 + dst->_maxy;
+
+ if (dx2 >= sx1 && dx1 <= sx2 && dy2 >= sy1 && dy1 <= sy2) {
+ sminrow = max(sy1, dy1) - sy1;
+ smincol = max(sx1, dx1) - sx1;
+ dminrow = max(sy1, dy1) - dy1;
+ dmincol = max(sx1, dx1) - dx1;
+ dmaxrow = min(sy2, dy2) - dy1;
+ dmaxcol = min(sx2, dx2) - dx1;
+
+ rc = copywin(src, dst,
+ sminrow, smincol,
+ dminrow, dmincol,
+ dmaxrow, dmaxcol,
+ flag);
+ }
+ _nc_unlock_window(dst);
+ _nc_unlock_window(src);
+ }
+ returnCode(rc);
+}
+
+/*
+**
+** overlay(win1, win2)
+**
+**
+** overlay() writes the overlapping area of win1 behind win2
+** on win2 non-destructively.
+**
+**/
+
+NCURSES_EXPORT(int)
+overlay(const WINDOW *win1, WINDOW *win2)
+{
+ T((T_CALLED("overlay(%p,%p)"), win1, win2));
+ returnCode(overlap(win1, win2, TRUE));
+}
+
+/*
+**
+** overwrite(win1, win2)
+**
+**
+** overwrite() writes the overlapping area of win1 behind win2
+** on win2 destructively.
+**
+**/
+
+NCURSES_EXPORT(int)
+overwrite(const WINDOW *win1, WINDOW *win2)
+{
+ T((T_CALLED("overwrite(%p,%p)"), win1, win2));
+ returnCode(overlap(win1, win2, FALSE));
+}
+
+NCURSES_EXPORT(int)
+copywin(const WINDOW *src, WINDOW *dst,
+ int sminrow, int smincol,
+ int dminrow, int dmincol,
+ int dmaxrow, int dmaxcol,
+ int over)
+{
+ int rc = ERR;
+ int sx, sy, dx, dy;
+ bool touched;
+ attr_t bk;
+ attr_t mask;
+
+ T((T_CALLED("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)"),
+ src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over));
+
+ if (src && dst) {
+
+ _nc_lock_window(src);
+ _nc_lock_window(dst);
+
+ bk = AttrOf(dst->_nc_bkgd);
+ mask = ~(attr_t) ((bk & A_COLOR) ? A_COLOR : 0);
+
+ /* make sure rectangle exists in source */
+ if ((sminrow + dmaxrow - dminrow) <= (src->_maxy + 1) &&
+ (smincol + dmaxcol - dmincol) <= (src->_maxx + 1)) {
+
+ T(("rectangle exists in source"));
+
+ /* make sure rectangle fits in destination */
+ if (dmaxrow <= dst->_maxy && dmaxcol <= dst->_maxx) {
+
+ T(("rectangle fits in destination"));
+
+ for (dy = dminrow, sy = sminrow;
+ dy <= dmaxrow;
+ sy++, dy++) {
+
+ touched = FALSE;
+ for (dx = dmincol, sx = smincol;
+ dx <= dmaxcol;
+ sx++, dx++) {
+ if (over) {
+ if ((CharOf(src->_line[sy].text[sx]) != L(' ')) &&
+ (!CharEq(dst->_line[dy].text[dx],
+ src->_line[sy].text[sx]))) {
+ dst->_line[dy].text[dx] =
+ src->_line[sy].text[sx];
+ SetAttr(dst->_line[dy].text[dx],
+ ((AttrOf(src->_line[sy].text[sx]) &
+ mask) | bk));
+ touched = TRUE;
+ }
+ } else {
+ if (!CharEq(dst->_line[dy].text[dx],
+ src->_line[sy].text[sx])) {
+ dst->_line[dy].text[dx] =
+ src->_line[sy].text[sx];
+ touched = TRUE;
+ }
+ }
+ }
+ if (touched) {
+ touchline(dst, dminrow, (dmaxrow - dminrow + 1));
+ }
+ }
+ T(("finished copywin"));
+ rc = OK;
+ }
+ }
+ _nc_unlock_window(dst);
+ _nc_unlock_window(src);
+ }
+ returnCode(rc);
+}
diff --git a/ncurses/base/lib_pad.c b/ncurses/base/lib_pad.c
new file mode 100644
index 000000000000..6cad9c54b064
--- /dev/null
+++ b/ncurses/base/lib_pad.c
@@ -0,0 +1,322 @@
+/****************************************************************************
+ * Copyright (c) 1998-2004,2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+ * lib_pad.c
+ * newpad -- create a new pad
+ * pnoutrefresh -- refresh a pad, no update
+ * pechochar -- add a char to a pad and refresh
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_pad.c,v 1.41 2006/10/14 20:47:13 tom Exp $")
+
+NCURSES_EXPORT(WINDOW *)
+newpad(int l, int c)
+{
+ WINDOW *win;
+ NCURSES_CH_T *ptr;
+ int i;
+
+ T((T_CALLED("newpad(%d, %d)"), l, c));
+
+ if (l <= 0 || c <= 0)
+ returnWin(0);
+
+ if ((win = _nc_makenew(l, c, 0, 0, _ISPAD)) == NULL)
+ returnWin(0);
+
+ for (i = 0; i < l; i++) {
+ if_USE_SCROLL_HINTS(win->_line[i].oldindex = _NEWINDEX);
+ if ((win->_line[i].text = typeCalloc(NCURSES_CH_T, ((size_t) c))) == 0) {
+ (void) _nc_freewin(win);
+ returnWin(0);
+ }
+ for (ptr = win->_line[i].text; ptr < win->_line[i].text + c; ptr++)
+ SetChar(*ptr, BLANK_TEXT, BLANK_ATTR);
+ }
+
+ returnWin(win);
+}
+
+NCURSES_EXPORT(WINDOW *)
+subpad(WINDOW *orig, int l, int c, int begy, int begx)
+{
+ WINDOW *win = (WINDOW *) 0;
+
+ T((T_CALLED("subpad(%d, %d)"), l, c));
+
+ if (orig) {
+ if (!(orig->_flags & _ISPAD)
+ || ((win = derwin(orig, l, c, begy, begx)) == NULL))
+ returnWin(0);
+ }
+ returnWin(win);
+}
+
+NCURSES_EXPORT(int)
+prefresh(WINDOW *win,
+ int pminrow,
+ int pmincol,
+ int sminrow,
+ int smincol,
+ int smaxrow,
+ int smaxcol)
+{
+ T((T_CALLED("prefresh()")));
+ if (pnoutrefresh(win, pminrow, pmincol, sminrow, smincol, smaxrow,
+ smaxcol) != ERR
+ && doupdate() != ERR) {
+ returnCode(OK);
+ }
+ returnCode(ERR);
+}
+
+NCURSES_EXPORT(int)
+pnoutrefresh(WINDOW *win,
+ int pminrow,
+ int pmincol,
+ int sminrow,
+ int smincol,
+ int smaxrow,
+ int smaxcol)
+{
+ NCURSES_SIZE_T i, j;
+ NCURSES_SIZE_T m, n;
+ NCURSES_SIZE_T pmaxrow;
+ NCURSES_SIZE_T pmaxcol;
+
+#if USE_SCROLL_HINTS
+ const int my_len = 2; /* parameterize the threshold for hardscroll */
+ NCURSES_SIZE_T displaced;
+ bool wide;
+#endif
+
+ T((T_CALLED("pnoutrefresh(%p, %d, %d, %d, %d, %d, %d)"),
+ win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol));
+
+ if (win == 0)
+ returnCode(ERR);
+
+ if (!(win->_flags & _ISPAD))
+ returnCode(ERR);
+
+ /* negative values are interpreted as zero */
+ if (pminrow < 0)
+ pminrow = 0;
+ if (pmincol < 0)
+ pmincol = 0;
+ if (sminrow < 0)
+ sminrow = 0;
+ if (smincol < 0)
+ smincol = 0;
+
+ pmaxrow = pminrow + smaxrow - sminrow;
+ pmaxcol = pmincol + smaxcol - smincol;
+
+ T((" pminrow + smaxrow - sminrow %ld, win->_maxy %ld",
+ (long) pmaxrow, (long) win->_maxy));
+ T((" pmincol + smaxcol - smincol %ld, win->_maxx %ld",
+ (long) pmaxcol, (long) win->_maxx));
+
+ /*
+ * Trim the caller's screen size back to the actual limits.
+ */
+ if (pmaxrow > win->_maxy) {
+ smaxrow -= (pmaxrow - win->_maxy);
+ pmaxrow = pminrow + smaxrow - sminrow;
+ }
+ if (pmaxcol > win->_maxx) {
+ smaxcol -= (pmaxcol - win->_maxx);
+ pmaxcol = pmincol + smaxcol - smincol;
+ }
+
+ if (smaxrow >= screen_lines
+ || smaxcol >= screen_columns
+ || sminrow > smaxrow
+ || smincol > smaxcol)
+ returnCode(ERR);
+
+ T(("pad being refreshed"));
+
+#if USE_SCROLL_HINTS
+ if (win->_pad._pad_y >= 0) {
+ displaced = pminrow - win->_pad._pad_y
+ - (sminrow - win->_pad._pad_top);
+ T(("pad being shifted by %d line(s)", displaced));
+ } else
+ displaced = 0;
+#endif
+
+ /*
+ * For pure efficiency, we'd want to transfer scrolling information
+ * from the pad to newscr whenever the window is wide enough that
+ * its update will dominate the cost of the update for the horizontal
+ * band of newscr that it occupies. Unfortunately, this threshold
+ * tends to be complex to estimate, and in any case scrolling the
+ * whole band and rewriting the parts outside win's image would look
+ * really ugly. So. What we do is consider the pad "wide" if it
+ * either (a) occupies the whole width of newscr, or (b) occupies
+ * all but at most one column on either vertical edge of the screen
+ * (this caters to fussy people who put boxes around full-screen
+ * windows). Note that changing this formula will not break any code,
+ * merely change the costs of various update cases.
+ */
+#if USE_SCROLL_HINTS
+ wide = (smincol < my_len && smaxcol > (newscr->_maxx - my_len));
+#endif
+
+ for (i = pminrow, m = sminrow + win->_yoffset;
+ i <= pmaxrow && m <= newscr->_maxy;
+ i++, m++) {
+ register struct ldat *nline = &newscr->_line[m];
+ register struct ldat *oline = &win->_line[i];
+ for (j = pmincol, n = smincol; j <= pmaxcol; j++, n++) {
+ NCURSES_CH_T ch = oline->text[j];
+#if USE_WIDEC_SUPPORT
+ /*
+ * Special case for leftmost character of the displayed area.
+ * Only half of a double-width character may be visible.
+ */
+ if (j == pmincol
+ && j > 0
+ && isWidecExt(ch)) {
+ SetChar(ch, L(' '), AttrOf(oline->text[j - 1]));
+ }
+#endif
+ if (!CharEq(ch, nline->text[n])) {
+ nline->text[n] = ch;
+ CHANGED_CELL(nline, n);
+ }
+ }
+
+#if USE_SCROLL_HINTS
+ if (wide) {
+ int nind = m + displaced;
+ if (oline->oldindex < 0
+ || nind < sminrow
+ || nind > smaxrow) {
+ nind = _NEWINDEX;
+ } else if (displaced) {
+ register struct ldat *pline = &curscr->_line[nind];
+ for (j = 0; j <= my_len; j++) {
+ int k = newscr->_maxx - j;
+ if (pline->text[j] != nline->text[j]
+ || pline->text[k] != nline->text[k]) {
+ nind = _NEWINDEX;
+ break;
+ }
+ }
+ }
+
+ nline->oldindex = nind;
+ }
+#endif /* USE_SCROLL_HINTS */
+ oline->firstchar = oline->lastchar = _NOCHANGE;
+ if_USE_SCROLL_HINTS(oline->oldindex = i);
+ }
+
+ /*
+ * Clean up debris from scrolling or resizing the pad, so we do not
+ * accidentally pick up the index value during the next call to this
+ * procedure. The only rows that should have an index value are those
+ * that are displayed during this cycle.
+ */
+#if USE_SCROLL_HINTS
+ for (i = pminrow - 1; (i >= 0) && (win->_line[i].oldindex >= 0); i--)
+ win->_line[i].oldindex = _NEWINDEX;
+ for (i = pmaxrow + 1; (i <= win->_maxy)
+ && (win->_line[i].oldindex >= 0); i++)
+ win->_line[i].oldindex = _NEWINDEX;
+#endif
+
+ win->_begx = smincol;
+ win->_begy = sminrow;
+
+ if (win->_clear) {
+ win->_clear = FALSE;
+ newscr->_clear = TRUE;
+ }
+
+ /*
+ * Use the pad's current position, if it will be visible.
+ * If not, don't do anything; it's not an error.
+ */
+ if (win->_leaveok == FALSE
+ && win->_cury >= pminrow
+ && win->_curx >= pmincol
+ && win->_cury <= pmaxrow
+ && win->_curx <= pmaxcol) {
+ newscr->_cury = win->_cury - pminrow + win->_begy + win->_yoffset;
+ newscr->_curx = win->_curx - pmincol + win->_begx;
+ }
+ newscr->_leaveok = win->_leaveok;
+ win->_flags &= ~_HASMOVED;
+
+ /*
+ * Update our cache of the line-numbers that we displayed from the pad.
+ * We will use this on subsequent calls to this function to derive
+ * values to stuff into 'oldindex[]' -- for scrolling optimization.
+ */
+ win->_pad._pad_y = pminrow;
+ win->_pad._pad_x = pmincol;
+ win->_pad._pad_top = sminrow;
+ win->_pad._pad_left = smincol;
+ win->_pad._pad_bottom = smaxrow;
+ win->_pad._pad_right = smaxcol;
+
+ returnCode(OK);
+}
+
+NCURSES_EXPORT(int)
+pechochar(WINDOW *pad, const chtype ch)
+{
+ T((T_CALLED("pechochar(%p, %s)"), pad, _tracechtype(ch)));
+
+ if (pad == 0)
+ returnCode(ERR);
+
+ if (!(pad->_flags & _ISPAD))
+ returnCode(wechochar(pad, ch));
+
+ waddch(pad, ch);
+ prefresh(pad, pad->_pad._pad_y,
+ pad->_pad._pad_x,
+ pad->_pad._pad_top,
+ pad->_pad._pad_left,
+ pad->_pad._pad_bottom,
+ pad->_pad._pad_right);
+
+ returnCode(OK);
+}
diff --git a/ncurses/base/lib_printw.c b/ncurses/base/lib_printw.c
new file mode 100644
index 000000000000..62ae921e650d
--- /dev/null
+++ b/ncurses/base/lib_printw.c
@@ -0,0 +1,138 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey <dickey@clark.net> 1997 *
+ ****************************************************************************/
+
+/*
+** lib_printw.c
+**
+** The routines printw(), wprintw() and friends.
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_printw.c,v 1.18 2006/12/17 19:21:39 tom Exp $")
+
+NCURSES_EXPORT(int)
+printw(const char *fmt,...)
+{
+ va_list argp;
+ int code;
+
+#ifdef TRACE
+ va_start(argp, fmt);
+ T((T_CALLED("printw(%s%s)"),
+ _nc_visbuf(fmt), _nc_varargs(fmt, argp)));
+ va_end(argp);
+#endif
+
+ va_start(argp, fmt);
+ code = vwprintw(stdscr, fmt, argp);
+ va_end(argp);
+
+ returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+wprintw(WINDOW *win, const char *fmt,...)
+{
+ va_list argp;
+ int code;
+
+#ifdef TRACE
+ va_start(argp, fmt);
+ T((T_CALLED("wprintw(%p,%s%s)"),
+ win, _nc_visbuf(fmt), _nc_varargs(fmt, argp)));
+ va_end(argp);
+#endif
+
+ va_start(argp, fmt);
+ code = vwprintw(win, fmt, argp);
+ va_end(argp);
+
+ returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+mvprintw(int y, int x, const char *fmt,...)
+{
+ va_list argp;
+ int code;
+
+#ifdef TRACE
+ va_start(argp, fmt);
+ T((T_CALLED("mvprintw(%d,%d,%s%s)"),
+ y, x, _nc_visbuf(fmt), _nc_varargs(fmt, argp)));
+ va_end(argp);
+#endif
+
+ if ((code = move(y, x)) != ERR) {
+ va_start(argp, fmt);
+ code = vwprintw(stdscr, fmt, argp);
+ va_end(argp);
+ }
+ returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+mvwprintw(WINDOW *win, int y, int x, const char *fmt,...)
+{
+ va_list argp;
+ int code;
+
+#ifdef TRACE
+ va_start(argp, fmt);
+ T((T_CALLED("mvwprintw(%d,%d,%p,%s%s)"),
+ y, x, win, _nc_visbuf(fmt), _nc_varargs(fmt, argp)));
+ va_end(argp);
+#endif
+
+ if ((code = wmove(win, y, x)) != ERR) {
+ va_start(argp, fmt);
+ code = vwprintw(win, fmt, argp);
+ va_end(argp);
+ }
+ returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+vwprintw(WINDOW *win, const char *fmt, va_list argp)
+{
+ char *buf;
+ int code = ERR;
+
+ T((T_CALLED("vwprintw(%p,%s,va_list)"), win, _nc_visbuf(fmt)));
+
+ if ((buf = _nc_printf_string(fmt, argp)) != 0) {
+ code = waddstr(win, buf);
+ }
+ returnCode(code);
+}
diff --git a/ncurses/base/lib_redrawln.c b/ncurses/base/lib_redrawln.c
new file mode 100644
index 000000000000..6b0905f07d67
--- /dev/null
+++ b/ncurses/base/lib_redrawln.c
@@ -0,0 +1,84 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey <dickey@clark.net> 1997 *
+ ****************************************************************************/
+
+/*
+ * lib_redrawln.c
+ *
+ * The routine wredrawln().
+ *
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_redrawln.c,v 1.12 2007/10/13 20:08:56 tom Exp $")
+
+NCURSES_EXPORT(int)
+wredrawln(WINDOW *win, int beg, int num)
+{
+ int i;
+ int end;
+ size_t len;
+
+ T((T_CALLED("wredrawln(%p,%d,%d)"), win, beg, num));
+
+ if (win == 0)
+ returnCode(ERR);
+
+ if (beg < 0)
+ beg = 0;
+
+ if (touchline(win, beg, num) == ERR)
+ returnCode(ERR);
+
+ if (touchline(curscr, beg + win->_begy, num) == ERR)
+ returnCode(ERR);
+
+ end = beg + num;
+ if (end > curscr->_maxy + 1)
+ end = curscr->_maxy + 1;
+ if (end > win->_maxy + 1)
+ end = win->_maxy + 1;
+
+ len = (win->_maxx + 1);
+ if (len > (size_t) (curscr->_maxx + 1))
+ len = (size_t) (curscr->_maxx + 1);
+ len *= sizeof(curscr->_line[0].text[0]);
+
+ for (i = beg; i < end; i++) {
+ int crow = i + win->_begy;
+
+ memset(curscr->_line[crow].text + win->_begx, 0, len);
+ _nc_make_oldhash(crow);
+ }
+
+ returnCode(OK);
+}
diff --git a/ncurses/base/lib_refresh.c b/ncurses/base/lib_refresh.c
new file mode 100644
index 000000000000..2a9cafb7b0ad
--- /dev/null
+++ b/ncurses/base/lib_refresh.c
@@ -0,0 +1,288 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+ * lib_refresh.c
+ *
+ * The routines wrefresh() and wnoutrefresh().
+ *
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_refresh.c,v 1.41 2007/09/29 20:39:34 tom Exp $")
+
+NCURSES_EXPORT(int)
+wrefresh(WINDOW *win)
+{
+ int code;
+
+ T((T_CALLED("wrefresh(%p)"), win));
+
+ if (win == 0) {
+ code = ERR;
+ } else if (win == curscr) {
+ curscr->_clear = TRUE;
+ code = doupdate();
+ } else if ((code = wnoutrefresh(win)) == OK) {
+ if (win->_clear)
+ newscr->_clear = TRUE;
+ code = doupdate();
+ /*
+ * Reset the clearok() flag in case it was set for the special
+ * case in hardscroll.c (if we don't reset it here, we'll get 2
+ * refreshes because the flag is copied from stdscr to newscr).
+ * Resetting the flag shouldn't do any harm, anyway.
+ */
+ win->_clear = FALSE;
+ }
+ returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+wnoutrefresh(WINDOW *win)
+{
+ NCURSES_SIZE_T limit_x;
+ NCURSES_SIZE_T src_row, src_col;
+ NCURSES_SIZE_T begx;
+ NCURSES_SIZE_T begy;
+ NCURSES_SIZE_T dst_row, dst_col;
+#if USE_SCROLL_HINTS
+ bool wide;
+#endif
+
+ T((T_CALLED("wnoutrefresh(%p)"), win));
+#ifdef TRACE
+ if (USE_TRACEF(TRACE_UPDATE)) {
+ _tracedump("...win", win);
+ _nc_unlock_global(tracef);
+ }
+#endif /* TRACE */
+
+ /*
+ * This function will break badly if we try to refresh a pad.
+ */
+ if ((win == 0)
+ || (win->_flags & _ISPAD))
+ returnCode(ERR);
+
+ /* put them here so "win == 0" won't break our code */
+ begx = win->_begx;
+ begy = win->_begy;
+
+ newscr->_nc_bkgd = win->_nc_bkgd;
+ WINDOW_ATTRS(newscr) = WINDOW_ATTRS(win);
+
+ /* merge in change information from all subwindows of this window */
+ wsyncdown(win);
+
+#if USE_SCROLL_HINTS
+ /*
+ * For pure efficiency, we'd want to transfer scrolling information
+ * from the window to newscr whenever the window is wide enough that
+ * its update will dominate the cost of the update for the horizontal
+ * band of newscr that it occupies. Unfortunately, this threshold
+ * tends to be complex to estimate, and in any case scrolling the
+ * whole band and rewriting the parts outside win's image would look
+ * really ugly. So. What we do is consider the window "wide" if it
+ * either (a) occupies the whole width of newscr, or (b) occupies
+ * all but at most one column on either vertical edge of the screen
+ * (this caters to fussy people who put boxes around full-screen
+ * windows). Note that changing this formula will not break any code,
+ * merely change the costs of various update cases.
+ */
+ wide = (begx <= 1 && win->_maxx >= (newscr->_maxx - 1));
+#endif
+
+ win->_flags &= ~_HASMOVED;
+
+ /*
+ * Microtweaking alert! This double loop is one of the genuine
+ * hot spots in the code. Even gcc doesn't seem to do enough
+ * common-subexpression chunking to make it really tense,
+ * so we'll force the issue.
+ */
+
+ /* limit(dst_col) */
+ limit_x = win->_maxx;
+ /* limit(src_col) */
+ if (limit_x > newscr->_maxx - begx)
+ limit_x = newscr->_maxx - begx;
+
+ for (src_row = 0, dst_row = begy + win->_yoffset;
+ src_row <= win->_maxy && dst_row <= newscr->_maxy;
+ src_row++, dst_row++) {
+ register struct ldat *nline = &newscr->_line[dst_row];
+ register struct ldat *oline = &win->_line[src_row];
+
+ if (oline->firstchar != _NOCHANGE) {
+ int last_src = oline->lastchar;
+
+ if (last_src > limit_x)
+ last_src = limit_x;
+
+ src_col = oline->firstchar;
+ dst_col = src_col + begx;
+
+ if_WIDEC({
+ register int j;
+
+ /*
+ * Ensure that we will copy complete multi-column characters
+ * on the left-boundary.
+ */
+ if (isWidecExt(oline->text[src_col])) {
+ j = 1 + dst_col - WidecExt(oline->text[src_col]);
+ if (j < 0)
+ j = 0;
+ if (dst_col > j) {
+ src_col -= (dst_col - j);
+ dst_col = j;
+ }
+ }
+
+ /*
+ * Ensure that we will copy complete multi-column characters
+ * on the right-boundary.
+ */
+ j = last_src;
+ if (WidecExt(oline->text[j])) {
+ ++j;
+ while (j <= limit_x) {
+ if (isWidecBase(oline->text[j])) {
+ break;
+ } else {
+ last_src = j;
+ }
+ ++j;
+ }
+ }
+ });
+
+ if_WIDEC({
+ static cchar_t blank = BLANK;
+ int last_dst = begx + ((last_src < win->_maxx)
+ ? last_src
+ : win->_maxx);
+ int fix_left = dst_col;
+ int fix_right = last_dst;
+ register int j;
+
+ /*
+ * Check for boundary cases where we may overwrite part of a
+ * multi-column character. For those, wipe the remainder of
+ * the character to blanks.
+ */
+ j = dst_col;
+ if (isWidecExt(nline->text[j])) {
+ /*
+ * On the left, we only care about multi-column characters
+ * that extend into the changed region.
+ */
+ fix_left = 1 + j - WidecExt(nline->text[j]);
+ if (fix_left < 0)
+ fix_left = 0; /* only if cell is corrupt */
+ }
+
+ j = last_dst;
+ if (WidecExt(nline->text[j]) != 0) {
+ /*
+ * On the right, any multi-column character is a problem,
+ * unless it happens to be contained in the change, and
+ * ending at the right boundary of the change. The
+ * computation for 'fix_left' accounts for the left-side of
+ * this character. Find the end of the character.
+ */
+ ++j;
+ while (j <= newscr->_maxx && isWidecExt(nline->text[j])) {
+ fix_right = j++;
+ }
+ }
+
+ /*
+ * The analysis is simpler if we do the clearing afterwards.
+ * Do that now.
+ */
+ if (fix_left < dst_col || fix_right > last_dst) {
+ for (j = fix_left; j <= fix_right; ++j) {
+ nline->text[j] = blank;
+ CHANGED_CELL(nline, j);
+ }
+ }
+ });
+
+ /*
+ * Copy the changed text.
+ */
+ for (; src_col <= last_src; src_col++, dst_col++) {
+ if (!CharEq(oline->text[src_col], nline->text[dst_col])) {
+ nline->text[dst_col] = oline->text[src_col];
+ CHANGED_CELL(nline, dst_col);
+ }
+ }
+
+ }
+#if USE_SCROLL_HINTS
+ if (wide) {
+ int oind = oline->oldindex;
+
+ nline->oldindex = ((oind == _NEWINDEX)
+ ? _NEWINDEX
+ : (begy + oind + win->_yoffset));
+ }
+#endif /* USE_SCROLL_HINTS */
+
+ oline->firstchar = oline->lastchar = _NOCHANGE;
+ if_USE_SCROLL_HINTS(oline->oldindex = src_row);
+ }
+
+ if (win->_clear) {
+ win->_clear = FALSE;
+ newscr->_clear = TRUE;
+ }
+
+ if (!win->_leaveok) {
+ newscr->_cury = win->_cury + win->_begy + win->_yoffset;
+ newscr->_curx = win->_curx + win->_begx;
+ }
+ newscr->_leaveok = win->_leaveok;
+
+#ifdef TRACE
+ if (USE_TRACEF(TRACE_UPDATE)) {
+ _tracedump("newscr", newscr);
+ _nc_unlock_global(tracef);
+ }
+#endif /* TRACE */
+ returnCode(OK);
+}
diff --git a/ncurses/base/lib_restart.c b/ncurses/base/lib_restart.c
new file mode 100644
index 000000000000..9742ff629fbd
--- /dev/null
+++ b/ncurses/base/lib_restart.c
@@ -0,0 +1,99 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+ * Terminfo-only terminal setup routines:
+ *
+ * int restartterm(const char *, int, int *)
+ * TERMINAL *set_curterm(TERMINAL *)
+ * int del_curterm(TERMINAL *)
+ */
+
+#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.9 2008/05/03 22:43:52 tom Exp $")
+
+NCURSES_EXPORT(int)
+restartterm(NCURSES_CONST char *termp, int filenum, int *errret)
+{
+ int result;
+
+ T((T_CALLED("restartterm(%s,%d,%p)"), termp, filenum, errret));
+
+ if (setupterm(termp, filenum, errret) != OK) {
+ result = ERR;
+ } else if (SP != 0) {
+ int saveecho = SP->_echo;
+ int savecbreak = SP->_cbreak;
+ int saveraw = SP->_raw;
+ int savenl = SP->_nl;
+
+ if (saveecho)
+ echo();
+ else
+ noecho();
+
+ if (savecbreak) {
+ cbreak();
+ noraw();
+ } else if (saveraw) {
+ nocbreak();
+ raw();
+ } else {
+ nocbreak();
+ noraw();
+ }
+ if (savenl)
+ nl();
+ else
+ nonl();
+
+ reset_prog_mode();
+
+#if USE_SIZECHANGE
+ _nc_update_screensize(SP);
+#endif
+
+ result = OK;
+ } else {
+ result = ERR;
+ }
+ returnCode(result);
+}
diff --git a/ncurses/base/lib_scanw.c b/ncurses/base/lib_scanw.c
new file mode 100644
index 000000000000..b8a5a227a1a9
--- /dev/null
+++ b/ncurses/base/lib_scanw.c
@@ -0,0 +1,106 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_scanw.c
+**
+** The routines scanw(), wscanw() and friends.
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_scanw.c,v 1.11 2001/06/30 23:39:41 tom Exp $")
+
+NCURSES_EXPORT(int)
+vwscanw(WINDOW *win, NCURSES_CONST char *fmt, va_list argp)
+{
+ char buf[BUFSIZ];
+
+ if (wgetnstr(win, buf, sizeof(buf) - 1) == ERR)
+ return (ERR);
+
+ return (vsscanf(buf, fmt, argp));
+}
+
+NCURSES_EXPORT(int)
+scanw(NCURSES_CONST char *fmt,...)
+{
+ int code;
+ va_list ap;
+
+ T(("scanw(\"%s\",...) called", fmt));
+
+ va_start(ap, fmt);
+ code = vwscanw(stdscr, fmt, ap);
+ va_end(ap);
+ return (code);
+}
+
+NCURSES_EXPORT(int)
+wscanw(WINDOW *win, NCURSES_CONST char *fmt,...)
+{
+ int code;
+ va_list ap;
+
+ T(("wscanw(%p,\"%s\",...) called", win, fmt));
+
+ va_start(ap, fmt);
+ code = vwscanw(win, fmt, ap);
+ va_end(ap);
+ return (code);
+}
+
+NCURSES_EXPORT(int)
+mvscanw(int y, int x, NCURSES_CONST char *fmt,...)
+{
+ int code;
+ va_list ap;
+
+ va_start(ap, fmt);
+ code = (move(y, x) == OK) ? vwscanw(stdscr, fmt, ap) : ERR;
+ va_end(ap);
+ return (code);
+}
+
+NCURSES_EXPORT(int)
+mvwscanw(WINDOW *win, int y, int x, NCURSES_CONST char *fmt,...)
+{
+ int code;
+ va_list ap;
+
+ va_start(ap, fmt);
+ code = (wmove(win, y, x) == OK) ? vwscanw(win, fmt, ap) : ERR;
+ va_end(ap);
+ return (code);
+}
diff --git a/ncurses/base/lib_screen.c b/ncurses/base/lib_screen.c
new file mode 100644
index 000000000000..e6aecbdaab47
--- /dev/null
+++ b/ncurses/base/lib_screen.c
@@ -0,0 +1,214 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996 on *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_screen.c,v 1.30 2007/03/10 23:20:41 tom Exp $")
+
+NCURSES_EXPORT(WINDOW *)
+getwin(FILE *filep)
+{
+ WINDOW tmp, *nwin;
+ int n;
+
+ T((T_CALLED("getwin(%p)"), filep));
+
+ clearerr(filep);
+ (void) fread(&tmp, sizeof(WINDOW), 1, filep);
+ if (ferror(filep))
+ returnWin(0);
+
+ if (tmp._flags & _ISPAD) {
+ nwin = newpad(tmp._maxy + 1, tmp._maxx + 1);
+ } else {
+ nwin = newwin(tmp._maxy + 1, tmp._maxx + 1, 0, 0);
+ }
+
+ /*
+ * We deliberately do not restore the _parx, _pary, or _parent
+ * fields, because the window hierarchy within which they
+ * made sense is probably gone.
+ */
+ if (nwin != 0) {
+ nwin->_curx = tmp._curx;
+ nwin->_cury = tmp._cury;
+ nwin->_maxy = tmp._maxy;
+ nwin->_maxx = tmp._maxx;
+ nwin->_begy = tmp._begy;
+ nwin->_begx = tmp._begx;
+ nwin->_yoffset = tmp._yoffset;
+ nwin->_flags = tmp._flags & ~(_SUBWIN);
+
+ WINDOW_ATTRS(nwin) = WINDOW_ATTRS(&tmp);
+ nwin->_nc_bkgd = tmp._nc_bkgd;
+
+ nwin->_notimeout = tmp._notimeout;
+ nwin->_clear = tmp._clear;
+ nwin->_leaveok = tmp._leaveok;
+ nwin->_idlok = tmp._idlok;
+ nwin->_idcok = tmp._idcok;
+ nwin->_immed = tmp._immed;
+ nwin->_scroll = tmp._scroll;
+ nwin->_sync = tmp._sync;
+ nwin->_use_keypad = tmp._use_keypad;
+ nwin->_delay = tmp._delay;
+
+ nwin->_regtop = tmp._regtop;
+ nwin->_regbottom = tmp._regbottom;
+
+ if (tmp._flags & _ISPAD)
+ nwin->_pad = tmp._pad;
+
+ for (n = 0; n <= nwin->_maxy; n++) {
+ clearerr(filep);
+ (void) fread(nwin->_line[n].text,
+ sizeof(NCURSES_CH_T),
+ (size_t) (nwin->_maxx + 1),
+ filep);
+ if (ferror(filep)) {
+ delwin(nwin);
+ returnWin(0);
+ }
+ }
+ touchwin(nwin);
+ }
+ returnWin(nwin);
+}
+
+NCURSES_EXPORT(int)
+putwin(WINDOW *win, FILE *filep)
+{
+ int code = ERR;
+ int n;
+
+ T((T_CALLED("putwin(%p,%p)"), win, filep));
+
+ if (win != 0) {
+ size_t len = (win->_maxx + 1);
+
+ clearerr(filep);
+ if (fwrite(win, sizeof(WINDOW), 1, filep) != 1
+ || ferror(filep))
+ returnCode(code);
+
+ for (n = 0; n <= win->_maxy; n++) {
+ if (fwrite(win->_line[n].text,
+ sizeof(NCURSES_CH_T), len, filep) != len
+ || ferror(filep)) {
+ returnCode(code);
+ }
+ }
+ code = OK;
+ }
+ returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+scr_restore(const char *file)
+{
+ FILE *fp = 0;
+
+ T((T_CALLED("scr_restore(%s)"), _nc_visbuf(file)));
+
+ if (_nc_access(file, R_OK) < 0
+ || (fp = fopen(file, "rb")) == 0) {
+ returnCode(ERR);
+ } else {
+ delwin(newscr);
+ SP->_newscr = getwin(fp);
+#if !USE_REENTRANT
+ newscr = SP->_newscr;
+#endif
+ (void) fclose(fp);
+ returnCode(OK);
+ }
+}
+
+NCURSES_EXPORT(int)
+scr_dump(const char *file)
+{
+ FILE *fp = 0;
+
+ T((T_CALLED("scr_dump(%s)"), _nc_visbuf(file)));
+
+ if (_nc_access(file, W_OK) < 0
+ || (fp = fopen(file, "wb")) == 0) {
+ returnCode(ERR);
+ } else {
+ (void) putwin(newscr, fp);
+ (void) fclose(fp);
+ returnCode(OK);
+ }
+}
+
+NCURSES_EXPORT(int)
+scr_init(const char *file)
+{
+ FILE *fp = 0;
+
+ T((T_CALLED("scr_init(%s)"), _nc_visbuf(file)));
+
+ if (exit_ca_mode && non_rev_rmcup)
+ returnCode(ERR);
+
+ if (_nc_access(file, R_OK) < 0
+ || (fp = fopen(file, "rb")) == 0) {
+ returnCode(ERR);
+ } else {
+ delwin(curscr);
+ SP->_curscr = getwin(fp);
+#if !USE_REENTRANT
+ curscr = SP->_curscr;
+#endif
+ (void) fclose(fp);
+ returnCode(OK);
+ }
+}
+
+NCURSES_EXPORT(int)
+scr_set(const char *file)
+{
+ T((T_CALLED("scr_set(%s)"), _nc_visbuf(file)));
+
+ if (scr_init(file) == ERR) {
+ returnCode(ERR);
+ } else {
+ delwin(newscr);
+ SP->_newscr = dupwin(curscr);
+#if !USE_REENTRANT
+ newscr = SP->_newscr;
+#endif
+ returnCode(OK);
+ }
+}
diff --git a/ncurses/base/lib_scroll.c b/ncurses/base/lib_scroll.c
new file mode 100644
index 000000000000..ac85bd55ea1d
--- /dev/null
+++ b/ncurses/base/lib_scroll.c
@@ -0,0 +1,150 @@
+/****************************************************************************
+ * Copyright (c) 1998-2004,2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey 1996-2003 *
+ * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_scroll.c
+**
+** The routine wscrl(win, n).
+** positive n scroll the window up (ie. move lines down)
+** negative n scroll the window down (ie. move lines up)
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_scroll.c,v 1.26 2006/10/14 20:46:08 tom Exp $")
+
+NCURSES_EXPORT(void)
+_nc_scroll_window(WINDOW *win,
+ int const n,
+ NCURSES_SIZE_T const top,
+ NCURSES_SIZE_T const bottom,
+ NCURSES_CH_T blank)
+{
+ int limit;
+ int line;
+ int j;
+ size_t to_copy = (size_t) (sizeof(NCURSES_CH_T) * (win->_maxx + 1));
+
+ TR(TRACE_MOVE, ("_nc_scroll_window(%p, %d, %ld, %ld)",
+ win, n, (long) top, (long) bottom));
+
+ if (top < 0
+ || bottom < top
+ || bottom > win->_maxy) {
+ TR(TRACE_MOVE, ("nothing to scroll"));
+ return;
+ }
+
+ /*
+ * This used to do a line-text pointer-shuffle instead of text copies.
+ * That (a) doesn't work when the window is derived and doesn't have
+ * its own storage, (b) doesn't save you a lot on modern machines
+ * anyway. Your typical memcpy implementations are coded in
+ * assembler using a tight BLT loop; for the size of copies we're
+ * talking here, the total execution time is dominated by the one-time
+ * setup cost. So there is no point in trying to be excessively
+ * clever -- esr.
+ */
+
+ /* shift n lines downwards */
+ if (n < 0) {
+ limit = top - n;
+ for (line = bottom; line >= limit && line >= 0; line--) {
+ TR(TRACE_MOVE, ("...copying %d to %d", line + n, line));
+ memcpy(win->_line[line].text,
+ win->_line[line + n].text,
+ to_copy);
+ if_USE_SCROLL_HINTS(win->_line[line].oldindex =
+ win->_line[line + n].oldindex);
+ }
+ for (line = top; line < limit && line <= win->_maxy; line++) {
+ TR(TRACE_MOVE, ("...filling %d", line));
+ for (j = 0; j <= win->_maxx; j++)
+ win->_line[line].text[j] = blank;
+ if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX);
+ }
+ }
+
+ /* shift n lines upwards */
+ if (n > 0) {
+ limit = bottom - n;
+ for (line = top; line <= limit && line <= win->_maxy; line++) {
+ memcpy(win->_line[line].text,
+ win->_line[line + n].text,
+ to_copy);
+ if_USE_SCROLL_HINTS(win->_line[line].oldindex =
+ win->_line[line + n].oldindex);
+ }
+ for (line = bottom; line > limit && line >= 0; line--) {
+ for (j = 0; j <= win->_maxx; j++)
+ win->_line[line].text[j] = blank;
+ if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX);
+ }
+ }
+ touchline(win, top, bottom - top + 1);
+
+ if_WIDEC({
+ if (WINDOW_EXT(win, addch_used) != 0) {
+ int next = WINDOW_EXT(win, addch_y) + n;
+ if (next < 0 || next > win->_maxy) {
+ TR(TRACE_VIRTPUT,
+ ("Alert discarded multibyte on scroll"));
+ WINDOW_EXT(win, addch_y) = 0;
+ } else {
+ TR(TRACE_VIRTPUT, ("scrolled working position to %d,%d",
+ WINDOW_EXT(win, addch_y),
+ WINDOW_EXT(win, addch_x)));
+ WINDOW_EXT(win, addch_y) = next;
+ }
+ }
+ })
+}
+
+NCURSES_EXPORT(int)
+wscrl(WINDOW *win, int n)
+{
+ T((T_CALLED("wscrl(%p,%d)"), win, n));
+
+ if (!win || !win->_scroll) {
+ TR(TRACE_MOVE, ("...scrollok is false"));
+ returnCode(ERR);
+ }
+
+ if (n != 0) {
+ _nc_scroll_window(win, n, win->_regtop, win->_regbottom, win->_nc_bkgd);
+ _nc_synchook(win);
+ }
+ returnCode(OK);
+}
diff --git a/ncurses/base/lib_scrollok.c b/ncurses/base/lib_scrollok.c
new file mode 100644
index 000000000000..f6b30259be73
--- /dev/null
+++ b/ncurses/base/lib_scrollok.c
@@ -0,0 +1,55 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_scrollok.c
+**
+** The routine scrollok.
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_scrollok.c,v 1.4 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(int)
+scrollok(WINDOW *win, bool flag)
+{
+ T((T_CALLED("scrollok(%p,%d)"), win, flag));
+
+ if (win) {
+ win->_scroll = flag;
+ returnCode(OK);
+ } else
+ returnCode(ERR);
+}
diff --git a/ncurses/base/lib_scrreg.c b/ncurses/base/lib_scrreg.c
new file mode 100644
index 000000000000..c85d60f1164d
--- /dev/null
+++ b/ncurses/base/lib_scrreg.c
@@ -0,0 +1,60 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_scrreg.c
+**
+** The routine wsetscrreg().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_scrreg.c,v 1.10 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(int)
+wsetscrreg(WINDOW *win, int top, int bottom)
+{
+ T((T_CALLED("wsetscrreg(%p,%d,%d)"), win, top, bottom));
+
+ if (win &&
+ top >= 0 && top <= win->_maxy &&
+ bottom >= 0 && bottom <= win->_maxy &&
+ bottom > top) {
+ win->_regtop = (NCURSES_SIZE_T) top;
+ win->_regbottom = (NCURSES_SIZE_T) bottom;
+
+ returnCode(OK);
+ } else
+ returnCode(ERR);
+}
diff --git a/ncurses/base/lib_set_term.c b/ncurses/base/lib_set_term.c
new file mode 100644
index 000000000000..eee1cfc7b259
--- /dev/null
+++ b/ncurses/base/lib_set_term.c
@@ -0,0 +1,655 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+** lib_set_term.c
+**
+** The routine set_term().
+**
+*/
+
+#include <curses.priv.h>
+
+#include <term.h> /* cur_term */
+#include <tic.h>
+
+MODULE_ID("$Id: lib_set_term.c,v 1.108 2008/05/03 22:42:43 tom Exp $")
+
+NCURSES_EXPORT(SCREEN *)
+set_term(SCREEN *screenp)
+{
+ SCREEN *oldSP;
+
+ T((T_CALLED("set_term(%p)"), screenp));
+
+ _nc_lock_global(set_SP);
+
+ oldSP = SP;
+ _nc_set_screen(screenp);
+
+ if (SP != 0) {
+ set_curterm(SP->_term);
+#if !USE_REENTRANT
+ curscr = SP->_curscr;
+ newscr = SP->_newscr;
+ stdscr = SP->_stdscr;
+ COLORS = SP->_color_count;
+ COLOR_PAIRS = SP->_pair_count;
+#endif
+ } else {
+ set_curterm(0);
+#if !USE_REENTRANT
+ curscr = 0;
+ newscr = 0;
+ stdscr = 0;
+ COLORS = 0;
+ COLOR_PAIRS = 0;
+#endif
+ }
+
+ _nc_unlock_global(set_SP);
+
+ T((T_RETURN("%p"), oldSP));
+ return (oldSP);
+}
+
+static void
+_nc_free_keytry(TRIES * kt)
+{
+ if (kt != 0) {
+ _nc_free_keytry(kt->child);
+ _nc_free_keytry(kt->sibling);
+ free(kt);
+ }
+}
+
+static bool
+delink_screen(SCREEN *sp)
+{
+ SCREEN *last = 0;
+ SCREEN *temp;
+ bool result = FALSE;
+
+ for (each_screen(temp)) {
+ if (temp == sp) {
+ if (last)
+ last = sp->_next_screen;
+ else
+ _nc_screen_chain = sp->_next_screen;
+ result = TRUE;
+ break;
+ }
+ last = temp;
+ }
+ return result;
+}
+
+/*
+ * Free the storage associated with the given SCREEN sp.
+ */
+NCURSES_EXPORT(void)
+delscreen(SCREEN *sp)
+{
+ int i;
+
+ T((T_CALLED("delscreen(%p)"), sp));
+
+ _nc_lock_global(set_SP);
+ if (delink_screen(sp)) {
+
+ (void) _nc_freewin(sp->_curscr);
+ (void) _nc_freewin(sp->_newscr);
+ (void) _nc_freewin(sp->_stdscr);
+
+ if (sp->_slk != 0) {
+ if (sp->_slk->ent != 0) {
+ for (i = 0; i < sp->_slk->labcnt; ++i) {
+ FreeIfNeeded(sp->_slk->ent[i].ent_text);
+ FreeIfNeeded(sp->_slk->ent[i].form_text);
+ }
+ free(sp->_slk->ent);
+ }
+ free(sp->_slk);
+ sp->_slk = 0;
+ }
+
+ _nc_free_keytry(sp->_keytry);
+ sp->_keytry = 0;
+
+ _nc_free_keytry(sp->_key_ok);
+ sp->_key_ok = 0;
+
+ FreeIfNeeded(sp->_current_attr);
+
+ FreeIfNeeded(sp->_color_table);
+ FreeIfNeeded(sp->_color_pairs);
+
+ FreeIfNeeded(sp->oldhash);
+ FreeIfNeeded(sp->newhash);
+ FreeIfNeeded(sp->hashtab);
+
+ FreeIfNeeded(sp->_acs_map);
+ FreeIfNeeded(sp->_screen_acs_map);
+
+ del_curterm(sp->_term);
+
+ /*
+ * 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);
+ }
+
+ free(sp);
+
+ /*
+ * If this was the current screen, reset everything that the
+ * application might try to use (except cur_term, which may have
+ * multiple references in different screens).
+ */
+ if (sp == SP) {
+#if !USE_REENTRANT
+ curscr = 0;
+ newscr = 0;
+ stdscr = 0;
+ COLORS = 0;
+ COLOR_PAIRS = 0;
+#endif
+ _nc_set_screen(0);
+ }
+ }
+ _nc_unlock_global(set_SP);
+
+ returnVoid;
+}
+
+static bool
+no_mouse_event(SCREEN *sp GCC_UNUSED)
+{
+ return FALSE;
+}
+
+static bool
+no_mouse_inline(SCREEN *sp GCC_UNUSED)
+{
+ return FALSE;
+}
+
+static bool
+no_mouse_parse(int code GCC_UNUSED)
+{
+ return TRUE;
+}
+
+static void
+no_mouse_resume(SCREEN *sp GCC_UNUSED)
+{
+}
+
+static void
+no_mouse_wrap(SCREEN *sp GCC_UNUSED)
+{
+}
+
+#if NCURSES_EXT_FUNCS && USE_COLORFGBG
+static char *
+extract_fgbg(char *src, int *result)
+{
+ char *dst = 0;
+ long value = strtol(src, &dst, 0);
+
+ if (dst == 0) {
+ dst = src;
+ } else if (value >= 0) {
+ *result = value;
+ }
+ while (*dst != 0 && *dst != ';')
+ dst++;
+ if (*dst == ';')
+ dst++;
+ return dst;
+}
+#endif
+
+/* OS-independent screen initializations */
+NCURSES_EXPORT(int)
+_nc_setupscreen(int slines GCC_UNUSED,
+ int scolumns GCC_UNUSED,
+ FILE *output,
+ bool filtered,
+ int slk_format)
+{
+ char *env;
+ int bottom_stolen = 0;
+ bool support_cookies = USE_XMC_SUPPORT;
+ ripoff_t *rop;
+
+ T((T_CALLED("_nc_setupscreen(%d, %d, %p, %d, %d)"),
+ slines, scolumns, output, filtered, slk_format));
+
+ assert(SP == 0); /* has been reset in newterm() ! */
+ if (!_nc_alloc_screen()
+ || ((SP->_acs_map = typeCalloc(chtype, ACS_LEN)) == 0)
+ || ((SP->_screen_acs_map = typeCalloc(bool, ACS_LEN)) == 0)) {
+ returnCode(ERR);
+ }
+
+ T(("created SP %p", SP));
+ SP->_next_screen = _nc_screen_chain;
+ _nc_screen_chain = SP;
+
+ if ((SP->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == 0)
+ returnCode(ERR);
+
+ /*
+ * We should always check the screensize, just in case.
+ */
+ _nc_get_screensize(SP, &slines, &scolumns);
+ SET_LINES(slines);
+ SET_COLS(scolumns);
+ T((T_CREATE("screen %s %dx%d"), termname(), LINES, COLS));
+
+ SP->_filtered = filtered;
+
+ /* implement filter mode */
+ if (filtered) {
+ slines = 1;
+ SET_LINES(slines);
+ clear_screen = 0;
+ cursor_down = parm_down_cursor = 0;
+ cursor_address = 0;
+ cursor_up = parm_up_cursor = 0;
+ row_address = 0;
+
+ cursor_home = carriage_return;
+ T(("filter screensize %dx%d", LINES, COLS));
+ }
+#ifdef __DJGPP__
+ T(("setting output mode to binary"));
+ fflush(output);
+ setmode(output, O_BINARY);
+#endif
+ _nc_set_buffer(output, TRUE);
+ SP->_term = cur_term;
+ SP->_lines = slines;
+ SP->_lines_avail = slines;
+ SP->_columns = scolumns;
+ SP->_cursrow = -1;
+ SP->_curscol = -1;
+ SP->_nl = TRUE;
+ SP->_raw = FALSE;
+ SP->_cbreak = 0;
+ SP->_echo = TRUE;
+ SP->_fifohead = -1;
+ SP->_endwin = TRUE;
+ SP->_ofp = output;
+ SP->_cursor = -1; /* cannot know real cursor shape */
+
+#if NCURSES_NO_PADDING
+ SP->_no_padding = getenv("NCURSES_NO_PADDING") != 0;
+ TR(TRACE_CHARPUT | TRACE_MOVE, ("padding will%s be used",
+ SP->_no_padding ? " not" : ""));
+#endif
+
+#if NCURSES_EXT_FUNCS
+ SP->_default_color = FALSE;
+ SP->_has_sgr_39_49 = FALSE;
+
+ /*
+ * Set our assumption of the terminal's default foreground and background
+ * colors. The curs_color man-page states that we can assume that the
+ * background is black. The origin of this assumption appears to be
+ * terminals that displayed colored text, but no colored backgrounds, e.g.,
+ * the first colored terminals around 1980. More recent ones with better
+ * technology can display not only colored backgrounds, but all
+ * combinations. So a terminal might be something other than "white" on
+ * black (green/black looks monochrome too), but black on white or even
+ * on ivory.
+ *
+ * White-on-black is the simplest thing to use for monochrome. Almost
+ * all applications that use color paint both text and background, so
+ * the distinction is moot. But a few do not - which is why we leave this
+ * configurable (a better solution is to use assume_default_colors() for
+ * the rare applications that do require that sort of appearance, since
+ * is appears that more users expect to be able to make a white-on-black
+ * or black-on-white display under control of the application than not).
+ */
+#ifdef USE_ASSUMED_COLOR
+ SP->_default_fg = COLOR_WHITE;
+ SP->_default_bg = COLOR_BLACK;
+#else
+ SP->_default_fg = C_MASK;
+ SP->_default_bg = C_MASK;
+#endif
+
+ /*
+ * Allow those assumed/default color assumptions to be overridden at
+ * runtime:
+ */
+ if (getenv("NCURSES_ASSUMED_COLORS") != 0) {
+ char *p = getenv("NCURSES_ASSUMED_COLORS");
+ int fg, bg;
+ char sep1, sep2;
+ int count = sscanf(p, "%d%c%d%c", &fg, &sep1, &bg, &sep2);
+ if (count >= 1) {
+ SP->_default_fg = (fg >= 0 && fg < max_colors) ? fg : C_MASK;
+ if (count >= 3) {
+ SP->_default_bg = (bg >= 0 && bg < max_colors) ? bg : C_MASK;
+ }
+ TR(TRACE_CHARPUT | TRACE_MOVE,
+ ("from environment assumed fg=%d, bg=%d",
+ SP->_default_fg,
+ SP->_default_bg));
+ }
+ }
+#if USE_COLORFGBG
+ /*
+ * If rxvt's $COLORFGBG variable is set, use it to specify the assumed
+ * default colors. Note that rxvt (mis)uses bold colors, equating a bold
+ * color to that value plus 8. We'll only use the non-bold color for now -
+ * decide later if it is worth having default attributes as well.
+ */
+ if (getenv("COLORFGBG") != 0) {
+ char *p = getenv("COLORFGBG");
+ TR(TRACE_CHARPUT | TRACE_MOVE, ("decoding COLORFGBG %s", p));
+ p = extract_fgbg(p, &(SP->_default_fg));
+ p = extract_fgbg(p, &(SP->_default_bg));
+ if (*p) /* assume rxvt was compiled with xpm support */
+ p = extract_fgbg(p, &(SP->_default_bg));
+ TR(TRACE_CHARPUT | TRACE_MOVE, ("decoded fg=%d, bg=%d",
+ SP->_default_fg, SP->_default_bg));
+ if (SP->_default_fg >= max_colors) {
+ if (set_a_foreground != ABSENT_STRING
+ && !strcmp(set_a_foreground, "\033[3%p1%dm")) {
+ set_a_foreground = "\033[3%?%p1%{8}%>%t9%e%p1%d%;m";
+ } else {
+ SP->_default_fg %= max_colors;
+ }
+ }
+ if (SP->_default_bg >= max_colors) {
+ if (set_a_background != ABSENT_STRING
+ && !strcmp(set_a_background, "\033[4%p1%dm")) {
+ set_a_background = "\033[4%?%p1%{8}%>%t9%e%p1%d%;m";
+ } else {
+ SP->_default_bg %= max_colors;
+ }
+ }
+ }
+#endif
+#endif /* NCURSES_EXT_FUNCS */
+
+ SP->_maxclick = DEFAULT_MAXCLICK;
+ SP->_mouse_event = no_mouse_event;
+ SP->_mouse_inline = no_mouse_inline;
+ SP->_mouse_parse = no_mouse_parse;
+ SP->_mouse_resume = no_mouse_resume;
+ SP->_mouse_wrap = no_mouse_wrap;
+ SP->_mouse_fd = -1;
+
+ /* initialize the panel hooks */
+ SP->_panelHook.top_panel = (struct panel *) 0;
+ SP->_panelHook.bottom_panel = (struct panel *) 0;
+ SP->_panelHook.stdscr_pseudo_panel = (struct panel *) 0;
+
+ /*
+ * If we've no magic cookie support, we suppress attributes that xmc would
+ * affect, i.e., the attributes that affect the rendition of a space.
+ */
+ SP->_ok_attributes = termattrs();
+ if (has_colors()) {
+ SP->_ok_attributes |= A_COLOR;
+ }
+#if USE_XMC_SUPPORT
+ /*
+ * If we have no magic-cookie support compiled-in, or if it is suppressed
+ * in the environment, reset the support-flag.
+ */
+ if (magic_cookie_glitch >= 0) {
+ if (getenv("NCURSES_NO_MAGIC_COOKIE") != 0) {
+ support_cookies = FALSE;
+ }
+ }
+#endif
+
+ if (!support_cookies && magic_cookie_glitch >= 0) {
+ T(("will disable attributes to work w/o magic cookies"));
+ }
+
+ if (magic_cookie_glitch > 0) { /* tvi, wyse */
+
+ SP->_xmc_triggers = SP->_ok_attributes & (
+ A_STANDOUT |
+ A_UNDERLINE |
+ A_REVERSE |
+ A_BLINK |
+ A_DIM |
+ A_BOLD |
+ A_INVIS |
+ A_PROTECT
+ );
+#if 0
+ /*
+ * We "should" treat colors as an attribute. The wyse350 (and its
+ * clones) appear to be the only ones that have both colors and magic
+ * cookies.
+ */
+ if (has_colors()) {
+ SP->_xmc_triggers |= A_COLOR;
+ }
+#endif
+ SP->_xmc_suppress = SP->_xmc_triggers & (chtype) ~(A_BOLD);
+
+ T(("magic cookie attributes %s", _traceattr(SP->_xmc_suppress)));
+ /*
+ * Supporting line-drawing may be possible. But make the regular
+ * video attributes work first.
+ */
+ acs_chars = ABSENT_STRING;
+ ena_acs = ABSENT_STRING;
+ enter_alt_charset_mode = ABSENT_STRING;
+ exit_alt_charset_mode = ABSENT_STRING;
+#if USE_XMC_SUPPORT
+ /*
+ * To keep the cookie support simple, suppress all of the optimization
+ * hooks except for clear_screen and the cursor addressing.
+ */
+ if (support_cookies) {
+ clr_eol = ABSENT_STRING;
+ clr_eos = ABSENT_STRING;
+ set_attributes = ABSENT_STRING;
+ }
+#endif
+ } else if (magic_cookie_glitch == 0) { /* hpterm */
+ }
+
+ /*
+ * If magic cookies are not supported, cancel the strings that set
+ * video attributes.
+ */
+ if (!support_cookies && magic_cookie_glitch >= 0) {
+ magic_cookie_glitch = ABSENT_NUMERIC;
+ set_attributes = ABSENT_STRING;
+ enter_blink_mode = ABSENT_STRING;
+ enter_bold_mode = ABSENT_STRING;
+ enter_dim_mode = ABSENT_STRING;
+ enter_reverse_mode = ABSENT_STRING;
+ enter_standout_mode = ABSENT_STRING;
+ enter_underline_mode = ABSENT_STRING;
+ }
+
+ /* initialize normal acs before wide, since we use mapping in the latter */
+#if !USE_WIDEC_SUPPORT
+ if (_nc_unicode_locale() && _nc_locale_breaks_acs()) {
+ acs_chars = NULL;
+ ena_acs = NULL;
+ enter_alt_charset_mode = NULL;
+ exit_alt_charset_mode = NULL;
+ set_attributes = NULL;
+ }
+#endif
+ _nc_init_acs();
+#if USE_WIDEC_SUPPORT
+ _nc_init_wacs();
+
+ SP->_screen_acs_fix = (_nc_unicode_locale() && _nc_locale_breaks_acs());
+#endif
+ env = _nc_get_locale();
+ SP->_legacy_coding = ((env == 0)
+ || !strcmp(env, "C")
+ || !strcmp(env, "POSIX"));
+ T(("legacy-coding %d", SP->_legacy_coding));
+
+ _nc_idcok = TRUE;
+ _nc_idlok = FALSE;
+
+ SP->oldhash = 0;
+ SP->newhash = 0;
+
+ T(("creating newscr"));
+ if ((SP->_newscr = newwin(slines, scolumns, 0, 0)) == 0)
+ returnCode(ERR);
+
+ T(("creating curscr"));
+ if ((SP->_curscr = newwin(slines, scolumns, 0, 0)) == 0)
+ returnCode(ERR);
+
+#if !USE_REENTRANT
+ newscr = SP->_newscr;
+ curscr = SP->_curscr;
+#endif
+#if USE_SIZECHANGE
+ SP->_resize = resizeterm;
+#endif
+
+ newscr->_clear = TRUE;
+ curscr->_clear = FALSE;
+
+ def_shell_mode();
+ def_prog_mode();
+
+ for (rop = ripoff_stack;
+ rop != ripoff_sp && (rop - ripoff_stack) < N_RIPS;
+ rop++) {
+
+ /* If we must simulate soft labels, grab off the line to be used.
+ We assume that we must simulate, if it is none of the standard
+ formats (4-4 or 3-2-3) for which there may be some hardware
+ support. */
+ if (rop->hook == _nc_slk_initialize)
+ if (!(num_labels <= 0 || !SLK_STDFMT(slk_format)))
+ continue;
+ if (rop->hook) {
+ int count;
+ WINDOW *w;
+
+ count = (rop->line < 0) ? -rop->line : rop->line;
+ T(("ripping off %i lines at %s", count,
+ ((rop->line < 0)
+ ? "bottom"
+ : "top")));
+
+ w = newwin(count, scolumns,
+ ((rop->line < 0)
+ ? SP->_lines_avail - count
+ : 0),
+ 0);
+ if (w) {
+ rop->win = w;
+ rop->hook(w, scolumns);
+ } else {
+ returnCode(ERR);
+ }
+ if (rop->line < 0)
+ bottom_stolen += count;
+ else
+ SP->_topstolen += count;
+ SP->_lines_avail -= count;
+ }
+ }
+ /* reset the stack */
+ ripoff_sp = ripoff_stack;
+
+ T(("creating stdscr"));
+ assert((SP->_lines_avail + SP->_topstolen + bottom_stolen) == slines);
+ if ((SP->_stdscr = newwin(SP->_lines_avail, scolumns, 0, 0)) == 0)
+ returnCode(ERR);
+
+ SET_LINES(SP->_lines_avail);
+#if !USE_REENTRANT
+ stdscr = SP->_stdscr;
+#endif
+
+ returnCode(OK);
+}
+
+/*
+ * The internal implementation interprets line as the number of lines to rip
+ * off from the top or bottom.
+ */
+NCURSES_EXPORT(int)
+_nc_ripoffline(int line, int (*init) (WINDOW *, int))
+{
+ T((T_CALLED("_nc_ripoffline(%d, %p)"), line, init));
+
+ if (line != 0) {
+
+ if (ripoff_sp == 0)
+ ripoff_sp = ripoff_stack;
+ if (ripoff_sp >= ripoff_stack + N_RIPS)
+ returnCode(ERR);
+
+ ripoff_sp->line = line;
+ ripoff_sp->hook = init;
+ ripoff_sp++;
+ }
+
+ returnCode(OK);
+}
+
+NCURSES_EXPORT(int)
+ripoffline(int line, int (*init) (WINDOW *, int))
+{
+ START_TRACE();
+ T((T_CALLED("ripoffline(%d,%p)"), line, init));
+
+ if (line == 0)
+ returnCode(OK);
+
+ returnCode(_nc_ripoffline((line < 0) ? -1 : 1, init));
+}
diff --git a/ncurses/base/lib_slk.c b/ncurses/base/lib_slk.c
new file mode 100644
index 000000000000..27b21b08d718
--- /dev/null
+++ b/ncurses/base/lib_slk.c
@@ -0,0 +1,219 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Authors: *
+ * Gerhard Fuernkranz 1993 (original) *
+ * Zeyd M. Ben-Halim 1992,1995 (sic) *
+ * Eric S. Raymond *
+ * Juergen Pfeifer 1996-on *
+ * Thomas E. Dickey *
+ ****************************************************************************/
+
+/*
+ * lib_slk.c
+ * Soft key routines.
+ */
+
+#include <curses.priv.h>
+
+#include <ctype.h>
+#include <term.h> /* num_labels, label_*, plab_norm */
+
+MODULE_ID("$Id: lib_slk.c,v 1.31 2008/01/12 20:21:00 tom Exp $")
+
+/*
+ * We'd like to move these into the screen context structure, but cannot,
+ * because slk_init() is called before initscr()/newterm().
+ */
+NCURSES_EXPORT_VAR(int)
+_nc_slk_format = 0; /* one more than format specified in slk_init() */
+
+/*
+ * Paint the info line for the PC style SLK emulation.
+ */
+static void
+slk_paint_info(WINDOW *win)
+{
+ if (win && SP->slk_format == 4) {
+ int i;
+
+ mvwhline(win, 0, 0, 0, getmaxx(win));
+ wmove(win, 0, 0);
+
+ for (i = 0; i < SP->_slk->maxlab; i++) {
+ mvwprintw(win, 0, SP->_slk->ent[i].ent_x, "F%d", i + 1);
+ }
+ }
+}
+
+/*
+ * Free any memory related to soft labels, return an error.
+ */
+static int
+slk_failed(void)
+{
+ if (SP->_slk) {
+ FreeIfNeeded(SP->_slk->ent);
+ free(SP->_slk);
+ SP->_slk = (SLK *) 0;
+ }
+ return ERR;
+}
+
+/*
+ * Initialize soft labels.
+ * Called from newterm()
+ */
+NCURSES_EXPORT(int)
+_nc_slk_initialize(WINDOW *stwin, int cols)
+{
+ int i, x;
+ int res = OK;
+ unsigned max_length;
+
+ T((T_CALLED("_nc_slk_initialize()")));
+
+ if (SP->_slk) { /* we did this already, so simply return */
+ returnCode(OK);
+ } else if ((SP->_slk = typeCalloc(SLK, 1)) == 0)
+ returnCode(ERR);
+
+ SP->_slk->ent = NULL;
+
+ /*
+ * If we use colors, vidputs() will suppress video attributes that conflict
+ * with colors. In that case, we're still guaranteed that "reverse" would
+ * work.
+ */
+ if ((no_color_video & 1) == 0)
+ SetAttr(SP->_slk->attr, A_STANDOUT);
+ else
+ SetAttr(SP->_slk->attr, A_REVERSE);
+
+ SP->_slk->maxlab = ((num_labels > 0)
+ ? num_labels
+ : MAX_SKEY(_nc_globals.slk_format));
+ SP->_slk->maxlen = ((num_labels > 0)
+ ? label_width * label_height
+ : MAX_SKEY_LEN(_nc_globals.slk_format));
+ SP->_slk->labcnt = ((SP->_slk->maxlab < MAX_SKEY(_nc_globals.slk_format))
+ ? MAX_SKEY(_nc_globals.slk_format)
+ : SP->_slk->maxlab);
+
+ if (SP->_slk->maxlen <= 0
+ || SP->_slk->labcnt <= 0
+ || (SP->_slk->ent = typeCalloc(slk_ent,
+ (unsigned) SP->_slk->labcnt)) == NULL)
+ returnCode(slk_failed());
+
+ max_length = SP->_slk->maxlen;
+ for (i = 0; i < SP->_slk->labcnt; i++) {
+ size_t used = max_length + 1;
+
+ if ((SP->_slk->ent[i].ent_text = (char *) _nc_doalloc(0, used)) == 0)
+ returnCode(slk_failed());
+ memset(SP->_slk->ent[i].ent_text, 0, used);
+
+ if ((SP->_slk->ent[i].form_text = (char *) _nc_doalloc(0, used)) == 0)
+ returnCode(slk_failed());
+ memset(SP->_slk->ent[i].form_text, 0, used);
+
+ memset(SP->_slk->ent[i].form_text, ' ', max_length);
+ SP->_slk->ent[i].visible = (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;
+ }
+ slk_paint_info(stwin);
+ } else {
+ if (_nc_globals.slk_format == 2) { /* 4-4 */
+ int gap = cols - (SP->_slk->maxlab * max_length) - 6;
+
+ if (gap < 1)
+ gap = 1;
+ for (i = x = 0; i < SP->_slk->maxlab; i++) {
+ SP->_slk->ent[i].ent_x = x;
+ x += max_length;
+ x += (i == 3) ? gap : 1;
+ }
+ } else {
+ if (_nc_globals.slk_format == 1) { /* 1 -> 3-2-3 */
+ int gap = (cols - (SP->_slk->maxlab * max_length) - 5)
+ / 2;
+
+ if (gap < 1)
+ gap = 1;
+ for (i = x = 0; i < SP->_slk->maxlab; i++) {
+ SP->_slk->ent[i].ent_x = x;
+ x += max_length;
+ x += (i == 2 || i == 4) ? gap : 1;
+ }
+ } else
+ returnCode(slk_failed());
+ }
+ }
+ SP->_slk->dirty = TRUE;
+ if ((SP->_slk->win = stwin) == NULL) {
+ returnCode(slk_failed());
+ }
+
+ /* We now reset the format so that the next newterm has again
+ * per default no SLK keys and may call slk_init again to
+ * define a new layout. (juergen 03-Mar-1999)
+ */
+ SP->slk_format = _nc_globals.slk_format;
+ _nc_globals.slk_format = 0;
+ returnCode(res);
+}
+
+/*
+ * Restore the soft labels on the screen.
+ */
+NCURSES_EXPORT(int)
+slk_restore(void)
+{
+ T((T_CALLED("slk_restore()")));
+
+ if (SP->_slk == NULL)
+ return (ERR);
+ SP->_slk->hidden = FALSE;
+ SP->_slk->dirty = TRUE;
+ /* we have to repaint info line eventually */
+ slk_paint_info(SP->_slk->win);
+
+ returnCode(slk_refresh());
+}
diff --git a/ncurses/base/lib_slkatr_set.c b/ncurses/base/lib_slkatr_set.c
new file mode 100644
index 000000000000..f83616beaf17
--- /dev/null
+++ b/ncurses/base/lib_slkatr_set.c
@@ -0,0 +1,59 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer, 1998 *
+ * and: Thomas E. Dickey 2005 *
+ ****************************************************************************/
+
+/*
+ * lib_slkatr_set.c
+ * Soft key routines.
+ * Set the label's attributes
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slkatr_set.c,v 1.10 2005/01/28 21:11:53 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_attr_set(const attr_t attr, short color_pair_number, void *opts)
+{
+ T((T_CALLED("slk_attr_set(%s,%d)"), _traceattr(attr), color_pair_number));
+
+ if (SP != 0 && SP->_slk != 0 && !opts &&
+ color_pair_number >= 0 && color_pair_number < COLOR_PAIRS) {
+ TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP->_slk->attr))));
+ SetAttr(SP->_slk->attr, attr);
+ if (color_pair_number > 0) {
+ SetPair(SP->_slk->attr, color_pair_number);
+ }
+ TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr))));
+ returnCode(OK);
+ } else
+ returnCode(ERR);
+}
diff --git a/ncurses/base/lib_slkatrof.c b/ncurses/base/lib_slkatrof.c
new file mode 100644
index 000000000000..14b4c3bfadcc
--- /dev/null
+++ b/ncurses/base/lib_slkatrof.c
@@ -0,0 +1,58 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer, 1997 *
+ * and: Thomas E. Dickey 2005 *
+ ****************************************************************************/
+
+/*
+ * lib_slkatrof.c
+ * Soft key routines.
+ * Switch off labels attributes
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slkatrof.c,v 1.8 2005/01/08 23:01:32 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_attroff(const chtype attr)
+{
+ T((T_CALLED("slk_attroff(%s)"), _traceattr(attr)));
+
+ if (SP != 0 && SP->_slk != 0) {
+ TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP->_slk->attr))));
+ RemAttr(SP->_slk->attr, attr);
+ if ((attr & A_COLOR) != 0) {
+ SetPair(SP->_slk->attr, 0);
+ }
+ TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr))));
+ returnCode(OK);
+ } else
+ returnCode(ERR);
+}
diff --git a/ncurses/base/lib_slkatron.c b/ncurses/base/lib_slkatron.c
new file mode 100644
index 000000000000..90add86dc1c8
--- /dev/null
+++ b/ncurses/base/lib_slkatron.c
@@ -0,0 +1,58 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer, 1997 *
+ * and: Thomas E. Dickey 2005 *
+ ****************************************************************************/
+
+/*
+ * lib_slkatron.c
+ * Soft key routines.
+ * Switch on labels attributes
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slkatron.c,v 1.8 2005/01/08 23:02:01 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_attron(const chtype attr)
+{
+ T((T_CALLED("slk_attron(%s)"), _traceattr(attr)));
+
+ if (SP != 0 && SP->_slk != 0) {
+ TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP->_slk->attr))));
+ AddAttr(SP->_slk->attr, attr);
+ if ((attr & A_COLOR) != 0) {
+ SetPair(SP->_slk->attr, PAIR_NUMBER(attr));
+ }
+ TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr))));
+ returnCode(OK);
+ } else
+ returnCode(ERR);
+}
diff --git a/ncurses/base/lib_slkatrset.c b/ncurses/base/lib_slkatrset.c
new file mode 100644
index 000000000000..8da9981b3b3e
--- /dev/null
+++ b/ncurses/base/lib_slkatrset.c
@@ -0,0 +1,53 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer, 1997 *
+ * and: Thomas E. Dickey 2005 *
+ ****************************************************************************/
+
+/*
+ * lib_slkatrset.c
+ * Soft key routines.
+ * Set the labels attributes
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slkatrset.c,v 1.7 2005/01/08 21:46:47 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_attrset(const chtype attr)
+{
+ T((T_CALLED("slk_attrset(%s)"), _traceattr(attr)));
+
+ if (SP != 0 && SP->_slk != 0) {
+ SetAttr(SP->_slk->attr, attr);
+ returnCode(OK);
+ } else
+ returnCode(ERR);
+}
diff --git a/ncurses/base/lib_slkattr.c b/ncurses/base/lib_slkattr.c
new file mode 100644
index 000000000000..da82ee5b623e
--- /dev/null
+++ b/ncurses/base/lib_slkattr.c
@@ -0,0 +1,56 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer, 1997 *
+ * and: Thomas E. Dickey 2005 *
+ ****************************************************************************/
+
+/*
+ * lib_slkattr.c
+ * Soft key routines.
+ * Fetch the labels attributes
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slkattr.c,v 1.6 2005/01/08 21:44:28 tom Exp $")
+
+NCURSES_EXPORT(attr_t)
+slk_attr(void)
+{
+ T((T_CALLED("slk_attr()")));
+
+ if (SP != 0 && SP->_slk != 0) {
+ attr_t result = AttrOf(SP->_slk->attr) & ALL_BUT_COLOR;
+ int pair = GetPair(SP->_slk->attr);
+
+ result |= COLOR_PAIR(pair);
+ returnAttr(result);
+ } else
+ returnAttr(0);
+}
diff --git a/ncurses/base/lib_slkclear.c b/ncurses/base/lib_slkclear.c
new file mode 100644
index 000000000000..946ceeaf0e0d
--- /dev/null
+++ b/ncurses/base/lib_slkclear.c
@@ -0,0 +1,66 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Juergen Pfeifer 1996-1999 *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+ * lib_slkclear.c
+ * Soft key routines.
+ * Remove soft labels from the screen.
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slkclear.c,v 1.10 2007/12/29 17:51:47 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_clear(void)
+{
+ int rc = ERR;
+
+ T((T_CALLED("slk_clear()")));
+
+ if (SP != NULL && SP->_slk != NULL) {
+ SP->_slk->hidden = TRUE;
+ /* For simulated SLK's it looks much more natural to
+ inherit those attributes from the standard screen */
+ SP->_slk->win->_nc_bkgd = stdscr->_nc_bkgd;
+ WINDOW_ATTRS(SP->_slk->win) = WINDOW_ATTRS(stdscr);
+ if (SP->_slk->win == stdscr) {
+ rc = OK;
+ } else {
+ werase(SP->_slk->win);
+ rc = wrefresh(SP->_slk->win);
+ }
+ }
+ returnCode(rc);
+}
diff --git a/ncurses/base/lib_slkcolor.c b/ncurses/base/lib_slkcolor.c
new file mode 100644
index 000000000000..b677b65a529a
--- /dev/null
+++ b/ncurses/base/lib_slkcolor.c
@@ -0,0 +1,56 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer, 1998 *
+ * and: Thomas E. Dickey 2005 *
+ ****************************************************************************/
+
+/*
+ * lib_slkcolor.c
+ * Soft key routines.
+ * Set the label's color
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slkcolor.c,v 1.12 2005/01/28 21:11:53 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_color(short color_pair_number)
+{
+ T((T_CALLED("slk_color(%d)"), color_pair_number));
+
+ if (SP != 0 && SP->_slk != 0 &&
+ color_pair_number >= 0 && color_pair_number < COLOR_PAIRS) {
+ TR(TRACE_ATTRS, ("... current is %s", _tracech_t(CHREF(SP->_slk->attr))));
+ SetPair(SP->_slk->attr, color_pair_number);
+ TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr))));
+ returnCode(OK);
+ } else
+ returnCode(ERR);
+}
diff --git a/ncurses/base/lib_slkinit.c b/ncurses/base/lib_slkinit.c
new file mode 100644
index 000000000000..c440109b34e6
--- /dev/null
+++ b/ncurses/base/lib_slkinit.c
@@ -0,0 +1,55 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+ * lib_slkinit.c
+ * Soft key routines.
+ * Initialize soft labels. Called by the user before initscr().
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slkinit.c,v 1.7 2008/01/12 20:23:39 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_init(int format)
+{
+ int code = ERR;
+
+ T((T_CALLED("slk_init(%d)"), format));
+ if (format >= 0 && format <= 3 && !_nc_globals.slk_format) {
+ _nc_globals.slk_format = 1 + format;
+ code = _nc_ripoffline(-SLK_LINES(_nc_globals.slk_format), _nc_slk_initialize);
+ }
+ returnCode(code);
+}
diff --git a/ncurses/base/lib_slklab.c b/ncurses/base/lib_slklab.c
new file mode 100644
index 000000000000..42bb4ac1425d
--- /dev/null
+++ b/ncurses/base/lib_slklab.c
@@ -0,0 +1,51 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2003 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+ * lib_slklab.c
+ * Soft key routines.
+ * Fetch the label text.
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slklab.c,v 1.7 2003/03/29 22:53:48 tom Exp $")
+
+NCURSES_EXPORT(char *)
+slk_label(int n)
+{
+ T((T_CALLED("slk_label(%d)"), n));
+
+ if (SP == NULL || SP->_slk == NULL || n < 1 || n > SP->_slk->labcnt)
+ returnPtr(0);
+ returnPtr(SP->_slk->ent[n - 1].ent_text);
+}
diff --git a/ncurses/base/lib_slkrefr.c b/ncurses/base/lib_slkrefr.c
new file mode 100644
index 000000000000..c8ca28b9dd84
--- /dev/null
+++ b/ncurses/base/lib_slkrefr.c
@@ -0,0 +1,122 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Juergen Pfeifer 1996-on *
+ * and: Thomas E. Dickey *
+ ****************************************************************************/
+
+/*
+ * lib_slkrefr.c
+ * Write SLK window to the (virtual) screen.
+ */
+#include <curses.priv.h>
+#include <term.h> /* num_labels, label_*, plab_norm */
+
+MODULE_ID("$Id: lib_slkrefr.c,v 1.15 2006/11/25 22:32:15 tom Exp $")
+
+/*
+ * Write the soft labels to the soft-key window.
+ */
+static void
+slk_intern_refresh(SLK * slk)
+{
+ int i;
+ int fmt = SP->slk_format;
+
+ for (i = 0; i < slk->labcnt; i++) {
+ if (slk->dirty || slk->ent[i].dirty) {
+ if (slk->ent[i].visible) {
+ if (num_labels > 0 && SLK_STDFMT(fmt)) {
+ if (i < num_labels) {
+ TPUTS_TRACE("plab_norm");
+ putp(TPARM_2(plab_norm, i + 1, slk->ent[i].form_text));
+ }
+ } else {
+ wmove(slk->win, SLK_LINES(fmt) - 1, slk->ent[i].ent_x);
+ if (SP && SP->_slk) {
+ wattrset(slk->win, AttrOf(SP->_slk->attr));
+ }
+ waddstr(slk->win, slk->ent[i].form_text);
+ /* if we simulate SLK's, it's looking much more
+ natural to use the current ATTRIBUTE also
+ for the label window */
+ wattrset(slk->win, WINDOW_ATTRS(stdscr));
+ }
+ }
+ slk->ent[i].dirty = FALSE;
+ }
+ }
+ slk->dirty = FALSE;
+
+ if (num_labels > 0) {
+ if (slk->hidden) {
+ TPUTS_TRACE("label_off");
+ putp(label_off);
+ } else {
+ TPUTS_TRACE("label_on");
+ putp(label_on);
+ }
+ }
+}
+
+/*
+ * Refresh the soft labels.
+ */
+NCURSES_EXPORT(int)
+slk_noutrefresh(void)
+{
+ T((T_CALLED("slk_noutrefresh()")));
+
+ if (SP == NULL || SP->_slk == NULL)
+ returnCode(ERR);
+ if (SP->_slk->hidden)
+ returnCode(OK);
+ slk_intern_refresh(SP->_slk);
+
+ returnCode(wnoutrefresh(SP->_slk->win));
+}
+
+/*
+ * Refresh the soft labels.
+ */
+NCURSES_EXPORT(int)
+slk_refresh(void)
+{
+ T((T_CALLED("slk_refresh()")));
+
+ if (SP == NULL || SP->_slk == NULL)
+ returnCode(ERR);
+ if (SP->_slk->hidden)
+ returnCode(OK);
+ slk_intern_refresh(SP->_slk);
+
+ returnCode(wrefresh(SP->_slk->win));
+}
diff --git a/ncurses/base/lib_slkset.c b/ncurses/base/lib_slkset.c
new file mode 100644
index 000000000000..e19f88e60ac4
--- /dev/null
+++ b/ncurses/base/lib_slkset.c
@@ -0,0 +1,149 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Juergen Pfeifer *
+ * and: Thomas E. Dickey *
+ ****************************************************************************/
+
+/*
+ * lib_slkset.c
+ * Set soft label text.
+ */
+#include <curses.priv.h>
+#include <ctype.h>
+
+#if USE_WIDEC_SUPPORT
+#if HAVE_WCTYPE_H
+#include <wctype.h>
+#endif
+#endif
+
+MODULE_ID("$Id: lib_slkset.c,v 1.17 2007/10/13 20:08:46 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_set(int i, const char *astr, int format)
+{
+ SLK *slk;
+ int offset;
+ int numchrs;
+ int numcols;
+ int limit;
+ const char *str = astr;
+ const char *p;
+
+ T((T_CALLED("slk_set(%d, \"%s\", %d)"), i, str, format));
+
+ if (SP == 0
+ || (slk = SP->_slk) == 0
+ || i < 1
+ || i > slk->labcnt
+ || format < 0
+ || format > 2)
+ returnCode(ERR);
+ if (str == NULL)
+ str = "";
+ --i; /* Adjust numbering of labels */
+
+ limit = MAX_SKEY_LEN(SP->slk_format);
+ while (isspace(UChar(*str)))
+ str++; /* skip over leading spaces */
+ p = str;
+
+#if USE_WIDEC_SUPPORT
+ numcols = 0;
+ while (*p != 0) {
+ mbstate_t state;
+ wchar_t wc;
+ size_t need;
+
+ init_mb(state);
+ need = mbrtowc(0, p, strlen(p), &state);
+ if (need == (size_t) -1)
+ break;
+ mbrtowc(&wc, p, need, &state);
+ if (!iswprint((wint_t) wc))
+ break;
+ if (wcwidth(wc) + numcols > limit)
+ break;
+ numcols += wcwidth(wc);
+ p += need;
+ }
+ numchrs = (p - str);
+#else
+ while (isprint(UChar(*p)))
+ p++; /* The first non-print stops */
+
+ numcols = (p - str);
+ if (numcols > limit)
+ numcols = limit;
+ numchrs = numcols;
+#endif
+
+ FreeIfNeeded(slk->ent[i].ent_text);
+ if ((slk->ent[i].ent_text = strdup(str)) == 0)
+ returnCode(ERR);
+ slk->ent[i].ent_text[numchrs] = '\0';
+
+ if ((slk->ent[i].form_text = (char *) _nc_doalloc(slk->ent[i].form_text,
+ (unsigned) (limit +
+ numchrs + 1))
+ ) == 0)
+ returnCode(ERR);
+
+ switch (format) {
+ default:
+ case 0: /* left-justified */
+ offset = 0;
+ break;
+ case 1: /* centered */
+ offset = (limit - numcols) / 2;
+ break;
+ case 2: /* right-justified */
+ offset = limit - numcols;
+ break;
+ }
+ if (offset <= 0)
+ offset = 0;
+ else
+ memset(slk->ent[i].form_text, ' ', (unsigned) offset);
+
+ memcpy(slk->ent[i].form_text + offset,
+ slk->ent[i].ent_text,
+ (unsigned) numchrs);
+
+ if (offset < limit) {
+ memset(slk->ent[i].form_text + offset + numchrs,
+ ' ',
+ (unsigned) (limit - (offset + numcols)));
+ }
+
+ slk->ent[i].form_text[numchrs - numcols + limit] = 0;
+ slk->ent[i].dirty = TRUE;
+ returnCode(OK);
+}
diff --git a/ncurses/base/lib_slktouch.c b/ncurses/base/lib_slktouch.c
new file mode 100644
index 000000000000..5eb5df385b82
--- /dev/null
+++ b/ncurses/base/lib_slktouch.c
@@ -0,0 +1,53 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+ * lib_slktouch.c
+ * Soft key routines.
+ * Force the code to believe that the soft keys have been changed.
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slktouch.c,v 1.5 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_touch(void)
+{
+ T((T_CALLED("slk_touch()")));
+
+ if (SP == NULL || SP->_slk == NULL)
+ returnCode(ERR);
+ SP->_slk->dirty = TRUE;
+
+ returnCode(OK);
+}
diff --git a/ncurses/base/lib_touch.c b/ncurses/base/lib_touch.c
new file mode 100644
index 000000000000..2ac21f2e0d1f
--- /dev/null
+++ b/ncurses/base/lib_touch.c
@@ -0,0 +1,91 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_touch.c
+**
+** The routines untouchwin(),
+** wtouchln(),
+** is_linetouched()
+** is_wintouched().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_touch.c,v 1.9 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(bool)
+is_linetouched(WINDOW *win, int line)
+{
+ T((T_CALLED("is_linetouched(%p,%d)"), win, line));
+
+ /* XSI doesn't define any error */
+ if (!win || (line > win->_maxy) || (line < 0))
+ returnCode((bool) ERR);
+
+ returnCode(win->_line[line].firstchar != _NOCHANGE ? TRUE : FALSE);
+}
+
+NCURSES_EXPORT(bool)
+is_wintouched(WINDOW *win)
+{
+ int i;
+
+ T((T_CALLED("is_wintouched(%p)"), win));
+
+ if (win)
+ for (i = 0; i <= win->_maxy; i++)
+ if (win->_line[i].firstchar != _NOCHANGE)
+ returnCode(TRUE);
+ returnCode(FALSE);
+}
+
+NCURSES_EXPORT(int)
+wtouchln(WINDOW *win, int y, int n, int changed)
+{
+ int i;
+
+ T((T_CALLED("wtouchln(%p,%d,%d,%d)"), win, y, n, changed));
+
+ if (!win || (n < 0) || (y < 0) || (y > win->_maxy))
+ returnCode(ERR);
+
+ for (i = y; i < y + n; i++) {
+ if (i > win->_maxy)
+ break;
+ win->_line[i].firstchar = changed ? 0 : _NOCHANGE;
+ win->_line[i].lastchar = changed ? win->_maxx : _NOCHANGE;
+ }
+ returnCode(OK);
+}
diff --git a/ncurses/base/lib_ungetch.c b/ncurses/base/lib_ungetch.c
new file mode 100644
index 000000000000..2eda99017bed
--- /dev/null
+++ b/ncurses/base/lib_ungetch.c
@@ -0,0 +1,90 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+** lib_ungetch.c
+**
+** The routine ungetch().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_ungetch.c,v 1.10 2008/05/03 20:20:58 tom Exp $")
+
+#include <fifo_defs.h>
+
+#ifdef TRACE
+NCURSES_EXPORT(void)
+_nc_fifo_dump(SCREEN *sp)
+{
+ int i;
+ T(("head = %d, tail = %d, peek = %d", head, tail, peek));
+ for (i = 0; i < 10; i++)
+ T(("char %d = %s", i, _tracechar(sp->_fifo[i])));
+}
+#endif /* TRACE */
+
+NCURSES_EXPORT(int)
+_nc_ungetch(SCREEN *sp, int ch)
+{
+ int rc = ERR;
+
+ if (tail != -1) {
+ if (head == -1) {
+ head = 0;
+ t_inc();
+ peek = tail; /* no raw keys */
+ } else
+ h_dec();
+
+ sp->_fifo[head] = ch;
+ T(("ungetch %s ok", _tracechar(ch)));
+#ifdef TRACE
+ if (USE_TRACEF(TRACE_IEVENT)) {
+ _nc_fifo_dump(sp);
+ _nc_unlock_global(tracef);
+ }
+#endif
+ rc = OK;
+ }
+ return rc;
+}
+
+NCURSES_EXPORT(int)
+ungetch(int ch)
+{
+ T((T_CALLED("ungetch(%s)"), _tracechar(ch)));
+ returnCode(_nc_ungetch(SP, ch));
+}
diff --git a/ncurses/base/lib_vline.c b/ncurses/base/lib_vline.c
new file mode 100644
index 000000000000..1a2537e7eb6a
--- /dev/null
+++ b/ncurses/base/lib_vline.c
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_vline.c
+**
+** The routine wvline().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_vline.c,v 1.10 2006/03/11 21:52:19 tom Exp $")
+
+NCURSES_EXPORT(int)
+wvline(WINDOW *win, chtype ch, int n)
+{
+ int code = ERR;
+ NCURSES_SIZE_T row, col;
+ NCURSES_SIZE_T end;
+
+ T((T_CALLED("wvline(%p,%s,%d)"), win, _tracechtype(ch), n));
+
+ if (win) {
+ NCURSES_CH_T wch;
+ row = win->_cury;
+ col = win->_curx;
+ end = row + n - 1;
+ if (end > win->_maxy)
+ end = win->_maxy;
+
+ if (ch == 0)
+ SetChar2(wch, ACS_VLINE);
+ else
+ SetChar2(wch, ch);
+ wch = _nc_render(win, wch);
+
+ while (end >= row) {
+ struct ldat *line = &(win->_line[end]);
+ line->text[col] = wch;
+ CHANGED_CELL(line, col);
+ end--;
+ }
+
+ _nc_synchook(win);
+ code = OK;
+ }
+ returnCode(code);
+}
diff --git a/ncurses/base/lib_wattroff.c b/ncurses/base/lib_wattroff.c
new file mode 100644
index 000000000000..bf2020e06027
--- /dev/null
+++ b/ncurses/base/lib_wattroff.c
@@ -0,0 +1,64 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+** lib_wattroff.c
+**
+** The routine wattr_off().
+**
+*/
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_wattroff.c,v 1.9 2006/05/27 19:30:33 tom Exp $")
+
+NCURSES_EXPORT(int)
+wattr_off(WINDOW *win, attr_t at, void *opts GCC_UNUSED)
+{
+ T((T_CALLED("wattr_off(%p,%s)"), win, _traceattr(at)));
+ if (win) {
+ T(("... current %s (%d)",
+ _traceattr(WINDOW_ATTRS(win)),
+ GET_WINDOW_PAIR(win)));
+
+ if_EXT_COLORS({
+ if (at & A_COLOR)
+ win->_color = 0;
+ });
+ toggle_attr_off(WINDOW_ATTRS(win), at);
+ returnCode(OK);
+ } else
+ returnCode(ERR);
+}
diff --git a/ncurses/base/lib_wattron.c b/ncurses/base/lib_wattron.c
new file mode 100644
index 000000000000..2e17d965e94a
--- /dev/null
+++ b/ncurses/base/lib_wattron.c
@@ -0,0 +1,64 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+** lib_wattron.c
+**
+** The routines wattr_on().
+**
+*/
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_wattron.c,v 1.9 2006/05/27 19:30:46 tom Exp $")
+
+NCURSES_EXPORT(int)
+wattr_on(WINDOW *win, attr_t at, void *opts GCC_UNUSED)
+{
+ T((T_CALLED("wattr_on(%p,%s)"), win, _traceattr(at)));
+ if (win != 0) {
+ T(("... current %s (%d)",
+ _traceattr(WINDOW_ATTRS(win)),
+ GET_WINDOW_PAIR(win)));
+
+ if_EXT_COLORS({
+ if (at & A_COLOR)
+ win->_color = PAIR_NUMBER(at);
+ });
+ toggle_attr_on(WINDOW_ATTRS(win), at);
+ returnCode(OK);
+ } else
+ returnCode(ERR);
+}
diff --git a/ncurses/base/lib_winch.c b/ncurses/base/lib_winch.c
new file mode 100644
index 000000000000..18da9c594945
--- /dev/null
+++ b/ncurses/base/lib_winch.c
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey <dickey@clark.net> 1998 *
+ ****************************************************************************/
+
+/*
+** lib_winch.c
+**
+** The routine winch().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_winch.c,v 1.5 2001/06/02 23:42:08 skimo Exp $")
+
+NCURSES_EXPORT(chtype)
+winch(WINDOW *win)
+{
+ T((T_CALLED("winch(%p)"), win));
+ if (win != 0) {
+ returnChar(CharOf(win->_line[win->_cury].text[win->_curx]) |
+ AttrOf(win->_line[win->_cury].text[win->_curx]));
+ } else {
+ returnChar(0);
+ }
+}
diff --git a/ncurses/base/lib_window.c b/ncurses/base/lib_window.c
new file mode 100644
index 000000000000..ac61cb01da99
--- /dev/null
+++ b/ncurses/base/lib_window.c
@@ -0,0 +1,250 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+** lib_window.c
+**
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_window.c,v 1.24 2008/04/12 22:40:21 tom Exp $")
+
+NCURSES_EXPORT(void)
+_nc_synchook(WINDOW *win)
+/* hook to be called after each window change */
+{
+ if (win->_immed)
+ wrefresh(win);
+ if (win->_sync)
+ wsyncup(win);
+}
+
+NCURSES_EXPORT(int)
+mvderwin(WINDOW *win, int y, int x)
+/* move a derived window */
+{
+ WINDOW *orig;
+ int i;
+
+ T((T_CALLED("mvderwin(%p,%d,%d)"), win, y, x));
+
+ if (win && (orig = win->_parent)) {
+ if (win->_parx == x && win->_pary == y)
+ returnCode(OK);
+ if (x < 0 || y < 0)
+ returnCode(ERR);
+ if ((x + getmaxx(win) > getmaxx(orig)) ||
+ (y + getmaxy(win) > getmaxy(orig)))
+ returnCode(ERR);
+ } else
+ returnCode(ERR);
+ wsyncup(win);
+ win->_parx = x;
+ win->_pary = y;
+ for (i = 0; i < getmaxy(win); i++)
+ win->_line[i].text = &(orig->_line[y++].text[x]);
+ returnCode(OK);
+}
+
+NCURSES_EXPORT(int)
+syncok(WINDOW *win, bool bf)
+/* enable/disable automatic wsyncup() on each change to window */
+{
+ T((T_CALLED("syncok(%p,%d)"), win, bf));
+
+ if (win) {
+ win->_sync = bf;
+ returnCode(OK);
+ } else
+ returnCode(ERR);
+}
+
+NCURSES_EXPORT(void)
+wsyncup(WINDOW *win)
+/* mark changed every cell in win's ancestors that is changed in win */
+/* Rewritten by J. Pfeifer, 1-Apr-96 (don't even think that...) */
+{
+ WINDOW *wp;
+
+ T((T_CALLED("wsyncup(%p)"), win));
+ if (win && win->_parent) {
+ for (wp = win; wp->_parent; wp = wp->_parent) {
+ int y;
+ WINDOW *pp = wp->_parent;
+
+ assert((wp->_pary <= pp->_maxy) &&
+ ((wp->_pary + wp->_maxy) <= pp->_maxy));
+
+ for (y = 0; y <= wp->_maxy; y++) {
+ int left = wp->_line[y].firstchar;
+ if (left >= 0) { /* line is touched */
+ struct ldat *line = &(pp->_line[wp->_pary + y]);
+ /* left & right character in parent window coordinates */
+ int right = wp->_line[y].lastchar + wp->_parx;
+ left += wp->_parx;
+
+ CHANGED_RANGE(line, left, right);
+ }
+ }
+ }
+ }
+ returnVoid;
+}
+
+NCURSES_EXPORT(void)
+wsyncdown(WINDOW *win)
+/* mark changed every cell in win that is changed in any of its ancestors */
+/* Rewritten by J. Pfeifer, 1-Apr-96 (don't even think that...) */
+{
+ T((T_CALLED("wsyncdown(%p)"), win));
+
+ if (win && win->_parent) {
+ WINDOW *pp = win->_parent;
+ int y;
+
+ /* This recursion guarantees, that the changes are propagated down-
+ wards from the root to our direct parent. */
+ wsyncdown(pp);
+
+ /* and now we only have to propagate the changes from our direct
+ parent, if there are any. */
+ assert((win->_pary <= pp->_maxy) &&
+ ((win->_pary + win->_maxy) <= pp->_maxy));
+
+ for (y = 0; y <= win->_maxy; y++) {
+ if (pp->_line[win->_pary + y].firstchar >= 0) { /* parent changed */
+ struct ldat *line = &(win->_line[y]);
+ /* left and right character in child coordinates */
+ int left = pp->_line[win->_pary + y].firstchar - win->_parx;
+ int right = pp->_line[win->_pary + y].lastchar - win->_parx;
+ /* The change may be outside the child's range */
+ if (left < 0)
+ left = 0;
+ if (right > win->_maxx)
+ right = win->_maxx;
+ CHANGED_RANGE(line, left, right);
+ }
+ }
+ }
+ returnVoid;
+}
+
+NCURSES_EXPORT(void)
+wcursyncup(WINDOW *win)
+/* sync the cursor in all derived windows to its value in the base window */
+{
+ WINDOW *wp;
+
+ T((T_CALLED("wcursyncup(%p)"), win));
+ for (wp = win; wp && wp->_parent; wp = wp->_parent) {
+ wmove(wp->_parent, wp->_pary + wp->_cury, wp->_parx + wp->_curx);
+ }
+ returnVoid;
+}
+
+NCURSES_EXPORT(WINDOW *)
+dupwin(WINDOW *win)
+/* make an exact duplicate of the given window */
+{
+ WINDOW *nwin = 0;
+ size_t linesize;
+ int i;
+
+ T((T_CALLED("dupwin(%p)"), win));
+
+ if (win != 0) {
+
+ _nc_lock_window(win);
+ if (win->_flags & _ISPAD) {
+ nwin = newpad(win->_maxy + 1,
+ win->_maxx + 1);
+ } else {
+ nwin = newwin(win->_maxy + 1,
+ win->_maxx + 1,
+ win->_begy,
+ win->_begx);
+ }
+
+ if (nwin != 0) {
+
+ nwin->_curx = win->_curx;
+ nwin->_cury = win->_cury;
+ nwin->_maxy = win->_maxy;
+ nwin->_maxx = win->_maxx;
+ nwin->_begy = win->_begy;
+ nwin->_begx = win->_begx;
+ nwin->_yoffset = win->_yoffset;
+
+ nwin->_flags = win->_flags & ~_SUBWIN;
+ /* Due to the use of newwin(), the clone is not a subwindow.
+ * The text is really copied into the clone.
+ */
+
+ WINDOW_ATTRS(nwin) = WINDOW_ATTRS(win);
+ nwin->_nc_bkgd = win->_nc_bkgd;
+
+ nwin->_notimeout = win->_notimeout;
+ nwin->_clear = win->_clear;
+ nwin->_leaveok = win->_leaveok;
+ nwin->_scroll = win->_scroll;
+ nwin->_idlok = win->_idlok;
+ nwin->_idcok = win->_idcok;
+ nwin->_immed = win->_immed;
+ nwin->_sync = win->_sync;
+ nwin->_use_keypad = win->_use_keypad;
+ nwin->_delay = win->_delay;
+
+ nwin->_parx = 0;
+ nwin->_pary = 0;
+ nwin->_parent = (WINDOW *) 0;
+ /* See above: the clone isn't a subwindow! */
+
+ nwin->_regtop = win->_regtop;
+ nwin->_regbottom = win->_regbottom;
+
+ if (win->_flags & _ISPAD)
+ nwin->_pad = win->_pad;
+
+ linesize = (win->_maxx + 1) * sizeof(NCURSES_CH_T);
+ for (i = 0; i <= nwin->_maxy; i++) {
+ memcpy(nwin->_line[i].text, win->_line[i].text, linesize);
+ nwin->_line[i].firstchar = win->_line[i].firstchar;
+ nwin->_line[i].lastchar = win->_line[i].lastchar;
+ }
+ }
+ _nc_unlock_window(win);
+ }
+ returnWin(nwin);
+}
diff --git a/ncurses/base/memmove.c b/ncurses/base/memmove.c
new file mode 100644
index 000000000000..093ad72954ff
--- /dev/null
+++ b/ncurses/base/memmove.c
@@ -0,0 +1,69 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2007 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: memmove.c,v 1.5 2007/08/11 17:12:43 tom Exp $")
+
+/****************************************************************************
+ * Author: Thomas E. Dickey <dickey@clark.net> 1998 *
+ ****************************************************************************/
+
+#if USE_MY_MEMMOVE
+#define DST ((char *)s1)
+#define SRC ((const char *)s2)
+NCURSES_EXPORT(void *)
+_nc_memmove(void *s1, const void *s2, size_t n)
+{
+ if (n != 0) {
+ if ((DST + n > SRC) && (SRC + n > DST)) {
+ static char *bfr;
+ static size_t length;
+ register size_t j;
+ if (length < n) {
+ length = (n * 3) / 2;
+ bfr = typeRealloc(char, length, bfr);
+ }
+ for (j = 0; j < n; j++)
+ bfr[j] = SRC[j];
+ s2 = bfr;
+ }
+ while (n-- != 0)
+ DST[n] = SRC[n];
+ }
+ return s1;
+}
+#else
+extern
+NCURSES_EXPORT(void)
+_nc_memmove(void); /* quiet's gcc warning */
+NCURSES_EXPORT(void)
+_nc_memmove(void)
+{
+} /* nonempty for strict ANSI compilers */
+#endif /* USE_MY_MEMMOVE */
diff --git a/ncurses/base/nc_panel.c b/ncurses/base/nc_panel.c
new file mode 100644
index 000000000000..59bfbbe86ef6
--- /dev/null
+++ b/ncurses/base/nc_panel.c
@@ -0,0 +1,41 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey <dickey@clark.net> 1997 *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: nc_panel.c,v 1.4 2000/12/10 02:43:28 tom Exp $")
+
+NCURSES_EXPORT(struct panelhook *)
+_nc_panelhook(void)
+{
+ return (SP ? &(SP->_panelHook) : NULL);
+}
diff --git a/ncurses/base/resizeterm.c b/ncurses/base/resizeterm.c
new file mode 100644
index 000000000000..cf2c998e239f
--- /dev/null
+++ b/ncurses/base/resizeterm.c
@@ -0,0 +1,455 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey *
+ ****************************************************************************/
+
+/*
+ * This is an extension to the curses library. It provides callers with a hook
+ * into the NCURSES data to resize windows, primarily for use by programs
+ * running in an X Window terminal (e.g., xterm). I abstracted this module
+ * from my application library for NCURSES because it must be compiled with
+ * the private data structures -- T.Dickey 1995/7/4.
+ */
+
+#include <curses.priv.h>
+#include <term.h>
+
+MODULE_ID("$Id: resizeterm.c,v 1.32 2008/05/03 14:28:55 tom Exp $")
+
+#define stolen_lines (screen_lines - SP->_lines_avail)
+
+/*
+ * If we're trying to be reentrant, do not want any local statics.
+ */
+#if USE_REENTRANT
+#define EXTRA_ARGS , CurLines, CurCols
+#define EXTRA_DCLS , int CurLines, int CurCols
+#else
+static int current_lines;
+static int current_cols;
+#define CurLines current_lines
+#define CurCols current_cols
+#define EXTRA_ARGS /* nothing */
+#define EXTRA_DCLS /* nothing */
+#endif
+
+#ifdef TRACE
+static void
+show_window_sizes(const char *name)
+{
+ WINDOWLIST *wp;
+
+ _nc_lock_global(windowlist);
+ _tracef("%s resizing: %2d x %2d (%2d x %2d)", name, LINES, COLS,
+ screen_lines, screen_columns);
+ for (each_window(wp)) {
+ _tracef(" window %p is %2ld x %2ld at %2ld,%2ld",
+ &(wp->win),
+ (long) wp->win._maxy + 1,
+ (long) wp->win._maxx + 1,
+ (long) wp->win._begy,
+ (long) wp->win._begx);
+ }
+ _nc_unlock_global(windowlist);
+}
+#endif
+
+/*
+ * Return true if the given dimensions do not match the internal terminal
+ * structure's size.
+ */
+NCURSES_EXPORT(bool)
+is_term_resized(int ToLines, int ToCols)
+{
+ T((T_CALLED("is_term_resized(%d, %d)"), ToLines, ToCols));
+ returnCode(ToLines > 0
+ && ToCols > 0
+ && (ToLines != screen_lines
+ || ToCols != screen_columns));
+}
+
+/*
+ */
+static ripoff_t *
+ripped_window(WINDOW *win)
+{
+ ripoff_t *result = 0;
+ ripoff_t *rop;
+
+ if (win != 0) {
+ for (each_ripoff(rop)) {
+ if (rop->win == win && rop->line != 0) {
+ result = rop;
+ break;
+ }
+ }
+ }
+ return result;
+}
+
+/*
+ * Returns the number of lines from the bottom for the beginning of a ripped
+ * off window.
+ */
+static int
+ripped_bottom(WINDOW *win)
+{
+ int result = 0;
+ ripoff_t *rop;
+
+ if (win != 0) {
+ for (each_ripoff(rop)) {
+ if (rop->line < 0) {
+ result -= rop->line;
+ if (rop->win == win) {
+ break;
+ }
+ }
+ }
+ }
+ return result;
+}
+
+/*
+ * Return the number of levels of child-windows under the current window.
+ */
+static int
+child_depth(WINDOW *cmp)
+{
+ int depth = 0;
+
+ if (cmp != 0) {
+ WINDOWLIST *wp;
+
+ for (each_window(wp)) {
+ WINDOW *tst = &(wp->win);
+ if (tst->_parent == cmp) {
+ depth = 1 + child_depth(tst);
+ break;
+ }
+ }
+ }
+ return depth;
+}
+
+/*
+ * Return the number of levels of parent-windows above the current window.
+ */
+static int
+parent_depth(WINDOW *cmp)
+{
+ int depth = 0;
+
+ if (cmp != 0) {
+ WINDOW *tst;
+ while ((tst = cmp->_parent) != 0) {
+ ++depth;
+ cmp = tst;
+ }
+ }
+ return depth;
+}
+
+/*
+ * FIXME: must adjust position so it's within the parent!
+ */
+static int
+adjust_window(WINDOW *win, int ToLines, int ToCols, int stolen EXTRA_DCLS)
+{
+ int result;
+ int bottom = CurLines + SP->_topstolen - stolen;
+ int myLines = win->_maxy + 1;
+ int myCols = win->_maxx + 1;
+ ripoff_t *rop = ripped_window(win);
+
+ T((T_CALLED("adjust_window(%p,%d,%d)%s depth %d/%d currently %ldx%ld at %ld,%ld"),
+ win, ToLines, ToCols,
+ (rop != 0) ? " (rip)" : "",
+ parent_depth(win),
+ child_depth(win),
+ (long) getmaxy(win), (long) getmaxx(win),
+ (long) getbegy(win) + win->_yoffset, (long) getbegx(win)));
+
+ if (rop != 0 && rop->line < 0) {
+ /*
+ * If it is a ripped-off window at the bottom of the screen, simply
+ * move it to the same relative position.
+ */
+ win->_begy = ToLines - ripped_bottom(win) - 0 - win->_yoffset;
+ } else if (win->_begy >= bottom) {
+ /*
+ * If it is below the bottom of the new screen, move up by the same
+ * amount that the screen shrank.
+ */
+ win->_begy += (ToLines - CurLines);
+ } else {
+ if (myLines == (CurLines - stolen)
+ && ToLines != CurLines) {
+ myLines = ToLines - stolen;
+ } else if (myLines == CurLines
+ && ToLines != CurLines) {
+ myLines = ToLines;
+ }
+ }
+
+ if (myLines > ToLines) {
+ myLines = ToLines;
+ }
+
+ if (myCols > ToCols)
+ myCols = ToCols;
+
+ if (myCols == CurCols
+ && ToCols != CurCols)
+ myCols = ToCols;
+
+ result = wresize(win, myLines, myCols);
+ returnCode(result);
+}
+
+/*
+ * If we're decreasing size, recursively search for windows that have no
+ * children, decrease those to fit, then decrease the containing window, etc.
+ */
+static int
+decrease_size(int ToLines, int ToCols, int stolen EXTRA_DCLS)
+{
+ bool found;
+ int depth = 0;
+ WINDOWLIST *wp;
+
+ T((T_CALLED("decrease_size(%d, %d)"), ToLines, ToCols));
+
+ do {
+ found = FALSE;
+ TR(TRACE_UPDATE, ("decreasing size of windows to %dx%d, depth=%d",
+ ToLines, ToCols, depth));
+ for (each_window(wp)) {
+ WINDOW *win = &(wp->win);
+
+ if (!(win->_flags & _ISPAD)) {
+ if (child_depth(win) == depth) {
+ found = TRUE;
+ if (adjust_window(win, ToLines, ToCols,
+ stolen EXTRA_ARGS) != OK)
+ returnCode(ERR);
+ }
+ }
+ }
+ ++depth;
+ } while (found);
+ returnCode(OK);
+}
+
+/*
+ * If we're increasing size, recursively search for windows that have no
+ * parent, increase those to fit, then increase the contained window, etc.
+ */
+static int
+increase_size(int ToLines, int ToCols, int stolen EXTRA_DCLS)
+{
+ bool found;
+ int depth = 0;
+ WINDOWLIST *wp;
+
+ T((T_CALLED("increase_size(%d, %d)"), ToLines, ToCols));
+
+ do {
+ found = FALSE;
+ TR(TRACE_UPDATE, ("increasing size of windows to %dx%d, depth=%d",
+ ToLines, ToCols, depth));
+ for (each_window(wp)) {
+ WINDOW *win = &(wp->win);
+
+ if (!(win->_flags & _ISPAD)) {
+ if (parent_depth(win) == depth) {
+ found = TRUE;
+ if (adjust_window(win, ToLines, ToCols,
+ stolen EXTRA_ARGS) != OK)
+ returnCode(ERR);
+ }
+ }
+ }
+ ++depth;
+ } while (found);
+ returnCode(OK);
+}
+
+/*
+ * This function reallocates NCURSES window structures, with no side-effects
+ * such as ungetch().
+ */
+NCURSES_EXPORT(int)
+resize_term(int ToLines, int ToCols)
+{
+ int result = OK EXTRA_ARGS;
+ int was_stolen;
+
+ T((T_CALLED("resize_term(%d,%d) old(%d,%d)"),
+ ToLines, ToCols,
+ screen_lines, screen_columns));
+
+ if (SP == 0) {
+ returnCode(ERR);
+ }
+
+ _nc_lock_global(windowlist);
+
+ was_stolen = (screen_lines - SP->_lines_avail);
+ if (is_term_resized(ToLines, ToCols)) {
+ int myLines = CurLines = screen_lines;
+ int myCols = CurCols = screen_columns;
+
+#ifdef TRACE
+ if (USE_TRACEF(TRACE_UPDATE)) {
+ show_window_sizes("before");
+ _nc_unlock_global(tracef);
+ }
+#endif
+ if (ToLines > screen_lines) {
+ increase_size(myLines = ToLines, myCols, was_stolen EXTRA_ARGS);
+ CurLines = myLines;
+ CurCols = myCols;
+ }
+
+ if (ToCols > screen_columns) {
+ increase_size(myLines, myCols = ToCols, was_stolen EXTRA_ARGS);
+ CurLines = myLines;
+ CurCols = myCols;
+ }
+
+ if (ToLines < myLines ||
+ ToCols < myCols) {
+ decrease_size(ToLines, ToCols, was_stolen EXTRA_ARGS);
+ }
+
+ screen_lines = lines = ToLines;
+ screen_columns = columns = ToCols;
+
+ SP->_lines_avail = lines - was_stolen;
+
+ if (SP->oldhash) {
+ FreeAndNull(SP->oldhash);
+ }
+ if (SP->newhash) {
+ FreeAndNull(SP->newhash);
+ }
+#ifdef TRACE
+ if (USE_TRACEF(TRACE_UPDATE)) {
+ SET_LINES(ToLines - was_stolen);
+ SET_COLS(ToCols);
+ show_window_sizes("after");
+ _nc_unlock_global(tracef);
+ }
+#endif
+ }
+
+ /*
+ * Always update LINES, to allow for call from lib_doupdate.c which
+ * needs to have the count adjusted by the stolen (ripped off) lines.
+ */
+ SET_LINES(ToLines - was_stolen);
+ SET_COLS(ToCols);
+
+ _nc_unlock_global(windowlist);
+
+ returnCode(result);
+}
+
+/*
+ * This function reallocates NCURSES window structures. It is invoked in
+ * response to a SIGWINCH interrupt. Other user-defined windows may also need
+ * to be reallocated.
+ *
+ * Because this performs memory allocation, it should not (in general) be
+ * invoked directly from the signal handler.
+ */
+NCURSES_EXPORT(int)
+resizeterm(int ToLines, int ToCols)
+{
+ int result = ERR;
+
+ T((T_CALLED("resizeterm(%d,%d) old(%d,%d)"),
+ ToLines, ToCols,
+ screen_lines, screen_columns));
+
+ if (SP != 0) {
+ result = OK;
+ SP->_sig_winch = FALSE;
+
+ if (is_term_resized(ToLines, ToCols)) {
+#if USE_SIGWINCH
+ ripoff_t *rop;
+ bool slk_visible = (SP != 0
+ && SP->_slk != 0
+ && !(SP->_slk->hidden));
+
+ if (slk_visible) {
+ slk_clear();
+ }
+#endif
+ result = resize_term(ToLines, ToCols);
+
+#if USE_SIGWINCH
+ ungetch(KEY_RESIZE); /* so application can know this */
+ clearok(curscr, TRUE); /* screen contents are unknown */
+
+ /* ripped-off lines are a special case: if we did not lengthen
+ * them, we haven't moved them either. repaint them, too.
+ *
+ * for the rest - stdscr and other windows - the client has to
+ * decide which to repaint, since without panels, ncurses does
+ * not know which are really on top.
+ */
+ for (each_ripoff(rop)) {
+ if (rop->win != stdscr
+ && rop->win != 0
+ && rop->line < 0) {
+
+ if (rop->hook != _nc_slk_initialize) {
+ touchwin(rop->win);
+ wnoutrefresh(rop->win);
+ }
+ }
+ }
+
+ /* soft-keys are a special case: we _know_ how to repaint them */
+ if (slk_visible) {
+ slk_restore();
+ slk_touch();
+
+ slk_refresh();
+ }
+#endif
+ }
+ }
+
+ returnCode(result);
+}
diff --git a/ncurses/base/safe_sprintf.c b/ncurses/base/safe_sprintf.c
new file mode 100644
index 000000000000..8fc5d89dd210
--- /dev/null
+++ b/ncurses/base/safe_sprintf.c
@@ -0,0 +1,264 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2007 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey <dickey@clark.net> 1997 *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: safe_sprintf.c,v 1.20 2007/04/21 22:28:06 tom Exp $")
+
+#if USE_SAFE_SPRINTF
+
+typedef enum {
+ Flags, Width, Prec, Type, Format
+} PRINTF;
+
+#define VA_INTGR(type) ival = va_arg(ap, type)
+#define VA_FLOAT(type) fval = va_arg(ap, type)
+#define VA_POINT(type) pval = (void *)va_arg(ap, type)
+
+/*
+ * Scan a variable-argument list for printf to determine the number of
+ * characters that would be emitted.
+ */
+static int
+_nc_printf_length(const char *fmt, va_list ap)
+{
+ size_t length = BUFSIZ;
+ char *buffer;
+ char *format;
+ int len = 0;
+ size_t fmt_len;
+ char fmt_arg[BUFSIZ];
+
+ if (fmt == 0 || *fmt == '\0')
+ return 0;
+ fmt_len = strlen(fmt) + 1;
+ if ((format = typeMalloc(char, fmt_len)) == 0)
+ return -1;
+ if ((buffer = typeMalloc(char, length)) == 0) {
+ free(format);
+ return -1;
+ }
+
+ while (*fmt != '\0') {
+ if (*fmt == '%') {
+ static char dummy[] = "";
+ PRINTF state = Flags;
+ char *pval = dummy; /* avoid const-cast */
+ double fval = 0.0;
+ int done = FALSE;
+ int ival = 0;
+ int prec = -1;
+ int type = 0;
+ int used = 0;
+ int width = -1;
+ size_t f = 0;
+
+ format[f++] = *fmt;
+ while (*++fmt != '\0' && len >= 0 && !done) {
+ format[f++] = *fmt;
+
+ if (isdigit(UChar(*fmt))) {
+ int num = *fmt - '0';
+ if (state == Flags && num != 0)
+ state = Width;
+ if (state == Width) {
+ if (width < 0)
+ width = 0;
+ width = (width * 10) + num;
+ } else if (state == Prec) {
+ if (prec < 0)
+ prec = 0;
+ prec = (prec * 10) + num;
+ }
+ } else if (*fmt == '*') {
+ VA_INTGR(int);
+ if (state == Flags)
+ state = Width;
+ if (state == Width) {
+ width = ival;
+ } else if (state == Prec) {
+ prec = ival;
+ }
+ sprintf(fmt_arg, "%d", ival);
+ fmt_len += strlen(fmt_arg);
+ if ((format = realloc(format, fmt_len)) == 0) {
+ return -1;
+ }
+ strcpy(&format[--f], fmt_arg);
+ f = strlen(format);
+ } else if (isalpha(UChar(*fmt))) {
+ done = TRUE;
+ switch (*fmt) {
+ case 'Z': /* FALLTHRU */
+ case 'h': /* FALLTHRU */
+ case 'l': /* FALLTHRU */
+ done = FALSE;
+ type = *fmt;
+ break;
+ case 'i': /* FALLTHRU */
+ case 'd': /* FALLTHRU */
+ case 'u': /* FALLTHRU */
+ case 'x': /* FALLTHRU */
+ case 'X': /* FALLTHRU */
+ if (type == 'l')
+ VA_INTGR(long);
+ else if (type == 'Z')
+ VA_INTGR(size_t);
+ else
+ VA_INTGR(int);
+ used = 'i';
+ break;
+ case 'f': /* FALLTHRU */
+ case 'e': /* FALLTHRU */
+ case 'E': /* FALLTHRU */
+ case 'g': /* FALLTHRU */
+ case 'G': /* FALLTHRU */
+ VA_FLOAT(double);
+ used = 'f';
+ break;
+ case 'c':
+ VA_INTGR(int);
+ used = 'i';
+ break;
+ case 's':
+ VA_POINT(char *);
+ if (prec < 0)
+ prec = strlen(pval);
+ if (prec > (int) length) {
+ length = length + prec;
+ buffer = typeRealloc(char, length, buffer);
+ if (buffer == 0) {
+ free(format);
+ return -1;
+ }
+ }
+ used = 'p';
+ break;
+ case 'p':
+ VA_POINT(void *);
+ used = 'p';
+ break;
+ case 'n':
+ VA_POINT(int *);
+ used = 0;
+ break;
+ default:
+ break;
+ }
+ } else if (*fmt == '.') {
+ state = Prec;
+ } else if (*fmt == '%') {
+ done = TRUE;
+ used = 'p';
+ }
+ }
+ format[f] = '\0';
+ switch (used) {
+ case 'i':
+ sprintf(buffer, format, ival);
+ break;
+ case 'f':
+ sprintf(buffer, format, fval);
+ break;
+ default:
+ sprintf(buffer, format, pval);
+ break;
+ }
+ len += (int) strlen(buffer);
+ } else {
+ fmt++;
+ len++;
+ }
+ }
+
+ free(buffer);
+ free(format);
+ return len;
+}
+#endif
+
+#define my_buffer _nc_globals.safeprint_buf
+#define my_length _nc_globals.safeprint_used
+
+/*
+ * Wrapper for vsprintf that allocates a buffer big enough to hold the result.
+ */
+NCURSES_EXPORT(char *)
+_nc_printf_string(const char *fmt, va_list ap)
+{
+ char *result = 0;
+
+ if (fmt != 0) {
+#if USE_SAFE_SPRINTF
+ int len = _nc_printf_length(fmt, ap);
+
+ if ((int) my_length < len + 1) {
+ my_length = 2 * (len + 1);
+ my_buffer = typeRealloc(char, my_length, my_buffer);
+ }
+ if (my_buffer != 0) {
+ *my_buffer = '\0';
+ if (len >= 0) {
+ vsprintf(my_buffer, fmt, ap);
+ }
+ result = my_buffer;
+ }
+#else
+#define MyCols _nc_globals.safeprint_cols
+#define MyRows _nc_globals.safeprint_rows
+
+ if (screen_lines > MyRows || screen_columns > MyCols) {
+ if (screen_lines > MyRows)
+ MyRows = screen_lines;
+ if (screen_columns > MyCols)
+ MyCols = screen_columns;
+ my_length = (MyRows * (MyCols + 1)) + 1;
+ my_buffer = typeRealloc(char, my_length, my_buffer);
+ }
+
+ if (my_buffer != 0) {
+# if HAVE_VSNPRINTF
+ vsnprintf(my_buffer, my_length, fmt, ap); /* GNU extension */
+# else
+ vsprintf(my_buffer, fmt, ap); /* ANSI */
+# endif
+ result = my_buffer;
+ }
+#endif
+ } else if (my_buffer != 0) { /* see _nc_freeall() */
+ free(my_buffer);
+ my_buffer = 0;
+ my_length = 0;
+ }
+ return result;
+}
diff --git a/ncurses/base/sigaction.c b/ncurses/base/sigaction.c
new file mode 100644
index 000000000000..36442e090a41
--- /dev/null
+++ b/ncurses/base/sigaction.c
@@ -0,0 +1,99 @@
+/****************************************************************************
+ * Copyright (c) 1998-2002,2003 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-2003 *
+ ****************************************************************************/
+
+/* This file provides sigaction() emulation using sigvec() */
+/* Use only if this is non POSIX system */
+
+MODULE_ID("$Id: sigaction.c,v 1.14 2003/12/07 01:06:52 tom Exp $")
+
+static int
+_nc_sigaction(int sig, sigaction_t * sigact, sigaction_t * osigact)
+{
+ return sigvec(sig, sigact, osigact);
+}
+
+static int
+_nc_sigemptyset(sigset_t * mask)
+{
+ *mask = 0;
+ return 0;
+}
+
+static int
+_nc_sigprocmask(int mode, sigset_t * mask, sigset_t * omask)
+{
+ sigset_t current = sigsetmask(0);
+
+ if (omask)
+ *omask = current;
+
+ if (mode == SIG_BLOCK)
+ current |= *mask;
+ else if (mode == SIG_UNBLOCK)
+ current &= ~*mask;
+ else if (mode == SIG_SETMASK)
+ current = *mask;
+
+ sigsetmask(current);
+ return 0;
+}
+
+static int
+_nc_sigaddset(sigset_t * mask, int sig)
+{
+ *mask |= sigmask(sig);
+ return 0;
+}
+
+/* not used in lib_tstp.c */
+#if 0
+static int
+_nc_sigsuspend(sigset_t * mask)
+{
+ return sigpause(*mask);
+}
+
+static int
+_nc_sigdelset(sigset_t * mask, int sig)
+{
+ *mask &= ~sigmask(sig);
+ return 0;
+}
+
+static int
+_nc_sigismember(sigset_t * mask, int sig)
+{
+ return (*mask & sigmask(sig)) != 0;
+}
+#endif
diff --git a/ncurses/base/tries.c b/ncurses/base/tries.c
new file mode 100644
index 000000000000..983a75ae7882
--- /dev/null
+++ b/ncurses/base/tries.c
@@ -0,0 +1,143 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey <dickey@clark.net> 1997 *
+ ****************************************************************************/
+
+/*
+** tries.c
+**
+** Functions to manage the tree of partial-completions for keycodes.
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: tries.c,v 1.25 2007/09/29 20:37:13 tom Exp $")
+
+/*
+ * Expand a keycode into the string that it corresponds to, returning null if
+ * no match was found, otherwise allocating a string of the result.
+ */
+NCURSES_EXPORT(char *)
+_nc_expand_try(TRIES * tree, unsigned code, int *count, size_t len)
+{
+ TRIES *ptr = tree;
+ char *result = 0;
+
+ if (code != 0) {
+ while (ptr != 0) {
+ if ((result = _nc_expand_try(ptr->child, code, count, len + 1))
+ != 0) {
+ break;
+ }
+ if (ptr->value == code) {
+ *count -= 1;
+ if (*count == -1) {
+ result = typeCalloc(char, len + 2);
+ break;
+ }
+ }
+ ptr = ptr->sibling;
+ }
+ }
+ if (result != 0) {
+ if (ptr != 0 && (result[len] = ptr->ch) == 0)
+ *((unsigned char *) (result + len)) = 128;
+#ifdef TRACE
+ if (len == 0 && USE_TRACEF(TRACE_MAXIMUM)) {
+ _tracef("expand_key %s %s", _tracechar(code), _nc_visbuf(result));
+ _nc_unlock_global(tracef);
+ }
+#endif
+ }
+ return result;
+}
+
+/*
+ * Remove a code from the specified tree, freeing the unused nodes. Returns
+ * true if the code was found/removed.
+ */
+NCURSES_EXPORT(int)
+_nc_remove_key(TRIES ** tree, unsigned code)
+{
+ T((T_CALLED("_nc_remove_key(%p,%d)"), tree, code));
+
+ if (code == 0)
+ returnCode(FALSE);
+
+ while (*tree != 0) {
+ if (_nc_remove_key(&(*tree)->child, code)) {
+ returnCode(TRUE);
+ }
+ if ((*tree)->value == code) {
+ if ((*tree)->child) {
+ /* don't cut the whole sub-tree */
+ (*tree)->value = 0;
+ } else {
+ TRIES *to_free = *tree;
+ *tree = (*tree)->sibling;
+ free(to_free);
+ }
+ returnCode(TRUE);
+ }
+ tree = &(*tree)->sibling;
+ }
+ returnCode(FALSE);
+}
+
+/*
+ * Remove a string from the specified tree, freeing the unused nodes. Returns
+ * true if the string was found/removed.
+ */
+NCURSES_EXPORT(int)
+_nc_remove_string(TRIES ** tree, const char *string)
+{
+ T((T_CALLED("_nc_remove_string(%p,%s)"), tree, _nc_visbuf(string)));
+
+ if (string == 0 || *string == 0)
+ returnCode(FALSE);
+
+ while (*tree != 0) {
+ if (UChar((*tree)->ch) == UChar(*string)) {
+ if (string[1] != 0)
+ returnCode(_nc_remove_string(&(*tree)->child, string + 1));
+ if ((*tree)->child == 0) {
+ TRIES *to_free = *tree;
+ *tree = (*tree)->sibling;
+ free(to_free);
+ returnCode(TRUE);
+ } else {
+ returnCode(FALSE);
+ }
+ }
+ tree = &(*tree)->sibling;
+ }
+ returnCode(FALSE);
+}
diff --git a/ncurses/base/use_window.c b/ncurses/base/use_window.c
new file mode 100644
index 000000000000..4d0fdf6705be
--- /dev/null
+++ b/ncurses/base/use_window.c
@@ -0,0 +1,78 @@
+/****************************************************************************
+ * Copyright (c) 2007,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey 2007 *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: use_window.c,v 1.7 2008/05/03 14:09:38 tom Exp $")
+
+#ifdef USE_PTHREADS
+NCURSES_EXPORT(void)
+_nc_lock_window(const WINDOW *win)
+{
+ WINDOWLIST *p;
+
+ _nc_lock_global(windowlist);
+ for (each_window(p)) {
+ if (&(p->win) == win) {
+ _nc_mutex_lock(&(p->mutex_use_window));
+ break;
+ }
+ }
+}
+
+NCURSES_EXPORT(void)
+_nc_unlock_window(const WINDOW *win)
+{
+ WINDOWLIST *p;
+
+ for (each_window(p)) {
+ if (&(p->win) == win) {
+ _nc_mutex_unlock(&(p->mutex_use_window));
+ break;
+ }
+ }
+ _nc_unlock_global(windowlist);
+}
+#endif
+
+NCURSES_EXPORT(int)
+use_window(WINDOW *win, NCURSES_WINDOW_CB func, void *data)
+{
+ int code = OK;
+
+ T((T_CALLED("use_window(%p,%p,%p)"), win, func, data));
+ _nc_lock_window(win);
+ code = func(win, data);
+ _nc_unlock_window(win);
+
+ returnCode(code);
+}
diff --git a/ncurses/base/version.c b/ncurses/base/version.c
new file mode 100644
index 000000000000..ef83967d46b3
--- /dev/null
+++ b/ncurses/base/version.c
@@ -0,0 +1,42 @@
+/****************************************************************************
+ * Copyright (c) 1999-2004,2005 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey <dickey@clark.net> 1999 *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: version.c,v 1.6 2005/01/02 01:23:54 tom Exp $")
+
+NCURSES_EXPORT(const char *)
+curses_version(void)
+{
+ T((T_CALLED("curses_version()")));
+ returnCPtr("ncurses " NCURSES_VERSION_STRING);
+}
diff --git a/ncurses/base/vsscanf.c b/ncurses/base/vsscanf.c
new file mode 100644
index 000000000000..e6253c3a38a3
--- /dev/null
+++ b/ncurses/base/vsscanf.c
@@ -0,0 +1,356 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * State-machine fallback written by Thomas E. Dickey 2002 *
+ ****************************************************************************/
+
+/*
+ * This function is needed to support vwscanw
+ */
+
+#include <curses.priv.h>
+
+#if !HAVE_VSSCANF
+
+MODULE_ID("$Id: vsscanf.c,v 1.18 2004/04/03 20:27:02 tom Exp $")
+
+#if !(HAVE_VFSCANF || HAVE__DOSCAN)
+
+#include <ctype.h>
+
+#define L_SQUARE '['
+#define R_SQUARE ']'
+
+typedef enum {
+ cUnknown
+ ,cError /* anything that isn't ANSI */
+ ,cAssigned
+ ,cChar
+ ,cInt
+ ,cFloat
+ ,cDouble
+ ,cPointer
+ ,cLong
+ ,cShort
+ ,cRange
+ ,cString
+} ChunkType;
+
+typedef enum {
+ oUnknown
+ ,oShort
+ ,oLong
+} OtherType;
+
+typedef enum {
+ sUnknown
+ ,sPercent /* last was '%' beginning a format */
+ ,sNormal /* ...somewhere in the middle */
+ ,sLeft /* last was left square bracket beginning a range */
+ ,sRange /* ...somewhere in the middle */
+ ,sFinal /* last finished a format */
+} ScanState;
+
+static ChunkType
+final_ch(int ch, OtherType other)
+{
+ ChunkType result = cUnknown;
+
+ switch (ch) {
+ case 'c':
+ if (other == oUnknown)
+ result = cChar;
+ else
+ result = cError;
+ break;
+ case 'd':
+ case 'i':
+ case 'X':
+ case 'x':
+ switch (other) {
+ case oUnknown:
+ result = cInt;
+ break;
+ case oShort:
+ result = cShort;
+ break;
+ case oLong:
+ result = cLong;
+ break;
+ }
+ break;
+ case 'E':
+ case 'e':
+ case 'f':
+ case 'g':
+ switch (other) {
+ case oUnknown:
+ result = cFloat;
+ break;
+ case oShort:
+ result = cError;
+ break;
+ case oLong:
+ result = cDouble;
+ break;
+ }
+ break;
+ case 'n':
+ if (other == oUnknown)
+ result = cAssigned;
+ else
+ result = cError;
+ break;
+ case 'p':
+ if (other == oUnknown)
+ result = cPointer;
+ else
+ result = cError;
+ break;
+ case 's':
+ if (other == oUnknown)
+ result = cString;
+ else
+ result = cError;
+ break;
+ }
+ return result;
+}
+
+static OtherType
+other_ch(int ch)
+{
+ OtherType result = oUnknown;
+ switch (ch) {
+ case 'h':
+ result = oShort;
+ break;
+ case 'l':
+ result = oLong;
+ break;
+ }
+ return result;
+}
+#endif
+
+/*VARARGS2*/
+NCURSES_EXPORT(int)
+vsscanf(const char *str, const char *format, va_list ap)
+{
+#if HAVE_VFSCANF || HAVE__DOSCAN
+ /*
+ * This code should work on anything descended from AT&T SVr1.
+ */
+ FILE strbuf;
+
+ strbuf._flag = _IOREAD;
+ strbuf._ptr = strbuf._base = (unsigned char *) str;
+ strbuf._cnt = strlen(str);
+ strbuf._file = _NFILE;
+
+#if HAVE_VFSCANF
+ return (vfscanf(&strbuf, format, ap));
+#else
+ return (_doscan(&strbuf, format, ap));
+#endif
+#else
+ static int can_convert = -1;
+
+ int assigned = 0;
+ int consumed = 0;
+
+ T((T_CALLED("vsscanf(%s,%s,...)"),
+ _nc_visbuf2(1, str),
+ _nc_visbuf2(2, format)));
+
+ /*
+ * This relies on having a working "%n" format conversion. Check if it
+ * works. Only very old C libraries do not support it.
+ *
+ * FIXME: move this check into the configure script.
+ */
+ if (can_convert < 0) {
+ int check1;
+ int check2;
+ if (sscanf("123", "%d%n", &check1, &check2) > 0
+ && check1 == 123
+ && check2 == 3) {
+ can_convert = 1;
+ } else {
+ can_convert = 0;
+ }
+ }
+
+ if (can_convert) {
+ size_t len_fmt = strlen(format) + 32;
+ char *my_fmt = malloc(len_fmt);
+ ChunkType chunk, ctest;
+ OtherType other, otest;
+ ScanState state;
+ unsigned n;
+ int eaten;
+ void *pointer;
+
+ if (my_fmt != 0) {
+ /*
+ * Split the original format into chunks, adding a "%n" to the end
+ * of each (except of course if it used %n), and use that
+ * information to decide where to start scanning the next chunk.
+ *
+ * FIXME: does %n count bytes or characters? If the latter, this
+ * will require further work for multibyte strings.
+ */
+ while (*format != '\0') {
+ /* find a chunk */
+ state = sUnknown;
+ chunk = cUnknown;
+ other = oUnknown;
+ pointer = 0;
+ for (n = 0; format[n] != 0 && state != sFinal; ++n) {
+ my_fmt[n] = format[n];
+ switch (state) {
+ case sUnknown:
+ if (format[n] == '%')
+ state = sPercent;
+ break;
+ case sPercent:
+ if (format[n] == '%') {
+ state = sUnknown;
+ } else if (format[n] == L_SQUARE) {
+ state = sLeft;
+ } else {
+ state = sNormal;
+ --n;
+ }
+ break;
+ case sLeft:
+ state = sRange;
+ if (format[n] == '^') {
+ ++n;
+ my_fmt[n] = format[n];
+ }
+ break;
+ case sRange:
+ if (format[n] == R_SQUARE) {
+ state = sFinal;
+ chunk = cRange;
+ }
+ break;
+ case sNormal:
+ if (format[n] == '*') {
+ state = sUnknown;
+ } else {
+ if ((ctest = final_ch(format[n], other)) != cUnknown) {
+ state = sFinal;
+ chunk = ctest;
+ } else if ((otest = other_ch(format[n])) != oUnknown) {
+ other = otest;
+ } else if (isalpha(UChar(format[n]))) {
+ state = sFinal;
+ chunk = cError;
+ }
+ }
+ break;
+ case sFinal:
+ break;
+ }
+ }
+ my_fmt[n] = '\0';
+ format += n;
+
+ if (chunk == cUnknown
+ || chunk == cError) {
+ if (assigned == 0)
+ assigned = EOF;
+ break;
+ }
+
+ /* add %n, if the format was not that */
+ if (chunk != cAssigned) {
+ strcat(my_fmt, "%n");
+ }
+
+ switch (chunk) {
+ case cAssigned:
+ strcat(my_fmt, "%n");
+ pointer = &eaten;
+ break;
+ case cInt:
+ pointer = va_arg(ap, int *);
+ break;
+ case cShort:
+ pointer = va_arg(ap, short *);
+ break;
+ case cFloat:
+ pointer = va_arg(ap, float *);
+ break;
+ case cDouble:
+ pointer = va_arg(ap, double *);
+ break;
+ case cLong:
+ pointer = va_arg(ap, long *);
+ break;
+ case cPointer:
+ pointer = va_arg(ap, void *);
+ break;
+ case cChar:
+ case cRange:
+ case cString:
+ pointer = va_arg(ap, char *);
+ break;
+ case cError:
+ case cUnknown:
+ break;
+ }
+ /* do the conversion */
+ T(("...converting chunk #%d type %d(%s,%s)",
+ assigned + 1, chunk,
+ _nc_visbuf2(1, str + consumed),
+ _nc_visbuf2(2, my_fmt)));
+ if (sscanf(str + consumed, my_fmt, pointer, &eaten) > 0)
+ consumed += eaten;
+ else
+ break;
+ ++assigned;
+ }
+ free(my_fmt);
+ }
+ }
+ returnCode(assigned);
+#endif
+}
+#else
+extern
+NCURSES_EXPORT(void)
+_nc_vsscanf(void); /* quiet's gcc warning */
+NCURSES_EXPORT(void)
+_nc_vsscanf(void)
+{
+} /* nonempty for strict ANSI compilers */
+#endif /* !HAVE_VSSCANF */
diff --git a/ncurses/base/wresize.c b/ncurses/base/wresize.c
new file mode 100644
index 000000000000..ac808c4d2884
--- /dev/null
+++ b/ncurses/base/wresize.c
@@ -0,0 +1,246 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey 1996-2002 *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: wresize.c,v 1.28 2008/05/03 14:13:51 tom Exp $")
+
+static int
+cleanup_lines(struct ldat *data, int length)
+{
+ while (--length >= 0)
+ free(data[length].text);
+ free(data);
+ return ERR;
+}
+
+/*
+ * If we have reallocated the ldat structs, we will have to repair pointers
+ * used in subwindows.
+ */
+static void
+repair_subwindows(WINDOW *cmp)
+{
+ WINDOWLIST *wp;
+ struct ldat *pline = cmp->_line;
+ int row;
+
+ _nc_lock_global(windowlist);
+
+ for (each_window(wp)) {
+ WINDOW *tst = &(wp->win);
+
+ if (tst->_parent == cmp) {
+
+ if (tst->_pary > cmp->_maxy)
+ tst->_pary = cmp->_maxy;
+ if (tst->_parx > cmp->_maxx)
+ tst->_parx = cmp->_maxx;
+
+ if (tst->_maxy + tst->_pary > cmp->_maxy)
+ tst->_maxy = cmp->_maxy - tst->_pary;
+ if (tst->_maxx + tst->_parx > cmp->_maxx)
+ tst->_maxx = cmp->_maxx - tst->_parx;
+
+ for (row = 0; row <= tst->_maxy; ++row) {
+ tst->_line[row].text = &pline[tst->_pary + row].text[tst->_parx];
+ }
+ repair_subwindows(tst);
+ }
+ }
+ _nc_unlock_global(windowlist);
+}
+
+/*
+ * Reallocate a curses WINDOW struct to either shrink or grow to the specified
+ * new lines/columns. If it grows, the new character cells are filled with
+ * blanks. The application is responsible for repainting the blank area.
+ */
+NCURSES_EXPORT(int)
+wresize(WINDOW *win, int ToLines, int ToCols)
+{
+ int col, row, size_x, size_y;
+ struct ldat *pline;
+ struct ldat *new_lines = 0;
+
+#ifdef TRACE
+ T((T_CALLED("wresize(%p,%d,%d)"), win, ToLines, ToCols));
+ if (win) {
+ TR(TRACE_UPDATE, ("...beg (%ld, %ld), max(%ld,%ld), reg(%ld,%ld)",
+ (long) win->_begy, (long) win->_begx,
+ (long) win->_maxy, (long) win->_maxx,
+ (long) win->_regtop, (long) win->_regbottom));
+ if (USE_TRACEF(TRACE_UPDATE)) {
+ _tracedump("...before", win);
+ _nc_unlock_global(tracef);
+ }
+ }
+#endif
+
+ if (!win || --ToLines < 0 || --ToCols < 0)
+ returnCode(ERR);
+
+ size_x = win->_maxx;
+ size_y = win->_maxy;
+
+ if (ToLines == size_y
+ && ToCols == size_x)
+ returnCode(OK);
+
+ if ((win->_flags & _SUBWIN)) {
+ /*
+ * Check if the new limits will fit into the parent window's size. If
+ * not, do not resize. We could adjust the location of the subwindow,
+ * but the application may not like that.
+ */
+ if (win->_pary + ToLines > win->_parent->_maxy
+ || win->_parx + ToCols > win->_parent->_maxx) {
+ returnCode(ERR);
+ }
+ pline = win->_parent->_line;
+ } else {
+ pline = 0;
+ }
+
+ /*
+ * Allocate new memory as needed. Do the allocations without modifying
+ * the original window, in case an allocation fails. Always allocate
+ * (at least temporarily) the array pointing to the individual lines.
+ */
+ new_lines = typeCalloc(struct ldat, (unsigned) (ToLines + 1));
+ if (new_lines == 0)
+ returnCode(ERR);
+
+ /*
+ * For each line in the target, allocate or adjust pointers for the
+ * corresponding text, depending on whether this is a window or a
+ * subwindow.
+ */
+ for (row = 0; row <= ToLines; ++row) {
+ int begin = (row > size_y) ? 0 : (size_x + 1);
+ int end = ToCols;
+ NCURSES_CH_T *s;
+
+ if (!(win->_flags & _SUBWIN)) {
+ if (row <= size_y) {
+ if (ToCols != size_x) {
+ if ((s = typeMalloc(NCURSES_CH_T, ToCols + 1)) == 0)
+ returnCode(cleanup_lines(new_lines, row));
+ for (col = 0; col <= ToCols; ++col) {
+ s[col] = (col <= size_x
+ ? win->_line[row].text[col]
+ : win->_nc_bkgd);
+ }
+ } else {
+ s = win->_line[row].text;
+ }
+ } else {
+ if ((s = typeMalloc(NCURSES_CH_T, ToCols + 1)) == 0)
+ returnCode(cleanup_lines(new_lines, row));
+ for (col = 0; col <= ToCols; ++col)
+ s[col] = win->_nc_bkgd;
+ }
+ } else {
+ s = &pline[win->_pary + row].text[win->_parx];
+ }
+
+ if_USE_SCROLL_HINTS(new_lines[row].oldindex = row);
+ if (row <= size_y) {
+ new_lines[row].firstchar = win->_line[row].firstchar;
+ new_lines[row].lastchar = win->_line[row].lastchar;
+ }
+ if ((ToCols != size_x) || (row > size_y)) {
+ if (end >= begin) { /* growing */
+ if (new_lines[row].firstchar < begin)
+ new_lines[row].firstchar = begin;
+ } else { /* shrinking */
+ new_lines[row].firstchar = 0;
+ }
+ new_lines[row].lastchar = ToCols;
+ }
+ new_lines[row].text = s;
+ }
+
+ /*
+ * Dispose of unwanted memory.
+ */
+ if (!(win->_flags & _SUBWIN)) {
+ if (ToCols == size_x) {
+ for (row = ToLines + 1; row <= size_y; row++) {
+ free(win->_line[row].text);
+ }
+ } else {
+ for (row = 0; row <= size_y; row++) {
+ free(win->_line[row].text);
+ }
+ }
+ }
+
+ free(win->_line);
+ win->_line = new_lines;
+
+ /*
+ * Finally, adjust the parameters showing screen size and cursor
+ * position:
+ */
+ win->_maxx = ToCols;
+ win->_maxy = ToLines;
+
+ if (win->_regtop > win->_maxy)
+ win->_regtop = win->_maxy;
+ if (win->_regbottom > win->_maxy
+ || win->_regbottom == size_y)
+ win->_regbottom = win->_maxy;
+
+ if (win->_curx > win->_maxx)
+ win->_curx = win->_maxx;
+ if (win->_cury > win->_maxy)
+ win->_cury = win->_maxy;
+
+ /*
+ * Check for subwindows of this one, and readjust pointers to our text,
+ * if needed.
+ */
+ repair_subwindows(win);
+
+#ifdef TRACE
+ TR(TRACE_UPDATE, ("...beg (%ld, %ld), max(%ld,%ld), reg(%ld,%ld)",
+ (long) win->_begy, (long) win->_begx,
+ (long) win->_maxy, (long) win->_maxx,
+ (long) win->_regtop, (long) win->_regbottom));
+ if (USE_TRACEF(TRACE_UPDATE)) {
+ _tracedump("...after:", win);
+ _nc_unlock_global(tracef);
+ }
+#endif
+ returnCode(OK);
+}