diff options
Diffstat (limited to 'contrib/ncurses/ncurses/base')
66 files changed, 3704 insertions, 1732 deletions
diff --git a/contrib/ncurses/ncurses/base/MKkeyname.awk b/contrib/ncurses/ncurses/base/MKkeyname.awk index b8cd5da..11dcfe5 100644 --- a/contrib/ncurses/ncurses/base/MKkeyname.awk +++ b/contrib/ncurses/ncurses/base/MKkeyname.awk @@ -1,6 +1,6 @@ -# $Id: MKkeyname.awk,v 1.22 2002/05/25 22:25:06 tom Exp $ +# $Id: MKkeyname.awk,v 1.30 2006/05/20 17:35:30 tom Exp $ ############################################################################## -# Copyright (c) 1999-2001,2002 Free Software Foundation, Inc. # +# 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"), # @@ -31,6 +31,7 @@ BEGIN { print "" print "#include <curses.priv.h>" print "#include <tic.h>" + print "#include <term_entry.h>" print "" print "const struct kn _nc_key_names[] = {" } @@ -42,49 +43,93 @@ BEGIN { END { printf "\t{ 0, 0 }};\n" print "" + print "#define SIZEOF_TABLE 256" + print "static char **keyname_table;" + print "" print "NCURSES_EXPORT(NCURSES_CONST char *) keyname (int c)" print "{" - print "static char **table;" - print "int i;" - print "char name[20];" - print "char *p;" - print "" - print "\tif (c == -1) return \"-1\";" + print " int i;" + print " char name[20];" + print " char *p;" + print " NCURSES_CONST char *result = 0;" print "" - print "\tfor (i = 0; _nc_key_names[i].name != 0; i++)" - print "\t\tif (_nc_key_names[i].code == c)" - print "\t\t\treturn (NCURSES_CONST char *)_nc_key_names[i].name;" - print "\tif (c < 0 || c >= 256) return \"UNKNOWN KEY\";" + print " if (c == -1) {" + print " result = \"-1\";" + 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 "\tif (table == 0)" - print "\t\ttable = typeCalloc(char *, 256);" - print "\tif (table == 0)" - print "\t\treturn keyname(256);" + print " if (result == 0 && (c >= 0 && c < SIZEOF_TABLE)) {" + print " if (keyname_table == 0)" + print " keyname_table = typeCalloc(char *, SIZEOF_TABLE);" + print " if (keyname_table != 0) {" + print " if (keyname_table[c] == 0) {" + print " int cc = c;" + print " p = name;" + print " if (cc >= 128) {" + 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 " keyname_table[c] = strdup(name);" + print " }" + print " result = keyname_table[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 "\tif (table[c] == 0) {" - print "\t\tp = name;" - print "\t\tif (c >= 128) {" - print "\t\t\tstrcpy(p, \"M-\");" - print "\t\t\tp += 2;" - print "\t\t\tc -= 128;" - print "\t\t}" - print "\t\tif (c < 32)" - print "\t\t\tsprintf(p, \"^%c\", c + '@');" - print "\t\telse if (c == 127)" - print "\t\t\tstrcpy(p, \"^?\");" - print "\t\telse" - print "\t\t\tsprintf(p, \"%c\", c);" - print "\t\ttable[c] = strdup(name);" - print "\t}" - print "\treturn (NCURSES_CONST char *)table[c];" + 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 USE_WIDEC_SUPPORT" print "NCURSES_EXPORT(NCURSES_CONST char *) key_name (wchar_t c)" print "{" - print "\tchar *result = keyname((int)c);" - print "\tif (!strncmp(result, \"M-\", 2)) result = \"UNKNOWN KEY\";" - print "\treturn result;" + print " NCURSES_CONST char *result = keyname((int)c);" + print " if (!strncmp(result, \"M-\", 2)) result = 0;" + print " return result;" print "}" print "#endif" + print "" + print "#if NO_LEAKS" + print "void _nc_keyname_leaks(void)" + print "{" + print " int j;" + print " if (keyname_table != 0) {" + print " for (j = 0; j < SIZEOF_TABLE; ++j) {" + print " FreeIfNeeded(keyname_table[j]);" + print " }" + print " FreeAndNull(keyname_table);" + print " }" + print "}" + print "#endif /* NO_LEAKS */" } diff --git a/contrib/ncurses/ncurses/base/MKlib_gen.sh b/contrib/ncurses/ncurses/base/MKlib_gen.sh index e172feb..30c44ff 100755 --- a/contrib/ncurses/ncurses/base/MKlib_gen.sh +++ b/contrib/ncurses/ncurses/base/MKlib_gen.sh @@ -2,10 +2,10 @@ # # MKlib_gen.sh -- generate sources from curses.h macro definitions # -# ($Id: MKlib_gen.sh,v 1.18 2002/04/30 00:37:55 tom Exp $) +# ($Id: MKlib_gen.sh,v 1.27 2006/07/01 21:25:39 tom Exp $) # ############################################################################## -# Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. # +# 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"), # @@ -39,14 +39,14 @@ # # 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 +# 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 +# 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 @@ -54,6 +54,14 @@ # 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 -I../include" AWK="$2" USE="$3" @@ -74,19 +82,19 @@ if test "$USE" = implemented ; then cat >$ED1 <<EOF1 /^extern.*implemented/{ h - s/^.*implemented:\([^ *]*\).*/P_#if_USE_\1_SUPPORT/p + s/^.*implemented:\([^ *]*\).*/P_POUNDCif_USE_\1_SUPPORT/p g s/^extern \([^;]*\);.*/\1/p g - s/^.*implemented:\([^ *]*\).*/P_#endif/p + s/^.*implemented:\([^ *]*\).*/P_POUNDCendif/p } /^extern.*generated/{ h - s/^.*generated:\([^ *]*\).*/P_#if_USE_\1_SUPPORT/p + s/^.*generated:\([^ *]*\).*/P_POUNDCif_USE_\1_SUPPORT/p g s/^extern \([^;]*\);.*/\1/p g - s/^.*generated:\([^ *]*\).*/P_#endif/p + s/^.*generated:\([^ *]*\).*/P_POUNDCendif/p } EOF1 else @@ -94,11 +102,11 @@ else cat >$ED1 <<EOF1 /^extern.*${ALL}/{ h - s/^.*${ALL}:\([^ *]*\).*/P_#if_USE_\1_SUPPORT/p + s/^.*${ALL}:\([^ *]*\).*/P_POUNDCif_USE_\1_SUPPORT/p g s/^extern \([^;]*\);.*/\1/p g - s/^.*${ALL}:\([^ *]*\).*/P_#endif/p + s/^.*${ALL}:\([^ *]*\).*/P_POUNDCendif/p } EOF1 fi @@ -126,13 +134,14 @@ cat >$ED2 <<EOF2 s/)/ z)/ s/\.\.\. z)/...)/ :nc - /(/s// ( / + s/(/ ( / s/)/ )/ EOF2 cat >$ED3 <<EOF3 /^P_/{ - s/^P_#if_/#if / + s/^P_POUNDCif_/#if / + s/^P_POUNDCendif/#endif/ s/^P_// b done } @@ -143,7 +152,7 @@ cat >$ED3 <<EOF3 s/ )/)/g s/ gen_/ / s/^M_/#undef / - /^%%/s// / + s/^[ ]*%[ ]*%[ ]*/ / :done EOF3 @@ -167,12 +176,12 @@ cat >$AW1 <<\EOF1 BEGIN { skip=0; } -/^P_#if/ { +/^P_POUNDCif/ { print "\n" print $0 skip=0; } -/^P_#endif/ { +/^P_POUNDCendif/ { print $0 skip=1; } @@ -195,6 +204,10 @@ $0 !~ /^P_/ { 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 { @@ -244,13 +257,17 @@ $0 !~ /^P_/ { 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" ) - pointer = 1; + va_list = 1; + else if ( ch == "..." ) + varargs = 1; else if ( ch == "char" ) argtype = "char"; else if ( ch == "int" ) @@ -263,7 +280,11 @@ $0 !~ /^P_/ { argtype = "attr"; if ( ch == "," || ch == ")" ) { - if (pointer) { + 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 "," @@ -282,10 +303,17 @@ $0 !~ /^P_/ { comma = comma "(long)" } } - if (ch == ",") + if (ch == ",") { args = args comma "a" ++num; - else if ( argcount != 0 && $check != "..." ) - args = args comma "z" + } 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 ")" @@ -352,6 +380,7 @@ BEGIN { 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 "" } @@ -366,6 +395,7 @@ EOF1 cat >$TMP <<EOF #include <ncurses_cfg.h> +#undef NCURSES_NOMACROS #include <curses.h> DECLARATIONS @@ -379,7 +409,10 @@ sed -n -f $ED1 \ | sed -e 's/^\([a-z_][a-z_]*[ *]*\)/\1 gen_/' -e 's/ / /g' >>$TMP $preprocessor $TMP 2>/dev/null \ -| sed -e 's/ / /g' -e 's/^ //' \ +| sed \ + -e 's/ / /g' \ + -e 's/^ //' \ + -e 's/^_Bool/bool/' \ | $AWK -f $AW2 \ | sed -f $ED3 \ | sed \ diff --git a/contrib/ncurses/ncurses/base/MKunctrl.awk b/contrib/ncurses/ncurses/base/MKunctrl.awk index d8a6587..e153fa8 100644 --- a/contrib/ncurses/ncurses/base/MKunctrl.awk +++ b/contrib/ncurses/ncurses/base/MKunctrl.awk @@ -1,6 +1,6 @@ -# $Id: MKunctrl.awk,v 1.9 2001/06/02 23:59:20 skimo Exp $ +# $Id: MKunctrl.awk,v 1.11 2005/12/17 22:48:37 tom Exp $ ############################################################################## -# Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. # +# 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"), # @@ -41,6 +41,7 @@ BEGIN { END { print "NCURSES_EXPORT(NCURSES_CONST char *) unctrl (register chtype ch)" print "{" + printf "static const char* const table[] = {" for ( ch = 0; ch < 256; ch++ ) { gap = "," @@ -63,7 +64,44 @@ END { printf "%s", gap } print "};" + + print "" + print "#if NCURSES_EXT_FUNCS" + printf "static const char* const table2[] = {" + for ( ch = 128; ch < 160; ch++ ) { + gap = "," + if ((ch % 8) == 0) + printf "\n " + if (ch >= 128 && ch < 160) { + printf "\"\\%03o\"", ch + gap = gap " " + } + if (ch == 255) + gap = "\n" + else if (((ch + 1) % 8) != 0) + gap = gap " " + printf "%s", gap + } + print "};" + print "#endif /* NCURSES_EXT_FUNCS */" + + print "" + print "\tint check = ChCharOf(ch);" + print "\tconst char *result;" print "" - print "\treturn (NCURSES_CONST char *)table[ChCharOf(ch)];" + print "\tif (check >= 0 && check < (int)SIZEOF(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))" + print "\t\t\tresult = table2[check - 128];" + print "\t\telse" + print "#endif /* NCURSES_EXT_FUNCS */" + print "\t\t\tresult = table[check];" + print "\t} else {" + print "\t\tresult = 0;" + print "\t}" + print "\treturn (NCURSES_CONST char *)result;" print "}" } diff --git a/contrib/ncurses/ncurses/base/README b/contrib/ncurses/ncurses/base/README index ffa1696..4677e42 100644 --- a/contrib/ncurses/ncurses/base/README +++ b/contrib/ncurses/ncurses/base/README @@ -1,4 +1,32 @@ --- $Id: README,v 1.1 1998/11/14 22:58:22 tom Exp $ +------------------------------------------------------------------------------- +-- 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. diff --git a/contrib/ncurses/ncurses/base/define_key.c b/contrib/ncurses/ncurses/base/define_key.c index 7fc885f..3b5299a 100644 --- a/contrib/ncurses/ncurses/base/define_key.c +++ b/contrib/ncurses/ncurses/base/define_key.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * 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 * @@ -27,30 +27,35 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + * Author: Thomas E. Dickey 1997-on * ****************************************************************************/ #include <curses.priv.h> -MODULE_ID("$Id: define_key.c,v 1.6 2000/12/10 02:43:26 tom Exp $") +MODULE_ID("$Id: define_key.c,v 1.10 2006/06/17 18:19:48 tom Exp $") NCURSES_EXPORT(int) -define_key -(char *str, int keycode) +define_key(const char *str, int keycode) { int code = ERR; T((T_CALLED("define_key(%s,%d)"), _nc_visbuf(str), keycode)); - if (keycode > 0) { + if (SP == 0) { + code = ERR; + } else if (keycode > 0) { if (str != 0) { define_key(str, 0); } else if (has_key(keycode)) { - while (_nc_remove_key(&(SP->_keytry), keycode)) + while (_nc_remove_key(&(SP->_keytry), (unsigned) keycode)) code = OK; } if (str != 0) { - (void) _nc_add_to_try(&(SP->_keytry), str, keycode); - code = OK; + if (key_defined(str) == 0) { + (void) _nc_add_to_try(&(SP->_keytry), str, (unsigned) keycode); + code = OK; + } else { + code = ERR; + } } } else { while (_nc_remove_string(&(SP->_keytry), str)) diff --git a/contrib/ncurses/ncurses/base/key_defined.c b/contrib/ncurses/ncurses/base/key_defined.c new file mode 100644 index 0000000..dac1887 --- /dev/null +++ b/contrib/ncurses/ncurses/base/key_defined.c @@ -0,0 +1,76 @@ +/**************************************************************************** + * Copyright (c) 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: Thomas E. Dickey, 2003 * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: key_defined.c,v 1.3 2003/05/17 23:12:27 tom Exp $") + +static int +find_definition(struct tries *tree, const char *str) +{ + struct tries *ptr; + int result = 0; + + 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 = -1; + } else if ((result = find_definition(ptr->child, str + 1)) == 0) { + result = ptr->value; + } else if (str[1] == '\0') { + result = -1; + } + } + if (result != 0) + break; + } + } + return (result); +} + +/* + * Returns the keycode associated with the given string. If none is found, + * return 0. If the string is only a prefix to other strings, return -1. + */ +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/contrib/ncurses/ncurses/base/keybound.c b/contrib/ncurses/ncurses/base/keybound.c index c8ca285..2995714 100644 --- a/contrib/ncurses/ncurses/base/keybound.c +++ b/contrib/ncurses/ncurses/base/keybound.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1999,2000 Free Software Foundation, Inc. * + * 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 * @@ -27,20 +27,25 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + * Author: Thomas E. Dickey 1999-on * ****************************************************************************/ #include <curses.priv.h> -MODULE_ID("$Id: keybound.c,v 1.3 2000/12/10 02:43:26 tom Exp $") +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) { - return _nc_expand_try(SP->_key_ok, code, &count, 0); + 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/contrib/ncurses/ncurses/base/keyok.c b/contrib/ncurses/ncurses/base/keyok.c index e3b4be2..4c99506 100644 --- a/contrib/ncurses/ncurses/base/keyok.c +++ b/contrib/ncurses/ncurses/base/keyok.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * 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 * @@ -32,7 +32,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: keyok.c,v 1.5 2000/12/10 02:43:26 tom Exp $") +MODULE_ID("$Id: keyok.c,v 1.6 2006/06/17 18:18:43 tom Exp $") /* * Enable (or disable) ncurses' interpretation of a keycode by adding (or @@ -52,21 +52,24 @@ keyok(int c, bool flag) char *s; T((T_CALLED("keyok(%d,%d)"), c, flag)); - if (flag) { - while ((s = _nc_expand_try(SP->_key_ok, c, &count, 0)) != 0 - && _nc_remove_key(&(SP->_key_ok), c)) { - _nc_add_to_try(&(SP->_keytry), s, c); - free(s); - code = OK; - count = 0; - } - } else { - while ((s = _nc_expand_try(SP->_keytry, c, &count, 0)) != 0 - && _nc_remove_key(&(SP->_keytry), c)) { - _nc_add_to_try(&(SP->_key_ok), s, c); - free(s); - code = OK; - count = 0; + 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)) { + _nc_add_to_try(&(SP->_keytry), s, ch); + free(s); + code = OK; + count = 0; + } + } else { + while ((s = _nc_expand_try(SP->_keytry, ch, &count, 0)) != 0 + && _nc_remove_key(&(SP->_keytry), ch)) { + _nc_add_to_try(&(SP->_key_ok), s, ch); + free(s); + code = OK; + count = 0; + } } } returnCode(code); diff --git a/contrib/ncurses/ncurses/base/legacy_coding.c b/contrib/ncurses/ncurses/base/legacy_coding.c new file mode 100644 index 0000000..1c2f160 --- /dev/null +++ b/contrib/ncurses/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/contrib/ncurses/ncurses/base/lib_addch.c b/contrib/ncurses/ncurses/base/lib_addch.c index 423a45e..9d73edf 100644 --- a/contrib/ncurses/ncurses/base/lib_addch.c +++ b/contrib/ncurses/ncurses/base/lib_addch.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. * + * 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 * @@ -36,7 +36,9 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$Id: lib_addch.c,v 1.64 2002/05/11 18:16:43 tom Exp $") +MODULE_ID("$Id: lib_addch.c,v 1.104 2006/10/14 20:31:19 tom Exp $") + +static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT); /* * Ugly microtweaking alert. Everything from here to end of module is @@ -49,29 +51,50 @@ MODULE_ID("$Id: lib_addch.c,v 1.64 2002/05/11 18:16:43 tom Exp $") */ /* 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)) +#define COLOR_MASK(ch) (~(attr_t)((ch) & A_COLOR ? A_COLOR : 0)) -static inline NCURSES_CH_T +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 = win->_attrs; + attr_t a = WINDOW_ATTRS(win); + int pair = GetPair(ch); - if (ISBLANK(ch) && AttrOf(ch) == A_NORMAL) { - /* color in attrs has precedence over bkgrnd */ + 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) & COLOR_MASK(a))); + 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) & A_ATTRIBUTES) & COLOR_MASK(a); + 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, ("bkg = %s, attrs = %s -> ch = %s", - _tracech_t2(1, CHREF(win->_nc_bkgd)), - _traceattr(win->_attrs), - _tracech_t2(3, CHREF(ch)))); + 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); } @@ -99,81 +122,300 @@ _nc_render(WINDOW *win, NCURSES_CH_T ch) #define CHECK_POSITION(win, x, y) /* nothing */ #endif -static inline int +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)); + SetChar(CHDEREF(ch), result, attrs); + 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")); + buffer[0] = CharOf(CHDEREF(ch)); + WINDOW_EXT(win, addch_used) = 1; + } + } + 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, win->_cury); - - /* - * If we're trying to add a character at the lower-right corner more - * than once, fail. (Moving the cursor will clear the flag). - */ -#if 0 /* Solaris 2.6 allows updating the corner more than once */ - if (win->_flags & _WRAPPED) { - if (x >= win->_maxx) - return (ERR); - win->_flags &= ~_WRAPPED; - } -#endif + CHECK_POSITION(win, x, y); ch = render_char(win, ch); - TR(TRACE_VIRTPUT, ("win attr = %s", _traceattr(win->_attrs))); - line = win->_line + win->_cury; + line = win->_line + y; CHANGED_CELL(line, x); - line->text[x++] = ch; + /* + * Build up multibyte characters until we have a wide-character. + */ if_WIDEC({ - if (wcwidth(CharOf(ch)) > 1) - AddAttr(line->text[x++], WA_NAC); + if (WINDOW_EXT(win, addch_used) != 0 || !Charable(ch)) { + int len = _nc_build_wch(win, CHREF(ch)); + + if (len > 0) { + if (is8bits(CharOf(ch))) { + const char *s = unctrl((chtype) CharOf(ch)); + if (s[1] != 0) { + return waddstr(win, s); + } + } + } else { + return OK; + } + } }); - TR(TRACE_VIRTPUT, ("(%d, %d) = %s", win->_cury, x, _tracech_t(CHREF(ch)))); - if (x > win->_maxx) { - /* - * 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). - */ - win->_flags |= _WRAPPED; - if (++win->_cury > win->_regbottom) { - win->_cury = win->_regbottom; - win->_curx = win->_maxx; - if (!win->_scroll) - return (ERR); - scroll(win); + /* + * 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; } - win->_curx = 0; - return (OK); + }); + + /* + * 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 inline int +static NCURSES_INLINE int waddch_nosync(WINDOW *win, const NCURSES_CH_T ch) /* the workhorse function -- add a character to the given window */ { - int x, y; - chtype t = 0; - const char *s = 0; + 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) - || ((t = CharOf(ch)) > 127) - || ((s = unctrl(t))[1] == 0)) + || ( +#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; @@ -187,7 +429,7 @@ waddch_nosync(WINDOW *win, const NCURSES_CH_T ch) */ if ((!win->_scroll && (y == win->_regbottom)) || (x <= win->_maxx)) { - NCURSES_CH_T blank = NewChar2(BLANK_TEXT, BLANK_ATTR); + NCURSES_CH_T blank = blankchar; AddAttr(blank, AttrOf(ch)); while (win->_curx < x) { if (waddch_literal(win, blank) == ERR) @@ -197,9 +439,8 @@ waddch_nosync(WINDOW *win, const NCURSES_CH_T ch) } else { wclrtoeol(win); win->_flags |= _WRAPPED; - if (++y > win->_regbottom) { + if (newline_forces_scroll(win, &y)) { x = win->_maxx; - y--; if (win->_scroll) { scroll(win); x = 0; @@ -211,8 +452,7 @@ waddch_nosync(WINDOW *win, const NCURSES_CH_T ch) break; case '\n': wclrtoeol(win); - if (++y > win->_regbottom) { - y--; + if (newline_forces_scroll(win, &y)) { if (win->_scroll) scroll(win); else @@ -253,7 +493,7 @@ _nc_waddch_nosync(WINDOW *win, const NCURSES_CH_T c) } /* - * The versions below call _nc_synhook(). We wanted to avoid this in the + * 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. */ @@ -299,41 +539,3 @@ wechochar(WINDOW *win, const chtype ch) TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code)); return (code); } - -#if USE_WIDEC_SUPPORT -NCURSES_EXPORT(int) -wadd_wch(WINDOW *win, const cchar_t * wch) -{ - int code = ERR; - - TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wadd_wch(%p, %s)"), win, - _tracech_t(wch))); - - 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) -wecho_wchar(WINDOW *win, const cchar_t * wch) -{ - int code = ERR; - - TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wecho_wchar(%p, %s)"), win, - _tracech_t(wch))); - - 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); -} -#endif /* USE_WIDEC_SUPPORT */ diff --git a/contrib/ncurses/ncurses/base/lib_addstr.c b/contrib/ncurses/ncurses/base/lib_addstr.c index 343555a3..b7a0b40 100644 --- a/contrib/ncurses/ncurses/base/lib_addstr.c +++ b/contrib/ncurses/ncurses/base/lib_addstr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,10 @@ /**************************************************************************** * 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 * ****************************************************************************/ /* @@ -40,68 +44,28 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_addstr.c,v 1.31 2001/12/19 01:05:52 tom Exp $") - -#if USE_WIDEC_SUPPORT -#define CONV_DATA mbstate_t state; wchar_t cached; int clen = 0 -#define CONV_INIT memset (&state, '\0', sizeof (state)); cached = (wchar_t)WEOF -#define NEXT_CHAR(s,ch, n) \ - { \ - int len, i = 0; \ - memset(&ch, 0, sizeof(cchar_t)); \ - if (cached != (wchar_t) WEOF) { \ - ch.chars[i++] = cached; \ - cached = (wchar_t) WEOF; \ - n -= clen; \ - s += clen; \ - } \ - for (; i < CCHARW_MAX && n > 0; ++i) { \ - if ((len = mbrtowc(&ch.chars[i], s, n, &state)) < 0) { \ - code = ERR; \ - break; \ - } \ - if (i == 0 || wcwidth(ch.chars[i]) == 0) { \ - n -= len; \ - s += len; \ - } else { \ - cached = ch.chars[i]; \ - clen = len; \ - ch.chars[i] = L'\0'; \ - break; \ - } \ - } \ - if (code == ERR) \ - break; \ - } -#else -#define CONV_DATA -#define CONV_INIT -#define NEXT_CHAR(s,ch, n) \ - ch = *s++; \ - --n -#endif +MODULE_ID("$Id: lib_addstr.c,v 1.46 2006/05/27 19:22:19 tom Exp $") NCURSES_EXPORT(int) -waddnstr(WINDOW *win, const char *const astr, int n) +waddnstr(WINDOW *win, const char *astr, int n) { - unsigned const char *str = (unsigned const char *) astr; + const char *str = astr; int code = ERR; - CONV_DATA; - T((T_CALLED("waddnstr(%p,%s,%d)"), win, _nc_visbuf(astr), n)); + 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(win->_attrs))); + 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)); - CONV_INIT; - while ((n > 0) && (*str != '\0')) { + while ((n-- > 0) && (*str != '\0')) { NCURSES_CH_T ch; - TR(TRACE_VIRTPUT, ("*str = %#x", *str)); - NEXT_CHAR(str, ch, n); + TR(TRACE_VIRTPUT, ("*str = %#o", UChar(*str))); + SetChar(ch, UChar(*str++), A_NORMAL); if (_nc_waddch_nosync(win, ch) == ERR) { code = ERR; break; @@ -114,11 +78,12 @@ waddnstr(WINDOW *win, const char *const astr, int n) } NCURSES_EXPORT(int) -waddchnstr(WINDOW *win, const chtype * const astr, int n) +waddchnstr(WINDOW *win, const chtype *astr, int n) { NCURSES_SIZE_T y = win->_cury; NCURSES_SIZE_T x = win->_curx; int code = OK; + int i; struct ldat *line; T((T_CALLED("waddchnstr(%p,%p,%d)"), win, astr, n)); @@ -138,15 +103,9 @@ waddchnstr(WINDOW *win, const chtype * const astr, int n) returnCode(code); line = &(win->_line[y]); -#if USE_WIDEC_SUPPORT - { - int i; - for (i = 0; i < n; ++i) - SetChar(line->text[i + x], ChCharOf(astr[i]), ChAttrOf(astr[i])); + for (i = 0; i < n && ChCharOf(astr[i]) != '\0'; ++i) { + SetChar2(line->text[i + x], astr[i]); } -#else - memcpy(line->text + x, astr, n * sizeof(*astr)); -#endif CHANGED_RANGE(line, x, x + n - 1); _nc_synchook(win); @@ -155,8 +114,8 @@ waddchnstr(WINDOW *win, const chtype * const astr, int n) #if USE_WIDEC_SUPPORT -int -_nc_wchstrlen(const cchar_t * s) +NCURSES_EXPORT(int) +_nc_wchstrlen(const cchar_t *s) { int result = 0; while (CharOf(s[result]) != L'\0') { @@ -166,13 +125,14 @@ _nc_wchstrlen(const cchar_t * s) } NCURSES_EXPORT(int) -wadd_wchnstr(WINDOW *win, const cchar_t * const astr, int n) +wadd_wchnstr(WINDOW *win, const cchar_t *astr, int n) { + static const NCURSES_CH_T blank = NewChar(BLANK_TEXT); NCURSES_SIZE_T y = win->_cury; NCURSES_SIZE_T x = win->_curx; int code = OK; struct ldat *line; - int i, start, end; + int i, j, start, len, end; T((T_CALLED("wadd_wchnstr(%p,%s,%d)"), win, _nc_viscbuf(astr, n), n)); @@ -190,22 +150,58 @@ wadd_wchnstr(WINDOW *win, const cchar_t * const astr, int n) line = &(win->_line[y]); start = x; end = x + n - 1; - if (isnac(line->text[x])) { - line->text[x - 1] = win->_nc_bkgd; - --start; + + /* + * 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; + } + } } - for (i = 0; i < n && x <= win->_maxx; ++i) { - line->text[x++] = astr[i]; - if (wcwidth(CharOf(astr[i])) > 1) { - if (x <= win->_maxx) - AddAttr(line->text[x++], WA_NAC); - else - line->text[x - 1] = win->_nc_bkgd; + + /* + * 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; } } - if (x <= win->_maxx && isnac(line->text[x])) { - line->text[x] = win->_nc_bkgd; + + /* + * 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); @@ -214,15 +210,15 @@ wadd_wchnstr(WINDOW *win, const cchar_t * const astr, int n) } NCURSES_EXPORT(int) -waddnwstr(WINDOW *win, const wchar_t * str, int n) +waddnwstr(WINDOW *win, const wchar_t *str, int n) { int code = ERR; - int i; - T((T_CALLED("waddnwstr(%p,%s,%d)"), win, _nc_viswbuf(str), n)); + 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(win->_attrs))); + TR(TRACE_VIRTPUT | TRACE_ATTRS, + ("... current %s", _traceattr(WINDOW_ATTRS(win)))); code = OK; if (n < 0) n = (int) wcslen(str); @@ -230,16 +226,9 @@ waddnwstr(WINDOW *win, const wchar_t * str, int n) 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", *str)); + TR(TRACE_VIRTPUT, ("*str[0] = %#lx", (unsigned long) *str)); SetChar(ch, *str++, A_NORMAL); - i = 1; - while (i < CCHARW_MAX && n > 0 && (*str != L('\0')) - && wcwidth(*str) == 0) { - TR(TRACE_VIRTPUT, ("*str[%d] = %#lx", i, *str)); - ch.chars[i++] = *str++; - --n; - } - if (_nc_waddch_nosync(win, ch) == ERR) { + if (wadd_wch(win, &ch) == ERR) { code = ERR; break; } diff --git a/contrib/ncurses/ncurses/base/lib_beep.c b/contrib/ncurses/ncurses/base/lib_beep.c index c23d0a1..b478f25 100644 --- a/contrib/ncurses/ncurses/base/lib_beep.c +++ b/contrib/ncurses/ncurses/base/lib_beep.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -41,7 +42,7 @@ #include <curses.priv.h> #include <term.h> /* beep, flash */ -MODULE_ID("$Id: lib_beep.c,v 1.9 2000/12/10 02:43:26 tom Exp $") +MODULE_ID("$Id: lib_beep.c,v 1.10 2005/04/09 15:20:04 tom Exp $") /* * beep() @@ -59,7 +60,9 @@ beep(void) T((T_CALLED("beep()"))); /* FIXME: should make sure that we are not in altchar mode */ - if (bell) { + if (cur_term == 0) { + res = ERR; + } else if (bell) { TPUTS_TRACE("bell"); res = putp(bell); _nc_flush(); diff --git a/contrib/ncurses/ncurses/base/lib_bkgd.c b/contrib/ncurses/ncurses/base/lib_bkgd.c index a3d7c30..e6a0cb0 100644 --- a/contrib/ncurses/ncurses/base/lib_bkgd.c +++ b/contrib/ncurses/ncurses/base/lib_bkgd.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -29,11 +29,14 @@ /**************************************************************************** * 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.26 2001/12/19 01:36:58 tom Exp $") +MODULE_ID("$Id: lib_bkgd.c,v 1.35 2006/05/27 19:20:11 tom Exp $") /* * Set the window's background information. @@ -41,7 +44,7 @@ MODULE_ID("$Id: lib_bkgd.c,v 1.26 2001/12/19 01:36:58 tom Exp $") #if USE_WIDEC_SUPPORT NCURSES_EXPORT(void) #else -static inline void +static NCURSES_INLINE void #endif wbkgrndset(WINDOW *win, const ARG_CH_T ch) { @@ -51,13 +54,26 @@ wbkgrndset(WINDOW *win, const ARG_CH_T ch) attr_t off = AttrOf(win->_nc_bkgd); attr_t on = AttrOf(CHDEREF(ch)); - toggle_attr_off(win->_attrs, off); - toggle_attr_on(win->_attrs, on); + toggle_attr_off(WINDOW_ATTRS(win), off); + toggle_attr_on(WINDOW_ATTRS(win), on); - if (CharOf(CHDEREF(ch)) == L('\0')) +#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))); - else + 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 @@ -70,9 +86,11 @@ wbkgrndset(WINDOW *win, const ARG_CH_T ch) int tmp; wgetbkgrnd(win, &wch); - tmp = wctob(CharOf(wch)); + tmp = _nc_to_char((wint_t) CharOf(wch)); - win->_bkgd = ((tmp == EOF) ? ' ' : (chtype) tmp) | AttrOf(wch); + win->_bkgd = (((tmp == EOF) ? ' ' : (chtype) tmp) + | (AttrOf(wch) & ALL_BUT_COLOR) + | COLOR_PAIR(GET_WINDOW_PAIR(win))); } #endif } @@ -93,7 +111,7 @@ wbkgdset(WINDOW *win, chtype ch) #if USE_WIDEC_SUPPORT NCURSES_EXPORT(int) #else -static inline int +static NCURSES_INLINE int #undef wbkgrnd #endif wbkgrnd(WINDOW *win, const ARG_CH_T ch) @@ -113,11 +131,11 @@ wbkgrnd(WINDOW *win, const ARG_CH_T ch) for (y = 0; y <= win->_maxy; y++) { for (x = 0; x <= win->_maxx; x++) { - if (CharEq(win->_line[y].text[x], old_bkgrnd)) + if (CharEq(win->_line[y].text[x], old_bkgrnd)) { win->_line[y].text[x] = win->_nc_bkgd; - else { + } else { NCURSES_CH_T wch = win->_line[y].text[x]; - RemAttr(wch, ~A_ALTCHARSET); + RemAttr(wch, (~(A_ALTCHARSET | A_CHARTEXT))); win->_line[y].text[x] = _nc_render(win, wch); } } @@ -130,7 +148,7 @@ wbkgrnd(WINDOW *win, const ARG_CH_T ch) } NCURSES_EXPORT(int) -wbkgd(WINDOW *win, const chtype ch) +wbkgd(WINDOW *win, chtype ch) { NCURSES_CH_T wch; SetChar2(wch, ch); diff --git a/contrib/ncurses/ncurses/base/lib_box.c b/contrib/ncurses/ncurses/base/lib_box.c index 7181edb..d6cfc6c 100644 --- a/contrib/ncurses/ncurses/base/lib_box.c +++ b/contrib/ncurses/ncurses/base/lib_box.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001,2002 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,8 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * + * and: Sven Verdoolaege 2001 * ****************************************************************************/ /* @@ -40,7 +42,21 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_box.c,v 1.18 2002/02/23 20:40:06 tom Exp $") +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, @@ -67,8 +83,6 @@ wborder(WINDOW *win, if (!win) returnCode(ERR); -#define RENDER_WITH_DEFAULT(ch,def) w ## ch = (ch == 0) ? def : ch - RENDER_WITH_DEFAULT(ls, ACS_VLINE); RENDER_WITH_DEFAULT(rs, ACS_VLINE); RENDER_WITH_DEFAULT(ts, ACS_HLINE); @@ -92,22 +106,22 @@ wborder(WINDOW *win, endy = win->_maxy; for (i = 0; i <= endx; i++) { - SetChar(win->_line[0].text[i], ChCharOf(wts), ChAttrOf(wts)); - SetChar(win->_line[endy].text[i], ChCharOf(wbs), ChAttrOf(wbs)); + 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++) { - SetChar(win->_line[i].text[0], ChCharOf(wls), ChAttrOf(wls)); - SetChar(win->_line[i].text[endx], ChCharOf(wrs), ChAttrOf(wrs)); + SetChar2(win->_line[i].text[0], wls); + SetChar2(win->_line[i].text[endx], wrs); win->_line[i].firstchar = 0; win->_line[i].lastchar = endx; } - SetChar(win->_line[0].text[0], ChCharOf(wtl), ChAttrOf(wtl)); - SetChar(win->_line[0].text[endx], ChCharOf(wtr), ChAttrOf(wtr)); - SetChar(win->_line[endy].text[0], ChCharOf(wbl), ChAttrOf(wbl)); - SetChar(win->_line[endy].text[endx], ChCharOf(wbr), ChAttrOf(wbr)); + 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/contrib/ncurses/ncurses/base/lib_chgat.c b/contrib/ncurses/ncurses/base/lib_chgat.c index 54e66ed..89eefa7 100644 --- a/contrib/ncurses/ncurses/base/lib_chgat.c +++ b/contrib/ncurses/ncurses/base/lib_chgat.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,8 @@ /**************************************************************************** * 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 * ****************************************************************************/ /* @@ -40,21 +42,25 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_chgat.c,v 1.5 2001/06/03 00:05:02 skimo Exp $") +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) +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(win->_line[win->_cury].text[i], attr); + 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 diff --git a/contrib/ncurses/ncurses/base/lib_clrbot.c b/contrib/ncurses/ncurses/base/lib_clrbot.c index bc12960..df196e8 100644 --- a/contrib/ncurses/ncurses/base/lib_clrbot.c +++ b/contrib/ncurses/ncurses/base/lib_clrbot.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -40,7 +40,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_clrbot.c,v 1.19 2001/12/19 01:05:59 tom Exp $") +MODULE_ID("$Id: lib_clrbot.c,v 1.20 2006/10/14 20:43:31 tom Exp $") NCURSES_EXPORT(int) wclrtobot(WINDOW *win) @@ -54,8 +54,8 @@ wclrtobot(WINDOW *win) NCURSES_SIZE_T startx = win->_curx; NCURSES_CH_T blank = win->_nc_bkgd; - T(("clearing from y = %d to y = %d with maxx = %d", - win->_cury, win->_maxy, win->_maxx)); + 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]); diff --git a/contrib/ncurses/ncurses/base/lib_color.c b/contrib/ncurses/ncurses/base/lib_color.c index 42d301d..a90ca9d 100644 --- a/contrib/ncurses/ncurses/base/lib_color.c +++ b/contrib/ncurses/ncurses/base/lib_color.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* lib_color.c @@ -41,7 +42,7 @@ #include <term.h> #include <tic.h> -MODULE_ID("$Id: lib_color.c,v 1.58 2001/09/01 21:42:59 tom Exp $") +MODULE_ID("$Id: lib_color.c,v 1.80 2006/11/26 01:33:16 tom Exp $") /* * These should be screen structure members. They need to be globals for @@ -51,6 +52,12 @@ MODULE_ID("$Id: lib_color.c,v 1.58 2001/09/01 21:42:59 tom Exp $") NCURSES_EXPORT_VAR(int) COLOR_PAIRS = 0; NCURSES_EXPORT_VAR(int) COLORS = 0; +#define DATA(r,g,b) {r,g,b, 0,0,0, 0} + +#define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts)) + +#define OkColorHi(n) (((n) < COLORS) && ((n) < max_colors)) + /* * 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. @@ -61,27 +68,27 @@ NCURSES_EXPORT_VAR(int) COLORS = 0; static const color_t cga_palette[] = { /* R G B */ - {RGB_OFF, RGB_OFF, RGB_OFF}, /* COLOR_BLACK */ - {RGB_ON, RGB_OFF, RGB_OFF}, /* COLOR_RED */ - {RGB_OFF, RGB_ON, RGB_OFF}, /* COLOR_GREEN */ - {RGB_ON, RGB_ON, RGB_OFF}, /* COLOR_YELLOW */ - {RGB_OFF, RGB_OFF, RGB_ON}, /* COLOR_BLUE */ - {RGB_ON, RGB_OFF, RGB_ON}, /* COLOR_MAGENTA */ - {RGB_OFF, RGB_ON, RGB_ON}, /* COLOR_CYAN */ - {RGB_ON, RGB_ON, RGB_ON}, /* COLOR_WHITE */ + 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 */ - { 0, 0, 0}, /* COLOR_BLACK */ - { 120, 50, 100}, /* COLOR_RED */ - { 240, 50, 100}, /* COLOR_GREEN */ - { 180, 50, 100}, /* COLOR_YELLOW */ - { 330, 50, 100}, /* COLOR_BLUE */ - { 60, 50, 100}, /* COLOR_MAGENTA */ - { 300, 50, 100}, /* COLOR_CYAN */ - { 0, 50, 100}, /* COLOR_WHITE */ + /* 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* */ @@ -128,10 +135,10 @@ set_background_color(int bg, int (*outc) (int)) { if (set_a_background) { TPUTS_TRACE("set_a_background"); - tputs(tparm(set_a_background, bg), 1, outc); + tputs(TPARM_1(set_a_background, bg), 1, outc); } else { TPUTS_TRACE("set_background"); - tputs(tparm(set_background, toggled_colors(bg)), 1, outc); + tputs(TPARM_1(set_background, toggled_colors(bg)), 1, outc); } } @@ -140,56 +147,19 @@ set_foreground_color(int fg, int (*outc) (int)) { if (set_a_foreground) { TPUTS_TRACE("set_a_foreground"); - tputs(tparm(set_a_foreground, fg), 1, outc); + tputs(TPARM_1(set_a_foreground, fg), 1, outc); } else { TPUTS_TRACE("set_foreground"); - tputs(tparm(set_foreground, toggled_colors(fg)), 1, outc); - } -} - -static bool -set_original_colors(void) -{ - if (orig_pair != 0) { - TPUTS_TRACE("orig_pair"); - putp(orig_pair); - return TRUE; - } else if (orig_colors != NULL) { - TPUTS_TRACE("orig_colors"); - putp(orig_colors); - return TRUE; + tputs(TPARM_1(set_foreground, toggled_colors(fg)), 1, outc); } - return FALSE; } -NCURSES_EXPORT(int) -start_color(void) +static void +init_color_table(void) { - int n; const color_t *tp; + int n; - T((T_CALLED("start_color()"))); - - if (set_original_colors() != TRUE) { - set_foreground_color(default_fg(), _nc_outch); - set_background_color(default_bg(), _nc_outch); - } - - if (VALID_NUMERIC(max_pairs)) - COLOR_PAIRS = SP->_pair_count = max_pairs; - else - returnCode(ERR); - if ((SP->_color_pairs = typeCalloc(unsigned short, max_pairs)) == 0) - returnCode(ERR); - SP->_color_pairs[0] = PAIR_OF(default_fg(), default_bg()); - if (VALID_NUMERIC(max_colors)) - COLORS = SP->_color_count = max_colors; - else - returnCode(ERR); - SP->_coloron = 1; - - if ((SP->_color_table = typeMalloc(color_t, COLORS)) == 0) - returnCode(ERR); tp = (hue_lightness_saturation) ? hls_palette : cga_palette; for (n = 0; n < COLORS; n++) { if (n < 8) { @@ -208,10 +178,91 @@ start_color(void) } } } +} - T(("started color: COLORS = %d, COLOR_PAIRS = %d", COLORS, COLOR_PAIRS)); +/* + * Reset the color pair, e.g., to whatever color pair 0 is. + */ +static bool +reset_color_pair(void) +{ + bool result = FALSE; - returnCode(OK); + 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) { + COLOR_PAIRS = SP->_pair_count = max_pairs; + COLORS = SP->_color_count = max_colors; + + 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> */ @@ -259,27 +310,27 @@ rgb2hls(short r, short g, short b, short *h, short *l, short *s) NCURSES_EXPORT(int) init_pair(short pair, short f, short b) { - unsigned result; + colorpair_t result; T((T_CALLED("init_pair(%d,%d,%d)"), pair, f, b)); - if ((pair < 0) || (pair >= COLOR_PAIRS)) + if ((pair < 0) || (pair >= COLOR_PAIRS) || SP == 0 || !SP->_coloron) returnCode(ERR); #if NCURSES_EXT_FUNCS if (SP->_default_color) { if (f < 0) - f = C_MASK; + f = COLOR_DEFAULT; if (b < 0) - b = C_MASK; - if (f >= COLORS && f != C_MASK) + b = COLOR_DEFAULT; + if (!OkColorHi(f) && !isDefaultColor(f)) returnCode(ERR); - if (b >= COLORS && b != C_MASK) + if (!OkColorHi(b) && !isDefaultColor(b)) returnCode(ERR); } else #endif { - if ((f < 0) || (f >= COLORS) - || (b < 0) || (b >= COLORS) + if ((f < 0) || !OkColorHi(f) + || (b < 0) || !OkColorHi(b) || (pair < 1)) returnCode(ERR); } @@ -293,13 +344,12 @@ init_pair(short pair, short f, short b) if (SP->_color_pairs[pair] != 0 && SP->_color_pairs[pair] != result) { int y, x; - attr_t z = COLOR_PAIR(pair); for (y = 0; y <= curscr->_maxy; y++) { struct ldat *ptr = &(curscr->_line[y]); bool changed = FALSE; for (x = 0; x <= curscr->_maxx; x++) { - if ((AttrOf(ptr->text[x]) & A_COLOR) == z) { + 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); @@ -312,8 +362,8 @@ init_pair(short pair, short f, short b) } } SP->_color_pairs[pair] = result; - if ((int) (SP->_current_attr & A_COLOR) == COLOR_PAIR(pair)) - SP->_current_attr |= A_COLOR; /* force attribute update */ + if (GET_SCREEN_PAIR(SP) == pair) + SET_SCREEN_PAIR(SP, (chtype) (~0)); /* force attribute update */ if (initialize_pair) { const color_t *tp = hue_lightness_saturation ? hls_palette : cga_palette; @@ -323,47 +373,53 @@ init_pair(short pair, short f, short b) tp[f].red, tp[f].green, tp[f].blue, tp[b].red, tp[b].green, tp[b].blue)); - if (initialize_pair) { - TPUTS_TRACE("initialize_pair"); - putp(tparm(initialize_pair, - 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) { - T((T_CALLED("init_color(%d,%d,%d,%d)"), color, r, g, b)); + int result = ERR; - if (initialize_color == NULL) - returnCode(ERR); - - if (color < 0 || color >= COLORS) - returnCode(ERR); - if (r < 0 || r > 1000 || g < 0 || g > 1000 || b < 0 || b > 1000) - returnCode(ERR); + T((T_CALLED("init_color(%d,%d,%d,%d)"), color, r, g, 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; - } + 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; + } - if (initialize_color) { TPUTS_TRACE("initialize_color"); - putp(tparm(initialize_color, color, r, g, b)); + putp(TPARM_4(initialize_color, color, r, g, b)); + SP->_color_defs = max(color + 1, SP->_color_defs); + result = OK; } - returnCode(OK); + returnCode(result); } NCURSES_EXPORT(bool) @@ -388,38 +444,65 @@ has_colors(void) NCURSES_EXPORT(int) color_content(short color, short *r, short *g, short *b) { - T((T_CALLED("color_content(%d,%p,%p,%p)"), color, r, g, b)); - if (color < 0 || color >= COLORS) - returnCode(ERR); + int result; - if (r) - *r = SP->_color_table[color].red; - if (g) - *g = SP->_color_table[color].green; - if (b) - *b = SP->_color_table[color].blue; - returnCode(OK); + 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; + + T(("...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)) - returnCode(ERR); - if (f) - *f = ((SP->_color_pairs[pair] >> C_SHIFT) & C_MASK); - if (b) - *b = (SP->_color_pairs[pair] & C_MASK); + 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); - returnCode(OK); +#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; + + T(("...pair_content(%d,%d,%d)", pair, fg, bg)); + result = OK; + } + returnCode(result); } NCURSES_EXPORT(void) -_nc_do_color(int old_pair, int pair, bool reverse, int (*outc) (int)) +_nc_do_color(short old_pair, short pair, bool reverse, int (*outc) (int)) { - NCURSES_COLOR_T fg = C_MASK, bg = C_MASK; + 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) { @@ -427,41 +510,46 @@ _nc_do_color(int old_pair, int pair, bool reverse, int (*outc) (int)) } else if (pair != 0) { if (set_color_pair) { TPUTS_TRACE("set_color_pair"); - tputs(tparm(set_color_pair, pair), 1, outc); + tputs(TPARM_1(set_color_pair, pair), 1, outc); return; } else if (SP != 0) { - pair_content(pair, &fg, &bg); + pair_content((short) pair, &fg, &bg); } } - if (old_pair >= 0 && SP != 0) { - pair_content(old_pair, &old_fg, &old_bg); - if ((fg == C_MASK && old_fg != C_MASK) - || (bg == C_MASK && old_bg != C_MASK)) { + 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 && old_bg == C_MASK && old_fg != C_MASK) { + if (SP->_has_sgr_39_49 + && isDefaultColor(old_bg) + && !isDefaultColor(old_fg)) { tputs("\033[39m", 1, outc); - } else if (SP->_has_sgr_39_49 && old_fg == C_MASK && old_bg != C_MASK) { + } else if (SP->_has_sgr_39_49 + && isDefaultColor(old_fg) + && !isDefaultColor(old_bg)) { tputs("\033[49m", 1, outc); } else #endif - set_original_colors(); + reset_color_pair(); } } else { - set_original_colors(); + reset_color_pair(); if (old_pair < 0) return; } #if NCURSES_EXT_FUNCS - if (fg == C_MASK) + if (isDefaultColor(fg)) fg = default_fg(); - if (bg == C_MASK) + if (isDefaultColor(bg)) bg = default_bg(); #endif @@ -474,10 +562,10 @@ _nc_do_color(int old_pair, int pair, bool reverse, int (*outc) (int)) TR(TRACE_ATTRS, ("setting colors: pair = %d, fg = %d, bg = %d", pair, fg, bg)); - if (fg != C_MASK) { + if (!isDefaultColor(fg)) { set_foreground_color(fg, outc); } - if (bg != C_MASK) { + if (!isDefaultColor(bg)) { set_background_color(bg, outc); } } diff --git a/contrib/ncurses/ncurses/base/lib_colorset.c b/contrib/ncurses/ncurses/base/lib_colorset.c index b496c78..a973c53 100644 --- a/contrib/ncurses/ncurses/base/lib_colorset.c +++ b/contrib/ncurses/ncurses/base/lib_colorset.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * 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 * @@ -27,7 +27,8 @@ ****************************************************************************/ /**************************************************************************** - * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1998 * + * Author: Juergen Pfeifer, 1998 * + * and: Thomas E. Dickey, 2005 * ****************************************************************************/ /* @@ -40,19 +41,19 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$Id: lib_colorset.c,v 1.7 2000/12/10 01:24:50 tom Exp $") +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) +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) PAIR_NUMBER(win->_attrs))); - toggle_attr_on(win->_attrs, COLOR_PAIR(color_pair_number)); + 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/contrib/ncurses/ncurses/base/lib_dft_fgbg.c b/contrib/ncurses/ncurses/base/lib_dft_fgbg.c index 24705c9..8953c14 100644 --- a/contrib/ncurses/ncurses/base/lib_dft_fgbg.c +++ b/contrib/ncurses/ncurses/base/lib_dft_fgbg.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * 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 * @@ -27,13 +27,13 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1997,1999 * + * Author: Thomas E. Dickey * ****************************************************************************/ #include <curses.priv.h> #include <term.h> -MODULE_ID("$Id: lib_dft_fgbg.c,v 1.15 2000/12/10 02:43:27 tom Exp $") +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 @@ -43,7 +43,7 @@ NCURSES_EXPORT(int) use_default_colors(void) { T((T_CALLED("use_default_colors()"))); - returnCode(assume_default_colors(C_MASK, C_MASK)); + returnCode(assume_default_colors(-1, -1)); } /* @@ -61,11 +61,15 @@ assume_default_colors(int fg, int bg) if (initialize_pair) /* don't know how to handle this */ returnCode(ERR); - SP->_default_color = (fg < 0 || fg == C_MASK) || (bg < 0 || bg == C_MASK); + SP->_default_color = isDefaultColor(fg) || isDefaultColor(bg); SP->_has_sgr_39_49 = (tigetflag("AX") == TRUE); - SP->_default_fg = (fg >= 0) ? (fg & C_MASK) : C_MASK; - SP->_default_bg = (bg >= 0) ? (bg & C_MASK) : C_MASK; - if (SP->_color_pairs != 0) - init_pair(0, fg, bg); + 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/contrib/ncurses/ncurses/base/lib_erase.c b/contrib/ncurses/ncurses/base/lib_erase.c index 5e39731..2566e8b 100644 --- a/contrib/ncurses/ncurses/base/lib_erase.c +++ b/contrib/ncurses/ncurses/base/lib_erase.c @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -40,7 +41,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_erase.c,v 1.15 2001/12/19 01:06:13 tom Exp $") +MODULE_ID("$Id: lib_erase.c,v 1.16 2005/10/30 00:36:36 tom Exp $") NCURSES_EXPORT(int) werase(WINDOW *win) @@ -58,6 +59,24 @@ werase(WINDOW *win) 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; diff --git a/contrib/ncurses/ncurses/base/lib_freeall.c b/contrib/ncurses/ncurses/base/lib_freeall.c index 2063c6f..27897a9 100644 --- a/contrib/ncurses/ncurses/base/lib_freeall.c +++ b/contrib/ncurses/ncurses/base/lib_freeall.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * 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 * @@ -27,11 +27,12 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 * + * Author: Thomas E. Dickey 1996,1997 * ****************************************************************************/ #include <curses.priv.h> #include <term_entry.h> +#include <tic.h> #if HAVE_NC_FREEALL @@ -39,31 +40,7 @@ extern int malloc_errfd; /* FIXME */ #endif -MODULE_ID("$Id: lib_freeall.c,v 1.19 2001/09/15 21:32:48 tom Exp $") - -static void -free_slk(SLK * p) -{ - if (p != 0) { - FreeIfNeeded(p->ent); - FreeIfNeeded(p->buffer); - free(p); - } -} - -static void -free_tries(struct tries *p) -{ - struct tries *q; - - while (p != 0) { - q = p->sibling; - if (p->child != 0) - free_tries(p->child); - free(p); - p = q; - } -} +MODULE_ID("$Id: lib_freeall.c,v 1.38 2006/12/02 22:36:43 tom Exp $") /* * Free all ncurses data. This is used for testing only (there's no practical @@ -73,9 +50,15 @@ NCURSES_EXPORT(void) _nc_freeall(void) { WINDOWLIST *p, *q; + char *s; + static va_list empty_va; + T((T_CALLED("_nc_freeall()"))); #if NO_LEAKS _nc_free_tparm(); + if (_nc_oldnums != 0) { + FreeAndNull(_nc_oldnums); + } #endif if (SP != 0) { while (_nc_windows != 0) { @@ -98,39 +81,57 @@ _nc_freeall(void) } } } - - free_tries(SP->_keytry); - free_tries(SP->_key_ok); - free_slk(SP->_slk); - FreeIfNeeded(SP->_color_pairs); - FreeIfNeeded(SP->_color_table); - FreeIfNeeded(SP->oldhash); - FreeIfNeeded(SP->newhash); - FreeIfNeeded(SP->hashtab); -#if !BROKEN_LINKER - FreeAndNull(SP); -#endif + delscreen(SP); } +#if NO_LEAKS + _nc_tgetent_leaks(); +#endif + del_curterm(cur_term); + _nc_free_entries(_nc_head); + _nc_get_type(0); + _nc_first_name(0); +#if USE_WIDEC_SUPPORT + FreeIfNeeded(_nc_wacs); +#endif +#if NO_LEAKS + _nc_alloc_entry_leaks(); + _nc_captoinfo_leaks(); + _nc_comp_scan_leaks(); + _nc_keyname_leaks(); + _nc_tic_expand(0, FALSE, 0); +#endif - if (cur_term != 0) { - _nc_free_termtype(&(cur_term->type)); - free(cur_term); - } + if ((s = _nc_home_terminfo()) != 0) + free(s); + + (void) _nc_printf_string(0, empty_va); #ifdef TRACE (void) _nc_trace_buf(-1, 0); #endif + #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); } diff --git a/contrib/ncurses/ncurses/base/lib_getch.c b/contrib/ncurses/ncurses/base/lib_getch.c index af1be33..7891edf 100644 --- a/contrib/ncurses/ncurses/base/lib_getch.c +++ b/contrib/ncurses/ncurses/base/lib_getch.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -40,14 +41,46 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_getch.c,v 1.61 2002/06/16 00:31:57 tom Exp $") +MODULE_ID("$Id: lib_getch.c,v 1.75 2006/03/04 20:06:09 tom Exp $") #include <fifo_defs.h> NCURSES_EXPORT_VAR(int) ESCDELAY = 1000; /* max interval betw. chars in funkeys, in millisecs */ -static inline int +#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(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(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(void) { int ch = SP->_fifo[peek]; @@ -57,7 +90,7 @@ fifo_peek(void) return ch; } -static inline int +static NCURSES_INLINE int fifo_pull(void) { int ch; @@ -77,12 +110,14 @@ fifo_pull(void) return ch; } -static inline int -fifo_push(void) +static NCURSES_INLINE int +fifo_push(EVENTLIST_0th(_nc_eventlist * evl)) { int n; - int ch; + int ch = 0; + int mask = 0; + (void) mask; if (tail == -1) return ERR; @@ -91,15 +126,48 @@ fifo_push(void) errno = 0; #endif -#if USE_GPM_SUPPORT || defined(USE_EMX_MOUSE) - if ((SP->_mouse_fd >= 0) - && (_nc_timed_wait(3, -1, (int *) 0) & 2)) { +#ifdef NCURSES_WGETCH_EVENTS + if (evl +#if USE_GPM_SUPPORT || USE_EMX_MOUSE || USE_SYSMOUSE + || (SP->_mouse_fd >= 0) +#endif + ) { + mask = check_mouse_activity(-1 EVENTLIST_2nd(evl)); + } else + mask = 0; + + if (mask & 4) { + T(("fifo_push: ungetch KEY_EVENT")); + ungetch(KEY_EVENT); + return KEY_EVENT; + } +#elif USE_GPM_SUPPORT || USE_EMX_MOUSE || USE_SYSMOUSE + if (SP->_mouse_fd >= 0) { + mask = check_mouse_activity(-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; @@ -138,7 +206,7 @@ fifo_push(void) return ch; } -static inline void +static NCURSES_INLINE void fifo_clear(void) { memset(SP->_fifo, 0, sizeof(SP->_fifo)); @@ -146,21 +214,27 @@ fifo_clear(void) tail = peek = 0; } -static int kgetch(void); +static int kgetch(EVENTLIST_0th(_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) +_nc_wgetch(WINDOW *win, + unsigned long *result, + int use_meta + EVENTLIST_2nd(_nc_eventlist * evl)) { int ch; +#ifdef NCURSES_WGETCH_EVENTS + long event_delay = -1; +#endif - T((T_CALLED("wgetch(%p)"), win)); + T((T_CALLED("_nc_wgetch(%p)"), win)); *result = 0; - if (!win) + if (win == 0 || SP == 0) returnCode(ERR); if (cooked_key_in_fifo()) { @@ -170,24 +244,47 @@ _nc_wgetch(WINDOW *win, unsigned long *result, int use_meta) *result = fifo_pull(); returnCode(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->_raw && !SP->_cbreak) { + if (head == -1 && + !SP->_notty && + !SP->_raw && + !SP->_cbreak && + !SP->_called_wgetch) { char buf[MAXCOLUMNS], *sp; + int rc; TR(TRACE_IEVENT, ("filling queue in cooked mode")); - wgetnstr(win, buf, MAXCOLUMNS); + SP->_called_wgetch = TRUE; + rc = wgetnstr(win, buf, MAXCOLUMNS); + SP->_called_wgetch = FALSE; /* ungetch in reverse order */ - ungetch('\n'); +#ifdef NCURSES_WGETCH_EVENTS + if (rc != KEY_EVENT) +#endif + ungetch('\n'); for (sp = buf + strlen(buf); sp > buf; sp--) ungetch(sp[-1]); +#ifdef NCURSES_WGETCH_EVENTS + /* Return it first */ + if (rc == KEY_EVENT) { + *result = rc; + returnCode(OK); + } +#endif + *result = fifo_pull(); returnCode(OK); } @@ -199,19 +296,34 @@ _nc_wgetch(WINDOW *win, unsigned long *result, int use_meta) wrefresh(win); if (!win->_notimeout && (win->_delay >= 0 || SP->_cbreak > 1)) { - int delay; + 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, ("timed delay in wgetch()")); - if (SP->_cbreak > 1) - delay = (SP->_cbreak - 1) * 100; - else - delay = win->_delay; + TR(TRACE_IEVENT, ("delay is %d milliseconds", delay)); - TR(TRACE_IEVENT, ("delay is %d milliseconds", delay)); + rc = check_mouse_activity(delay EVENTLIST_2nd(evl)); - if (head == -1) /* fifo is empty */ - if (!_nc_timed_wait(3, delay, (int *) 0)) +#ifdef NCURSES_WGETCH_EVENTS + if (rc & 4) { + *result = KEY_EVENT; + returnCode(OK); + } +#endif + if (!rc) returnCode(ERR); + } /* else go on to read data available */ } @@ -228,9 +340,10 @@ _nc_wgetch(WINDOW *win, unsigned long *result, int use_meta) * increase the wait with mouseinterval(). */ int runcount = 0; + int rc; do { - ch = kgetch(); + ch = kgetch(EVENTLIST_1st(evl)); if (ch == KEY_MOUSE) { ++runcount; if (SP->_mouse_inline(SP)) @@ -240,16 +353,32 @@ _nc_wgetch(WINDOW *win, unsigned long *result, int use_meta) break; } while (ch == KEY_MOUSE - && (_nc_timed_wait(3, SP->_maxclick, (int *) 0) + && (((rc = check_mouse_activity(SP->_maxclick + EVENTLIST_2nd(evl))) != 0 + && !(rc & 4)) || !SP->_mouse_parse(runcount))); - if (runcount > 0 && ch != KEY_MOUSE) { - /* mouse event sequence ended by keystroke, push it */ +#ifdef NCURSES_WGETCH_EVENTS + if ((rc & 4) && !ch == KEY_EVENT) { ungetch(ch); - ch = KEY_MOUSE; + 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) { + ungetch(KEY_MOUSE); /* FIXME This interrupts a gesture... */ + } else +#endif + { + /* mouse event sequence ended by keystroke, store keystroke */ + ungetch(ch); + ch = KEY_MOUSE; + } } } else { if (head == -1) - fifo_push(); + fifo_push(EVENTLIST_1st(evl)); ch = fifo_pull(); } @@ -312,6 +441,24 @@ _nc_wgetch(WINDOW *win, unsigned long *result, int use_meta) returnCode(ch >= KEY_MIN ? KEY_CODE_YES : OK); } +#ifdef NCURSES_WGETCH_EVENTS +NCURSES_EXPORT(int) +wgetch_events(WINDOW *win, _nc_eventlist * evl) +{ + int code; + unsigned long value; + + T((T_CALLED("wgetch_events(%p,%p)"), win, evl)); + code = _nc_wgetch(win, + &value, + SP->_use_meta + EVENTLIST_2nd(evl)); + if (code != ERR) + code = value; + returnCode(code); +} +#endif + NCURSES_EXPORT(int) wgetch(WINDOW *win) { @@ -319,7 +466,10 @@ wgetch(WINDOW *win) unsigned long value; T((T_CALLED("wgetch(%p)"), win)); - code = _nc_wgetch(win, &value, SP->_use_meta); + code = _nc_wgetch(win, + &value, + (SP ? SP->_use_meta : 0) + EVENTLIST_2nd((_nc_eventlist *) 0)); if (code != ERR) code = value; returnCode(code); @@ -341,7 +491,7 @@ wgetch(WINDOW *win) */ static int -kgetch(void) +kgetch(EVENTLIST_0th(_nc_eventlist * evl)) { struct tries *ptr; int ch = 0; @@ -352,14 +502,28 @@ kgetch(void) ptr = SP->_keytry; for (;;) { - if (!raw_key_in_fifo()) { - if (fifo_push() == ERR) { + if (cooked_key_in_fifo() && SP->_fifo[head] >= KEY_MIN) { + break; + } else if (!raw_key_in_fifo()) { + ch = fifo_push(EVENTLIST_1st(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(); /* Remove KEY_EVENT from the queue */ + } +#endif } + ch = fifo_peek(); 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 */ @@ -389,8 +553,19 @@ kgetch(void) ptr = ptr->child; if (!raw_key_in_fifo()) { + int rc; + TR(TRACE_IEVENT, ("waiting for rest of sequence")); - if (!_nc_timed_wait(3, timeleft, &timeleft)) { + rc = check_mouse_activity(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; } diff --git a/contrib/ncurses/ncurses/base/lib_getstr.c b/contrib/ncurses/ncurses/base/lib_getstr.c index cd58f18..274e878 100644 --- a/contrib/ncurses/ncurses/base/lib_getstr.c +++ b/contrib/ncurses/ncurses/base/lib_getstr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * 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 * @@ -41,7 +41,7 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("$Id: lib_getstr.c,v 1.23 2000/12/10 02:43:27 tom Exp $") +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 @@ -70,7 +70,10 @@ WipeOut(WINDOW *win, int y, int x, char *first, char *last, bool echoed) } NCURSES_EXPORT(int) -wgetnstr(WINDOW *win, char *str, int maxlen) +wgetnstr_events(WINDOW *win, + char *str, + int maxlen, + EVENTLIST_1st(_nc_eventlist * evl)) { TTY buf; bool oldnl, oldecho, oldraw, oldcbreak; @@ -105,7 +108,7 @@ wgetnstr(WINDOW *win, char *str, int maxlen) if (is_wintouched(win) || (win->_flags & _HASMOVED)) wrefresh(win); - while ((ch = wgetch(win)) != ERR) { + 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 @@ -122,6 +125,14 @@ wgetnstr(WINDOW *win, char *str, int maxlen) 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); @@ -185,9 +196,29 @@ wgetnstr(WINDOW *win, char *str, int maxlen) *str = '\0'; if (ch == ERR) - returnCode(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/contrib/ncurses/ncurses/base/lib_hline.c b/contrib/ncurses/ncurses/base/lib_hline.c index 2cb6cc5..2ef2cc5 100644 --- a/contrib/ncurses/ncurses/base/lib_hline.c +++ b/contrib/ncurses/ncurses/base/lib_hline.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -40,7 +40,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_hline.c,v 1.10 2001/06/03 00:39:24 skimo Exp $") +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) @@ -63,9 +63,9 @@ whline(WINDOW *win, chtype ch, int n) CHANGED_RANGE(line, start, end); if (ch == 0) - SetChar(wch, ChCharOf(ACS_HLINE), ChAttrOf(ACS_HLINE)); + SetChar2(wch, ACS_HLINE); else - SetChar(wch, ChCharOf(ch), ChAttrOf(ch)); + SetChar2(wch, ch); wch = _nc_render(win, wch); while (end >= start) { diff --git a/contrib/ncurses/ncurses/base/lib_initscr.c b/contrib/ncurses/ncurses/base/lib_initscr.c index 832da74..d2ae281 100644 --- a/contrib/ncurses/ncurses/base/lib_initscr.c +++ b/contrib/ncurses/ncurses/base/lib_initscr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-2003 * ****************************************************************************/ /* @@ -39,27 +40,20 @@ */ #include <curses.priv.h> -#include <tic.h> /* for MAX_ALIAS */ #if HAVE_SYS_TERMIO_H #include <sys/termio.h> /* needed for ISC */ #endif -MODULE_ID("$Id: lib_initscr.c,v 1.29 2001/08/26 01:05:05 tom Exp $") +MODULE_ID("$Id: lib_initscr.c,v 1.34 2005/10/22 20:30:38 tom Exp $") NCURSES_EXPORT(WINDOW *) initscr(void) { static bool initialized = FALSE; NCURSES_CONST char *name; - int value; -#ifdef TRACE - int t = _nc_getenv_num("NCURSES_TRACE"); - - if (t >= 0) - trace(t); -#endif + START_TRACE(); T((T_CALLED("initscr()"))); /* Portable applications must not call initscr() more than once */ if (!initialized) { @@ -68,16 +62,28 @@ initscr(void) 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); } - /* allow user to set maximum escape delay from the environment */ - if ((value = _nc_getenv_num("ESCDELAY")) >= 0) { - ESCDELAY = value; - } - /* def_shell_mode - done in newterm/_nc_setupscreen */ def_prog_mode(); } diff --git a/contrib/ncurses/ncurses/base/lib_insch.c b/contrib/ncurses/ncurses/base/lib_insch.c index c3671e5..b8a856d 100644 --- a/contrib/ncurses/ncurses/base/lib_insch.c +++ b/contrib/ncurses/ncurses/base/lib_insch.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,8 @@ /**************************************************************************** * 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 * ****************************************************************************/ /* @@ -39,30 +41,99 @@ */ #include <curses.priv.h> +#include <ctype.h> -MODULE_ID("$Id: lib_insch.c,v 1.15 2001/06/09 23:47:38 skimo Exp $") +MODULE_ID("$Id: lib_insch.c,v 1.24 2005/02/26 19:27:28 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') { + if ((code = _nc_insert_ch(win, ChAttrOf(ch) | UChar(*s))) != OK) + break; + ++s; + } + } +#if USE_WIDEC_SUPPORT + else { + /* + * Handle multibyte characters here + */ + SetChar2(wch, ch); + wch = _nc_render(win, wch); + if (_nc_build_wch(win, &wch) >= 0) + code = wins_wch(win, &wch); + } +#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) { - 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; - NCURSES_CH_T wch; - SetChar2(wch, c); + if (win != 0) { + oy = win->_cury; + ox = win->_curx; - CHANGED_TO_EOL(line, win->_curx, win->_maxx); - while (temp1 > end) - *temp1-- = *temp2--; + code = _nc_insert_ch(win, c); - *temp1 = _nc_render(win, wch); - code = OK; + win->_curx = ox; + win->_cury = oy; + _nc_synchook(win); } returnCode(code); } diff --git a/contrib/ncurses/ncurses/base/lib_insdel.c b/contrib/ncurses/ncurses/base/lib_insdel.c index 432bcac..342c654 100644 --- a/contrib/ncurses/ncurses/base/lib_insdel.c +++ b/contrib/ncurses/ncurses/base/lib_insdel.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -42,14 +42,14 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_insdel.c,v 1.11 2001/12/19 01:10:49 tom Exp $") +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("winsdel(%p,%d)"), win, n)); + T((T_CALLED("winsdelln(%p,%d)"), win, n)); if (win) { if (n != 0) { diff --git a/contrib/ncurses/ncurses/base/lib_insnstr.c b/contrib/ncurses/ncurses/base/lib_insnstr.c new file mode 100644 index 0000000..b6ddfde --- /dev/null +++ b/contrib/ncurses/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/contrib/ncurses/ncurses/base/lib_instr.c b/contrib/ncurses/ncurses/base/lib_instr.c index 3eaf989..809952f 100644 --- a/contrib/ncurses/ncurses/base/lib_instr.c +++ b/contrib/ncurses/ncurses/base/lib_instr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -40,7 +41,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_instr.c,v 1.11 2001/06/02 23:42:06 skimo Exp $") +MODULE_ID("$Id: lib_instr.c,v 1.15 2005/11/20 01:38:03 tom Exp $") NCURSES_EXPORT(int) winnstr(WINDOW *win, char *str, int n) @@ -59,7 +60,47 @@ winnstr(WINDOW *win, char *str, int n) n = win->_maxx - win->_curx + 1; for (; i < n;) { - str[i++] = CharOf(win->_line[row].text[col]); +#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) { col = 0; if (++row > win->_maxy) @@ -68,5 +109,6 @@ winnstr(WINDOW *win, char *str, int n) } } str[i] = '\0'; /* SVr4 does not seem to count the null */ + T(("winnstr returns %s", _nc_visbuf(str))); returnCode(i); } diff --git a/contrib/ncurses/ncurses/base/lib_mouse.c b/contrib/ncurses/ncurses/base/lib_mouse.c index 69af58d..f302327 100644 --- a/contrib/ncurses/ncurses/base/lib_mouse.c +++ b/contrib/ncurses/ncurses/base/lib_mouse.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000,2002 Free Software Foundation, Inc. * + * 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 * @@ -29,14 +29,18 @@ /**************************************************************************** * 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 first method used is xterm's internal mouse-tracking facility. - * The second is Alessandro Rubini's GPM server. + * 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: * @@ -74,36 +78,81 @@ #endif #include <curses.priv.h> + +MODULE_ID("$Id: lib_mouse.c,v 1.85 2006/11/25 22:30:28 tom Exp $") + #include <term.h> +#include <tic.h> #if USE_GPM_SUPPORT -#ifndef LINT /* don't need this for llib-lncurses */ -#undef buttons /* term.h defines this, and gpm uses it! */ -#include <gpm.h> #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 - -MODULE_ID("$Id: lib_mouse.c,v 1.58 2002/01/12 22:38:07 tom Exp $") +#endif /* use_SYSMOUSE */ #define MY_TRACE TRACE_ICALLS|TRACE_IEVENT -#define INVALID_EVENT -1 +#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 -static int mousetype; -#define M_XTERM -1 /* use xterm's mouse tracking? */ -#define M_NONE 0 /* no mouse device */ -#define M_GPM 1 /* use GPM */ -#define M_QNX 2 /* QNX mouse on console */ -#define M_QNX_TERM 3 /* QNX mouse on pterm/xterm (using qansi-m) */ +#define INVALID_EVENT -1 +#define NORMAL_EVENT 0 #if USE_GPM_SUPPORT -#ifndef LINT -static Gpm_Connect gpm_connect; -#endif + +#ifndef LIBGPM_SONAME +#define LIBGPM_SONAME "libgpm.so" #endif -static mmask_t eventmask; /* current event mask */ +#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 *); @@ -111,14 +160,15 @@ static void _nc_mouse_wrap(SCREEN *); /* maintain a circular list of mouse events */ -/* The definition of the circular list size (EV_MAX), is in curses.priv.h, so - * wgetch() may refer to the size and call _nc_mouse_parse() before circular - * list overflow. - */ -static MEVENT events[EV_MAX]; /* hold the last mouse event seen */ -static MEVENT *eventp = events; /* next free slot in event queue */ -#define NEXT(ep) ((ep == events + EV_MAX - 1) ? events : ep + 1) -#define PREV(ep) ((ep == events) ? events + EV_MAX - 1 : ep - 1) +#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 @@ -128,24 +178,18 @@ _trace_slot(const char *tag) _tracef(tag); - for (ep = events; ep < events + EV_MAX; ep++) + for (ep = SP->_mouse_events; ep < SP->_mouse_events + EV_MAX; ep++) _tracef("mouse event queue slot %ld = %s", - (long) (ep - events), + (long) (ep - SP->_mouse_events), _tracemouse(ep)); } #endif -#ifdef USE_EMX_MOUSE +#if USE_EMX_MOUSE # define TOP_ROW 0 # define LEFT_COL 0 -static int mouse_wfd; -static int mouse_thread; -static int mouse_activated; -static char mouse_buttons[] = -{0, 1, 3, 2}; - # define M_FD(sp) sp->_mouse_fd static void @@ -158,7 +202,7 @@ write_event(int down, int button, int x, int y) buf[3] = ' ' + (button - 1) + (down ? 0 : 0x40); buf[4] = ' ' + x - LEFT_COL + 1; buf[5] = ' ' + y - TOP_ROW + 1; - DosWrite(mouse_wfd, buf, 6, &ignore); + DosWrite(SP->_emxmouse_wfd, buf, 6, &ignore); } static void @@ -190,7 +234,7 @@ mouse_server(unsigned long ignored GCC_UNUSED) sprintf(err, "Error reading mouse queue, rc=%lu.\r\n", rc); break; } - if (!mouse_activated) + if (!SP->_emxmouse_activated) goto finish; /* @@ -202,13 +246,13 @@ mouse_server(unsigned long ignored GCC_UNUSED) */ if ((mouev.fs ^ oldstate) & MOUSE_BN1_DOWN) write_event(mouev.fs & MOUSE_BN1_DOWN, - mouse_buttons[1], mouev.col, mouev.row); + SP->_emxmouse_buttons[1], mouev.col, mouev.row); if ((mouev.fs ^ oldstate) & MOUSE_BN2_DOWN) write_event(mouev.fs & MOUSE_BN2_DOWN, - mouse_buttons[3], mouev.col, mouev.row); + SP->_emxmouse_buttons[3], mouev.col, mouev.row); if ((mouev.fs ^ oldstate) & MOUSE_BN3_DOWN) write_event(mouev.fs & MOUSE_BN3_DOWN, - mouse_buttons[2], mouev.col, mouev.row); + SP->_emxmouse_buttons[2], mouev.col, mouev.row); finish: oldstate = mouev.fs; @@ -223,185 +267,455 @@ mouse_server(unsigned long ignored GCC_UNUSED) 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 -server_state(const int state) -{ /* It would be nice to implement pointer-off and stop looping... */ - mouse_activated = state; +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 int initialized; +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 */ static void initialize_mousetype(void) { static const char *xterm_kmous = "\033[M"; + T((T_CALLED("initialize_mousetype()"))); + /* Try gpm first, because gpm may be configured to run in xterm */ #if USE_GPM_SUPPORT - /* GPM: initialize connection to gpm server */ - gpm_connect.eventMask = GPM_DOWN | GPM_UP; - gpm_connect.defaultMask = ~(gpm_connect.eventMask | GPM_HARD); - gpm_connect.minMod = 0; - gpm_connect.maxMod = ~((1 << KG_SHIFT) | (1 << KG_SHIFTL) | (1 << KG_SHIFTR)); - if (Gpm_Open(&gpm_connect, 0) >= 0) { /* returns the file-descriptor */ - mousetype = M_GPM; - SP->_mouse_fd = gpm_fd; - return; - } + 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 */ -#ifdef USE_EMX_MOUSE - if (!mouse_thread +#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"); - return; + returnVoid; } else { int rc; - if (!mouse_buttons[0]) { + if (!SP->_emxmouse_buttons[0]) { char *s = getenv("MOUSE_BUTTONS_123"); - mouse_buttons[0] = 1; + SP->_emxmouse_buttons[0] = 1; if (s && strlen(s) >= 3) { - mouse_buttons[1] = s[0] - '0'; - mouse_buttons[2] = s[1] - '0'; - mouse_buttons[3] = s[2] - '0'; + 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; } } - mouse_wfd = handles[1]; + 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 *) &mouse_thread, + rc = DosCreateThread((unsigned long *) &SP->_emxmouse_thread, mouse_server, 0, 0, 8192); if (rc) { printf("mouse thread error %d=%#x", rc, rc); - return; } else { - mousetype = M_XTERM; - return; + SP->_mouse_type = M_XTERM; } + returnVoid; } } -#endif +#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)) { - mousetype = M_XTERM; - return; + 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) { (void) _nc_add_to_try(&(SP->_keytry), xterm_kmous, KEY_MOUSE); - mousetype = M_XTERM; - return; + init_xterm_mouse(); } + returnVoid; } -static void +static bool _nc_mouse_init(void) /* initialize the mouse */ { + bool result = FALSE; int i; - if (!initialized) { - initialized = TRUE; + if (SP != 0) { + if (!SP->_mouse_initialized) { + SP->_mouse_initialized = TRUE; - TR(MY_TRACE, ("_nc_mouse_init() called")); + TR(MY_TRACE, ("_nc_mouse_init() called")); - for (i = 0; i < EV_MAX; i++) - events[i].id = INVALID_EVENT; + SP->_mouse_eventp = SP->_mouse_events; + for (i = 0; i < EV_MAX; i++) + SP->_mouse_events[i].id = INVALID_EVENT; - initialize_mousetype(); + initialize_mousetype(); - T(("_nc_mouse_init() set mousetype to %d", 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) -/* query to see if there is a pending mouse event */ +_nc_mouse_event(SCREEN *sp GCC_UNUSED) { -#if USE_GPM_SUPPORT - /* GPM: query server for event, return TRUE if we find one */ - Gpm_Event ev; + MEVENT *eventp = SP->_mouse_eventp; + bool result = FALSE; - if (gpm_fd >= 0 - && (_nc_timed_wait(3, 0, (int *) 0) & 2) != 0 - && Gpm_GetEvent(&ev) == 1) { - eventp->id = 0; /* there's only one mouse... */ + (void) eventp; - 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; + 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; - eventp->x = ev.x - 1; - eventp->y = ev.y - 1; - eventp->z = 0; +#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; + } - /* bump the next-free pointer into the circular list */ - eventp = NEXT(eventp); - return (TRUE); - } + 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 -#ifdef USE_EMX_MOUSE - if (SP->_mouse_fd >= 0 - && (_nc_timed_wait(3, 0, (int *) 0) & 2) != 0) { - 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]); +#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; } - return TRUE; + break; +#endif /* USE_SYSMOUSE */ + + case M_NONE: + break; } -#endif /* USE_EMX_MOUSE */ - /* xterm: never have to query, mouse events are in the keyboard stream */ - return (FALSE); /* no event waiting */ + return result; /* true if we found an event */ } static bool -_nc_mouse_inline(SCREEN * sp) +_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 (mousetype == M_XTERM) { + if (SP->_mouse_type == M_XTERM) { unsigned char kbuf[4]; - MEVENT *prev; + mmask_t prev; size_t grabbed; int res; @@ -432,13 +746,15 @@ _nc_mouse_inline(SCREEN * sp) * (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. It always does under Linux but often - * fails to under Solaris. + * 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. */ -#ifdef USE_EMX_MOUSE +#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); @@ -451,59 +767,71 @@ _nc_mouse_inline(SCREEN * sp) TR(TRACE_IEVENT, ("_nc_mouse_inline sees the following xterm data: '%s'", kbuf)); - eventp->id = 0; /* there's only one mouse... */ + /* 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: - eventp->bstate = BUTTON1_PRESSED; -#ifdef USE_EMX_MOUSE - if (kbuf[0] & 0x40) - eventp->bstate = BUTTON1_RELEASED; -#endif + if (kbuf[0] & 64) + eventp->bstate = MASK_PRESS(4); + else + PRESS_POSITION(1); break; case 0x1: - eventp->bstate = BUTTON2_PRESSED; -#ifdef USE_EMX_MOUSE - if (kbuf[0] & 0x40) - eventp->bstate = BUTTON2_RELEASED; +#if NCURSES_MOUSE_VERSION == 2 + if (kbuf[0] & 64) + eventp->bstate = MASK_PRESS(5); + else #endif + PRESS_POSITION(2); break; case 0x2: - eventp->bstate = BUTTON3_PRESSED; -#ifdef USE_EMX_MOUSE - if (kbuf[0] & 0x40) - eventp->bstate = BUTTON3_RELEASED; -#endif + PRESS_POSITION(3); break; case 0x3: /* - * Release events aren't reported for individual buttons, - * just for the button set as a whole... + * 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. */ - eventp->bstate = - (BUTTON1_RELEASED | - BUTTON2_RELEASED | - BUTTON3_RELEASED); - /* - * ...however, because there are no kinds of mouse events under - * xterm that can intervene between press and release, we can - * deduce which buttons were actually released by looking at the - * previous event. - */ - prev = PREV(eventp); - if (!(prev->bstate & BUTTON1_PRESSED)) - eventp->bstate &= ~BUTTON1_RELEASED; - if (!(prev->bstate & BUTTON2_PRESSED)) - eventp->bstate &= ~BUTTON2_RELEASED; - if (!(prev->bstate & BUTTON3_PRESSED)) - eventp->bstate &= ~BUTTON3_RELEASED; + 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; @@ -520,45 +848,53 @@ _nc_mouse_inline(SCREEN * sp) TR(MY_TRACE, ("_nc_mouse_inline: primitive mouse-event %s has slot %ld", _tracemouse(eventp), - (long) (eventp - events))); + (long) (eventp - SP->_mouse_events))); /* bump the next-free pointer into the circular list */ - eventp = NEXT(eventp); + SP->_mouse_eventp = NEXT(eventp); #if 0 /* this return would be needed for QNX's mods to lib_getch.c */ return (TRUE); #endif } - return (FALSE); + return (result); } static void mouse_activate(bool on) { - if (!on && !initialized) + if (!on && !SP->_mouse_initialized) return; - _nc_mouse_init(); + if (!_nc_mouse_init()) + return; if (on) { - switch (mousetype) { + switch (SP->_mouse_type) { case M_XTERM: #if NCURSES_EXT_FUNCS keyok(KEY_MOUSE, on); #endif TPUTS_TRACE("xterm mouse initialization"); -#ifdef USE_EMX_MOUSE - server_state(1); -#else - putp("\033[?1000h"); -#endif + enable_xterm_mouse(1); break; #if USE_GPM_SUPPORT case M_GPM: - SP->_mouse_fd = gpm_fd; + 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'). @@ -568,22 +904,26 @@ mouse_activate(bool on) SP->_mouse_parse = _nc_mouse_parse; SP->_mouse_resume = _nc_mouse_resume; SP->_mouse_wrap = _nc_mouse_wrap; - } else { - switch (mousetype) { + switch (SP->_mouse_type) { case M_XTERM: TPUTS_TRACE("xterm mouse deinitialization"); -#ifdef USE_EMX_MOUSE - server_state(0); -#else - putp("\033[?1000l"); -#endif + 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(); @@ -599,8 +939,10 @@ 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)); @@ -609,7 +951,7 @@ _nc_mouse_parse(int 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 collaps this run into a single higher-level event + * 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 @@ -630,9 +972,9 @@ _nc_mouse_parse(int runcount) TR(MY_TRACE, ("_nc_mouse_parse: returning simple mouse event %s at slot %ld", _tracemouse(prev), - (long) (prev - events))); - return (prev->id >= 0) - ? ((prev->bstate & eventmask) ? TRUE : FALSE) + (long) (prev - SP->_mouse_events))); + return (prev->id >= NORMAL_EVENT) + ? ((prev->bstate & SP->_mouse_mask) ? TRUE : FALSE) : FALSE; } @@ -646,8 +988,8 @@ _nc_mouse_parse(int runcount) if (_nc_tracing & TRACE_IEVENT) { _trace_slot("before mouse press/release merge:"); _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d", - (long) (runp - events), - (long) ((eventp - events) + (EV_MAX - 1)) % EV_MAX, + (long) (runp - SP->_mouse_events), + (long) ((eventp - SP->_mouse_events) + (EV_MAX - 1)) % EV_MAX, runcount); } #endif /* TRACE */ @@ -656,32 +998,27 @@ _nc_mouse_parse(int runcount) 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 & (BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED)) - && (!(ep->bstate & BUTTON1_PRESSED) - == !(next->bstate & BUTTON1_RELEASED)) - && (!(ep->bstate & BUTTON2_PRESSED) - == !(next->bstate & BUTTON2_RELEASED)) - && (!(ep->bstate & BUTTON3_PRESSED) - == !(next->bstate & BUTTON3_RELEASED)) + && (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 ) { - if ((eventmask & BUTTON1_CLICKED) - && (ep->bstate & BUTTON1_PRESSED)) { - ep->bstate &= ~BUTTON1_PRESSED; - ep->bstate |= BUTTON1_CLICKED; - merge = TRUE; - } - if ((eventmask & BUTTON2_CLICKED) - && (ep->bstate & BUTTON2_PRESSED)) { - ep->bstate &= ~BUTTON2_PRESSED; - ep->bstate |= BUTTON2_CLICKED; - merge = TRUE; - } - if ((eventmask & BUTTON3_CLICKED) - && (ep->bstate & BUTTON3_PRESSED)) { - ep->bstate &= ~BUTTON3_PRESSED; - ep->bstate |= BUTTON3_CLICKED; - merge = TRUE; + for (b = 1; b <= MAX_BUTTONS; ++b) { + if ((SP->_mouse_mask & MASK_CLICK(b)) + && (ep->bstate & MASK_PRESS(b))) { + ep->bstate &= ~MASK_PRESS(b); + ep->bstate |= MASK_CLICK(b); + merge = TRUE; + } } if (merge) next->id = INVALID_EVENT; @@ -694,8 +1031,8 @@ _nc_mouse_parse(int runcount) if (_nc_tracing & TRACE_IEVENT) { _trace_slot("before mouse click merge:"); _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d", - (long) (runp - events), - (long) ((eventp - events) + (EV_MAX - 1)) % EV_MAX, + (long) (runp - SP->_mouse_events), + (long) ((eventp - SP->_mouse_events) + (EV_MAX - 1)) % EV_MAX, runcount); } #endif /* TRACE */ @@ -729,56 +1066,30 @@ _nc_mouse_parse(int runcount) continue; /* merge click events forward */ - if ((ep->bstate & - (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED)) - && (follower->bstate & - (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED))) { - if ((eventmask & BUTTON1_DOUBLE_CLICKED) - && (follower->bstate & BUTTON1_CLICKED)) { - follower->bstate &= ~BUTTON1_CLICKED; - follower->bstate |= BUTTON1_DOUBLE_CLICKED; - merge = TRUE; - } - if ((eventmask & BUTTON2_DOUBLE_CLICKED) - && (follower->bstate & BUTTON2_CLICKED)) { - follower->bstate &= ~BUTTON2_CLICKED; - follower->bstate |= BUTTON2_DOUBLE_CLICKED; - merge = TRUE; - } - if ((eventmask & BUTTON3_DOUBLE_CLICKED) - && (follower->bstate & BUTTON3_CLICKED)) { - follower->bstate &= ~BUTTON3_CLICKED; - follower->bstate |= BUTTON3_DOUBLE_CLICKED; - merge = TRUE; + 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 & - (BUTTON1_DOUBLE_CLICKED - | BUTTON2_DOUBLE_CLICKED - | BUTTON3_DOUBLE_CLICKED)) - && (follower->bstate & - (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED))) { - if ((eventmask & BUTTON1_TRIPLE_CLICKED) - && (follower->bstate & BUTTON1_CLICKED)) { - follower->bstate &= ~BUTTON1_CLICKED; - follower->bstate |= BUTTON1_TRIPLE_CLICKED; - merge = TRUE; - } - if ((eventmask & BUTTON2_TRIPLE_CLICKED) - && (follower->bstate & BUTTON2_CLICKED)) { - follower->bstate &= ~BUTTON2_CLICKED; - follower->bstate |= BUTTON2_TRIPLE_CLICKED; - merge = TRUE; - } - if ((eventmask & BUTTON3_TRIPLE_CLICKED) - && (follower->bstate & BUTTON3_CLICKED)) { - follower->bstate &= ~BUTTON3_CLICKED; - follower->bstate |= BUTTON3_TRIPLE_CLICKED; - merge = TRUE; + 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; @@ -791,8 +1102,8 @@ _nc_mouse_parse(int runcount) if (_nc_tracing & TRACE_IEVENT) { _trace_slot("before mouse event queue compaction:"); _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d", - (long) (runp - events), - (long) ((eventp - events) + (EV_MAX - 1)) % EV_MAX, + (long) (runp - SP->_mouse_events), + (long) ((eventp - SP->_mouse_events) + (EV_MAX - 1)) % EV_MAX, runcount); } #endif /* TRACE */ @@ -802,15 +1113,15 @@ _nc_mouse_parse(int runcount) * don't match the current event mask. */ for (; runcount; prev = PREV(eventp), runcount--) - if (prev->id == INVALID_EVENT || !(prev->bstate & eventmask)) { - eventp = prev; + if (prev->id == INVALID_EVENT || !(prev->bstate & SP->_mouse_mask)) { + SP->_mouse_eventp = eventp = prev; } #ifdef TRACE if (_nc_tracing & TRACE_IEVENT) { _trace_slot("after mouse event queue compaction:"); _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d", - (long) (runp - events), - (long) ((eventp - events) + (EV_MAX - 1)) % EV_MAX, + (long) (runp - SP->_mouse_events), + (long) ((eventp - SP->_mouse_events) + (EV_MAX - 1)) % EV_MAX, runcount); } for (ep = runp; ep != eventp; ep = NEXT(ep)) @@ -818,7 +1129,7 @@ _nc_mouse_parse(int runcount) TR(MY_TRACE, ("_nc_mouse_parse: returning composite mouse event %s at slot %ld", _tracemouse(ep), - (long) (ep - events))); + (long) (ep - SP->_mouse_events))); #endif /* TRACE */ /* after all this, do we have a valid event? */ @@ -826,35 +1137,62 @@ _nc_mouse_parse(int runcount) } static void -_nc_mouse_wrap(SCREEN * sp GCC_UNUSED) +_nc_mouse_wrap(SCREEN *sp GCC_UNUSED) /* release mouse -- called by endwin() before shellout/exit */ { TR(MY_TRACE, ("_nc_mouse_wrap() called")); - switch (mousetype) { + switch (SP->_mouse_type) { case M_XTERM: - if (eventmask) + 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) +_nc_mouse_resume(SCREEN *sp GCC_UNUSED) /* re-connect to mouse -- called by doupdate() after shellout */ { TR(MY_TRACE, ("_nc_mouse_resume() called")); - /* xterm: re-enable reporting */ - if (mousetype == M_XTERM && eventmask) - mouse_activate(TRUE); + switch (SP->_mouse_type) { + case M_XTERM: + /* xterm: re-enable reporting */ + if (SP->_mouse_mask) + mouse_activate(TRUE); + break; - /* GPM: reclaim our event set */ +#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; + } } /************************************************************************** @@ -869,7 +1207,8 @@ getmouse(MEVENT * aevent) { T((T_CALLED("getmouse(%p)"), aevent)); - if (aevent && (mousetype != M_NONE)) { + if ((aevent != 0) && (SP != 0) && (SP->_mouse_type != M_NONE)) { + MEVENT *eventp = SP->_mouse_eventp; /* compute the current-event pointer */ MEVENT *prev = PREV(eventp); @@ -878,7 +1217,7 @@ getmouse(MEVENT * aevent) TR(TRACE_IEVENT, ("getmouse: returning event %s from slot %ld", _tracemouse(prev), - (long) (prev - events))); + (long) (prev - SP->_mouse_events))); prev->id = INVALID_EVENT; /* so the queue slot becomes free */ returnCode(OK); @@ -890,14 +1229,23 @@ NCURSES_EXPORT(int) ungetmouse(MEVENT * aevent) /* enqueue a synthesized mouse event to be seen by the next wgetch() */ { - /* stick the given event in the next-free slot */ - *eventp = *aevent; + int result = ERR; + + T((T_CALLED("ungetmouse(%p)"), aevent)); - /* bump the next-free pointer into the circular list */ - eventp = NEXT(eventp); + if (aevent != 0 && SP != 0) { + MEVENT *eventp = SP->_mouse_eventp; - /* push back the notification event on the keyboard queue */ - return ungetch(KEY_MOUSE); + /* 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) @@ -906,45 +1254,54 @@ mousemask(mmask_t newmask, mmask_t * oldmask) { mmask_t result = 0; - T((T_CALLED("mousemask(%#lx,%p)"), newmask, oldmask)); + T((T_CALLED("mousemask(%#lx,%p)"), (unsigned long) newmask, oldmask)); - if (oldmask) - *oldmask = eventmask; - - if (!newmask && !initialized) - returnCode(0); - - _nc_mouse_init(); - if (mousetype != M_NONE) { - eventmask = newmask & - (BUTTON_ALT | BUTTON_CTRL | BUTTON_SHIFT - | BUTTON1_PRESSED | BUTTON1_RELEASED | BUTTON1_CLICKED - | BUTTON1_DOUBLE_CLICKED | BUTTON1_TRIPLE_CLICKED - | BUTTON2_PRESSED | BUTTON2_RELEASED | BUTTON2_CLICKED - | BUTTON2_DOUBLE_CLICKED | BUTTON2_TRIPLE_CLICKED - | BUTTON3_PRESSED | BUTTON3_RELEASED | BUTTON3_CLICKED - | BUTTON3_DOUBLE_CLICKED | BUTTON3_TRIPLE_CLICKED); - - mouse_activate(eventmask != 0); - - result = eventmask; + 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; } - - returnCode(result); + returnBits(result); } NCURSES_EXPORT(bool) wenclose(const WINDOW *win, int y, int x) /* check to see if given window encloses given screen location */ { - if (win) { + bool result = FALSE; + + T((T_CALLED("wenclose(%p,%d,%d)"), win, y, x)); + + if (win != 0) { y -= win->_yoffset; - return ((win->_begy <= y && - win->_begx <= x && - (win->_begx + win->_maxx) >= x && - (win->_begy + win->_maxy) >= y) ? TRUE : FALSE); + result = ((win->_begy <= y && + win->_begx <= x && + (win->_begx + win->_maxx) >= x && + (win->_begy + win->_maxy) >= y) ? TRUE : FALSE); } - return FALSE; + returnBool(result); } NCURSES_EXPORT(int) @@ -953,6 +1310,8 @@ mouseinterval(int maxclick) { int oldval; + T((T_CALLED("mouseinterval(%d)"), maxclick)); + if (SP != 0) { oldval = SP->_maxclick; if (maxclick >= 0) @@ -961,7 +1320,7 @@ mouseinterval(int maxclick) oldval = DEFAULT_MAXCLICK; } - return (oldval); + returnCode(oldval); } /* This may be used by other routines to ask for the existence of mouse @@ -969,15 +1328,16 @@ mouseinterval(int maxclick) NCURSES_EXPORT(int) _nc_has_mouse(void) { - return (mousetype == M_NONE ? 0 : 1); + return (SP->_mouse_type == M_NONE ? 0 : 1); } NCURSES_EXPORT(bool) -wmouse_trafo -(const WINDOW *win, int *pY, int *pX, bool to_screen) +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; @@ -999,7 +1359,5 @@ wmouse_trafo *pY = y; } } - return (result); + returnBool(result); } - -/* lib_mouse.c ends here */ diff --git a/contrib/ncurses/ncurses/base/lib_move.c b/contrib/ncurses/ncurses/base/lib_move.c index e917eb7..652c44d 100644 --- a/contrib/ncurses/ncurses/base/lib_move.c +++ b/contrib/ncurses/ncurses/base/lib_move.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -40,16 +41,14 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_move.c,v 1.11 2000/12/10 02:43:27 tom Exp $") +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 (win && - x >= 0 && x <= win->_maxx && - y >= 0 && y <= win->_maxy) { + if (LEGALYX(win, y, x)) { win->_curx = (NCURSES_SIZE_T) x; win->_cury = (NCURSES_SIZE_T) y; diff --git a/contrib/ncurses/ncurses/base/lib_mvwin.c b/contrib/ncurses/ncurses/base/lib_mvwin.c index 63d54cc..e4dad4a 100644 --- a/contrib/ncurses/ncurses/base/lib_mvwin.c +++ b/contrib/ncurses/ncurses/base/lib_mvwin.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -40,7 +40,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_mvwin.c,v 1.12 2001/12/19 01:06:22 tom Exp $") +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) @@ -50,6 +50,11 @@ mvwin(WINDOW *win, int by, int 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; @@ -89,6 +94,7 @@ mvwin(WINDOW *win, int by, int bx) } returnCode(err); } +#endif if (by + win->_maxy > screen_lines - 1 || bx + win->_maxx > screen_columns - 1 diff --git a/contrib/ncurses/ncurses/base/lib_newterm.c b/contrib/ncurses/ncurses/base/lib_newterm.c index d95c4a9..fe201d6 100644 --- a/contrib/ncurses/ncurses/base/lib_newterm.c +++ b/contrib/ncurses/ncurses/base/lib_newterm.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -47,7 +48,7 @@ #include <term.h> /* clear_screen, cup & friends, cur_term */ #include <tic.h> -MODULE_ID("$Id: lib_newterm.c,v 1.52 2001/08/04 16:47:48 tom Exp $") +MODULE_ID("$Id: lib_newterm.c,v 1.64 2006/01/14 15:36:24 tom Exp $") #ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */ #define ONLCR 0 @@ -61,21 +62,30 @@ MODULE_ID("$Id: lib_newterm.c,v 1.52 2001/08/04 16:47:48 tom Exp $") * The newterm function also initializes terminal settings, and since initscr * is supposed to behave as if it calls newterm, we do it here. */ -static inline int +static NCURSES_INLINE int _nc_initscr(void) { + int result = ERR; + /* for extended XPG4 conformance requires cbreak() at this point */ /* (SVr4 curses does this anyway) */ - cbreak(); + if (cbreak() == OK) { + TTY buf; + buf = cur_term->Nttyb; #ifdef TERMIOS - cur_term->Nttyb.c_lflag &= ~(ECHO | ECHONL); - cur_term->Nttyb.c_iflag &= ~(ICRNL | INLCR | IGNCR); - cur_term->Nttyb.c_oflag &= ~(ONLCR); + 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 - cur_term->Nttyb.sg_flags &= ~(ECHO | CRMOD); + memset(&buf, 0, sizeof(buf)); #endif - return _nc_set_tty_mode(&cur_term->Nttyb); + if ((result = _nc_set_tty_mode(&buf)) == OK) + cur_term->Nttyb = buf; + } + return result; } /* @@ -84,126 +94,123 @@ _nc_initscr(void) * aside from possibly delaying a filter() call until some terminals have been * initialized. */ -static int filter_mode = FALSE; +static bool filter_mode = FALSE; NCURSES_EXPORT(void) filter(void) { + START_TRACE(); T((T_CALLED("filter"))); 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"))); + filter_mode = FALSE; + returnVoid; +} +#endif + NCURSES_EXPORT(SCREEN *) -newterm -(NCURSES_CONST char *name, FILE * ofp, FILE * ifp) +newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp) { + int value; int errret; int slk_format = _nc_slk_format; SCREEN *current; -#ifdef TRACE - int t = _nc_getenv_num("NCURSES_TRACE"); - - if (t >= 0) - trace(t); -#endif + SCREEN *result = 0; + START_TRACE(); T((T_CALLED("newterm(\"%s\",%p,%p)"), name, ofp, ifp)); - /* this loads the capability entry, then sets LINES and COLS */ - if (setupterm(name, fileno(ofp), &errret) == ERR) - returnSP(0); - - /* implement filter mode */ - if (filter_mode) { - LINES = 1; - - if (VALID_NUMERIC(init_tabs)) - TABSIZE = init_tabs; - else - TABSIZE = 8; - - T(("TABSIZE = %d", TABSIZE)); - - 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; - } + _nc_handle_sigwinch(0); - /* 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 (num_labels <= 0 || !SLK_STDFMT(slk_format)) - if (slk_format) { - if (ERR == _nc_ripoffline(-SLK_LINES(slk_format), - _nc_slk_initialize)) - returnSP(0); - } - /* this actually allocates the screen structure, and saves the - * original terminal settings. - */ - current = SP; - _nc_set_screen(0); - if (_nc_setupscreen(LINES, COLS, ofp) == ERR) { - _nc_set_screen(current); - returnSP(0); + /* allow user to set maximum escape delay from the environment */ + if ((value = _nc_getenv_num("ESCDELAY")) >= 0) { + ESCDELAY = value; } - /* 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); - SP->_checkfd = fileno(ifp); - typeahead(fileno(ifp)); + /* this loads the capability entry, then sets LINES and COLS */ + if (setupterm(name, fileno(ofp), &errret) == ERR) { + result = 0; + } else { + /* + * This actually allocates the screen structure, and saves the original + * terminal settings. + */ + current = SP; + _nc_set_screen(0); + if (_nc_setupscreen(LINES, COLS, ofp, 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)); + SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 && + !(cur_term->Ottyb.c_iflag & ISTRIP)); #else - SP->_use_meta = FALSE; + 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. - */ + 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); + 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(); + /* compute movement costs so we can do better move optimization */ + _nc_mvcur_init(); - /* initialize terminal to a sane state */ - _nc_screen_init(); + /* initialize terminal to a sane state */ + _nc_screen_init(); - /* Initialize the terminal line settings. */ - _nc_initscr(); + /* Initialize the terminal line settings. */ + _nc_initscr(); - _nc_signal_handler(TRUE); + _nc_signal_handler(TRUE); - returnSP(SP); + result = SP; + } + } + _nc_handle_sigwinch(1); + returnSP(result); } diff --git a/contrib/ncurses/ncurses/base/lib_newwin.c b/contrib/ncurses/ncurses/base/lib_newwin.c index 3cd8238..ba51633 100644 --- a/contrib/ncurses/ncurses/base/lib_newwin.c +++ b/contrib/ncurses/ncurses/base/lib_newwin.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -40,7 +41,36 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_newwin.c,v 1.33 2001/12/19 01:06:30 tom Exp $") +MODULE_ID("$Id: lib_newwin.c,v 1.38 2006/10/14 20:31:19 tom Exp $") + +static WINDOW * +remove_window_from_screen(WINDOW *win) +{ + SCREEN **scan = &_nc_screen_chain; + + while (*scan) { + SCREEN *sp = *scan; + if (sp->_curscr == win) { + sp->_curscr = 0; + if (win == curscr) + curscr = 0; + } else if (sp->_stdscr == win) { + sp->_stdscr = 0; + if (win == stdscr) + stdscr = 0; + } else if (sp->_newscr == win) { + sp->_newscr = 0; + if (win == newscr) + newscr = 0; + } else { + scan = &(*scan)->_next_screen; + continue; + } + break; + } + + return 0; +} NCURSES_EXPORT(int) _nc_freewin(WINDOW *win) @@ -52,6 +82,7 @@ _nc_freewin(WINDOW *win) if (win != 0) { for (p = _nc_windows, q = 0; p != 0; q = p, p = p->next) { if (&(p->win) == win) { + remove_window_from_screen(win); if (q == 0) _nc_windows = p->next; else @@ -64,13 +95,6 @@ _nc_freewin(WINDOW *win) free(win->_line); free(p); - if (win == curscr) - curscr = 0; - if (win == stdscr) - stdscr = 0; - if (win == newscr) - newscr = 0; - result = OK; T(("...deleted win=%p", win)); break; @@ -97,9 +121,6 @@ newwin(int num_lines, int num_columns, int begy, int begx) if (num_columns == 0) num_columns = screen_columns - begx; - if (num_columns + begx > SP->_columns || num_lines + begy > SP->_lines_avail) - returnWin(0); - if ((win = _nc_makenew(num_lines, num_columns, begy, begx, 0)) == 0) returnWin(0); @@ -152,7 +173,7 @@ derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx) win->_pary = begy; win->_parx = begx; - win->_attrs = orig->_attrs; + WINDOW_ATTRS(win) = WINDOW_ATTRS(orig); win->_nc_bkgd = orig->_nc_bkgd; for (i = 0; i < num_lines; i++) @@ -167,7 +188,7 @@ 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 = %d, begx = %d", w->_begy, w->_begx)); + T(("parent has begy = %ld, begx = %ld", (long) w->_begy, (long) w->_begx)); returnWin(derwin(w, l, c, y - w->_begy, x - w->_begx)); } @@ -189,6 +210,9 @@ _nc_makenew(int num_lines, int num_columns, int begy, int begx, int flags) T(("_nc_makenew(%d,%d,%d,%d)", num_lines, num_columns, begy, begx)); + if (SP == 0) + return 0; + if (!dimension_limit(num_lines) || !dimension_limit(num_columns)) return 0; @@ -211,7 +235,7 @@ _nc_makenew(int num_lines, int num_columns, int begy, int begx, int flags) win->_yoffset = SP->_topstolen; win->_flags = flags; - win->_attrs = A_NORMAL; + WINDOW_ATTRS(win) = A_NORMAL; SetChar(win->_nc_bkgd, BLANK_TEXT, BLANK_ATTR); win->_clear = is_pad ? FALSE : (num_lines == screen_lines diff --git a/contrib/ncurses/ncurses/base/lib_overlay.c b/contrib/ncurses/ncurses/base/lib_overlay.c index 010e6d1..9ecc458 100644 --- a/contrib/ncurses/ncurses/base/lib_overlay.c +++ b/contrib/ncurses/ncurses/base/lib_overlay.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -40,30 +40,60 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_overlay.c,v 1.20 2001/12/19 01:06:37 tom Exp $") +MODULE_ID("$Id: lib_overlay.c,v 1.22 2006/10/14 20:43:31 tom Exp $") static int overlap(const WINDOW *const s, WINDOW *const d, int const flag) { - int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol; + int sx1, sy1, sx2, sy2; + int dx1, dy1, dx2, dy2; + int sminrow, smincol; + int dminrow, dmincol; + int dmaxrow, dmaxcol; - T(("overlap : sby %d, sbx %d, smy %d, smx %d, dby %d, dbx %d, dmy %d, dmx %d", - s->_begy, s->_begx, s->_maxy, s->_maxx, - d->_begy, d->_begx, d->_maxy, d->_maxx)); + T((T_CALLED("overlap(%p,%p,%d)"), s, d, flag)); - if (!s || !d) + if (s == 0 || d == 0) { returnCode(ERR); - - sminrow = max(s->_begy, d->_begy) - s->_begy; - smincol = max(s->_begx, d->_begx) - s->_begx; - dminrow = max(s->_begy, d->_begy) - d->_begy; - dmincol = max(s->_begx, d->_begx) - d->_begx; - dmaxrow = min(s->_maxy + s->_begy, d->_maxy + d->_begy) - d->_begy; - dmaxcol = min(s->_maxx + s->_begx, d->_maxx + d->_begx) - d->_begx; - - return (copywin(s, d, - sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, - flag)); + } else { + T(("src : begy %ld, begx %ld, maxy %ld, maxx %ld", + (long) s->_begy, + (long) s->_begx, + (long) s->_maxy, + (long) s->_maxx)); + T(("dst : begy %ld, begx %ld, maxy %ld, maxx %ld", + (long) d->_begy, + (long) d->_begx, + (long) d->_maxy, + (long) d->_maxx)); + + sx1 = s->_begx; + sy1 = s->_begy; + sx2 = sx1 + s->_maxx; + sy2 = sy1 + s->_maxy; + + dx1 = d->_begx; + dy1 = d->_begy; + dx2 = dx1 + d->_maxx; + dy2 = dy1 + d->_maxy; + + if (dx2 < sx1 || dx1 > sx2 || dy2 < sy1 || dy1 > sy2) { + returnCode(ERR); /* No intersection */ + } else { + 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; + + returnCode(copywin(s, d, + sminrow, smincol, + dminrow, dmincol, + dmaxrow, dmaxcol, + flag)); + } + } } /* @@ -101,11 +131,11 @@ overwrite(const WINDOW *win1, WINDOW *win2) } NCURSES_EXPORT(int) -copywin -(const WINDOW *src, WINDOW *dst, - int sminrow, int smincol, - int dminrow, int dmincol, int dmaxrow, int dmaxcol, - int over) +copywin(const WINDOW *src, WINDOW *dst, + int sminrow, int smincol, + int dminrow, int dmincol, + int dmaxrow, int dmaxcol, + int over) { int sx, sy, dx, dy; bool touched; @@ -152,7 +182,7 @@ copywin } } if (touched) { - touchline(dst, 0, getmaxy(dst)); + touchline(dst, dminrow, (dmaxrow - dminrow + 1)); } } T(("finished copywin")); diff --git a/contrib/ncurses/ncurses/base/lib_pad.c b/contrib/ncurses/ncurses/base/lib_pad.c index 83983c3..6cad9c5 100644 --- a/contrib/ncurses/ncurses/base/lib_pad.c +++ b/contrib/ncurses/ncurses/base/lib_pad.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. * + * 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 * @@ -40,7 +40,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_pad.c,v 1.37 2002/05/23 23:39:26 tom Exp $") +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) @@ -71,8 +71,7 @@ newpad(int l, int c) } NCURSES_EXPORT(WINDOW *) -subpad -(WINDOW *orig, int l, int c, int begy, int begx) +subpad(WINDOW *orig, int l, int c, int begy, int begx) { WINDOW *win = (WINDOW *) 0; @@ -87,9 +86,13 @@ subpad } NCURSES_EXPORT(int) -prefresh -(WINDOW *win, int pminrow, int pmincol, - int sminrow, int smincol, int smaxrow, int smaxcol) +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, @@ -101,9 +104,13 @@ prefresh } NCURSES_EXPORT(int) -pnoutrefresh -(WINDOW *win, int pminrow, int pmincol, - int sminrow, int smincol, int smaxrow, int smaxcol) +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; @@ -138,8 +145,10 @@ pnoutrefresh pmaxrow = pminrow + smaxrow - sminrow; pmaxcol = pmincol + smaxcol - smincol; - T((" pminrow + smaxrow - sminrow %d, win->_maxy %d", pmaxrow, win->_maxy)); - T((" pmincol + smaxcol - smincol %d, win->_maxx %d", pmaxcol, win->_maxx)); + 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. @@ -153,8 +162,8 @@ pnoutrefresh pmaxcol = pmincol + smaxcol - smincol; } - if (smaxrow > screen_lines - || smaxcol > screen_columns + if (smaxrow >= screen_lines + || smaxcol >= screen_columns || sminrow > smaxrow || smincol > smaxcol) returnCode(ERR); @@ -202,7 +211,7 @@ pnoutrefresh */ if (j == pmincol && j > 0 - && isnac(ch)) { + && isWidecExt(ch)) { SetChar(ch, L(' '), AttrOf(oline->text[j - 1])); } #endif diff --git a/contrib/ncurses/ncurses/base/lib_printw.c b/contrib/ncurses/ncurses/base/lib_printw.c index f821a96..62ae921 100644 --- a/contrib/ncurses/ncurses/base/lib_printw.c +++ b/contrib/ncurses/ncurses/base/lib_printw.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -39,10 +39,10 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_printw.c,v 1.12 2001/10/20 20:33:46 tom Exp $") +MODULE_ID("$Id: lib_printw.c,v 1.18 2006/12/17 19:21:39 tom Exp $") NCURSES_EXPORT(int) -printw(NCURSES_CONST char *fmt,...) +printw(const char *fmt,...) { va_list argp; int code; @@ -62,7 +62,7 @@ printw(NCURSES_CONST char *fmt,...) } NCURSES_EXPORT(int) -wprintw(WINDOW *win, NCURSES_CONST char *fmt,...) +wprintw(WINDOW *win, const char *fmt,...) { va_list argp; int code; @@ -82,7 +82,7 @@ wprintw(WINDOW *win, NCURSES_CONST char *fmt,...) } NCURSES_EXPORT(int) -mvprintw(int y, int x, NCURSES_CONST char *fmt,...) +mvprintw(int y, int x, const char *fmt,...) { va_list argp; int code; @@ -103,7 +103,7 @@ mvprintw(int y, int x, NCURSES_CONST char *fmt,...) } NCURSES_EXPORT(int) -mvwprintw(WINDOW *win, int y, int x, NCURSES_CONST char *fmt,...) +mvwprintw(WINDOW *win, int y, int x, const char *fmt,...) { va_list argp; int code; @@ -124,19 +124,15 @@ mvwprintw(WINDOW *win, int y, int x, NCURSES_CONST char *fmt,...) } NCURSES_EXPORT(int) -vwprintw(WINDOW *win, NCURSES_CONST char *fmt, va_list argp) +vwprintw(WINDOW *win, const char *fmt, va_list argp) { char *buf; int code = ERR; - T((T_CALLED("wprintw(%p,%s,%p)"), - win, _nc_visbuf(fmt), argp)); + T((T_CALLED("vwprintw(%p,%s,va_list)"), win, _nc_visbuf(fmt))); if ((buf = _nc_printf_string(fmt, argp)) != 0) { code = waddstr(win, buf); -#if USE_SAFE_SPRINTF - free(buf); -#endif } returnCode(code); } diff --git a/contrib/ncurses/ncurses/base/lib_redrawln.c b/contrib/ncurses/ncurses/base/lib_redrawln.c index 91a0371..548ca97 100644 --- a/contrib/ncurses/ncurses/base/lib_redrawln.c +++ b/contrib/ncurses/ncurses/base/lib_redrawln.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -39,7 +39,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_redrawln.c,v 1.10 2001/09/29 17:41:31 tom Exp $") +MODULE_ID("$Id: lib_redrawln.c,v 1.11 2006/11/04 23:08:47 tom Exp $") NCURSES_EXPORT(int) wredrawln(WINDOW *win, int beg, int num) @@ -56,6 +56,9 @@ wredrawln(WINDOW *win, int beg, int num) 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; @@ -67,8 +70,10 @@ wredrawln(WINDOW *win, int beg, int num) len *= sizeof(curscr->_line[0].text[0]); for (i = beg; i < end; i++) { - memset(curscr->_line[i + win->_begy].text + win->_begx, 0, len); - _nc_make_oldhash(i + win->_begy); + int crow = i + win->_begy; + + memset(curscr->_line[crow].text + win->_begx, 0, len); + _nc_make_oldhash(crow); } returnCode(OK); diff --git a/contrib/ncurses/ncurses/base/lib_refresh.c b/contrib/ncurses/ncurses/base/lib_refresh.c index 42c1f49..27649df 100644 --- a/contrib/ncurses/ncurses/base/lib_refresh.c +++ b/contrib/ncurses/ncurses/base/lib_refresh.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -40,7 +41,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_refresh.c,v 1.31 2001/12/19 01:06:41 tom Exp $") +MODULE_ID("$Id: lib_refresh.c,v 1.34 2006/05/27 19:21:19 tom Exp $") NCURSES_EXPORT(int) wrefresh(WINDOW *win) @@ -49,7 +50,9 @@ wrefresh(WINDOW *win) T((T_CALLED("wrefresh(%p)"), win)); - if (win == curscr) { + if (win == 0) { + code = ERR; + } else if (win == curscr) { curscr->_clear = TRUE; code = doupdate(); } else if ((code = wnoutrefresh(win)) == OK) { @@ -97,7 +100,7 @@ wnoutrefresh(WINDOW *win) begy = win->_begy; newscr->_nc_bkgd = win->_nc_bkgd; - newscr->_attrs = win->_attrs; + WINDOW_ATTRS(newscr) = WINDOW_ATTRS(win); /* merge in change information from all subwindows of this window */ wsyncdown(win); @@ -132,8 +135,8 @@ wnoutrefresh(WINDOW *win) /* limit(n) */ limit_x = win->_maxx; /* limit(j) */ - if (limit_x > win->_maxx) - limit_x = win->_maxx; + if (limit_x > newscr->_maxx - begx) + limit_x = newscr->_maxx - begx; for (i = 0, m = begy + win->_yoffset; i <= win->_maxy && m <= newscr->_maxy; diff --git a/contrib/ncurses/ncurses/base/lib_restart.c b/contrib/ncurses/ncurses/base/lib_restart.c index 0068554..ca27a0f 100644 --- a/contrib/ncurses/ncurses/base/lib_restart.c +++ b/contrib/ncurses/ncurses/base/lib_restart.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -47,46 +48,52 @@ #include <term.h> /* lines, columns, cur_term */ -MODULE_ID("$Id: lib_restart.c,v 1.4 2000/12/10 01:26:52 tom Exp $") +MODULE_ID("$Id: lib_restart.c,v 1.6 2006/01/14 15:58:23 tom Exp $") NCURSES_EXPORT(int) -restartterm -(NCURSES_CONST char *termp, int filenum, int *errret) +restartterm(NCURSES_CONST char *termp, int filenum, int *errret) { int saveecho = SP->_echo; int savecbreak = SP->_cbreak; int saveraw = SP->_raw; int savenl = SP->_nl; + int result; T((T_CALLED("restartterm(%s,%d,%p)"), termp, filenum, errret)); - setupterm(termp, filenum, errret); + _nc_handle_sigwinch(0); + if (setupterm(termp, filenum, errret) != OK) { + result = ERR; + } else { - if (saveecho) - echo(); - else - noecho(); + if (saveecho) + echo(); + else + noecho(); - if (savecbreak) { - cbreak(); - noraw(); - } else if (saveraw) { - nocbreak(); - raw(); - } else { - nocbreak(); - noraw(); - } - if (savenl) - nl(); - else - nonl(); + if (savecbreak) { + cbreak(); + noraw(); + } else if (saveraw) { + nocbreak(); + raw(); + } else { + nocbreak(); + noraw(); + } + if (savenl) + nl(); + else + nonl(); - reset_prog_mode(); + reset_prog_mode(); #if USE_SIZECHANGE - _nc_update_screensize(); + _nc_update_screensize(); #endif - returnCode(OK); + result = OK; + } + _nc_handle_sigwinch(1); + returnCode(result); } diff --git a/contrib/ncurses/ncurses/base/lib_screen.c b/contrib/ncurses/ncurses/base/lib_screen.c index 3b2d929..5d67e19 100644 --- a/contrib/ncurses/ncurses/base/lib_screen.c +++ b/contrib/ncurses/ncurses/base/lib_screen.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -29,92 +29,105 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996 on * ****************************************************************************/ #include <curses.priv.h> -#include <sys/stat.h> -#include <time.h> -#include <term.h> /* exit_ca_mode, non_rev_rmcup */ - -MODULE_ID("$Id: lib_screen.c,v 1.19 2001/12/19 00:55:28 tom Exp $") - -static time_t dumptime; +MODULE_ID("$Id: lib_screen.c,v 1.29 2006/05/27 19:21:38 tom Exp $") NCURSES_EXPORT(WINDOW *) -getwin(FILE * filep) +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 ((nwin = newwin(tmp._maxy + 1, tmp._maxx + 1, 0, 0)) == 0) - 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. */ - 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 | _ISPAD); - - nwin->_attrs = tmp._attrs; - nwin->_nc_bkgd = tmp._nc_bkgd; - - nwin->_clear = tmp._clear; - nwin->_scroll = tmp._scroll; - nwin->_leaveok = tmp._leaveok; - nwin->_use_keypad = tmp._use_keypad; - nwin->_delay = tmp._delay; - nwin->_immed = tmp._immed; - nwin->_sync = tmp._sync; - - nwin->_regtop = tmp._regtop; - nwin->_regbottom = tmp._regbottom; - - for (n = 0; n < nwin->_maxy + 1; n++) { - (void) fread(nwin->_line[n].text, - sizeof(chtype), (size_t) (nwin->_maxx + 1), filep); - if (ferror(filep)) { - delwin(nwin); - returnWin(0); + 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); } - touchwin(nwin); - returnWin(nwin); } NCURSES_EXPORT(int) -putwin(WINDOW *win, FILE * filep) +putwin(WINDOW *win, FILE *filep) { int code = ERR; int n; T((T_CALLED("putwin(%p,%p)"), win, filep)); - if (win) { - (void) fwrite(win, sizeof(WINDOW), 1, filep); - if (ferror(filep)) - returnCode(code); + 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 + 1; n++) { - (void) fwrite(win->_line[n].text, - sizeof(chtype), (size_t) (win->_maxx + 1), filep); - if (ferror(filep)) + 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; } @@ -129,11 +142,11 @@ scr_restore(const char *file) T((T_CALLED("scr_restore(%s)"), _nc_visbuf(file))); if (_nc_access(file, R_OK) < 0 - || (fp = fopen(file, "rb")) == 0) + || (fp = fopen(file, "rb")) == 0) { returnCode(ERR); - else { + } else { delwin(newscr); - newscr = getwin(fp); + SP->_newscr = newscr = getwin(fp); (void) fclose(fp); returnCode(OK); } @@ -147,12 +160,11 @@ scr_dump(const char *file) T((T_CALLED("scr_dump(%s)"), _nc_visbuf(file))); if (_nc_access(file, W_OK) < 0 - || (fp = fopen(file, "wb")) == 0) + || (fp = fopen(file, "wb")) == 0) { returnCode(ERR); - else { + } else { (void) putwin(newscr, fp); (void) fclose(fp); - dumptime = time((time_t *) 0); returnCode(OK); } } @@ -161,7 +173,6 @@ NCURSES_EXPORT(int) scr_init(const char *file) { FILE *fp = 0; - struct stat stb; T((T_CALLED("scr_init(%s)"), _nc_visbuf(file))); @@ -169,13 +180,11 @@ scr_init(const char *file) returnCode(ERR); if (_nc_access(file, R_OK) < 0 - || (fp = fopen(file, "rb")) == 0) - returnCode(ERR); - else if (fstat(STDOUT_FILENO, &stb) || stb.st_mtime > dumptime) + || (fp = fopen(file, "rb")) == 0) { returnCode(ERR); - else { + } else { delwin(curscr); - curscr = getwin(fp); + SP->_curscr = curscr = getwin(fp); (void) fclose(fp); returnCode(OK); } @@ -186,11 +195,11 @@ scr_set(const char *file) { T((T_CALLED("scr_set(%s)"), _nc_visbuf(file))); - if (scr_init(file) == ERR) + if (scr_init(file) == ERR) { returnCode(ERR); - else { + } else { delwin(newscr); - newscr = dupwin(curscr); + SP->_newscr = newscr = dupwin(curscr); returnCode(OK); } } diff --git a/contrib/ncurses/ncurses/base/lib_scroll.c b/contrib/ncurses/ncurses/base/lib_scroll.c index 39c62d0..ac85bd5 100644 --- a/contrib/ncurses/ncurses/base/lib_scroll.c +++ b/contrib/ncurses/ncurses/base/lib_scroll.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -27,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey 1996-2001 * + * Author: Thomas E. Dickey 1996-2003 * * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ @@ -43,18 +43,22 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_scroll.c,v 1.23 2001/12/19 01:06:55 tom Exp $") +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) +_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, %d, %d)", win, n, top, bottom)); + TR(TRACE_MOVE, ("_nc_scroll_window(%p, %d, %ld, %ld)", + win, n, (long) top, (long) bottom)); if (top < 0 || bottom < top @@ -77,24 +81,15 @@ _nc_scroll_window(WINDOW *win, int const n, NCURSES_SIZE_T const top, /* shift n lines downwards */ if (n < 0) { limit = top - n; - if (limit > win->_maxy) - limit = win->_maxy; - for (line = bottom; line >= limit; line--) { - if (line + n >= 0) { - 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); - } else { - 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); - } + 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++) { + 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; @@ -105,31 +100,36 @@ _nc_scroll_window(WINDOW *win, int const n, NCURSES_SIZE_T const top, /* shift n lines upwards */ if (n > 0) { limit = bottom - n; - if (limit < 0) - limit = 0; - for (line = top; line <= limit; line++) { - if (line + n <= win->_maxy) { - 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); - } else { - 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); - } + 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--) { - TR(TRACE_MOVE, ("...filling %d", line)); + 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) @@ -142,11 +142,9 @@ wscrl(WINDOW *win, int n) returnCode(ERR); } - if (n == 0) - returnCode(OK); - - _nc_scroll_window(win, n, win->_regtop, win->_regbottom, win->_nc_bkgd); - - _nc_synchook(win); + if (n != 0) { + _nc_scroll_window(win, n, win->_regtop, win->_regbottom, win->_nc_bkgd); + _nc_synchook(win); + } returnCode(OK); } diff --git a/contrib/ncurses/ncurses/base/lib_set_term.c b/contrib/ncurses/ncurses/base/lib_set_term.c index f3940fa..bcc42d1 100644 --- a/contrib/ncurses/ncurses/base/lib_set_term.c +++ b/contrib/ncurses/ncurses/base/lib_set_term.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -43,10 +44,10 @@ #include <term.h> /* cur_term */ #include <tic.h> -MODULE_ID("$Id: lib_set_term.c,v 1.65 2002/06/15 18:40:20 tom Exp $") +MODULE_ID("$Id: lib_set_term.c,v 1.91 2006/05/20 14:58:02 tom Exp $") NCURSES_EXPORT(SCREEN *) -set_term(SCREEN * screenp) +set_term(SCREEN *screenp) { SCREEN *oldSP; @@ -61,7 +62,6 @@ set_term(SCREEN * screenp) stdscr = SP->_stdscr; COLORS = SP->_color_count; COLOR_PAIRS = SP->_pair_count; - memcpy(acs_map, SP->_acs_map, sizeof(chtype) * ACS_LEN); T((T_RETURN("%p"), oldSP)); return (oldSP); @@ -81,9 +81,10 @@ _nc_free_keytry(struct tries *kt) * Free the storage associated with the given SCREEN sp. */ NCURSES_EXPORT(void) -delscreen(SCREEN * sp) +delscreen(SCREEN *sp) { SCREEN **scan = &_nc_screen_chain; + int i; T((T_CALLED("delscreen(%p)"), sp)); @@ -98,14 +99,36 @@ delscreen(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); @@ -141,16 +164,16 @@ delscreen(SCREEN * sp) static ripoff_t rippedoff[5]; static ripoff_t *rsp = rippedoff; -#define N_RIPS SIZEOF(rippedoff) +#define N_RIPS SIZEOF(SP->_rippedoff) static bool -no_mouse_event(SCREEN * sp GCC_UNUSED) +no_mouse_event(SCREEN *sp GCC_UNUSED) { return FALSE; } static bool -no_mouse_inline(SCREEN * sp GCC_UNUSED) +no_mouse_inline(SCREEN *sp GCC_UNUSED) { return FALSE; } @@ -162,12 +185,12 @@ no_mouse_parse(int code GCC_UNUSED) } static void -no_mouse_resume(SCREEN * sp GCC_UNUSED) +no_mouse_resume(SCREEN *sp GCC_UNUSED) { } static void -no_mouse_wrap(SCREEN * sp GCC_UNUSED) +no_mouse_wrap(SCREEN *sp GCC_UNUSED) { } @@ -191,21 +214,67 @@ extract_fgbg(char *src, int *result) } #endif -NCURSES_EXPORT(int) -_nc_setupscreen -(short slines, short const scolumns, FILE * output) /* OS-independent screen initializations */ +NCURSES_EXPORT(int) +_nc_setupscreen(int slines, + int scolumns, + FILE *output, + bool filtered, + int slk_format) { int bottom_stolen = 0; - size_t i; + int i; + bool support_cookies = USE_XMC_SUPPORT; + + 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()) - return ERR; + 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); + + SP->_filtered = filtered; + + /* implement filter mode */ + if (filtered) { + slines = LINES = 1; + + 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)); + } + + /* 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 (num_labels <= 0 || !SLK_STDFMT(slk_format)) { + if (slk_format) { + if (ERR == _nc_ripoffline(-SLK_LINES(slk_format), + _nc_slk_initialize)) + returnCode(ERR); + } + } +#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; @@ -259,6 +328,26 @@ _nc_setupscreen 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 @@ -275,7 +364,7 @@ _nc_setupscreen 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 (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"; @@ -283,7 +372,7 @@ _nc_setupscreen SP->_default_fg %= max_colors; } } - if (SP->_default_bg > 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"; @@ -309,42 +398,104 @@ _nc_setupscreen 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. Note that this impacts the alternate character set mapping - * as well. + * 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) { - - SP->_xmc_triggers = termattrs() & ( - A_ALTCHARSET | - A_BLINK | - A_BOLD | - A_REVERSE | - A_STANDOUT | - A_UNDERLINE + 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 ); - SP->_xmc_suppress = SP->_xmc_triggers & (chtype) ~ (A_BOLD); +#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 this simple, suppress all of the optimization hooks - * except for clear_screen and the cursor addressing. + * To keep the cookie support simple, suppress all of the optimization + * hooks except for clear_screen and the cursor addressing. */ - clr_eol = 0; - clr_eos = 0; - set_attributes = 0; -#else - magic_cookie_glitch = ABSENT_NUMERIC; - acs_chars = 0; + 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 */ + _nc_init_acs(); #if USE_WIDEC_SUPPORT _nc_init_wacs(); + + SP->_screen_acs_fix = (_nc_unicode_locale() && _nc_locale_breaks_acs()); + { + char *env = _nc_get_locale(); + SP->_legacy_coding = ((env == 0) + || !strcmp(env, "C") + || !strcmp(env, "POSIX")); + } #endif - _nc_init_acs(); - memcpy(SP->_acs_map, acs_map, sizeof(chtype) * ACS_LEN); _nc_idcok = TRUE; _nc_idlok = FALSE; @@ -356,11 +507,11 @@ _nc_setupscreen T(("creating newscr")); if ((newscr = newwin(slines, scolumns, 0, 0)) == 0) - return ERR; + returnCode(ERR); T(("creating curscr")); if ((curscr = newwin(slines, scolumns, 0, 0)) == 0) - return ERR; + returnCode(ERR); SP->_newscr = newscr; SP->_curscr = curscr; @@ -374,42 +525,41 @@ _nc_setupscreen def_shell_mode(); def_prog_mode(); - for (i = 0, rsp = rippedoff; rsp->line && (i < N_RIPS); rsp++, i++) { + for (i = 0, rsp = rippedoff; rsp->line && (i < (int) N_RIPS); rsp++, i++) { + T(("ripping off line %d at %s", i, rsp->line < 0 ? "bottom" : "top")); + SP->_rippedoff[i] = rippedoff[i]; if (rsp->hook) { - WINDOW *w; int count = (rsp->line < 0) ? -rsp->line : rsp->line; - if (rsp->line < 0) { - w = newwin(count, scolumns, SP->_lines_avail - count, 0); - if (w) { - rsp->w = w; - rsp->hook(w, scolumns); - bottom_stolen += count; - } else - return ERR; - } else { - w = newwin(count, scolumns, 0, 0); - if (w) { - rsp->w = w; - rsp->hook(w, scolumns); - SP->_topstolen += count; - } else - return ERR; - } + SP->_rippedoff[i].w = newwin(count, + scolumns, + ((rsp->line < 0) + ? SP->_lines_avail - count + : 0), + 0); + if (SP->_rippedoff[i].w != 0) + SP->_rippedoff[i].hook(SP->_rippedoff[i].w, scolumns); + else + returnCode(ERR); + if (rsp->line < 0) + bottom_stolen += count; + else + SP->_topstolen += count; SP->_lines_avail -= count; } rsp->line = 0; } + SP->_rip_count = i; /* reset the stack */ rsp = rippedoff; T(("creating stdscr")); assert((SP->_lines_avail + SP->_topstolen + bottom_stolen) == slines); if ((stdscr = newwin(LINES = SP->_lines_avail, scolumns, 0, 0)) == 0) - return ERR; + returnCode(ERR); SP->_stdscr = stdscr; - return OK; + returnCode(OK); } /* The internal implementation interprets line as the number of @@ -418,18 +568,20 @@ _nc_setupscreen NCURSES_EXPORT(int) _nc_ripoffline(int line, int (*init) (WINDOW *, int)) { - if (line == 0) - return (OK); + T((T_CALLED("_nc_ripoffline(%d, %p)"), line, init)); + + if (line != 0) { - if (rsp >= rippedoff + N_RIPS) - return (ERR); + if (rsp >= rippedoff + N_RIPS) + returnCode(ERR); - rsp->line = line; - rsp->hook = init; - rsp->w = 0; - rsp++; + rsp->line = line; + rsp->hook = init; + rsp->w = 0; + rsp++; + } - return (OK); + returnCode(OK); } NCURSES_EXPORT(int) diff --git a/contrib/ncurses/ncurses/base/lib_slk.c b/contrib/ncurses/ncurses/base/lib_slk.c index 0204493..5609e3b 100644 --- a/contrib/ncurses/ncurses/base/lib_slk.c +++ b/contrib/ncurses/ncurses/base/lib_slk.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * 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 * @@ -27,8 +27,12 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * - * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * Authors: * + * Gerhard Fuernkranz 1993 (original) * + * Zeyd M. Ben-Halim 1992,1995 (sic) * + * Eric S. Raymond * + * Juergen Pfeifer 1996-on * + * Thomas E. Dickey * ****************************************************************************/ /* @@ -41,7 +45,7 @@ #include <ctype.h> #include <term.h> /* num_labels, label_*, plab_norm */ -MODULE_ID("$Id: lib_slk.c,v 1.20 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_slk.c,v 1.30 2005/01/08 21:56:36 tom Exp $") /* * We'd like to move these into the screen context structure, but cannot, @@ -54,8 +58,8 @@ _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) +static void +slk_paint_info(WINDOW *win) { if (win && SP->slk_format == 4) { int i; @@ -64,20 +68,26 @@ _nc_slk_format = 0; /* one more than format specified in slk_init() */ wmove(win, 0, 0); for (i = 0; i < SP->_slk->maxlab; i++) { - if (win && SP->slk_format == 4) { - mvwaddch(win, 0, SP->_slk->ent[i].x, (chtype) 'F'); - if (i < 9) - waddch(win, (chtype) '1' + i); - else { - waddch(win, (chtype) '1'); - waddch(win, (chtype) '0' + (i - 9)); - } - } + 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() */ @@ -86,92 +96,100 @@ _nc_slk_initialize(WINDOW *stwin, int cols) { int i, x; int res = OK; - char *p; + unsigned max_length; - T(("slk_initialize()")); + T((T_CALLED("_nc_slk_initialize()"))); if (SP->_slk) { /* we did this already, so simply return */ - return (OK); + returnCode(OK); } else if ((SP->_slk = typeCalloc(SLK, 1)) == 0) - return (ERR); + returnCode(ERR); SP->_slk->ent = NULL; - SP->_slk->buffer = NULL; - SP->_slk->attr = A_STANDOUT; - SP->_slk->maxlab = (num_labels > 0) ? - num_labels : MAX_SKEY(_nc_slk_format); - SP->_slk->maxlen = (num_labels > 0) ? - label_width * label_height : MAX_SKEY_LEN(_nc_slk_format); - SP->_slk->labcnt = (SP->_slk->maxlab < MAX_SKEY(_nc_slk_format)) ? - MAX_SKEY(_nc_slk_format) : SP->_slk->maxlab; + /* + * 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_slk_format)); + SP->_slk->maxlen = ((num_labels > 0) + ? label_width * label_height + : MAX_SKEY_LEN(_nc_slk_format)); + SP->_slk->labcnt = ((SP->_slk->maxlab < MAX_SKEY(_nc_slk_format)) + ? MAX_SKEY(_nc_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; - SP->_slk->ent = typeCalloc(slk_ent, SP->_slk->labcnt); - if (SP->_slk->ent == NULL) - goto exception; + 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); - p = SP->_slk->buffer = (char *) calloc(2 * SP->_slk->labcnt, (1 + SP->_slk->maxlen)); - if (SP->_slk->buffer == NULL) - goto exception; + 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); - for (i = 0; i < SP->_slk->labcnt; i++) { - SP->_slk->ent[i].text = p; - p += (1 + SP->_slk->maxlen); - SP->_slk->ent[i].form_text = p; - p += (1 + SP->_slk->maxlen); - memset(SP->_slk->ent[i].form_text, ' ', (unsigned) (SP->_slk->maxlen)); + memset(SP->_slk->ent[i].form_text, ' ', max_length); SP->_slk->ent[i].visible = (i < SP->_slk->maxlab); } if (_nc_slk_format >= 3) { /* PC style */ - int gap = (cols - 3 * (3 + 4 * SP->_slk->maxlen)) / 2; + 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].x = x; - x += SP->_slk->maxlen; + SP->_slk->ent[i].ent_x = x; + x += max_length; x += (i == 3 || i == 7) ? gap : 1; } - if (_nc_slk_format == 4) - slk_paint_info(stwin); + slk_paint_info(stwin); } else { if (_nc_slk_format == 2) { /* 4-4 */ - int gap = cols - (SP->_slk->maxlab * SP->_slk->maxlen) - 6; + 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].x = x; - x += SP->_slk->maxlen; + SP->_slk->ent[i].ent_x = x; + x += max_length; x += (i == 3) ? gap : 1; } } else { if (_nc_slk_format == 1) { /* 1 -> 3-2-3 */ - int gap = (cols - (SP->_slk->maxlab * SP->_slk->maxlen) - 5) + 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].x = x; - x += SP->_slk->maxlen; + SP->_slk->ent[i].ent_x = x; + x += max_length; x += (i == 2 || i == 4) ? gap : 1; } } else - goto exception; + returnCode(slk_failed()); } } SP->_slk->dirty = TRUE; if ((SP->_slk->win = stwin) == NULL) { - exception: - if (SP->_slk) { - FreeIfNeeded(SP->_slk->buffer); - FreeIfNeeded(SP->_slk->ent); - free(SP->_slk); - SP->_slk = (SLK *) 0; - res = (ERR); - } + returnCode(slk_failed()); } /* We now reset the format so that the next newterm has again @@ -180,7 +198,7 @@ _nc_slk_initialize(WINDOW *stwin, int cols) */ SP->slk_format = _nc_slk_format; _nc_slk_format = 0; - return (res); + returnCode(res); } /* diff --git a/contrib/ncurses/ncurses/base/lib_slkatr_set.c b/contrib/ncurses/ncurses/base/lib_slkatr_set.c index 5df314c..f83616b 100644 --- a/contrib/ncurses/ncurses/base/lib_slkatr_set.c +++ b/contrib/ncurses/ncurses/base/lib_slkatr_set.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * 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 * @@ -27,28 +27,32 @@ ****************************************************************************/ /**************************************************************************** - * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1998 * + * Author: Juergen Pfeifer, 1998 * + * and: Thomas E. Dickey 2005 * ****************************************************************************/ /* * lib_slkatr_set.c * Soft key routines. - * Set the labels attributes + * Set the label's attributes */ #include <curses.priv.h> -MODULE_ID("$Id: lib_slkatr_set.c,v 1.5 2000/12/10 02:43:27 tom Exp $") +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) +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) { - SP->_slk->attr = attr; - toggle_attr_on(SP->_slk->attr, COLOR_PAIR(color_pair_number)); + 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/contrib/ncurses/ncurses/base/lib_slkatrof.c b/contrib/ncurses/ncurses/base/lib_slkatrof.c index c271c34..14b4c3b 100644 --- a/contrib/ncurses/ncurses/base/lib_slkatrof.c +++ b/contrib/ncurses/ncurses/base/lib_slkatrof.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * 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 * @@ -27,8 +27,8 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * - * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * Author: Juergen Pfeifer, 1997 * + * and: Thomas E. Dickey 2005 * ****************************************************************************/ /* @@ -38,7 +38,7 @@ */ #include <curses.priv.h> -MODULE_ID("$Id: lib_slkatrof.c,v 1.6 2000/12/10 02:43:27 tom Exp $") +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) @@ -46,7 +46,12 @@ slk_attroff(const chtype attr) T((T_CALLED("slk_attroff(%s)"), _traceattr(attr))); if (SP != 0 && SP->_slk != 0) { - toggle_attr_off(SP->_slk->attr, attr); + 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/contrib/ncurses/ncurses/base/lib_slkatron.c b/contrib/ncurses/ncurses/base/lib_slkatron.c index d174b03..90add86 100644 --- a/contrib/ncurses/ncurses/base/lib_slkatron.c +++ b/contrib/ncurses/ncurses/base/lib_slkatron.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * 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 * @@ -27,8 +27,8 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * - * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * Author: Juergen Pfeifer, 1997 * + * and: Thomas E. Dickey 2005 * ****************************************************************************/ /* @@ -38,7 +38,7 @@ */ #include <curses.priv.h> -MODULE_ID("$Id: lib_slkatron.c,v 1.6 2000/12/10 02:43:27 tom Exp $") +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) @@ -46,7 +46,12 @@ slk_attron(const chtype attr) T((T_CALLED("slk_attron(%s)"), _traceattr(attr))); if (SP != 0 && SP->_slk != 0) { - toggle_attr_on(SP->_slk->attr, attr); + 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/contrib/ncurses/ncurses/base/lib_slkatrset.c b/contrib/ncurses/ncurses/base/lib_slkatrset.c index cda74ca..8da9981 100644 --- a/contrib/ncurses/ncurses/base/lib_slkatrset.c +++ b/contrib/ncurses/ncurses/base/lib_slkatrset.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * 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 * @@ -27,8 +27,8 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * - * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * Author: Juergen Pfeifer, 1997 * + * and: Thomas E. Dickey 2005 * ****************************************************************************/ /* @@ -38,7 +38,7 @@ */ #include <curses.priv.h> -MODULE_ID("$Id: lib_slkatrset.c,v 1.6 2000/12/10 02:43:27 tom Exp $") +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) @@ -46,7 +46,7 @@ slk_attrset(const chtype attr) T((T_CALLED("slk_attrset(%s)"), _traceattr(attr))); if (SP != 0 && SP->_slk != 0) { - SP->_slk->attr = attr; + SetAttr(SP->_slk->attr, attr); returnCode(OK); } else returnCode(ERR); diff --git a/contrib/ncurses/ncurses/base/lib_slkattr.c b/contrib/ncurses/ncurses/base/lib_slkattr.c index 5044a08..da82ee5 100644 --- a/contrib/ncurses/ncurses/base/lib_slkattr.c +++ b/contrib/ncurses/ncurses/base/lib_slkattr.c @@ -27,8 +27,8 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * - * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * Author: Juergen Pfeifer, 1997 * + * and: Thomas E. Dickey 2005 * ****************************************************************************/ /* @@ -38,7 +38,7 @@ */ #include <curses.priv.h> -MODULE_ID("$Id: lib_slkattr.c,v 1.5 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_slkattr.c,v 1.6 2005/01/08 21:44:28 tom Exp $") NCURSES_EXPORT(attr_t) slk_attr(void) @@ -46,7 +46,11 @@ slk_attr(void) T((T_CALLED("slk_attr()"))); if (SP != 0 && SP->_slk != 0) { - returnAttr(SP->_slk->attr); + 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/contrib/ncurses/ncurses/base/lib_slkclear.c b/contrib/ncurses/ncurses/base/lib_slkclear.c index 03e6721..99edcd5 100644 --- a/contrib/ncurses/ncurses/base/lib_slkclear.c +++ b/contrib/ncurses/ncurses/base/lib_slkclear.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -38,7 +38,7 @@ */ #include <curses.priv.h> -MODULE_ID("$Id: lib_slkclear.c,v 1.8 2001/12/19 01:07:01 tom Exp $") +MODULE_ID("$Id: lib_slkclear.c,v 1.9 2006/05/27 19:21:19 tom Exp $") NCURSES_EXPORT(int) slk_clear(void) @@ -51,7 +51,7 @@ slk_clear(void) /* For simulated SLK's it's looks much more natural to inherit those attributes from the standard screen */ SP->_slk->win->_nc_bkgd = stdscr->_nc_bkgd; - SP->_slk->win->_attrs = stdscr->_attrs; + WINDOW_ATTRS(SP->_slk->win) = WINDOW_ATTRS(stdscr); if (SP->_slk->win == stdscr) { returnCode(OK); } else { diff --git a/contrib/ncurses/ncurses/base/lib_slkcolor.c b/contrib/ncurses/ncurses/base/lib_slkcolor.c index 3e878e0..b677b65 100644 --- a/contrib/ncurses/ncurses/base/lib_slkcolor.c +++ b/contrib/ncurses/ncurses/base/lib_slkcolor.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * 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 * @@ -27,15 +27,18 @@ ****************************************************************************/ /**************************************************************************** - * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1998 * + * 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.7 2000/12/10 02:43:27 tom Exp $") +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) @@ -44,8 +47,9 @@ slk_color(short color_pair_number) if (SP != 0 && SP->_slk != 0 && color_pair_number >= 0 && color_pair_number < COLOR_PAIRS) { - T(("... current %ld", (long) PAIR_NUMBER(SP->_slk->attr))); - toggle_attr_on(SP->_slk->attr, COLOR_PAIR(color_pair_number)); + 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/contrib/ncurses/ncurses/base/lib_slklab.c b/contrib/ncurses/ncurses/base/lib_slklab.c index 0224e9b..42bb4ac 100644 --- a/contrib/ncurses/ncurses/base/lib_slklab.c +++ b/contrib/ncurses/ncurses/base/lib_slklab.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * 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 * @@ -38,7 +38,7 @@ */ #include <curses.priv.h> -MODULE_ID("$Id: lib_slklab.c,v 1.6 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_slklab.c,v 1.7 2003/03/29 22:53:48 tom Exp $") NCURSES_EXPORT(char *) slk_label(int n) @@ -47,5 +47,5 @@ slk_label(int n) if (SP == NULL || SP->_slk == NULL || n < 1 || n > SP->_slk->labcnt) returnPtr(0); - returnPtr(SP->_slk->ent[n - 1].text); + returnPtr(SP->_slk->ent[n - 1].ent_text); } diff --git a/contrib/ncurses/ncurses/base/lib_slkrefr.c b/contrib/ncurses/ncurses/base/lib_slkrefr.c index 18e5b0c..c8ca28b 100644 --- a/contrib/ncurses/ncurses/base/lib_slkrefr.c +++ b/contrib/ncurses/ncurses/base/lib_slkrefr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,8 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Juergen Pfeifer 1996-on * + * and: Thomas E. Dickey * ****************************************************************************/ /* @@ -38,7 +40,7 @@ #include <curses.priv.h> #include <term.h> /* num_labels, label_*, plab_norm */ -MODULE_ID("$Id: lib_slkrefr.c,v 1.10 2000/12/10 02:43:27 tom Exp $") +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. @@ -55,18 +57,18 @@ slk_intern_refresh(SLK * slk) if (num_labels > 0 && SLK_STDFMT(fmt)) { if (i < num_labels) { TPUTS_TRACE("plab_norm"); - putp(tparm(plab_norm, i + 1, slk->ent[i].form_text)); + putp(TPARM_2(plab_norm, i + 1, slk->ent[i].form_text)); } } else { - wmove(slk->win, SLK_LINES(fmt) - 1, slk->ent[i].x); - if (SP && SP->_slk) - wattrset(slk->win, SP->_slk->attr); - waddnstr(slk->win, slk->ent[i].form_text, - MAX_SKEY_LEN(fmt)); + 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, stdscr->_attrs); + wattrset(slk->win, WINDOW_ATTRS(stdscr)); } } slk->ent[i].dirty = FALSE; diff --git a/contrib/ncurses/ncurses/base/lib_slkset.c b/contrib/ncurses/ncurses/base/lib_slkset.c index d15002f..9379b36 100644 --- a/contrib/ncurses/ncurses/base/lib_slkset.c +++ b/contrib/ncurses/ncurses/base/lib_slkset.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -27,8 +27,8 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * - * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * Author: Juergen Pfeifer * + * and: Thomas E. Dickey * ****************************************************************************/ /* @@ -38,13 +38,22 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$Id: lib_slkset.c,v 1.7 2001/06/02 22:50:29 skimo Exp $") +#if USE_WIDEC_SUPPORT +#if HAVE_WCTYPE_H +#include <wctype.h> +#endif +#endif + +MODULE_ID("$Id: lib_slkset.c,v 1.16 2006/12/17 19:47:09 tom Exp $") NCURSES_EXPORT(int) slk_set(int i, const char *astr, int format) { SLK *slk = SP->_slk; - size_t len; + int offset; + int numchrs; + int numcols; + int limit; const char *str = astr; const char *p; @@ -54,44 +63,82 @@ slk_set(int i, const char *astr, int format) 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 */ - --i; /* Adjust numbering of labels */ + numcols = (p - str); + if (numcols > limit) + numcols = limit; + numchrs = numcols; +#endif - len = (size_t) (p - str); - if (len > (unsigned) slk->maxlen) - len = slk->maxlen; - if (len == 0) - slk->ent[i].text[0] = 0; - else - (void) strncpy(slk->ent[i].text, str, len); - memset(slk->ent[i].form_text, ' ', (unsigned) slk->maxlen); - slk->ent[i].text[slk->maxlen] = 0; - /* len = strlen(slk->ent[i].text); */ + 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 */ - memcpy(slk->ent[i].form_text, - slk->ent[i].text, - len); + offset = 0; break; case 1: /* centered */ - memcpy(slk->ent[i].form_text + (slk->maxlen - len) / 2, - slk->ent[i].text, - len); + offset = (limit - numcols) / 2; break; case 2: /* right-justified */ - memcpy(slk->ent[i].form_text + slk->maxlen - len, - slk->ent[i].text, - len); + offset = limit - numcols; break; } - slk->ent[i].form_text[slk->maxlen] = 0; + 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/contrib/ncurses/ncurses/base/lib_ungetch.c b/contrib/ncurses/ncurses/base/lib_ungetch.c index ba057c0..a6164df 100644 --- a/contrib/ncurses/ncurses/base/lib_ungetch.c +++ b/contrib/ncurses/ncurses/base/lib_ungetch.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -40,7 +40,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_ungetch.c,v 1.7 2001/12/29 23:01:09 tom Exp $") +MODULE_ID("$Id: lib_ungetch.c,v 1.8 2002/08/24 22:08:48 tom Exp $") #include <fifo_defs.h> @@ -58,7 +58,7 @@ _nc_fifo_dump(void) NCURSES_EXPORT(int) ungetch(int ch) { - T((T_CALLED("ungetch(%d)"), ch)); + T((T_CALLED("ungetch(%s)"), _tracechar(ch))); if (tail == -1) returnCode(ERR); @@ -70,7 +70,7 @@ ungetch(int ch) h_dec(); SP->_fifo[head] = ch; - T(("ungetch %#x ok", ch)); + T(("ungetch %s ok", _tracechar(ch))); #ifdef TRACE if (_nc_tracing & TRACE_IEVENT) _nc_fifo_dump(); diff --git a/contrib/ncurses/ncurses/base/lib_vline.c b/contrib/ncurses/ncurses/base/lib_vline.c index c19570b..1a2537e 100644 --- a/contrib/ncurses/ncurses/base/lib_vline.c +++ b/contrib/ncurses/ncurses/base/lib_vline.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -40,7 +40,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_vline.c,v 1.9 2001/06/03 00:39:24 skimo Exp $") +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) @@ -60,9 +60,9 @@ wvline(WINDOW *win, chtype ch, int n) end = win->_maxy; if (ch == 0) - SetChar(wch, ChCharOf(ACS_VLINE), ChAttrOf(ACS_VLINE)); + SetChar2(wch, ACS_VLINE); else - SetChar(wch, ChCharOf(ch), ChAttrOf(ch)); + SetChar2(wch, ch); wch = _nc_render(win, wch); while (end >= row) { diff --git a/contrib/ncurses/ncurses/base/lib_wattroff.c b/contrib/ncurses/ncurses/base/lib_wattroff.c index fa29b1a..bf2020e 100644 --- a/contrib/ncurses/ncurses/base/lib_wattroff.c +++ b/contrib/ncurses/ncurses/base/lib_wattroff.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -41,16 +42,22 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$Id: lib_wattroff.c,v 1.6 2000/12/10 02:43:28 tom Exp $") +MODULE_ID("$Id: lib_wattroff.c,v 1.9 2006/05/27 19:30:33 tom Exp $") NCURSES_EXPORT(int) -wattr_off -(WINDOW *win, NCURSES_CONST attr_t at, void *opts GCC_UNUSED) +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", _traceattr(win->_attrs))); - toggle_attr_off(win->_attrs, at); + 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/contrib/ncurses/ncurses/base/lib_wattron.c b/contrib/ncurses/ncurses/base/lib_wattron.c index 7bbc555..2e17d96 100644 --- a/contrib/ncurses/ncurses/base/lib_wattron.c +++ b/contrib/ncurses/ncurses/base/lib_wattron.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * 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 * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -41,16 +42,22 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$Id: lib_wattron.c,v 1.6 2000/12/10 02:43:28 tom Exp $") +MODULE_ID("$Id: lib_wattron.c,v 1.9 2006/05/27 19:30:46 tom Exp $") NCURSES_EXPORT(int) -wattr_on -(WINDOW *win, NCURSES_CONST attr_t at, void *opts GCC_UNUSED) +wattr_on(WINDOW *win, attr_t at, void *opts GCC_UNUSED) { T((T_CALLED("wattr_on(%p,%s)"), win, _traceattr(at))); - if (win) { - T(("... current %s", _traceattr(win->_attrs))); - toggle_attr_on(win->_attrs, 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/contrib/ncurses/ncurses/base/lib_window.c b/contrib/ncurses/ncurses/base/lib_window.c index 943f6e0..bb20f4f 100644 --- a/contrib/ncurses/ncurses/base/lib_window.c +++ b/contrib/ncurses/ncurses/base/lib_window.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -39,7 +39,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_window.c,v 1.18 2001/12/19 01:07:15 tom Exp $") +MODULE_ID("$Id: lib_window.c,v 1.22 2006/05/27 19:21:19 tom Exp $") NCURSES_EXPORT(void) _nc_synchook(WINDOW *win) @@ -178,55 +178,71 @@ NCURSES_EXPORT(WINDOW *) dupwin(WINDOW *win) /* make an exact duplicate of the given window */ { - WINDOW *nwin; + WINDOW *nwin = 0; size_t linesize; int i; T((T_CALLED("dupwin(%p)"), win)); - if ((win == NULL) || - ((nwin = newwin(win->_maxy + 1, win->_maxx + 1, win->_begy, - win->_begx)) == NULL)) - returnWin(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. - */ - - nwin->_attrs = win->_attrs; - nwin->_nc_bkgd = win->_nc_bkgd; - - nwin->_clear = win->_clear; - nwin->_scroll = win->_scroll; - nwin->_leaveok = win->_leaveok; - nwin->_use_keypad = win->_use_keypad; - nwin->_delay = win->_delay; - nwin->_immed = win->_immed; - nwin->_sync = win->_sync; - - 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; - - linesize = (win->_maxx + 1) * sizeof(chtype); - 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; - } + if (win != 0) { + + 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; + } + } + } returnWin(nwin); } diff --git a/contrib/ncurses/ncurses/base/resizeterm.c b/contrib/ncurses/ncurses/base/resizeterm.c index f454b20..46faccb 100644 --- a/contrib/ncurses/ncurses/base/resizeterm.c +++ b/contrib/ncurses/ncurses/base/resizeterm.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -27,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 * + * Author: Thomas E. Dickey * ****************************************************************************/ /* @@ -41,13 +41,191 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("$Id: resizeterm.c,v 1.13 2002/02/02 19:26:27 tom Exp $") +MODULE_ID("$Id: resizeterm.c,v 1.18 2006/10/14 20:43:31 tom Exp $") + +#define stolen_lines (screen_lines - SP->_lines_avail) + +static int current_lines; +static int current_cols; + +#ifdef TRACE +static void +show_window_sizes(const char *name) +{ + WINDOWLIST *wp; + + _tracef("%s resizing: %2d x %2d (%2d x %2d)", name, LINES, COLS, + screen_lines, screen_columns); + for (wp = _nc_windows; wp != 0; wp = wp->next) { + _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); + } +} +#endif NCURSES_EXPORT(bool) is_term_resized(int ToLines, int ToCols) { - return (ToLines != screen_lines - || ToCols != screen_columns); + T((T_CALLED("is_term_resized(%d, %d)"), ToLines, ToCols)); + returnCode(ToLines > 0 + && ToCols > 0 + && (ToLines != screen_lines + || ToCols != screen_columns)); +} + +/* + * 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 (wp = _nc_windows; wp != 0; wp = wp->next) { + 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) +{ + int result; + int bottom = current_lines + SP->_topstolen - stolen; + int myLines = win->_maxy + 1; + int myCols = win->_maxx + 1; + + T((T_CALLED("adjust_window(%p,%d,%d) currently %ldx%ld at %ld,%ld"), + win, ToLines, ToCols, + (long) getmaxy(win), (long) getmaxx(win), + (long) getbegy(win), (long) getbegx(win))); + + if (win->_begy >= bottom) { + win->_begy += (ToLines - current_lines); + } else { + if (myLines == current_lines - stolen + && ToLines != current_lines) + myLines = ToLines - stolen; + else if (myLines == current_lines + && ToLines != current_lines) + myLines = ToLines; + } + + if (myLines > ToLines) + myLines = ToLines; + + if (myCols > ToCols) + myCols = ToCols; + + if (myLines == current_lines + && ToLines != current_lines) + myLines = ToLines; + + if (myCols == current_cols + && ToCols != current_cols) + 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) +{ + 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 (wp = _nc_windows; wp != 0; wp = wp->next) { + WINDOW *win = &(wp->win); + + if (!(win->_flags & _ISPAD)) { + if (child_depth(win) == depth) { + found = TRUE; + if (adjust_window(win, ToLines, ToCols, stolen) != 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) +{ + 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 (wp = _nc_windows; wp != 0; wp = wp->next) { + WINDOW *win = &(wp->win); + + if (!(win->_flags & _ISPAD)) { + if (parent_depth(win) == depth) { + found = TRUE; + if (adjust_window(win, ToLines, ToCols, stolen) != OK) + returnCode(ERR); + } + } + } + ++depth; + } while (found); + returnCode(OK); } /* @@ -57,48 +235,42 @@ is_term_resized(int ToLines, int ToCols) NCURSES_EXPORT(int) resize_term(int ToLines, int ToCols) { - int stolen = screen_lines - SP->_lines_avail; - int bottom = screen_lines + SP->_topstolen - stolen; + int result = OK; + int was_stolen = (screen_lines - SP->_lines_avail); T((T_CALLED("resize_term(%d,%d) old(%d,%d)"), ToLines, ToCols, screen_lines, screen_columns)); if (is_term_resized(ToLines, ToCols)) { - WINDOWLIST *wp; + int myLines = current_lines = screen_lines; + int myCols = current_cols = screen_columns; - for (wp = _nc_windows; wp != 0; wp = wp->next) { - WINDOW *win = &(wp->win); - int myLines = win->_maxy + 1; - int myCols = win->_maxx + 1; - - /* pads aren't treated this way */ - if (win->_flags & _ISPAD) - continue; - - if (win->_begy >= bottom) { - win->_begy += (ToLines - screen_lines); - } else { - if (myLines == screen_lines - stolen - && ToLines != screen_lines) - myLines = ToLines - stolen; - else if (myLines == screen_lines - && ToLines != screen_lines) - myLines = ToLines; - } +#ifdef TRACE + if (_nc_tracing & TRACE_UPDATE) + show_window_sizes("before"); +#endif + if (ToLines > screen_lines) { + increase_size(myLines = ToLines, myCols, was_stolen); + current_lines = myLines; + current_cols = myCols; + } - if (myCols == screen_columns - && ToCols != screen_columns) - myCols = ToCols; + if (ToCols > screen_columns) { + increase_size(myLines, myCols = ToCols, was_stolen); + current_lines = myLines; + current_cols = myCols; + } - if (wresize(win, myLines, myCols) != OK) - returnCode(ERR); + if (ToLines < myLines || + ToCols < myCols) { + decrease_size(ToLines, ToCols, was_stolen); } screen_lines = lines = ToLines; screen_columns = columns = ToCols; - SP->_lines_avail = lines - stolen; + SP->_lines_avail = lines - was_stolen; if (SP->oldhash) { FreeAndNull(SP->oldhash); @@ -106,16 +278,23 @@ resize_term(int ToLines, int ToCols) if (SP->newhash) { FreeAndNull(SP->newhash); } +#ifdef TRACE + if (_nc_tracing & TRACE_UPDATE) { + LINES = ToLines - was_stolen; + COLS = ToCols; + show_window_sizes("after"); + } +#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. */ - LINES = ToLines - stolen; + LINES = ToLines - was_stolen; COLS = ToCols; - returnCode(OK); + returnCode(result); } /* diff --git a/contrib/ncurses/ncurses/base/safe_sprintf.c b/contrib/ncurses/ncurses/base/safe_sprintf.c index cb48365..81fe44f 100644 --- a/contrib/ncurses/ncurses/base/safe_sprintf.c +++ b/contrib/ncurses/ncurses/base/safe_sprintf.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * 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 * @@ -33,7 +33,7 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$Id: safe_sprintf.c,v 1.14 2001/07/08 00:58:34 tom Exp $") +MODULE_ID("$Id: safe_sprintf.c,v 1.18 2003/08/09 21:52:04 tom Exp $") #if USE_SAFE_SPRINTF @@ -56,10 +56,13 @@ _nc_printf_length(const char *fmt, va_list ap) char *buffer; char *format; int len = 0; + size_t fmt_len; + char fmt_arg[BUFSIZ]; if (fmt == 0 || *fmt == '\0') - return -1; - if ((format = typeMalloc(char, strlen(fmt) + 1)) == 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); @@ -106,7 +109,12 @@ _nc_printf_length(const char *fmt, va_list ap) } else if (state == Prec) { prec = ival; } - sprintf(&format[--f], "%d", 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; @@ -203,42 +211,52 @@ _nc_printf_length(const char *fmt, va_list ap) * 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) +_nc_printf_string(const char *fmt, va_list ap) { + static char *buf; + static size_t used; + char *result = 0; + + if (fmt != 0) { #if USE_SAFE_SPRINTF - char *buf = 0; - int len = _nc_printf_length(fmt, ap); + int len = _nc_printf_length(fmt, ap); - if (len > 0) { - if ((buf = typeMalloc(char, len + 1)) == 0) - return (0); - vsprintf(buf, fmt, ap); - } + if ((int) used < len + 1) { + used = 2 * (len + 1); + buf = typeRealloc(char, used, buf); + } + if (buf != 0) { + *buf = '\0'; + if (len >= 0) { + vsprintf(buf, fmt, ap); + } + result = buf; + } #else - static int rows, cols; - static char *buf; - static size_t len; - - if (screen_lines > rows || screen_columns > cols) { - if (screen_lines > rows) - rows = screen_lines; - if (screen_columns > cols) - cols = screen_columns; - len = (rows * (cols + 1)) + 1; - buf = typeRealloc(char, len, buf); - if (buf == 0) { - return (0); + static int rows, cols; + + if (screen_lines > rows || screen_columns > cols) { + if (screen_lines > rows) + rows = screen_lines; + if (screen_columns > cols) + cols = screen_columns; + used = (rows * (cols + 1)) + 1; + buf = typeRealloc(char, used, buf); } - } - if (buf != 0) { + if (buf != 0) { # if HAVE_VSNPRINTF - vsnprintf(buf, len, fmt, ap); /* GNU extension */ + vsnprintf(buf, used, fmt, ap); /* GNU extension */ # else - vsprintf(buf, fmt, ap); /* ANSI */ + vsprintf(buf, fmt, ap); /* ANSI */ # endif - } + result = buf; + } #endif - return buf; + } else if (buf != 0) { /* see _nc_freeall() */ + free(buf); + buf = 0; + used = 0; + } + return result; } diff --git a/contrib/ncurses/ncurses/base/sigaction.c b/contrib/ncurses/ncurses/base/sigaction.c index 8ba8629..36442e0 100644 --- a/contrib/ncurses/ncurses/base/sigaction.c +++ b/contrib/ncurses/ncurses/base/sigaction.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. * + * 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 * @@ -29,37 +29,29 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-2003 * ****************************************************************************/ -#include <curses.priv.h> - -#include <SigAction.h> - /* This file provides sigaction() emulation using sigvec() */ /* Use only if this is non POSIX system */ -#if !HAVE_SIGACTION && HAVE_SIGVEC +MODULE_ID("$Id: sigaction.c,v 1.14 2003/12/07 01:06:52 tom Exp $") -MODULE_ID("$Id: sigaction.c,v 1.13 2002/05/18 19:56:26 tom Exp $") - -NCURSES_EXPORT(int) -sigaction -(int sig, sigaction_t * sigact, sigaction_t * osigact) +static int +_nc_sigaction(int sig, sigaction_t * sigact, sigaction_t * osigact) { return sigvec(sig, sigact, osigact); } -NCURSES_EXPORT(int) -sigemptyset -(sigset_t * mask) +static int +_nc_sigemptyset(sigset_t * mask) { *mask = 0; return 0; } -NCURSES_EXPORT(int) -sigprocmask -(int mode, sigset_t * mask, sigset_t * omask) +static int +_nc_sigprocmask(int mode, sigset_t * mask, sigset_t * omask) { sigset_t current = sigsetmask(0); @@ -77,41 +69,31 @@ sigprocmask return 0; } -NCURSES_EXPORT(int) -sigsuspend(sigset_t * mask) +static int +_nc_sigaddset(sigset_t * mask, int sig) { - return sigpause(*mask); + *mask |= sigmask(sig); + return 0; } -NCURSES_EXPORT(int) -sigdelset -(sigset_t * mask, int sig) +/* not used in lib_tstp.c */ +#if 0 +static int +_nc_sigsuspend(sigset_t * mask) { - *mask &= ~sigmask(sig); - return 0; + return sigpause(*mask); } -NCURSES_EXPORT(int) -sigaddset -(sigset_t * mask, int sig) +static int +_nc_sigdelset(sigset_t * mask, int sig) { - *mask |= sigmask(sig); + *mask &= ~sigmask(sig); return 0; } -NCURSES_EXPORT(int) -sigismember -(sigset_t * mask, int sig) +static int +_nc_sigismember(sigset_t * mask, int sig) { return (*mask & sigmask(sig)) != 0; } - -#else -extern -NCURSES_EXPORT(void) -_nc_sigaction(void); /* quiet's gcc warning */ -NCURSES_EXPORT(void) -_nc_sigaction(void) -{ -} /* nonempty for strict ANSI compilers */ #endif diff --git a/contrib/ncurses/ncurses/base/tries.c b/contrib/ncurses/ncurses/base/tries.c index fe7d93e..4edb731 100644 --- a/contrib/ncurses/ncurses/base/tries.c +++ b/contrib/ncurses/ncurses/base/tries.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * 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 * @@ -39,15 +39,14 @@ #include <curses.priv.h> -MODULE_ID("$Id: tries.c,v 1.15 2001/12/16 00:50:40 tom Exp $") +MODULE_ID("$Id: tries.c,v 1.22 2005/11/26 20:09:18 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 -(struct tries *tree, unsigned short code, int *count, size_t len) +_nc_expand_try(struct tries *tree, unsigned code, int *count, size_t len) { struct tries *ptr = tree; char *result = 0; @@ -72,7 +71,7 @@ _nc_expand_try if ((result[len] = ptr->ch) == 0) *((unsigned char *) (result + len)) = 128; #ifdef TRACE - if (len == 0) + if (len == 0 && _nc_tracing != 0) _tracef("expand_key %s %s", _tracechar(code), _nc_visbuf(result)); #endif } @@ -84,8 +83,7 @@ _nc_expand_try * true if the code was found/removed. */ NCURSES_EXPORT(int) -_nc_remove_key -(struct tries **tree, unsigned short code) +_nc_remove_key(struct tries **tree, unsigned code) { T((T_CALLED("_nc_remove_key(%p,%d)"), tree, code)); @@ -117,7 +115,7 @@ _nc_remove_key * true if the string was found/removed. */ NCURSES_EXPORT(int) -_nc_remove_string(struct tries **tree, char *string) +_nc_remove_string(struct tries **tree, const char *string) { T((T_CALLED("_nc_remove_string(%p,%s)"), tree, _nc_visbuf(string))); @@ -125,18 +123,17 @@ _nc_remove_string(struct tries **tree, char *string) returnCode(FALSE); while (*tree != 0) { - if ((unsigned char) (*tree)->ch == (unsigned char) *string) { + if (UChar((*tree)->ch) == UChar(*string)) { if (string[1] != 0) returnCode(_nc_remove_string(&(*tree)->child, string + 1)); - if ((*tree)->child) { - /* don't cut the whole sub-tree */ - (*tree)->value = 0; - } else { + if ((*tree)->child == 0) { struct tries *to_free = *tree; *tree = (*tree)->sibling; free(to_free); + returnCode(TRUE); + } else { + returnCode(FALSE); } - returnCode(TRUE); } tree = &(*tree)->sibling; } diff --git a/contrib/ncurses/ncurses/base/version.c b/contrib/ncurses/ncurses/base/version.c index b78c99d..ef83967 100644 --- a/contrib/ncurses/ncurses/base/version.c +++ b/contrib/ncurses/ncurses/base/version.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1999,2000 Free Software Foundation, Inc. * + * 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 * @@ -32,16 +32,11 @@ #include <curses.priv.h> -MODULE_ID("$Id: version.c,v 1.4 2000/12/10 02:43:28 tom Exp $") +MODULE_ID("$Id: version.c,v 1.6 2005/01/02 01:23:54 tom Exp $") NCURSES_EXPORT(const char *) curses_version(void) { - static char my_version[80]; - T((T_CALLED("curses_version()"))); - sprintf(my_version, "ncurses %s.%d", - NCURSES_VERSION, - NCURSES_VERSION_PATCH); - returnPtr(my_version); + returnCPtr("ncurses " NCURSES_VERSION_STRING); } diff --git a/contrib/ncurses/ncurses/base/vsscanf.c b/contrib/ncurses/ncurses/base/vsscanf.c index 65794b7..e6253c3 100644 --- a/contrib/ncurses/ncurses/base/vsscanf.c +++ b/contrib/ncurses/ncurses/base/vsscanf.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001,2002 Free Software Foundation, Inc. * + * 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 * @@ -38,7 +38,7 @@ #if !HAVE_VSSCANF -MODULE_ID("$Id: vsscanf.c,v 1.15 2002/02/03 00:49:45 tom Exp $") +MODULE_ID("$Id: vsscanf.c,v 1.18 2004/04/03 20:27:02 tom Exp $") #if !(HAVE_VFSCANF || HAVE__DOSCAN) @@ -210,7 +210,8 @@ vsscanf(const char *str, const char *format, va_list ap) if (can_convert) { size_t len_fmt = strlen(format) + 32; char *my_fmt = malloc(len_fmt); - ChunkType other, chunk, check; + ChunkType chunk, ctest; + OtherType other, otest; ScanState state; unsigned n; int eaten; @@ -229,7 +230,7 @@ vsscanf(const char *str, const char *format, va_list ap) /* find a chunk */ state = sUnknown; chunk = cUnknown; - other = cUnknown; + other = oUnknown; pointer = 0; for (n = 0; format[n] != 0 && state != sFinal; ++n) { my_fmt[n] = format[n]; @@ -265,12 +266,12 @@ vsscanf(const char *str, const char *format, va_list ap) if (format[n] == '*') { state = sUnknown; } else { - if ((check = final_ch(format[n], other)) != cUnknown) { + if ((ctest = final_ch(format[n], other)) != cUnknown) { state = sFinal; - chunk = check; - } else if ((check = other_ch(format[n])) != oUnknown) { - other = check; - } else if (isalpha(format[n])) { + chunk = ctest; + } else if ((otest = other_ch(format[n])) != oUnknown) { + other = otest; + } else if (isalpha(UChar(format[n]))) { state = sFinal; chunk = cError; } diff --git a/contrib/ncurses/ncurses/base/wresize.c b/contrib/ncurses/ncurses/base/wresize.c index fa97a2b..ca6336d 100644 --- a/contrib/ncurses/ncurses/base/wresize.c +++ b/contrib/ncurses/ncurses/base/wresize.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. * + * 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 * @@ -27,38 +27,75 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 * + * Author: Thomas E. Dickey 1996-2002 * ****************************************************************************/ #include <curses.priv.h> -MODULE_ID("$Id: wresize.c,v 1.21 2002/05/11 19:36:29 tom Exp $") +MODULE_ID("$Id: wresize.c,v 1.24 2006/10/14 20:43:31 tom Exp $") + +static int +cleanup_lines(struct ldat *data, int length) +{ + while (--length >= 0) + free(data->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; + + for (wp = _nc_windows; wp != 0; wp = wp->next) { + 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); + } + } +} /* * 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. */ - -#define DOALLOC(p,t,n) typeRealloc(t, n, p) -#define ld_ALLOC(p,n) DOALLOC(p,struct ldat,n) -#define c_ALLOC(p,n) DOALLOC(p,NCURSES_CH_T,n) - NCURSES_EXPORT(int) wresize(WINDOW *win, int ToLines, int ToCols) { - register int row; - int size_x, size_y; + int col, row, size_x, size_y; struct ldat *pline; - NCURSES_CH_T blank; + struct ldat *new_lines = 0; #ifdef TRACE T((T_CALLED("wresize(%p,%d,%d)"), win, ToLines, ToCols)); if (win) { - TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)", - win->_begy, win->_begx, - win->_maxy, win->_maxx, - win->_regtop, win->_regbottom)); + 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 (_nc_tracing & TRACE_UPDATE) _tracedump("...before", win); } @@ -90,67 +127,83 @@ wresize(WINDOW *win, int ToLines, int ToCols) } /* - * If the number of lines has changed, adjust the size of the overall - * vector: + * 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. */ - if (ToLines != size_y) { - if (!(win->_flags & _SUBWIN)) { - for (row = ToLines + 1; row <= size_y; row++) - free((char *) (win->_line[row].text)); - } - - win->_line = ld_ALLOC(win->_line, ToLines + 1); - if (win->_line == 0) - returnCode(ERR); - - for (row = size_y + 1; row <= ToLines; row++) { - win->_line[row].text = 0; - win->_line[row].firstchar = 0; - win->_line[row].lastchar = ToCols; - if ((win->_flags & _SUBWIN)) { - win->_line[row].text = - &pline[win->_pary + row].text[win->_parx]; - } - } - } + new_lines = typeCalloc(struct ldat, (unsigned) (ToLines + 1)); + if (new_lines == 0) + returnCode(ERR); /* - * Adjust the width of the columns: + * For each line in the target, allocate or adjust pointers for the + * corresponding text, depending on whether this is a window or a + * subwindow. */ - blank = win->_nc_bkgd; - for (row = 0; row <= ToLines; row++) { - NCURSES_CH_T *s = win->_line[row].text; - int begin = (s == 0) ? 0 : size_x + 1; + for (row = 0; row <= ToLines; ++row) { + int begin = (row > size_y) ? 0 : (size_x + 1); int end = ToCols; + NCURSES_CH_T *s; - if_USE_SCROLL_HINTS(win->_line[row].oldindex = row); - - if (ToCols != size_x || s == 0) { - if (!(win->_flags & _SUBWIN)) { - win->_line[row].text = s = c_ALLOC(s, ToCols + 1); - if (win->_line[row].text == 0) - returnCode(ERR); + 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 { - win->_line[row].text = s = - &pline[win->_pary + row].text[win->_parx]; + 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 (win->_line[row].firstchar < begin) - win->_line[row].firstchar = begin; - if (!(win->_flags & _SUBWIN)) { - do { - s[end] = blank; - } while (--end >= begin); - } + if (new_lines[row].firstchar < begin) + new_lines[row].firstchar = begin; } else { /* shrinking */ - win->_line[row].firstchar = 0; + new_lines[row].firstchar = 0; } - win->_line[row].lastchar = ToCols; + 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: */ @@ -168,11 +221,17 @@ wresize(WINDOW *win, int ToLines, int ToCols) 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 (%d, %d), max(%d,%d), reg(%d,%d)", - win->_begy, win->_begx, - win->_maxy, win->_maxx, - win->_regtop, win->_regbottom)); + 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 (_nc_tracing & TRACE_UPDATE) _tracedump("...after:", win); #endif |