diff options
author | Rong-En Fan <rafan@FreeBSD.org> | 2007-01-20 07:32:02 +0000 |
---|---|---|
committer | Rong-En Fan <rafan@FreeBSD.org> | 2007-01-20 07:32:02 +0000 |
commit | 4a1a95108dd76c4259fe6c37c4471f7969b17983 (patch) | |
tree | 1c6c3b549401156e1dbd96b9a6b18521f63ffb58 /contrib/ncurses/ncurses | |
parent | 555c9cae3cf9146482732c28c06a73314b618149 (diff) | |
download | src-4a1a95108dd76c4259fe6c37c4471f7969b17983.tar.gz src-4a1a95108dd76c4259fe6c37c4471f7969b17983.zip |
Import ncurses 5.6-20061217 onto the vender branch
Approved by: delphij
Notes
Notes:
svn path=/vendor/ncurses/dist/; revision=166124
Diffstat (limited to 'contrib/ncurses/ncurses')
155 files changed, 11083 insertions, 4927 deletions
diff --git a/contrib/ncurses/ncurses/Makefile.in b/contrib/ncurses/ncurses/Makefile.in index 9b9a39eb173c..ce35c0340195 100644 --- a/contrib/ncurses/ncurses/Makefile.in +++ b/contrib/ncurses/ncurses/Makefile.in @@ -1,6 +1,6 @@ -# $Id: Makefile.in,v 1.83 2002/04/20 22:02:39 tom Exp $ +# $Id: Makefile.in,v 1.101 2006/10/14 19:08:11 tom Exp $ ############################################################################## -# Copyright (c) 1998,1999,2000,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"), # @@ -27,7 +27,7 @@ # authorization. # ############################################################################## # -# Author: Thomas E. Dickey 1996-2001 +# Author: Thomas E. Dickey 1996-on # # Makefile for ncurses source code. # @@ -48,11 +48,12 @@ SHELL = /bin/sh THIS = Makefile -x = @PROG_EXT@ - CF_MFLAGS = @cf_cv_makeflags@ @SET_MAKE@ +x = @EXEEXT@ +o = .@OBJEXT@ + MODEL = @DFT_LWR_MODEL@ DESTDIR = @DESTDIR@ top_srcdir = @top_srcdir@ @@ -65,10 +66,15 @@ includedir = @includedir@ datadir = @datadir@ LIBTOOL = @LIBTOOL@ +LIBTOOL_CLEAN = @LIB_CLEAN@ +LIBTOOL_COMPILE = @LIB_COMPILE@ +LIBTOOL_LINK = @LIB_LINK@ +LIBTOOL_INSTALL = @LIB_INSTALL@ +LIBTOOL_UNINSTALL = @LIB_UNINSTALL@ INSTALL = @INSTALL@ INSTALL_LIB = @INSTALL@ @INSTALL_LIB@ -INSTALL_PROG = @INSTALL_PROG@ +INSTALL_PROG = @INSTALL_PROGRAM@ INSTALL_DATA = @INSTALL_DATA@ AR = @AR@ @@ -82,15 +88,21 @@ CPP = @CPP@ CFLAGS = @CFLAGS@ INCDIR = $(srcdir)/../include -CPPFLAGS = -I../ncurses -I$(srcdir) @CPPFLAGS@ \ - -DHAVE_CONFIG_H +CPPFLAGS = -DHAVE_CONFIG_H -I../ncurses -I$(srcdir) @CPPFLAGS@ CCFLAGS = $(CPPFLAGS) $(CFLAGS) -HOSTCC = @BUILD_CC@ -HOSTCCFLAGS = @BUILD_CFLAGS@ $(CPPFLAGS) -HOSTLDFLAGS = @BUILD_LDFLAGS@ -HOSTLIBS = @BUILD_LIBS@ +BUILD_CPPFLAGS = -I../include @BUILD_CPPFLAGS@ +BUILD_CC = @BUILD_CC@ +BUILD_CCFLAGS = -DHAVE_CONFIG_H -I../ncurses -I$(srcdir) -I$(INCDIR) $(BUILD_CPPFLAGS) @BUILD_CFLAGS@ +BUILD_LDFLAGS = @BUILD_LDFLAGS@ +BUILD_LIBS = @BUILD_LIBS@ + +# The executables built in this directory are used for generating source that +# is compiled into the build, or are test-programs that are not installed. + +BUILD_EXEEXT = @BUILD_EXEEXT@ +x = @PROG_EXT@ CFLAGS_LIBTOOL = $(CCFLAGS) CFLAGS_NORMAL = $(CCFLAGS) @@ -114,7 +126,7 @@ NCURSES_MINOR = @NCURSES_MINOR@ REL_VERSION = @cf_cv_rel_version@ ABI_VERSION = @cf_cv_abi_version@ -RANLIB = @RANLIB@ +RANLIB = @LIB_PREP@ IMPORT_LIB = @IMPORT_LIB@ SHARED_LIB = @SHARED_LIB@ @@ -129,22 +141,22 @@ FALLBACK_LIST = @FALLBACK_LIST@ TERMINFO_CAPS = $(top_srcdir)/include/@TERMINFO_CAPS@ AUTO_SRC = \ - ../include/nomacros.h \ - codes.c \ - comp_captab.c \ - expanded.c \ - fallback.c \ + ./codes.c \ + ./comp_captab.c \ + ./expanded.c \ + ./fallback.c \ + ./lib_gen.c \ + ./lib_keyname.c \ + ./link_test.c \ + ./names.c \ + ./unctrl.c \ init_keytry.h \ keys.list \ - lib_gen.c \ - lib_keyname.c \ - link_test.c \ - names.c \ - unctrl.c + names-stamp TEST_DEPS = ../lib/@LIB_PREFIX@ncurses@DFT_DEP_SUFFIX@ TEST_ARGS = -L../lib -lncurses@DFT_ARG_SUFFIX@ -TEST_LDFLAGS = @LD_MODEL@ $(TEST_ARGS) @LIBS@ @EXTRA_LIBS@ @LOCAL_LDFLAGS@ @LDFLAGS@ +TEST_LDFLAGS = @LD_MODEL@ $(TEST_ARGS) @LIBS@ @LOCAL_LDFLAGS@ @LDFLAGS@ TEST_PROGS = \ captoinfo$x \ @@ -171,58 +183,61 @@ $(DESTDIR)$(libdir) : ../lib : ; mkdir $@ -fallback.c : $(tinfo)/MKfallback.sh +./fallback.c : $(tinfo)/MKfallback.sh sh $(tinfo)/MKfallback.sh @TERMINFO@ @TERMINFO_SRC@ $(FALLBACK_LIST) >$@ -lib_gen.c : $(base)/MKlib_gen.sh ../include/curses.h +./lib_gen.c : $(base)/MKlib_gen.sh ../include/curses.h sh $(base)/MKlib_gen.sh "$(CPP) $(CPPFLAGS)" "$(AWK)" generated <../include/curses.h >$@ -../include/nomacros.h : $(base)/MKlib_gen.sh ../include/curses.h - sh $(base)/MKlib_gen.sh "$(CPP) $(CPPFLAGS)" "$(AWK)" generated <../include/curses.h | \ - fgrep undef >$@ - -init_keytry.h: make_keys$x keys.list - ./make_keys keys.list > $@ +init_keytry.h: make_keys$(BUILD_EXEEXT) keys.list + ./make_keys$(BUILD_EXEEXT) keys.list > $@ keys.list : $(tinfo)/MKkeys_list.sh AWK=$(AWK) sh $(tinfo)/MKkeys_list.sh $(TERMINFO_CAPS) | sort >$@ -make_keys$x : \ +make_keys$(BUILD_EXEEXT) : \ $(tinfo)/make_keys.c \ - names.c - $(HOSTCC) -o $@ $(HOSTCCFLAGS) $(tinfo)/make_keys.c $(HOSTLDFLAGS) $(HOSTLIBS) + names-stamp + $(BUILD_CC) -o $@ $(BUILD_CCFLAGS) $(tinfo)/make_keys.c $(BUILD_LDFLAGS) $(BUILD_LIBS) -make_hash$x : \ +make_hash$(BUILD_EXEEXT) : \ $(tinfo)/comp_hash.c \ ../include/hashsize.h - $(HOSTCC) -o $@ $(HOSTCCFLAGS) -DMAIN_PROGRAM $(tinfo)/comp_hash.c $(HOSTLDFLAGS) $(HOSTLIBS) + $(BUILD_CC) -o $@ $(BUILD_CCFLAGS) -DMAIN_PROGRAM $(tinfo)/comp_hash.c $(BUILD_LDFLAGS) $(BUILD_LIBS) -expanded.c : $(serial)/MKexpanded.sh +./expanded.c : $(serial)/MKexpanded.sh sh $(serial)/MKexpanded.sh "$(CPP)" $(CPPFLAGS) > $@ -comp_captab.c: \ - make_hash$x \ +./comp_captab.c: \ + make_hash$(BUILD_EXEEXT) \ ../include/hashsize.h \ $(tinfo)/MKcaptab.awk sh $(tinfo)/MKcaptab.awk $(AWK) $(srcdir)/../include/@TERMINFO_CAPS@ > $@ -lib_keyname.c: keys.list $(base)/MKkeyname.awk +./lib_keyname.c: keys.list $(base)/MKkeyname.awk $(AWK) -f $(base)/MKkeyname.awk keys.list > $@ -names.c codes.c: $(tinfo)/MKnames.awk +names-stamp: $(tinfo)/MKnames.awk $(AWK) -f $(tinfo)/MKnames.awk $(srcdir)/../include/@TERMINFO_CAPS@ cat namehdr boolnames boolfnames numnames numfnames strnames strfnames nameftr >names.c cat namehdr boolcodes numcodes strcodes codeftr >codes.c -rm -f namehdr nameftr codeftr boolnames boolfnames boolcodes numnames numfnames numcodes strnames strfnames strcodes + @echo >$@ + +./names.c: names-stamp + @echo made $@ + +./codes.c: names-stamp + @echo made $@ -unctrl.c: $(base)/MKunctrl.awk +./unctrl.c: $(base)/MKunctrl.awk echo | $(AWK) -f $(base)/MKunctrl.awk >$@ tags: - ctags *.[ch] + ctags *.[ch] */*.[ch] @MAKE_UPPER_TAGS@TAGS: -@MAKE_UPPER_TAGS@ etags *.[ch] +@MAKE_UPPER_TAGS@ etags *.[ch] */*.[ch] mostlyclean :: -rm -f core tags TAGS *~ *.bak *.i *.ln *.atac trace @@ -230,8 +245,8 @@ mostlyclean :: clean :: mostlyclean -rm -f $(AUTO_SRC) - -rm -f make_keys$x - -rm -f make_hash$x + -rm -f make_keys$(BUILD_EXEEXT) + -rm -f make_hash$(BUILD_EXEEXT) -rm -rf .libs distclean :: clean @@ -248,7 +263,7 @@ realclean :: distclean # These rules build test-programs for the modules that have test-drivers test_progs : $(TEST_PROGS) -link_test.c : $(base)/MKlib_gen.sh ../include/curses.h +./link_test.c : $(base)/MKlib_gen.sh ../include/curses.h sh $(base)/MKlib_gen.sh "$(CPP) $(CPPFLAGS)" "$(AWK)" implemented <../include/curses.h >$@ captoinfo$x : $(tinfo)/captoinfo.c $(TEST_DEPS) @@ -261,15 +276,15 @@ hashmap$x : $(serial)/hashmap.c $(TEST_DEPS) @ECHO_LINK@ $(CC) -o $@ $(CFLAGS_DEFAULT) -DHASHDEBUG $(serial)/hashmap.c $(TEST_LDFLAGS) lib_mvcur$x : $(serial)/lib_mvcur.c $(TEST_DEPS) \ - ../@DFT_OBJ_SUBDIR@/dump_entry.o - @ECHO_LINK@ $(CC) -o $@ $(CFLAGS_DEFAULT) -DNCURSES_TEST -I$(serial)/../../progs $(serial)/lib_mvcur.c ../@DFT_OBJ_SUBDIR@/dump_entry.o $(TEST_LDFLAGS) + ../@DFT_OBJ_SUBDIR@/dump_entry$o + @ECHO_LINK@ $(CC) -o $@ $(CFLAGS_DEFAULT) -DNCURSES_TEST -I$(serial)/../../progs $(serial)/lib_mvcur.c ../@DFT_OBJ_SUBDIR@/dump_entry$o $(TEST_LDFLAGS) -link_test$x : link_test.c $(TEST_DEPS) \ - ../@DFT_OBJ_SUBDIR@/link_test.o - @ECHO_LINK@ $(CC) -o $@ $(CFLAGS_DEFAULT) ../@DFT_OBJ_SUBDIR@/link_test.o $(TEST_LDFLAGS) +link_test$x : ./link_test.c $(TEST_DEPS) \ + ../@DFT_OBJ_SUBDIR@/link_test$o + @ECHO_LINK@ $(CC) -o $@ $(CFLAGS_DEFAULT) ../@DFT_OBJ_SUBDIR@/link_test$o $(TEST_LDFLAGS) -../@DFT_OBJ_SUBDIR@/dump_entry.o: - cd ../progs && $(MAKE) ../@DFT_OBJ_SUBDIR@/dump_entry.o +../@DFT_OBJ_SUBDIR@/dump_entry$o: + cd ../progs && $(MAKE) ../@DFT_OBJ_SUBDIR@/dump_entry$o ############################################################################### # The remainder of this file is automatically generated during configuration diff --git a/contrib/ncurses/ncurses/README b/contrib/ncurses/ncurses/README index 20c94d3c2895..120aa5b82c1d 100644 --- a/contrib/ncurses/ncurses/README +++ b/contrib/ncurses/ncurses/README @@ -1,2 +1,31 @@ +------------------------------------------------------------------------------- +-- Copyright (c) 1998-2000,2006 Free Software Foundation, Inc. -- +-- -- +-- Permission is hereby granted, free of charge, to any person obtaining a -- +-- copy of this software and associated documentation files (the -- +-- "Software"), to deal in the Software without restriction, including -- +-- without limitation the rights to use, copy, modify, merge, publish, -- +-- distribute, distribute with modifications, sublicense, and/or sell copies -- +-- of the Software, and to permit persons to whom the Software is furnished -- +-- to do so, subject to the following conditions: -- +-- -- +-- The above copyright notice and this permission notice shall be included -- +-- in all copies or substantial portions of the Software. -- +-- -- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -- +-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- +-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -- +-- NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -- +-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- +-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -- +-- USE OR OTHER DEALINGS IN THE SOFTWARE. -- +-- -- +-- Except as contained in this notice, the name(s) of the above copyright -- +-- holders shall not be used in advertising or otherwise to promote the -- +-- sale, use or other dealings in this Software without prior written -- +-- authorization. -- +------------------------------------------------------------------------------- +-- $Id: README,v 1.9 2006/04/22 22:19:37 tom Exp $ +------------------------------------------------------------------------------- For discussion of the package internals, see hackguide.html in the doc/html directory. diff --git a/contrib/ncurses/ncurses/README.IZ b/contrib/ncurses/ncurses/README.IZ new file mode 100644 index 000000000000..78206cdfd712 --- /dev/null +++ b/contrib/ncurses/ncurses/README.IZ @@ -0,0 +1,95 @@ +------------------------------------------------------------------------------- +-- Copyright (c) 2002,2006 Free Software Foundation, Inc. -- +-- -- +-- Permission is hereby granted, free of charge, to any person obtaining a -- +-- copy of this software and associated documentation files (the -- +-- "Software"), to deal in the Software without restriction, including -- +-- without limitation the rights to use, copy, modify, merge, publish, -- +-- distribute, distribute with modifications, sublicense, and/or sell copies -- +-- of the Software, and to permit persons to whom the Software is furnished -- +-- to do so, subject to the following conditions: -- +-- -- +-- The above copyright notice and this permission notice shall be included -- +-- in all copies or substantial portions of the Software. -- +-- -- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -- +-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- +-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -- +-- NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -- +-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- +-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -- +-- USE OR OTHER DEALINGS IN THE SOFTWARE. -- +-- -- +-- Except as contained in this notice, the name(s) of the above copyright -- +-- holders shall not be used in advertising or otherwise to promote the -- +-- sale, use or other dealings in this Software without prior written -- +-- authorization. -- +------------------------------------------------------------------------------- +-- $Id: README.IZ,v 1.2 2006/04/22 23:13:05 tom Exp $ +--------------------------------------------------------------------- + +Here is the patch. I did no testing whatsoever with event watching +requests present (I need some applications which exersize this before +this, probably lynx ;-), but the code looks working "the normal way". + +I had no way to test that the poll() branch compiles/works... + +Here is the API: + +*) two new functions wgetch_events() wgetstrn_event() are introduced, + which allow an event-watch specification given as the last argument; + +*) if the last argument is NULL, they behave as wgetch() and + wgetstrn() (TESTED!); + +*) the event specification is a pointer to _nc_eventlist, which + contains bookkeeping elements (count and the summary of results), + and an array of pointers to _nc_event; + +*) each _nc_event is a typed union, with two types supported "as + shipped": _NC_EVENT_TIMEOUT_MSEC, _NC_EVENT_FILE. For + _NC_EVENT_FILE the fields are fd, flag, and the output field. + +*) The only supported flag "as shipped" is _NC_EVENT_FILE_READABLE. + If the file was found readable, the return field is set to this, + otherwise to 0; + +*) If these functions return KEY_EVENT, this means that the return + fields in both the _nc_eventlist and _nc_event structures make + sense. The field result_flags of _nc_eventlist may have a + combination of bits _NC_EVENT_TIMEOUT_MSEC and _NC_EVENT_FILE_READABLE + set; + +*) The timeout_msec field of _NC_EVENT_TIMEOUT_MSEC _nc_event's is + updated on return, even if the return is not KEY_EVENT. However, + the change in the value represents only the amount of time spent in + waiting for events, not the amount of time spent bookkeeping; + +*) the return KEY_EVENT of wgetstrn_event() means that the output + string includes the user input typed so far, but the user did not have + a chance to press ENTER (or whatever). This call should be + repeated (with "shifted" pointer to a buffer, of course) to + complete the input; + +*) The presence of this extension can be checked via inspecting + #ifdef NCURSES_EVENT_VERSION. This symbol is not defined on BeOS, + since there is no support for this on BeOS. + +Known issues: calls interrupted by KEY_EVENT reset the ESCDELAY +timer. This is not entirely new, since other synthetic events behave +the same (see "if (ch >= KEY_MIN)" branch of kgetch()). However, +KEY_EVENT may be generated in a continuous stream (say, when +downloading a file), thus this may be more important than with other +synthetic keys. An additional field in window structure which keeps +timestamp of the first raw key in the queue may be needed to +circumvent this. + +Another possible issue: KEY_EVENT has a preference over a user input, +so a stream of KEY_EVENT's can make input hard. Maybe use +result_flags as in input parameter too, which specifies whether the +user input should have higher precedence? + +Also: I took an opportunity to document kgetch() better. + +Enjoy, +Ilya diff --git a/contrib/ncurses/ncurses/SigAction.h b/contrib/ncurses/ncurses/SigAction.h index 53d12bfd42bc..5dfde643f6a1 100644 --- a/contrib/ncurses/ncurses/SigAction.h +++ b/contrib/ncurses/ncurses/SigAction.h @@ -32,7 +32,7 @@ ****************************************************************************/ /* - * $Id: SigAction.h,v 1.6 2000/12/10 02:36:10 tom Exp $ + * $Id: SigAction.h,v 1.8 2005/08/06 20:05:32 tom Exp $ * * This file exists to handle non-POSIX systems which don't have <unistd.h>, * and usually no sigaction() nor <termios.h> @@ -59,10 +59,6 @@ typedef struct sigaction sigaction_t; #if HAVE_SIGVEC -#if HAVE_LIBC_H -#include <libc.h> -#endif - #undef SIG_BLOCK #define SIG_BLOCK 00 @@ -105,12 +101,8 @@ typedef unsigned long sigset_t; #undef sigaddset #define sigaddset _nc_sigaddset -extern NCURSES_EXPORT(int) sigaction (int sig, sigaction_t * sigact, sigaction_t * osigact); -extern NCURSES_EXPORT(int) sigprocmask (int how, sigset_t *mask, sigset_t *omask); -extern NCURSES_EXPORT(int) sigemptyset (sigset_t *mask); -extern NCURSES_EXPORT(int) sigsuspend (sigset_t *mask); -extern NCURSES_EXPORT(int) sigdelset (sigset_t *mask, int sig); -extern NCURSES_EXPORT(int) sigaddset (sigset_t *mask, int sig); +/* tty/lib_tstp.c is the only user */ +#include <base/sigaction.c> #endif /* HAVE_SIGVEC */ #endif /* HAVE_SIGACTION */ diff --git a/contrib/ncurses/ncurses/base/MKkeyname.awk b/contrib/ncurses/ncurses/base/MKkeyname.awk index b8cd5da256a2..11dcfe5c2375 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 e172feb3baaf..30c44fff6f83 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 d8a6587e2c69..e153fa8c95c4 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 ffa16963e9e3..4677e42e6176 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 7fc885f8d9b3..3b5299a338e4 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 000000000000..dac188748770 --- /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 c8ca2856bb97..2995714ba936 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 e3b4be297c17..4c9950600c33 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 000000000000..1c2f160a605d --- /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 423a45e6abe4..9d73edfde5de 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 343555a39aff..b7a0b40ef948 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 c23d0a1d2ff1..b478f251a1bb 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 a3d7c306e29d..e6a0cb000b15 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 7181edb3ed34..d6cfc6cfe09c 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 54e66ed1ffae..89eefa7e82fe 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 bc12960e48f0..df196e815f82 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 42d301d5e9ad..a90ca9d34308 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 b496c78c9e39..a973c5350c8f 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 24705c9615e9..8953c148b09e 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 5e397312ffe3..2566e8b39820 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 2063c6fa593e..27897a9f6a2a 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 af1be33a18d5..7891edf3b079 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 cd58f1821a7f..274e87887371 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 2cb6cc5ce6fd..2ef2cc585e10 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 832da742f47b..d2ae281972a9 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 c3671e5d235b..b8a856df3a82 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 432bcace9e6a..342c6541f95f 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 000000000000..b6ddfde3c52b --- /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 3eaf9892b45b..809952fdf82f 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 69af58d5fe24..f30232795be4 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 e917eb780525..652c44d7b718 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 63d54ccda574..e4dad4a746f0 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 d95c4a9575c8..fe201d6b8e27 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 3cd8238b1e2e..ba516337b996 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 010e6d18c861..9ecc45821591 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 83983c3bbd1c..6cad9c54b064 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 f821a96ba7f0..62ae921e650d 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 91a03711de7c..548ca97e24c4 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 42c1f496c10a..27649df0669a 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 0068554cecb1..ca27a0fc4c60 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 3b2d9296a59a..5d67e1993cd9 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 39c62d0850e5..ac85bd55ea1d 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 f3940fa03c1c..bcc42d12298c 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 020449383e6c..5609e3b59024 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 5df314c6dca8..f83616beaf17 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 c271c342101a..14b4c3bfadcc 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 d174b0394926..90add86dc1c8 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 cda74cad42d0..8da9981b3b3e 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 5044a08d727a..da82ee5b623e 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 03e6721cbb29..99edcd538ec5 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 3e878e0024b2..b677b65a529a 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 0224e9b0c863..42bb4ac1425d 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 18e5b0c1c2f7..c8ca28b9dd84 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 d15002f17dba..9379b36322e2 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 ba057c043901..a6164df5edc1 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 c19570b66265..1a2537e7eb6a 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 fa29b1a759a6..bf2020e06027 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 7bbc555e2c52..2e17d965e94a 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 943f6e004312..bb20f4faf2a2 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 f454b20c8437..46faccb74380 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 cb48365f7f51..81fe44f0c783 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 8ba8629a4f50..36442e090a41 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 fe7d93ed5e10..4edb7317483c 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 b78c99d00e05..ef83967d46b3 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 65794b76623b..e6253c3a38a3 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 fa97a2bee52b..ca6336dc94b5 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 diff --git a/contrib/ncurses/ncurses/curses.priv.h b/contrib/ncurses/ncurses/curses.priv.h index efac8ae3e6e2..cfb3e62a62b0 100644 --- a/contrib/ncurses/ncurses/curses.priv.h +++ b/contrib/ncurses/ncurses/curses.priv.h @@ -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,12 +29,12 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * - * and: Thomas E. Dickey 1996-2002 * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* - * $Id: curses.priv.h,v 1.219 2002/05/25 12:22:43 tom Exp $ + * $Id: curses.priv.h,v 1.314 2006/12/10 00:55:14 tom Exp $ * * curses.priv.h * @@ -78,6 +78,11 @@ extern "C" { # include <sys/param.h> #endif +#include <assert.h> +#include <stdio.h> + +#include <errno.h> + #ifndef PATH_MAX # if defined(_POSIX_PATH_MAX) # define PATH_MAX _POSIX_PATH_MAX @@ -88,11 +93,6 @@ extern "C" { # endif #endif -#include <assert.h> -#include <stdio.h> - -#include <errno.h> - #if DECL_ERRNO extern int errno; #endif @@ -130,7 +130,9 @@ extern int errno; /* EMX mouse support */ #ifdef __EMX__ -#define USE_EMX_MOUSE +#define USE_EMX_MOUSE 1 +#else +#define USE_EMX_MOUSE 0 #endif #define DEFAULT_MAXCLICK 166 @@ -142,12 +144,15 @@ extern int errno; */ #if !NCURSES_EXT_FUNCS #undef HAVE_SIZECHANGE +#define HAVE_SIZECHANGE 0 #endif #if HAVE_SIZECHANGE && defined(SIGWINCH) #define USE_SIZECHANGE 1 #else +#define USE_SIZECHANGE 0 #undef USE_SIGWINCH +#define USE_SIGWINCH 0 #endif /* @@ -205,14 +210,6 @@ struct tries { }; /* - * Definitions for color pairs - */ -#define C_SHIFT 8 /* we need more bits than there are colors */ -#define C_MASK ((1 << C_SHIFT) - 1) - -#define PAIR_OF(fg, bg) ((((fg) & C_MASK) << C_SHIFT) | ((bg) & C_MASK)) - -/* * Common/troublesome character definitions */ #define L_BRACE '{' @@ -228,7 +225,9 @@ struct tries { typedef struct { - short red, green, blue; + short red, green, blue; /* what color_content() returns */ + short r, g, b; /* params to init_color() */ + int init; /* true if we called init_color() */ } color_t; @@ -251,150 +250,267 @@ color_t; #include <curses.h> /* we'll use -Ipath directive to get the right one! */ #include <term.h> +#include <term_entry.h> +#include <nc_tparm.h> + +#if NCURSES_EXT_COLORS && USE_WIDEC_SUPPORT +#define if_EXT_COLORS(stmt) stmt +#define NetPair(value,p) (value).ext_color = (p), \ + AttrOf(value) &= ALL_BUT_COLOR, \ + AttrOf(value) |= (A_COLOR & COLOR_PAIR((p > 255) ? 255 : p)) +#define SetPair(value,p) (value).ext_color = (p) +#define GetPair(value) (value).ext_color +#define unColor(n) (AttrOf(n) & ALL_BUT_COLOR) +#define GET_WINDOW_PAIR(w) (w)->_color +#define SET_WINDOW_PAIR(w,p) (w)->_color = (p) +#define SameAttrOf(a,b) (AttrOf(a) == AttrOf(b) && GetPair(a) == GetPair(b)) +#define VIDATTR(attr, pair) vid_attr(attr, pair, 0) +#else +#define if_EXT_COLORS(stmt) /* nothing */ +#define SetPair(value,p) RemAttr(value, A_COLOR), \ + SetAttr(value, AttrOf(value) | (A_COLOR & COLOR_PAIR(p))) +#define GetPair(value) PAIR_NUMBER(AttrOf(value)) +#define unColor(n) (AttrOf(n) & ALL_BUT_COLOR) +#define GET_WINDOW_PAIR(w) PAIR_NUMBER(WINDOW_ATTRS(w)) +#define SET_WINDOW_PAIR(w,p) WINDOW_ATTRS(w) &= ALL_BUT_COLOR, \ + WINDOW_ATTRS(w) |= (A_COLOR & COLOR_PAIR(p)) +#define SameAttrOf(a,b) (AttrOf(a) == AttrOf(b)) +#define VIDATTR(attr, pair) vidattr(attr) +#endif + +#define WINDOW_ATTRS(w) ((w)->_attrs) + +#define SCREEN_ATTRS(s) (*((s)->_current_attr)) +#define GET_SCREEN_PAIR(s) GetPair(SCREEN_ATTRS(s)) +#define SET_SCREEN_PAIR(s,p) SetPair(SCREEN_ATTRS(s), p) +/* + * Definitions for color pairs + */ +typedef unsigned colorpair_t; /* type big enough to store PAIR_OF() */ +#define C_SHIFT 9 /* we need more bits than there are colors */ +#define C_MASK ((1 << C_SHIFT) - 1) +#define PAIR_OF(fg, bg) ((((fg) & C_MASK) << C_SHIFT) | ((bg) & C_MASK)) +#define isDefaultColor(c) ((c) >= COLOR_DEFAULT || (c) < 0) + +#define COLOR_DEFAULT C_MASK + +#if defined(USE_TERMLIB) && !defined(NEED_NCURSES_CH_T) + +#undef NCURSES_CH_T /* this is not a termlib feature */ +#define NCURSES_CH_T void /* ...but we need a pointer in SCREEN */ + +#endif /* USE_TERMLIB */ + +#ifndef USE_TERMLIB struct ldat { - NCURSES_CH_T *text; /* text of the line */ - NCURSES_SIZE_T firstchar; /* first changed character in the line */ - NCURSES_SIZE_T lastchar; /* last changed character in the line */ - NCURSES_SIZE_T oldindex; /* index of the line at last update */ + NCURSES_CH_T *text; /* text of the line */ + NCURSES_SIZE_T firstchar; /* first changed character in the line */ + NCURSES_SIZE_T lastchar; /* last changed character in the line */ + NCURSES_SIZE_T oldindex; /* index of the line at last update */ }; +#endif /* USE_TERMLIB */ + +typedef enum { + M_XTERM = -1 /* use xterm's mouse tracking? */ + ,M_NONE = 0 /* no mouse device */ +#if USE_GPM_SUPPORT + ,M_GPM /* use GPM */ +#endif +#if USE_SYSMOUSE + ,M_SYSMOUSE /* FreeBSD sysmouse on console */ +#endif +} MouseType; /* - * Structure for soft labels. + * Structures for scrolling. */ +typedef struct { + unsigned long hashval; + int oldcount, newcount; + int oldindex, newindex; +} HASHMAP; + +/* + * Structures for soft labels. + */ + +struct _SLK; + +#ifndef USE_TERMLIB + typedef struct { - char *text; /* text for the label */ - char *form_text; /* formatted text (left/center/...) */ - int x; /* x coordinate of this field */ - char dirty; /* this label has changed */ - char visible; /* field is visible */ + char *ent_text; /* text for the label */ + char *form_text; /* formatted text (left/center/...) */ + int ent_x; /* x coordinate of this field */ + char dirty; /* this label has changed */ + char visible; /* field is visible */ } slk_ent; -typedef struct { - char dirty; /* all labels have changed */ - char hidden; /* soft labels are hidden */ - struct _win_st *win; +typedef struct _SLK { + char dirty; /* all labels have changed */ + char hidden; /* soft labels are hidden */ + WINDOW *win; slk_ent *ent; - char* buffer; /* buffer for labels */ - short maxlab; /* number of available labels */ - short labcnt; /* number of allocated labels */ - short maxlen; /* length of labels */ - chtype attr; /* soft label attribute */ + short maxlab; /* number of available labels */ + short labcnt; /* number of allocated labels */ + short maxlen; /* length of labels */ + NCURSES_CH_T attr; /* soft label attribute */ } SLK; -typedef struct { - unsigned long hashval; - int oldcount, newcount; - int oldindex, newindex; -} HASHMAP; +#endif /* USE_TERMLIB */ + +typedef struct { + int line; /* lines to take, < 0 => from bottom*/ + int (*hook)(WINDOW *, int); /* callback for user */ + WINDOW *w; /* maybe we need this for cleanup */ +} ripoff_t; + +#if USE_GPM_SUPPORT +#undef buttons /* term.h defines this, and gpm uses it! */ +#include <gpm.h> + +#ifdef HAVE_LIBDL +/* link dynamically to GPM */ +typedef int *TYPE_gpm_fd; +typedef int (*TYPE_Gpm_Open) (Gpm_Connect *, int); +typedef int (*TYPE_Gpm_Close) (void); +typedef int (*TYPE_Gpm_GetEvent) (Gpm_Event *); + +#define my_gpm_fd SP->_mouse_gpm_fd +#define my_Gpm_Open SP->_mouse_Gpm_Open +#define my_Gpm_Close SP->_mouse_Gpm_Close +#define my_Gpm_GetEvent SP->_mouse_Gpm_GetEvent +#else +/* link statically to GPM */ +#define my_gpm_fd &gpm_fd +#define my_Gpm_Open Gpm_Open +#define my_Gpm_Close Gpm_Close +#define my_Gpm_GetEvent Gpm_GetEvent +#endif /* HAVE_LIBDL */ +#endif /* USE_GPM_SUPPORT */ + +/* + * The SCREEN structure. + */ struct screen { - int _ifd; /* input file ptr for screen */ - FILE *_ofp; /* output file ptr for screen */ - char *_setbuf; /* buffered I/O for output */ - int _buffered; /* setvbuf uses _setbuf data */ - int _checkfd; /* filedesc for typeahead check */ - struct term *_term; /* terminal type information */ - short _lines; /* screen lines */ - short _columns; /* screen columns */ - short _lines_avail; /* lines available for stdscr */ - short _topstolen; /* lines stolen from top */ - - WINDOW *_curscr; /* current screen */ - WINDOW *_newscr; /* virtual screen to be updated to */ - WINDOW *_stdscr; /* screen's full-window context */ - - struct tries *_keytry; /* "Try" for use with keypad mode */ - struct tries *_key_ok; /* Disabled keys via keyok(,FALSE) */ - bool _tried; /* keypad mode was initialized */ - bool _keypad_on; /* keypad mode is currently on */ - - unsigned int _fifo[FIFO_SIZE]; /* input push-back buffer */ - short _fifohead, /* head of fifo queue */ - _fifotail, /* tail of fifo queue */ - _fifopeek, /* where to peek for next char */ - _fifohold; /* set if breakout marked */ - - int _endwin; /* are we out of window mode? */ - attr_t _current_attr; /* terminal attribute current set */ - int _coloron; /* is color enabled? */ - int _cursor; /* visibility of the cursor */ - int _cursrow; /* physical cursor row */ - int _curscol; /* physical cursor column */ - int _nl; /* True if NL -> CR/NL is on */ - int _raw; /* True if in raw mode */ - int _cbreak; /* 1 if in cbreak mode */ - /* > 1 if in halfdelay mode */ - int _echo; /* True if echo on */ - int _use_meta; /* use the meta key? */ - SLK *_slk; /* ptr to soft key struct / NULL */ - int slk_format; /* selected format for this screen */ + int _ifd; /* input file ptr for screen */ + FILE *_ofp; /* output file ptr for screen */ + char *_setbuf; /* buffered I/O for output */ + bool _filtered; /* filter() was called */ + bool _buffered; /* setvbuf uses _setbuf data */ + int _checkfd; /* filedesc for typeahead check */ + TERMINAL *_term; /* terminal type information */ + short _lines; /* screen lines */ + short _columns; /* screen columns */ + + short _lines_avail; /* lines available for stdscr */ + short _topstolen; /* lines stolen from top */ + ripoff_t _rippedoff[5]; /* list of lines stolen */ + int _rip_count; /* ...and total lines stolen */ + + WINDOW *_curscr; /* current screen */ + WINDOW *_newscr; /* virtual screen to be updated to */ + WINDOW *_stdscr; /* screen's full-window context */ + + struct tries *_keytry; /* "Try" for use with keypad mode */ + struct tries *_key_ok; /* Disabled keys via keyok(,FALSE) */ + bool _tried; /* keypad mode was initialized */ + bool _keypad_on; /* keypad mode is currently on */ + + bool _called_wgetch; /* check for recursion in wgetch() */ + int _fifo[FIFO_SIZE]; /* input push-back buffer */ + short _fifohead, /* head of fifo queue */ + _fifotail, /* tail of fifo queue */ + _fifopeek, /* where to peek for next char */ + _fifohold; /* set if breakout marked */ + + int _endwin; /* are we out of window mode? */ + NCURSES_CH_T *_current_attr; /* holds current attributes set */ + int _coloron; /* is color enabled? */ + int _color_defs; /* are colors modified */ + int _cursor; /* visibility of the cursor */ + int _cursrow; /* physical cursor row */ + int _curscol; /* physical cursor column */ + bool _notty; /* true if we cannot switch non-tty */ + int _nl; /* True if NL -> CR/NL is on */ + int _raw; /* True if in raw mode */ + int _cbreak; /* 1 if in cbreak mode */ + /* > 1 if in halfdelay mode */ + int _echo; /* True if echo on */ + int _use_meta; /* use the meta key? */ + struct _SLK *_slk; /* ptr to soft key struct / NULL */ + int slk_format; /* selected format for this screen */ /* cursor movement costs; units are 10ths of milliseconds */ #if NCURSES_NO_PADDING - int _no_padding; /* flag to set if padding disabled */ + int _no_padding; /* flag to set if padding disabled */ #endif - int _char_padding; /* cost of character put */ - int _cr_cost; /* cost of (carriage_return) */ - int _cup_cost; /* cost of (cursor_address) */ - int _home_cost; /* cost of (cursor_home) */ - int _ll_cost; /* cost of (cursor_to_ll) */ + int _char_padding; /* cost of character put */ + int _cr_cost; /* cost of (carriage_return) */ + int _cup_cost; /* cost of (cursor_address) */ + int _home_cost; /* cost of (cursor_home) */ + int _ll_cost; /* cost of (cursor_to_ll) */ #if USE_HARD_TABS - int _ht_cost; /* cost of (tab) */ - int _cbt_cost; /* cost of (backtab) */ + int _ht_cost; /* cost of (tab) */ + int _cbt_cost; /* cost of (backtab) */ #endif /* USE_HARD_TABS */ - int _cub1_cost; /* cost of (cursor_left) */ - int _cuf1_cost; /* cost of (cursor_right) */ - int _cud1_cost; /* cost of (cursor_down) */ - int _cuu1_cost; /* cost of (cursor_up) */ - int _cub_cost; /* cost of (parm_cursor_left) */ - int _cuf_cost; /* cost of (parm_cursor_right) */ - int _cud_cost; /* cost of (parm_cursor_down) */ - int _cuu_cost; /* cost of (parm_cursor_up) */ - int _hpa_cost; /* cost of (column_address) */ - int _vpa_cost; /* cost of (row_address) */ + int _cub1_cost; /* cost of (cursor_left) */ + int _cuf1_cost; /* cost of (cursor_right) */ + int _cud1_cost; /* cost of (cursor_down) */ + int _cuu1_cost; /* cost of (cursor_up) */ + int _cub_cost; /* cost of (parm_cursor_left) */ + int _cuf_cost; /* cost of (parm_cursor_right) */ + int _cud_cost; /* cost of (parm_cursor_down) */ + int _cuu_cost; /* cost of (parm_cursor_up) */ + int _hpa_cost; /* cost of (column_address) */ + int _vpa_cost; /* cost of (row_address) */ /* used in tty_update.c, must be chars */ - int _ed_cost; /* cost of (clr_eos) */ - int _el_cost; /* cost of (clr_eol) */ - int _el1_cost; /* cost of (clr_bol) */ - int _dch1_cost; /* cost of (delete_character) */ - int _ich1_cost; /* cost of (insert_character) */ - int _dch_cost; /* cost of (parm_dch) */ - int _ich_cost; /* cost of (parm_ich) */ - int _ech_cost; /* cost of (erase_chars) */ - int _rep_cost; /* cost of (repeat_char) */ - int _hpa_ch_cost; /* cost of (column_address) */ - int _cup_ch_cost; /* cost of (cursor_address) */ - int _cuf_ch_cost; /* cost of (parm_cursor_right) */ - int _inline_cost; /* cost of inline-move */ - int _smir_cost; /* cost of (enter_insert_mode) */ - int _rmir_cost; /* cost of (exit_insert_mode) */ - int _ip_cost; /* cost of (insert_padding) */ + int _ed_cost; /* cost of (clr_eos) */ + int _el_cost; /* cost of (clr_eol) */ + int _el1_cost; /* cost of (clr_bol) */ + int _dch1_cost; /* cost of (delete_character) */ + int _ich1_cost; /* cost of (insert_character) */ + int _dch_cost; /* cost of (parm_dch) */ + int _ich_cost; /* cost of (parm_ich) */ + int _ech_cost; /* cost of (erase_chars) */ + int _rep_cost; /* cost of (repeat_char) */ + int _hpa_ch_cost; /* cost of (column_address) */ + int _cup_ch_cost; /* cost of (cursor_address) */ + int _cuf_ch_cost; /* cost of (parm_cursor_right) */ + int _inline_cost; /* cost of inline-move */ + int _smir_cost; /* cost of (enter_insert_mode) */ + int _rmir_cost; /* cost of (exit_insert_mode) */ + int _ip_cost; /* cost of (insert_padding) */ /* used in lib_mvcur.c */ - char * _address_cursor; + char * _address_cursor; /* used in tty_update.c */ - int _scrolling; /* 1 if terminal's smart enough to */ + int _scrolling; /* 1 if terminal's smart enough to */ /* used in lib_color.c */ - color_t *_color_table; /* screen's color palette */ - int _color_count; /* count of colors in palette */ - unsigned short *_color_pairs; /* screen's color pair list */ - int _pair_count; /* count of color pairs */ + color_t *_color_table; /* screen's color palette */ + int _color_count; /* count of colors in palette */ + colorpair_t *_color_pairs; /* screen's color pair list */ + int _pair_count; /* count of color pairs */ #if NCURSES_EXT_FUNCS - bool _default_color; /* use default colors */ - bool _has_sgr_39_49; /* has ECMA default color support */ - int _default_fg; /* assumed default foreground */ - int _default_bg; /* assumed default background */ + bool _default_color; /* use default colors */ + bool _has_sgr_39_49; /* has ECMA default color support */ + int _default_fg; /* assumed default foreground */ + int _default_bg; /* assumed default background */ #endif - chtype _xmc_suppress; /* attributes to suppress if xmc */ - chtype _xmc_triggers; /* attributes to process if xmc */ - chtype _acs_map[ACS_LEN]; + chtype _ok_attributes; /* valid attributes for terminal */ + chtype _xmc_suppress; /* attributes to suppress if xmc */ + chtype _xmc_triggers; /* attributes to process if xmc */ + chtype * _acs_map; /* the real alternate-charset map */ + bool * _screen_acs_map; + /* used in lib_vidattr.c */ - bool _use_rmso; /* true if we may use 'rmso' */ - bool _use_rmul; /* true if we may use 'rmul' */ + bool _use_rmso; /* true if we may use 'rmso' */ + bool _use_rmul; /* true if we may use 'rmul' */ /* * These data correspond to the state of the idcok() and idlok() @@ -403,21 +519,57 @@ struct screen { * is given as an argument. However, ncurses implements this logic * only for the newscr/curscr update process, _not_ per-window. */ - bool _nc_sp_idlok; - bool _nc_sp_idcok; + bool _nc_sp_idlok; + bool _nc_sp_idcok; #define _nc_idlok SP->_nc_sp_idlok #define _nc_idcok SP->_nc_sp_idcok /* * These are the data that support the mouse interface. */ - int _maxclick; - bool (*_mouse_event) (SCREEN *); - bool (*_mouse_inline)(SCREEN *); - bool (*_mouse_parse) (int); - void (*_mouse_resume)(SCREEN *); - void (*_mouse_wrap) (SCREEN *); - int _mouse_fd; /* file-descriptor, if any */ + bool _mouse_initialized; + MouseType _mouse_type; + int _maxclick; + bool (*_mouse_event) (SCREEN *); + bool (*_mouse_inline)(SCREEN *); + bool (*_mouse_parse) (int); + void (*_mouse_resume)(SCREEN *); + void (*_mouse_wrap) (SCREEN *); + int _mouse_fd; /* file-descriptor, if any */ + bool _mouse_active; /* true if initialized */ + mmask_t _mouse_mask; + NCURSES_CONST char *_mouse_xtermcap; /* string to enable/disable mouse */ + MEVENT _mouse_events[EV_MAX]; /* hold the last mouse event seen */ + MEVENT *_mouse_eventp; /* next free slot in event queue */ + +#if USE_GPM_SUPPORT + bool _mouse_gpm_loaded; + bool _mouse_gpm_found; +#ifdef HAVE_LIBDL + TYPE_gpm_fd _mouse_gpm_fd; + TYPE_Gpm_Open _mouse_Gpm_Open; + TYPE_Gpm_Close _mouse_Gpm_Close; + TYPE_Gpm_GetEvent _mouse_Gpm_GetEvent; +#endif + Gpm_Connect _mouse_gpm_connect; +#endif /* USE_GPM_SUPPORT */ + +#if USE_EMX_MOUSE + int _emxmouse_wfd; + int _emxmouse_thread; + int _emxmouse_activated; + char _emxmouse_buttons[4]; +#endif + +#if USE_SYSMOUSE + MEVENT _sysmouse_fifo[FIFO_SIZE]; + int _sysmouse_head; + int _sysmouse_tail; + int _sysmouse_char_width; /* character width */ + int _sysmouse_char_height; /* character height */ + int _sysmouse_old_buttons; + int _sysmouse_new_buttons; +#endif /* * This supports automatic resizing @@ -426,60 +578,68 @@ struct screen { int (*_resize)(int,int); #endif - /* + /* * These are data that support the proper handling of the panel stack on an * per screen basis. */ - struct panelhook _panelHook; + struct panelhook _panelHook; /* * Linked-list of all windows, to support '_nc_resizeall()' and * '_nc_freeall()' */ - WINDOWLIST *_nc_sp_windows; + WINDOWLIST *_nc_sp_windows; #define _nc_windows SP->_nc_sp_windows - bool _sig_winch; - SCREEN *_next_screen; + bool _sig_winch; + SCREEN *_next_screen; /* hashes for old and new lines */ unsigned long *oldhash, *newhash; - HASHMAP *hashtab; + HASHMAP *hashtab; int hashtab_len; - bool _cleanup; /* cleanup after int/quit signal */ - int (*_outch)(int); /* output handler if not putc */ -}; + bool _cleanup; /* cleanup after int/quit signal */ + int (*_outch)(int); /* output handler if not putc */ -extern NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain; + int _legacy_coding; /* see use_legacy_coding() */ -#if NCURSES_NOMACROS -#include <nomacros.h> + /* + * ncurses/ncursesw are the same up to this point. + */ +#if USE_WIDEC_SUPPORT + /* recent versions of 'screen' have partially-working support for + * UTF-8, but do not permit ACS at the same time (see tty_update.c). + */ + bool _screen_acs_fix; #endif +}; + +extern NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain; -/* - * The margins are used in resizeterm() to retain the original layout after - * resizing. - */ WINDOWLIST { + WINDOW win; /* first, so WINDOW_EXT() works */ WINDOWLIST *next; -#if HAVE_RESIZETERM - int l_margin; - int r_margin; - int t_margin; - int b_margin; +#ifdef _XOPEN_SOURCE_EXTENDED + char addch_work[(MB_LEN_MAX * 9) + 1]; + unsigned addch_used; /* number of bytes in addch_work[] */ + int addch_x; /* x-position for addch_work[] */ + int addch_y; /* y-position for addch_work[] */ #endif - WINDOW win; }; -typedef struct { - int line; /* lines to take, < 0 => from bottom*/ - int (*hook)(struct _win_st *, int); /* callback for user */ - struct _win_st *w; /* maybe we need this for cleanup */ -} ripoff_t; +#define WINDOW_EXT(win,field) (((WINDOWLIST *)(win))->field) + +/* usually in <limits.h> */ +#ifndef UCHAR_MAX +#define UCHAR_MAX 255 +#endif /* The terminfo source is assumed to be 7-bit ASCII */ #define is7bits(c) ((unsigned)(c) < 128) +/* Checks for isprint() should be done on 8-bit characters (non-wide) */ +#define is8bits(c) ((unsigned)(c) <= UCHAR_MAX) + #ifndef min #define min(a,b) ((a) > (b) ? (b) : (a)) #endif @@ -530,22 +690,46 @@ typedef struct { #define O_BINARY 0 #endif +#ifdef TRACE +#define TRACE_OUTCHARS(n) _nc_outchars += (n); +#else +#define TRACE_OUTCHARS(n) /* nothing */ +#endif + #define UChar(c) ((unsigned char)(c)) #define ChCharOf(c) ((c) & (chtype)A_CHARTEXT) -#define ChAttrOf(c) ((c) & (chtype)A_ATTRIBUTES) +#define ChAttrOf(c) ((c) & (chtype)A_ATTRIBUTES) + +#ifndef MB_LEN_MAX +#define MB_LEN_MAX 8 /* should be >= MB_CUR_MAX, but that may be a function */ +#endif #if USE_WIDEC_SUPPORT /* { */ +#define isEILSEQ(status) ((status == (size_t)-1) && (errno == EILSEQ)) + +#define init_mb(state) memset(&state, 0, sizeof(state)) + +#if NCURSES_EXT_COLORS +#define NulColor , 0 +#else +#define NulColor /* nothing */ +#endif + +#define NulChar 0,0,0,0 /* FIXME: see CCHARW_MAX */ #define CharOf(c) ((c).chars[0]) #define AttrOf(c) ((c).attr) -#define AddAttr(c,a) (c).attr |= a -#define RemAttr(c,a) (c).attr &= ~(a) -#define SetAttr(c,a) (c).attr = a -#define NewChar(ch) { ChAttrOf(ch), { ChCharOf(ch) } } -#define NewChar2(c,a) { a, { c } } -#define CharEq(a,b) (!memcmp(&a, &b, sizeof(a))) -#define SetChar(ch,c,a) do { \ +#define AddAttr(c,a) AttrOf(c) |= ((a) & A_ATTRIBUTES) +#define RemAttr(c,a) AttrOf(c) &= ~((a) & A_ATTRIBUTES) +#define SetAttr(c,a) AttrOf(c) = ((a) & A_ATTRIBUTES) +#define NewChar2(c,a) { a, { c, NulChar } NulColor } +#define NewChar(ch) NewChar2(ChCharOf(ch), ChAttrOf(ch)) +#define CharEq(a,b) (!memcmp(&(a), &(b), sizeof(a))) +#define SetChar(ch,c,a) do { \ NCURSES_CH_T *_cp = &ch; \ - memset(_cp,0,sizeof(ch)); _cp->chars[0] = c; _cp->attr = a; \ + memset(_cp, 0, sizeof(ch)); \ + _cp->chars[0] = (c); \ + _cp->attr = (a); \ + if_EXT_COLORS(SetPair(ch, PAIR_NUMBER(a))); \ } while (0) #define CHREF(wch) (&wch) #define CHDEREF(wch) (*wch) @@ -553,55 +737,76 @@ typedef struct { #define CARG_CH_T const NCURSES_CH_T * #define PUTC_DATA char PUTC_buf[MB_LEN_MAX]; int PUTC_i, PUTC_n; \ mbstate_t PUT_st; wchar_t PUTC_ch -#define PUTC(ch,b) do { if(!isnac(ch)) { \ - memset (&PUT_st, '\0', sizeof (PUT_st)); \ - PUTC_i = 0; \ - do { \ - PUTC_ch = PUTC_i < CCHARW_MAX ? \ - (ch).chars[PUTC_i] : L'\0'; \ +#define PUTC_INIT init_mb (PUT_st) +#define PUTC(ch,b) do { if(!isWidecExt(ch)) { \ + if (Charable(ch)) { \ + fputc(CharOf(ch), b); \ + TRACE_OUTCHARS(1); \ + } else { \ + PUTC_INIT; \ + for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { \ + PUTC_ch = (ch).chars[PUTC_i]; \ + if (PUTC_ch == L'\0') \ + break; \ PUTC_n = wcrtomb(PUTC_buf, \ (ch).chars[PUTC_i], &PUT_st); \ - if (PUTC_ch == L'\0') \ - --PUTC_n; \ - if (PUTC_n <= 0) \ + if (PUTC_n <= 0) { \ + if (PUTC_ch && is8bits(PUTC_ch) && PUTC_i == 0) \ + putc(PUTC_ch,b); \ break; \ + } \ fwrite(PUTC_buf, (unsigned) PUTC_n, 1, b); \ - ++PUTC_i; \ - } while (PUTC_ch != L'\0'); \ - } } while (0) + } \ + TRACE_OUTCHARS(PUTC_i); \ + } } } while (0) -#define BLANK { WA_NORMAL, ' ' } +#define BLANK { WA_NORMAL, {' '} NulColor } +#define ZEROS { WA_NORMAL, {'\0'} NulColor } #define ISBLANK(ch) ((ch).chars[0] == L' ' && (ch).chars[1] == L'\0') -#define WA_NAC 1 -#define isnac(ch) (AttrOf(ch) & WA_NAC) + /* + * Wide characters cannot be represented in the A_CHARTEXT mask of + * attr_t's but an application might have set a narrow character there. + * But even in that case, it would only be a printable character, or + * zero. Otherwise we can use those bits to tell if a cell is the + * first or extension part of a wide character. + */ +#define WidecExt(ch) (AttrOf(ch) & A_CHARTEXT) +#define isWidecBase(ch) (WidecExt(ch) == 1) +#define isWidecExt(ch) (WidecExt(ch) > 1 && WidecExt(ch) < 32) +#define SetWidecExt(dst, ext) AttrOf(dst) &= ~A_CHARTEXT, \ + AttrOf(dst) |= (ext + 1) + #define if_WIDEC(code) code -#define Charable(ch) (!isnac(ch) && \ - (ch).chars[1] == L'\0' && \ - (wctob(CharOf(ch)) == (char)CharOf(ch))) +#define Charable(ch) ((SP != 0 && SP->_legacy_coding) \ + || (AttrOf(ch) & A_ALTCHARSET) \ + || (!isWidecExt(ch) && \ + (ch).chars[1] == L'\0' && \ + _nc_is_charable(CharOf(ch)))) #define L(ch) L ## ch #else /* }{ */ #define CharOf(c) ChCharOf(c) #define AttrOf(c) ChAttrOf(c) -#define AddAttr(c,a) c |= a -#define RemAttr(c,a) c &= ~(a & A_ATTRIBUTES) -#define SetAttr(c,a) c = (c & ~A_ATTRIBUTES) | a +#define AddAttr(c,a) c |= (a) +#define RemAttr(c,a) c &= ~((a) & A_ATTRIBUTES) +#define SetAttr(c,a) c = ((c) & ~A_ATTRIBUTES) | (a) #define NewChar(ch) (ch) -#define NewChar2(c,a) (c | a) -#define CharEq(a,b) (a == b) -#define SetChar(ch,c,a) ch = c | a +#define NewChar2(c,a) ((c) | (a)) +#define CharEq(a,b) ((a) == (b)) +#define SetChar(ch,c,a) ch = (c) | (a) #define CHREF(wch) wch #define CHDEREF(wch) wch #define ARG_CH_T NCURSES_CH_T #define CARG_CH_T NCURSES_CH_T #define PUTC_DATA int data = 0 -#define PUTC(a,b) do { data = CharOf(ch); putc(data,b); } while (0) +#define PUTC(ch,b) do { data = CharOf(ch); putc(data,b); } while (0) #define BLANK (' '|A_NORMAL) +#define ZEROS ('\0'|A_NORMAL) #define ISBLANK(ch) (CharOf(ch) == ' ') -#define isnac(ch) (0) +#define isWidecExt(ch) (0) #define if_WIDEC(code) /* nothing */ #define L(ch) ch @@ -616,6 +821,11 @@ typedef struct { #define CHANGED -1 +#define LEGALYX(w, y, x) \ + ((w) != 0 && \ + ((x) >= 0 && (x) <= (w)->_maxx && \ + (y) >= 0 && (y) <= (w)->_maxy)) + #define CHANGED_CELL(line,col) \ if (line->firstchar == _NOCHANGE) \ line->firstchar = line->lastchar = col; \ @@ -650,6 +860,23 @@ typedef struct { #include <nc_alloc.h> /* + * TTY bit definition for converting tabs to spaces. + */ +#ifdef TAB3 +# define OFLAGS_TABS TAB3 /* POSIX specifies TAB3 */ +#else +# ifdef XTABS +# define OFLAGS_TABS XTABS /* XTABS is usually the "same" */ +# else +# ifdef OXTABS +# define OFLAGS_TABS OXTABS /* the traditional BSD equivalent */ +# else +# define OFLAGS_TABS 0 +# endif +# endif +#endif + +/* * Prefixes for call/return points of library function traces. We use these to * instrument the public functions so that the traces can be easily transformed * into regression scripts. @@ -659,80 +886,114 @@ typedef struct { #define T_RETURN(fmt) "return }" fmt #ifdef TRACE + +#define START_TRACE() \ + if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \ + int t = _nc_getenv_num("NCURSES_TRACE"); \ + if (t >= 0) \ + trace((unsigned) t); \ + } + #define TR(n, a) if (_nc_tracing & (n)) _tracef a #define T(a) TR(TRACE_CALLS, a) #define TPUTS_TRACE(s) _nc_tputs_trace = s; #define TRACE_RETURN(value,type) return _nc_retrace_##type(value) -#define returnAttr(code) TRACE_RETURN(code,attr_t) -#define returnChar(code) TRACE_RETURN(code,chtype) -#define returnCode(code) TRACE_RETURN(code,int) -#define returnPtr(code) TRACE_RETURN(code,ptr) -#define returnSP(code) TRACE_RETURN(code,sp) -#define returnVoid T((T_RETURN(""))); return -#define returnWin(code) TRACE_RETURN(code,win) -extern NCURSES_EXPORT(SCREEN *) _nc_retrace_sp (SCREEN *); -extern NCURSES_EXPORT(WINDOW *) _nc_retrace_win (WINDOW *); -extern NCURSES_EXPORT(attr_t) _nc_retrace_attr_t (attr_t); -extern NCURSES_EXPORT(attr_t) _nc_retrace_chtype (chtype); -extern NCURSES_EXPORT(char *) _nc_retrace_ptr (char *); -extern NCURSES_EXPORT(char *) _nc_trace_ttymode(TTY *tty); -extern NCURSES_EXPORT(char *) _nc_varargs (const char *, va_list); -extern NCURSES_EXPORT(const char *) _nc_altcharset_name(attr_t, chtype); -extern NCURSES_EXPORT(int) _nc_retrace_int (int); -extern NCURSES_EXPORT(void) _nc_fifo_dump (void); + +#define returnAttr(code) TRACE_RETURN(code,attr_t) +#define returnBits(code) TRACE_RETURN(code,unsigned) +#define returnBool(code) TRACE_RETURN(code,bool) +#define returnCPtr(code) TRACE_RETURN(code,cptr) +#define returnCVoidPtr(code) TRACE_RETURN(code,cvoid_ptr) +#define returnChar(code) TRACE_RETURN(code,chtype) +#define returnCode(code) TRACE_RETURN(code,int) +#define returnPtr(code) TRACE_RETURN(code,ptr) +#define returnSP(code) TRACE_RETURN(code,sp) +#define returnVoid T((T_RETURN(""))); return +#define returnVoidPtr(code) TRACE_RETURN(code,void_ptr) +#define returnWin(code) TRACE_RETURN(code,win) + +extern NCURSES_EXPORT(NCURSES_BOOL) _nc_retrace_bool (NCURSES_BOOL); +extern NCURSES_EXPORT(NCURSES_CONST void *) _nc_retrace_cvoid_ptr (NCURSES_CONST void *); +extern NCURSES_EXPORT(SCREEN *) _nc_retrace_sp (SCREEN *); +extern NCURSES_EXPORT(WINDOW *) _nc_retrace_win (WINDOW *); +extern NCURSES_EXPORT(attr_t) _nc_retrace_attr_t (attr_t); +extern NCURSES_EXPORT(char *) _nc_retrace_ptr (char *); +extern NCURSES_EXPORT(char *) _nc_trace_ttymode(TTY *tty); +extern NCURSES_EXPORT(char *) _nc_varargs (const char *, va_list); +extern NCURSES_EXPORT(chtype) _nc_retrace_chtype (chtype); +extern NCURSES_EXPORT(const char *) _nc_altcharset_name(attr_t, chtype); +extern NCURSES_EXPORT(const char *) _nc_retrace_cptr (const char *); +extern NCURSES_EXPORT(int) _nc_retrace_int (int); +extern NCURSES_EXPORT(unsigned) _nc_retrace_unsigned (unsigned); +extern NCURSES_EXPORT(void *) _nc_retrace_void_ptr (void *); +extern NCURSES_EXPORT(void) _nc_fifo_dump (void); extern NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace; -extern NCURSES_EXPORT_VAR(long) _nc_outchars; -extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing; +extern NCURSES_EXPORT_VAR(long) _nc_outchars; +extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing; + #if USE_WIDEC_SUPPORT extern NCURSES_EXPORT(const char *) _nc_viswbuf2 (int, const wchar_t *); -extern NCURSES_EXPORT(const char *) _nc_viscbuf2 (int, const cchar_t *, int); -extern NCURSES_EXPORT(const char *) _nc_viscbuf (const cchar_t *, int); +extern NCURSES_EXPORT(const char *) _nc_viswbufn (const wchar_t *, int); #endif -#else + +extern NCURSES_EXPORT(const char *) _nc_viscbuf2 (int, const NCURSES_CH_T *, int); +extern NCURSES_EXPORT(const char *) _nc_viscbuf (const NCURSES_CH_T *, int); + +#else /* !TRACE */ + +#define START_TRACE() /* nothing */ + #define T(a) #define TR(n, a) #define TPUTS_TRACE(s) -#define returnAttr(code) return code -#define returnChar(code) return code -#define returnCode(code) return code -#define returnPtr(code) return code -#define returnSP(code) return code -#define returnVoid return -#define returnWin(code) return code -#endif + +#define returnAttr(code) return code +#define returnBits(code) return code +#define returnBool(code) return code +#define returnCPtr(code) return code +#define returnCVoidPtr(code) return code +#define returnChar(code) return code +#define returnCode(code) return code +#define returnPtr(code) return code +#define returnSP(code) return code +#define returnVoid return +#define returnVoidPtr(code) return code +#define returnWin(code) return code + +#endif /* TRACE/!TRACE */ + +/* + * Return-codes for tgetent() and friends. + */ +#define TGETENT_YES 1 /* entry is found */ +#define TGETENT_NO 0 /* entry is not found */ +#define TGETENT_ERR -1 /* an error occurred */ + +extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *); +extern NCURSES_EXPORT(const char *) _nc_visbufn (const char *, int); #define empty_module(name) \ extern NCURSES_EXPORT(void) name (void); \ NCURSES_EXPORT(void) name (void) { } -/* used in _nc_visbuf() whether or not we're tracing */ -extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *); - #define ALL_BUT_COLOR ((chtype)~(A_COLOR)) -#define IGNORE_COLOR_OFF FALSE -#define NONBLANK_ATTR (A_BOLD|A_DIM|A_BLINK) +#define NONBLANK_ATTR (A_NORMAL|A_BOLD|A_DIM|A_BLINK) #define XMC_CHANGES(c) ((c) & SP->_xmc_suppress) - #define toggle_attr_on(S,at) {\ - if (PAIR_NUMBER(at) > 0)\ + if (PAIR_NUMBER(at) > 0) {\ (S) = ((S) & ALL_BUT_COLOR) | (at);\ - else\ + } else {\ (S) |= (at);\ + }\ TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));} #define toggle_attr_off(S,at) {\ - if (IGNORE_COLOR_OFF == TRUE) {\ - if (PAIR_NUMBER(at) == 0xff) /* turn off color */\ - (S) &= ~(at);\ - else /* leave color alone */\ - (S) &= ~((at)&ALL_BUT_COLOR);\ + if (PAIR_NUMBER(at) > 0) {\ + (S) &= ~(at|A_COLOR);\ } else {\ - if (PAIR_NUMBER(at) > 0x00) /* turn off color */\ - (S) &= ~(at|A_COLOR);\ - else /* leave color alone */\ - (S) &= ~(at);\ + (S) &= ~(at);\ }\ TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));} @@ -749,15 +1010,15 @@ extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *); : ((enter_insert_mode && exit_insert_mode) \ ? SP->_smir_cost + SP->_rmir_cost + (SP->_ip_cost * count) \ : ((insert_character != 0) \ - ? (SP->_ich1_cost * count) \ + ? ((SP->_ich1_cost + SP->_ip_cost) * count) \ : INFINITY))) #if USE_XMC_SUPPORT -#define UpdateAttrs(a) if (SP->_current_attr != (a)) { \ - attr_t chg = SP->_current_attr; \ - vidattr((a)); \ +#define UpdateAttrs(c) if (!SameAttrOf(SCREEN_ATTRS(SP), c)) { \ + attr_t chg = AttrOf(SCREEN_ATTRS(SP)); \ + VIDATTR(AttrOf(c), GetPair(c)); \ if (magic_cookie_glitch > 0 \ - && XMC_CHANGES((chg ^ SP->_current_attr))) { \ + && XMC_CHANGES((chg ^ AttrOf(SCREEN_ATTRS(SP))))) { \ T(("%s @%d before glitch %d,%d", \ __FILE__, __LINE__, \ SP->_cursrow, \ @@ -766,8 +1027,21 @@ extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *); } \ } #else -#define UpdateAttrs(a) if (SP->_current_attr != (a)) \ - vidattr((a)); +#define UpdateAttrs(c) if (!SameAttrOf(SCREEN_ATTRS(SP), c)) \ + VIDATTR(AttrOf(c), GetPair(c)); +#endif + +/* + * Macros to make additional parameter to implement wgetch_events() + */ +#ifdef NCURSES_WGETCH_EVENTS +#define EVENTLIST_0th(param) param +#define EVENTLIST_1st(param) param +#define EVENTLIST_2nd(param) , param +#else +#define EVENTLIST_0th(param) void +#define EVENTLIST_1st(param) /* nothing */ +#define EVENTLIST_2nd(param) /* nothing */ #endif #if NCURSES_EXPANDED && NCURSES_EXT_FUNCS @@ -790,7 +1064,7 @@ extern NCURSES_EXPORT(int) _nc_InsCharCost (int); #undef UpdateAttrs #define UpdateAttrs(c) _nc_UpdateAttrs(c) -extern NCURSES_EXPORT(void) _nc_UpdateAttrs (chtype); +extern NCURSES_EXPORT(void) _nc_UpdateAttrs (NCURSES_CH_T); #else @@ -802,6 +1076,13 @@ extern NCURSES_EXPORT(void) _nc_expanded (void); #define getcwd(buf,len) getwd(buf) #endif +/* charable.c */ +#if USE_WIDEC_SUPPORT +extern NCURSES_EXPORT(bool) _nc_is_charable(wchar_t); +extern NCURSES_EXPORT(int) _nc_to_char(wint_t); +extern NCURSES_EXPORT(wint_t) _nc_to_widechar(int); +#endif + /* doupdate.c */ #if USE_XMC_SUPPORT extern NCURSES_EXPORT(void) _nc_do_xmc_glitch (attr_t); @@ -816,13 +1097,24 @@ extern NCURSES_EXPORT(void) _nc_linedump (void); extern NCURSES_EXPORT(void) _nc_init_acs (void); /* corresponds to traditional 'init_acs()' */ extern NCURSES_EXPORT(int) _nc_msec_cost (const char *const, int); /* used by 'tack' program */ -/* lib_addstr.c */ +/* lib_addch.c */ #if USE_WIDEC_SUPPORT +NCURSES_EXPORT(int) _nc_build_wch(WINDOW *win, ARG_CH_T ch); +#endif + +/* lib_addstr.c */ +#if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB) extern NCURSES_EXPORT(int) _nc_wchstrlen(const cchar_t *); #endif +/* lib_color.c */ +extern NCURSES_EXPORT(bool) _nc_reset_colors(void); + /* lib_getch.c */ -extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, unsigned long *, int); +extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, unsigned long *, int EVENTLIST_2nd(_nc_eventlist *)); + +/* lib_insch.c */ +extern NCURSES_EXPORT(int) _nc_insert_ch(WINDOW *, chtype); /* lib_mvcur.c */ #define INFINITY 1000000 /* cost: too high to use */ @@ -842,6 +1134,20 @@ extern NCURSES_EXPORT(int) _nc_has_mouse (void); /* lib_mvcur.c */ #define INFINITY 1000000 /* cost: too high to use */ +#define BAUDBYTE 9 /* 9 = 7 bits + 1 parity + 1 stop */ + +/* lib_setup.c */ +extern NCURSES_EXPORT(char *) _nc_get_locale(void); +extern NCURSES_EXPORT(int) _nc_unicode_locale(void); +extern NCURSES_EXPORT(int) _nc_locale_breaks_acs(void); +extern NCURSES_EXPORT(int) _nc_setupterm(NCURSES_CONST char *, int, int *, bool); + +/* lib_tstp.c */ +#if USE_SIGWINCH +extern NCURSES_EXPORT(int) _nc_handle_sigwinch(int); +#else +#define _nc_handle_sigwinch(a) /* nothing */ +#endif /* lib_wacs.c */ #if USE_WIDEC_SUPPORT @@ -849,9 +1155,10 @@ extern NCURSES_EXPORT(void) _nc_init_wacs(void); #endif typedef struct { - char *s_head; - char *s_tail; - size_t s_size; + char *s_head; /* beginning of the string (may be null) */ + char *s_tail; /* end of the string (may be null) */ + size_t s_size; /* current remaining size available */ + size_t s_init; /* total size available */ } string_desc; /* strings.c */ @@ -861,16 +1168,6 @@ extern NCURSES_EXPORT(string_desc *) _nc_str_copy (string_desc *, string_desc *) extern NCURSES_EXPORT(bool) _nc_safe_strcat (string_desc *, const char *); extern NCURSES_EXPORT(bool) _nc_safe_strcpy (string_desc *, const char *); -extern NCURSES_EXPORT(void) _nc_mvcur_init (void); -extern NCURSES_EXPORT(void) _nc_mvcur_resume (void); -extern NCURSES_EXPORT(void) _nc_mvcur_wrap (void); - -extern NCURSES_EXPORT(int) _nc_scrolln (int, int, int, int); - -extern NCURSES_EXPORT(void) _nc_screen_init (void); -extern NCURSES_EXPORT(void) _nc_screen_resume (void); -extern NCURSES_EXPORT(void) _nc_screen_wrap (void); - #if !HAVE_STRSTR #define strstr _nc_strstr extern NCURSES_EXPORT(char *) _nc_strstr (const char *, const char *); @@ -880,42 +1177,63 @@ extern NCURSES_EXPORT(char *) _nc_strstr (const char *, const char *); extern NCURSES_EXPORT(char *) _nc_printf_string (const char *, va_list); /* tries.c */ -extern NCURSES_EXPORT(void) _nc_add_to_try (struct tries **, const char *, unsigned short); -extern NCURSES_EXPORT(char *) _nc_expand_try (struct tries *, unsigned short, int *, size_t); -extern NCURSES_EXPORT(int) _nc_remove_key (struct tries **, unsigned short); -extern NCURSES_EXPORT(int) _nc_remove_string (struct tries **, char *); +extern NCURSES_EXPORT(void) _nc_add_to_try (struct tries **, const char *, unsigned); +extern NCURSES_EXPORT(char *) _nc_expand_try (struct tries *, unsigned, int *, size_t); +extern NCURSES_EXPORT(int) _nc_remove_key (struct tries **, unsigned); +extern NCURSES_EXPORT(int) _nc_remove_string (struct tries **, const char *); /* elsewhere ... */ +extern NCURSES_EXPORT(ENTRY *) _nc_delink_entry(ENTRY *, TERMTYPE *); extern NCURSES_EXPORT(WINDOW *) _nc_makenew (int, int, int, int, int); -extern NCURSES_EXPORT(char *) _nc_home_terminfo (void); extern NCURSES_EXPORT(char *) _nc_trace_buf (int, size_t); -extern NCURSES_EXPORT(NCURSES_CH_T) _nc_render (WINDOW *, NCURSES_CH_T); -extern NCURSES_EXPORT(int) _nc_access (const char *, int); +extern NCURSES_EXPORT(char *) _nc_trace_bufcat (int, const char *); +extern NCURSES_EXPORT(int) _nc_access (const char *, int); extern NCURSES_EXPORT(int) _nc_baudrate (int); extern NCURSES_EXPORT(int) _nc_freewin (WINDOW *); extern NCURSES_EXPORT(int) _nc_getenv_num (const char *); extern NCURSES_EXPORT(int) _nc_keypad (bool); extern NCURSES_EXPORT(int) _nc_ospeed (int); extern NCURSES_EXPORT(int) _nc_outch (int); -extern NCURSES_EXPORT(int) _nc_setupscreen (short, short const, FILE *); -extern NCURSES_EXPORT(int) _nc_timed_wait (int, int, int *); -extern NCURSES_EXPORT(int) _nc_waddch_nosync (WINDOW *, const NCURSES_CH_T); -extern NCURSES_EXPORT(void) _nc_do_color (int, int, bool, int (*)(int)); +extern NCURSES_EXPORT(int) _nc_read_termcap_entry (const char *const, TERMTYPE *const); +extern NCURSES_EXPORT(int) _nc_setupscreen (int, int, FILE *, bool, int); +extern NCURSES_EXPORT(int) _nc_timed_wait(int, int, int * EVENTLIST_2nd(_nc_eventlist *)); +extern NCURSES_EXPORT(void) _nc_do_color (short, short, bool, int (*)(int)); extern NCURSES_EXPORT(void) _nc_flush (void); +extern NCURSES_EXPORT(void) _nc_free_entry(ENTRY *, TERMTYPE *); extern NCURSES_EXPORT(void) _nc_freeall (void); extern NCURSES_EXPORT(void) _nc_hash_map (void); extern NCURSES_EXPORT(void) _nc_init_keytry (void); extern NCURSES_EXPORT(void) _nc_keep_tic_dir (const char *); extern NCURSES_EXPORT(void) _nc_make_oldhash (int i); -extern NCURSES_EXPORT(void) _nc_outstr (const char *str); extern NCURSES_EXPORT(void) _nc_scroll_oldhash (int n, int top, int bot); extern NCURSES_EXPORT(void) _nc_scroll_optimize (void); -extern NCURSES_EXPORT(void) _nc_scroll_window (WINDOW *, int const, short const, short const, NCURSES_CH_T); extern NCURSES_EXPORT(void) _nc_set_buffer (FILE *, bool); extern NCURSES_EXPORT(void) _nc_signal_handler (bool); extern NCURSES_EXPORT(void) _nc_synchook (WINDOW *); extern NCURSES_EXPORT(void) _nc_trace_tries (struct tries *); +#if NO_LEAKS +extern NCURSES_EXPORT(void) _nc_alloc_entry_leaks(void); +extern NCURSES_EXPORT(void) _nc_captoinfo_leaks(void); +extern NCURSES_EXPORT(void) _nc_comp_scan_leaks(void); +extern NCURSES_EXPORT(void) _nc_keyname_leaks(void); +extern NCURSES_EXPORT(void) _nc_tgetent_leaks(void); +#endif + +#ifndef USE_TERMLIB +extern NCURSES_EXPORT(NCURSES_CH_T) _nc_render (WINDOW *, NCURSES_CH_T); +extern NCURSES_EXPORT(int) _nc_waddch_nosync (WINDOW *, const NCURSES_CH_T); +extern NCURSES_EXPORT(void) _nc_scroll_window (WINDOW *, int const, NCURSES_SIZE_T const, NCURSES_SIZE_T const, NCURSES_CH_T); +#endif + +#if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB) +#ifdef linux +extern NCURSES_EXPORT(size_t) _nc_wcrtomb (char *, wchar_t, mbstate_t *); +#else +#define _nc_wcrtomb(s,wc,ps) wcrtomb(s,wc,ps) +#endif +#endif + #if USE_SIZECHANGE extern NCURSES_EXPORT(void) _nc_update_screensize (void); #endif @@ -926,6 +1244,13 @@ extern NCURSES_EXPORT(void) _nc_resize_margins (WINDOW *); #define _nc_resize_margins(wp) /* nothing */ #endif +#ifdef NCURSES_WGETCH_EVENTS +extern NCURSES_EXPORT(int) _nc_eventlist_timeout(_nc_eventlist *); +#else +#define wgetch_events(win, evl) wgetch(win) +#define wgetnstr_events(win, str, maxlen, evl) wgetnstr(win, str, maxlen) +#endif + /* * Not everyone has vsscanf(), but we'd like to use it for scanw(). */ @@ -938,9 +1263,7 @@ extern NCURSES_EXPORT_VAR(int *) _nc_oldnums; #define USE_SETBUF_0 0 -#define NC_BUFFERED(flag) \ - if ((SP->_buffered != 0) != flag) \ - _nc_set_buffer(SP->_ofp, flag) +#define NC_BUFFERED(flag) _nc_set_buffer(SP->_ofp, flag) #define NC_OUTPUT ((SP != 0) ? SP->_ofp : stdout) @@ -989,6 +1312,12 @@ extern NCURSES_EXPORT(int) _nc_slk_initialize (WINDOW *, int); extern NCURSES_EXPORT(int) _nc_ripoffline (int line, int (*init)(WINDOW *,int)); +/* + * Common error messages + */ +#define MSG_NO_MEMORY "Out of memory" +#define MSG_NO_INPUTS "Premature EOF" + #ifdef __cplusplus } #endif diff --git a/contrib/ncurses/ncurses/llib-lncurses b/contrib/ncurses/ncurses/llib-lncurses index 1a6e5cf109ba..594c72cd66f4 100644 --- a/contrib/ncurses/ncurses/llib-lncurses +++ b/contrib/ncurses/ncurses/llib-lncurses @@ -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 * @@ -27,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey 1996-2001,2002 * + * Author: Thomas E. Dickey 1996-2006 * ****************************************************************************/ /* LINTLIBRARY */ @@ -99,14 +99,14 @@ int wechochar( #undef waddnstr int waddnstr( WINDOW *win, - const char *const astr, + const char *astr, int n) { return(*(int *)0); } #undef waddchnstr int waddchnstr( WINDOW *win, - const chtype *const astr, + const chtype *astr, int n) { return(*(int *)0); } @@ -127,7 +127,7 @@ void wbkgdset( #undef wbkgd int wbkgd( WINDOW *win, - const chtype ch) + chtype ch) { return(*(int *)0); } /* ./base/lib_box.c */ @@ -194,6 +194,10 @@ int COLOR_PAIRS; #undef COLORS int COLORS; +#undef _nc_reset_colors +NCURSES_BOOL _nc_reset_colors(void) + { return(*(NCURSES_BOOL *)0); } + #undef start_color int start_color(void) { return(*(int *)0); } @@ -238,8 +242,8 @@ int pair_content( #undef _nc_do_color void _nc_do_color( - int old_pair, - int pair, + short old_pair, + short pair, NCURSES_BOOL reverse, int (*outc)( int p1)) @@ -912,7 +916,7 @@ int vline( #undef vw_printw int vw_printw( WINDOW *a1, - char *a2, + const char *a2, va_list z) { return(*(int *)0); } @@ -1013,11 +1017,51 @@ int wstandend( WINDOW *z) { return(*(int *)0); } +#undef getcurx +int getcurx( + const WINDOW *z) + { return(*(int *)0); } + +#undef getcury +int getcury( + const WINDOW *z) + { return(*(int *)0); } + +#undef getbegx +int getbegx( + const WINDOW *z) + { return(*(int *)0); } + +#undef getbegy +int getbegy( + const WINDOW *z) + { return(*(int *)0); } + +#undef getmaxx +int getmaxx( + const WINDOW *z) + { return(*(int *)0); } + +#undef getmaxy +int getmaxy( + const WINDOW *z) + { return(*(int *)0); } + +#undef getparx +int getparx( + const WINDOW *z) + { return(*(int *)0); } + +#undef getpary +int getpary( + const WINDOW *z) + { return(*(int *)0); } + #undef mouse_trafo NCURSES_BOOL mouse_trafo( int *a1, int *a2, - NCURSES_BOOL z) + NCURSES_BOOL z) { return(*(NCURSES_BOOL *)0); } /* ./base/lib_getch.c */ @@ -1082,6 +1126,12 @@ WINDOW *initscr(void) /* ./base/lib_insch.c */ +#undef _nc_insert_ch +int _nc_insert_ch( + WINDOW *win, + chtype ch) + { return(*(int *)0); } + #undef winsch int winsch( WINDOW *win, @@ -1096,7 +1146,7 @@ int winsdelln( int n) { return(*(int *)0); } -/* ./base/lib_insstr.c */ +/* ./base/lib_insnstr.c */ #undef winsnstr int winsnstr( @@ -1225,6 +1275,10 @@ int mvwin( void filter(void) { /* void */ } +#undef nofilter +void nofilter(void) + { /* void */ } + #undef newterm SCREEN *newterm( char *name, @@ -1360,14 +1414,14 @@ int pechochar( #undef printw int printw( - char *fmt, + const char *fmt, ...) { return(*(int *)0); } #undef wprintw int wprintw( WINDOW *win, - char *fmt, + const char *fmt, ...) { return(*(int *)0); } @@ -1375,7 +1429,7 @@ int wprintw( int mvprintw( int y, int x, - char *fmt, + const char *fmt, ...) { return(*(int *)0); } @@ -1384,14 +1438,14 @@ int mvwprintw( WINDOW *win, int y, int x, - char *fmt, + const char *fmt, ...) { return(*(int *)0); } #undef vwprintw int vwprintw( WINDOW *win, - char *fmt, + const char *fmt, va_list argp) { return(*(int *)0); } @@ -1466,8 +1520,6 @@ int mvwscanw( /* ./base/lib_screen.c */ -#include <time.h> - #undef getwin WINDOW *getwin( FILE *filep) @@ -1547,9 +1599,11 @@ void delscreen( #undef _nc_setupscreen int _nc_setupscreen( - short slines, - short const scolumns, - FILE *output) + int slines, + int scolumns, + FILE *output, + NCURSES_BOOL filtered, + int slk_format) { return(*(int *)0); } #undef _nc_ripoffline @@ -1692,46 +1746,6 @@ int wtouchln( int changed) { return(*(int *)0); } -/* ./trace/lib_traceatr.c */ - -#undef _traceattr2 -char *_traceattr2( - int bufnum, - attr_t newmode) - { return(*(char **)0); } - -#undef _traceattr -char *_traceattr( - attr_t newmode) - { return(*(char **)0); } - -#undef _nc_retrace_attr_t -attr_t _nc_retrace_attr_t( - attr_t code) - { return(*(attr_t *)0); } - -#undef _nc_altcharset_name -const char *_nc_altcharset_name( - attr_t attr, - chtype ch) - { return(*(const char **)0); } - -#undef _tracechtype2 -char *_tracechtype2( - int bufnum, - chtype ch) - { return(*(char **)0); } - -#undef _tracechtype -char *_tracechtype( - chtype ch) - { return(*(char **)0); } - -#undef _nc_retrace_chtype -attr_t _nc_retrace_chtype( - attr_t code) - { return(*(attr_t *)0); } - /* ./trace/lib_tracedmp.c */ #undef _tracedump @@ -1749,7 +1763,6 @@ char *_tracemouse( /* ./tty/lib_tstp.c */ -#include <signal.h> #include <SigAction.h> #undef _nc_signal_handler @@ -1883,11 +1896,6 @@ char *_nc_printf_string( int doupdate(void) { return(*(int *)0); } -#undef _nc_outstr -void _nc_outstr( - const char *str) - { /* void */ } - #undef _nc_scrolln int _nc_scrolln( int n, @@ -1931,25 +1939,19 @@ char *_nc_varargs( void _nc_memmove(void) { /* void */ } -/* ./base/sigaction.c */ - -#undef _nc_sigaction -void _nc_sigaction(void) - { /* void */ } - /* ./base/vsscanf.c */ #undef _nc_vsscanf void _nc_vsscanf(void) { /* void */ } -/* ./base/define_key.c */ +/* ./base/lib_freeall.c */ -#undef define_key -int define_key( - char *str, - int keycode) - { return(*(int *)0); } +#include <term_entry.h> + +#undef _nc_freeall +void _nc_freeall(void) + { /* void */ } /* ./expanded.c */ @@ -1980,20 +1982,11 @@ void _nc_UpdateAttrs( chtype c) { /* void */ } -/* ./base/keybound.c */ - -#undef keybound -char *keybound( - int code, - int count) - { return(*(char **)0); } +/* ./base/legacy_coding.c */ -/* ./base/keyok.c */ - -#undef keyok -int keyok( - int c, - NCURSES_BOOL flag) +#undef use_legacy_coding +int use_legacy_coding( + int level) { return(*(int *)0); } /* ./base/lib_dft_fgbg.c */ @@ -2008,14 +2001,6 @@ int assume_default_colors( int bg) { return(*(int *)0); } -/* ./base/lib_freeall.c */ - -#include <term_entry.h> - -#undef _nc_freeall -void _nc_freeall(void) - { /* void */ } - /* ./tinfo/lib_print.c */ #undef mcprint @@ -2051,34 +2036,6 @@ void _nc_trace_xnames( TERMTYPE *tp) { /* void */ } -/* ./base/tries.c */ - -#undef _nc_expand_try -char *_nc_expand_try( - struct tries *tree, - unsigned short code, - int *count, - size_t len) - { return(*(char **)0); } - -#undef _nc_remove_key -int _nc_remove_key( - struct tries **tree, - unsigned short code) - { return(*(int *)0); } - -#undef _nc_remove_string -int _nc_remove_string( - struct tries **tree, - char *string) - { return(*(int *)0); } - -/* ./base/version.c */ - -#undef curses_version -const char *curses_version(void) - { return(*(const char **)0); } - /* ./base/wresize.c */ #undef wresize @@ -2090,11 +2047,24 @@ int wresize( /* ./tinfo/access.c */ +#include <sys/stat.h> +#include <nc_alloc.h> + #undef _nc_rootname char *_nc_rootname( char *path) { return(*(char **)0); } +#undef _nc_is_abs_path +NCURSES_BOOL _nc_is_abs_path( + const char *path) + { return(*(NCURSES_BOOL *)0); } + +#undef _nc_pathlast +unsigned _nc_pathlast( + const char *path) + { return(*(unsigned *)0); } + #undef _nc_basename char *_nc_basename( char *path) @@ -2106,6 +2076,16 @@ int _nc_access( int mode) { return(*(int *)0); } +#undef _nc_is_dir_path +NCURSES_BOOL _nc_is_dir_path( + const char *path) + { return(*(NCURSES_BOOL *)0); } + +#undef _nc_is_file_path +NCURSES_BOOL _nc_is_file_path( + const char *path) + { return(*(NCURSES_BOOL *)0); } + #undef _nc_env_access int _nc_env_access(void) { return(*(int *)0); } @@ -2116,7 +2096,7 @@ int _nc_env_access(void) void _nc_add_to_try( struct tries **tree, const char *str, - unsigned short code) + unsigned code) { /* void */ } /* ./tinfo/alloc_entry.c */ @@ -2168,14 +2148,14 @@ void _nc_copy_termtype( char *_nc_captoinfo( const char *cap, const char *s, - int const parametrized) + int const parameterized) { return(*(char **)0); } #undef _nc_infotocap char *_nc_infotocap( const char *cap, const char *str, - int const parametrized) + int const parameterized) { return(*(char **)0); } /* ./codes.c */ @@ -2219,6 +2199,10 @@ int _nc_curr_line; #undef _nc_curr_col int _nc_curr_col; +#undef _nc_get_source +const char *_nc_get_source(void) + { return(*(const char **)0); } + #undef _nc_set_source void _nc_set_source( const char *const name) @@ -2280,6 +2264,10 @@ struct name_table_entry const *_nc_find_type_entry( /* ./tinfo/comp_parse.c */ +#undef _nc_check_termtype2 +void (*_nc_check_termtype2)( + TERMTYPE *p1, + NCURSES_BOOL p2); #undef _nc_check_termtype void (*_nc_check_termtype)( TERMTYPE *p1); @@ -2293,6 +2281,18 @@ void _nc_free_entries( ENTRY *headp) { /* void */ } +#undef _nc_delink_entry +ENTRY *_nc_delink_entry( + ENTRY *headp, + TERMTYPE *tterm) + { return(*(ENTRY **)0); } + +#undef _nc_free_entry +void _nc_free_entry( + ENTRY *headp, + TERMTYPE *tterm) + { /* void */ } + #undef _nc_entry_match NCURSES_BOOL _nc_entry_match( char *n1, @@ -2309,6 +2309,12 @@ void _nc_read_entry_source( ENTRY *p1)) { /* void */ } +#undef _nc_resolve_uses2 +int _nc_resolve_uses2( + NCURSES_BOOL fullresolve, + NCURSES_BOOL literal) + { return(*(int *)0); } + #undef _nc_resolve_uses int _nc_resolve_uses( NCURSES_BOOL fullresolve) @@ -2331,16 +2337,22 @@ struct token _nc_curr_token; #undef _nc_disable_period NCURSES_BOOL _nc_disable_period; +#undef _nc_reset_input +void _nc_reset_input( + FILE *fp, + char *buf) + { /* void */ } + #undef _nc_get_token int _nc_get_token( NCURSES_BOOL silent) { return(*(int *)0); } #undef _nc_trans_string -char _nc_trans_string( +int _nc_trans_string( char *ptr, char *last) - { return(*(char *)0); } + { return(*(int *)0); } #undef _nc_push_token void _nc_push_token( @@ -2352,10 +2364,32 @@ void _nc_panic_mode( char ch) { /* void */ } -#undef _nc_reset_input -void _nc_reset_input( - FILE *fp, - char *buf) +/* ./tinfo/db_iterator.c */ + +#undef _nc_tic_dir +const char *_nc_tic_dir( + const char *path) + { return(*(const char **)0); } + +#undef _nc_keep_tic_dir +void _nc_keep_tic_dir( + const char *path) + { /* void */ } + +#undef _nc_last_db +void _nc_last_db(void) + { /* void */ } + +#undef _nc_next_db +const char *_nc_next_db( + DBDIRS *state, + int *offset) + { return(*(const char **)0); } + +#undef _nc_first_db +void _nc_first_db( + DBDIRS *state, + int *offset) { /* void */ } /* ./tinfo/doalloc.c */ @@ -2419,7 +2453,7 @@ void _nc_init_keytry(void) /* ./tinfo/lib_acs.c */ #undef acs_map -chtype acs_map[128 ]; +chtype acs_map[128]; #undef _nc_init_acs void _nc_init_acs(void) @@ -2430,8 +2464,8 @@ void _nc_init_acs(void) #include <termcap.h> struct speed { - int s; - int sp; + int s; + int sp; }; #undef _nc_baudrate @@ -2518,6 +2552,8 @@ char *longname(void) /* ./tinfo/lib_napms.c */ +#include <time.h> + #undef napms int napms( int ms) @@ -2626,13 +2662,12 @@ int intrflush( /* ./tinfo/lib_setup.c */ +#include <locale.h> #include <sys/ioctl.h> +#include <langinfo.h> -#undef use_env -void use_env( - NCURSES_BOOL f) - { /* void */ } - +#undef ttytype +char ttytype[256]; #undef LINES int LINES; #undef COLS @@ -2640,12 +2675,39 @@ int COLS; #undef TABSIZE int TABSIZE; +#undef _nc_handle_sigwinch +int _nc_handle_sigwinch( + int enable) + { return(*(int *)0); } + +#undef use_env +void use_env( + NCURSES_BOOL f) + { /* void */ } + #undef _nc_update_screensize void _nc_update_screensize(void) { /* void */ } -#undef ttytype -char ttytype[256 ]; +#undef _nc_get_locale +char *_nc_get_locale(void) + { return(*(char **)0); } + +#undef _nc_unicode_locale +int _nc_unicode_locale(void) + { return(*(int *)0); } + +#undef _nc_locale_breaks_acs +int _nc_locale_breaks_acs(void) + { return(*(int *)0); } + +#undef _nc_setupterm +int _nc_setupterm( + char *tname, + int Filedes, + int *errret, + NCURSES_BOOL reuse) + { return(*(int *)0); } #undef setupterm int setupterm( @@ -2725,15 +2787,22 @@ char *tigetstr( typedef struct { union { - unsigned int num; - char *str; + int num; + char *str; } data; - NCURSES_BOOL num_type; + NCURSES_BOOL num_type; } stack_frame; #undef _nc_tparm_err int _nc_tparm_err; +#undef _nc_tparm_analyze +int _nc_tparm_analyze( + const char *string, + char *p_is_s[9], + int *popcount) + { return(*(int *)0); } + #undef tparm char *tparm( char *string, @@ -2796,16 +2865,41 @@ void _tracef( ...) { /* void */ } +#undef _nc_retrace_bool +NCURSES_BOOL _nc_retrace_bool( + NCURSES_BOOL code) + { return(*(NCURSES_BOOL *)0); } + #undef _nc_retrace_int int _nc_retrace_int( int code) { return(*(int *)0); } +#undef _nc_retrace_unsigned +unsigned _nc_retrace_unsigned( + unsigned code) + { return(*(unsigned *)0); } + #undef _nc_retrace_ptr char *_nc_retrace_ptr( char *code) { return(*(char **)0); } +#undef _nc_retrace_cptr +const char *_nc_retrace_cptr( + const char *code) + { return(*(const char **)0); } + +#undef _nc_retrace_cvoid_ptr +void *_nc_retrace_cvoid_ptr( + void *code) + { return(*(void **)0); } + +#undef _nc_retrace_void_ptr +void *_nc_retrace_void_ptr( + void *code) + { return(*(void **)0); } + #undef _nc_retrace_sp SCREEN *_nc_retrace_sp( SCREEN *code) @@ -2816,6 +2910,46 @@ WINDOW *_nc_retrace_win( WINDOW *code) { return(*(WINDOW **)0); } +/* ./trace/lib_traceatr.c */ + +#undef _traceattr2 +char *_traceattr2( + int bufnum, + chtype newmode) + { return(*(char **)0); } + +#undef _traceattr +char *_traceattr( + attr_t newmode) + { return(*(char **)0); } + +#undef _nc_retrace_attr_t +attr_t _nc_retrace_attr_t( + attr_t code) + { return(*(attr_t *)0); } + +#undef _nc_altcharset_name +const char *_nc_altcharset_name( + attr_t attr, + chtype ch) + { return(*(const char **)0); } + +#undef _tracechtype2 +char *_tracechtype2( + int bufnum, + chtype ch) + { return(*(char **)0); } + +#undef _tracechtype +char *_tracechtype( + chtype ch) + { return(*(char **)0); } + +#undef _nc_retrace_chtype +chtype _nc_retrace_chtype( + chtype code) + { return(*(chtype *)0); } + /* ./trace/lib_tracebits.c */ typedef struct { @@ -2823,6 +2957,11 @@ typedef struct { const char *name; } BITNAMES; +#undef _nc_trace_ttymode +char *_nc_trace_ttymode( + struct termios *tty) + { return(*(char **)0); } + #undef _nc_tracebits char *_nc_tracebits(void) { return(*(char **)0); } @@ -2930,15 +3069,14 @@ typedef struct { /* ./tinfo/read_entry.c */ -#undef _nc_tic_dir -const char *_nc_tic_dir( - const char *path) - { return(*(const char **)0); } +#include <hashed_db.h> -#undef _nc_keep_tic_dir -void _nc_keep_tic_dir( - const char *path) - { /* void */ } +#undef _nc_read_termtype +int _nc_read_termtype( + TERMTYPE *ptr, + char *buffer, + int limit) + { return(*(int *)0); } #undef _nc_read_file_entry int _nc_read_file_entry( @@ -2948,13 +3086,15 @@ int _nc_read_file_entry( #undef _nc_read_entry int _nc_read_entry( - const char *const tn, + const char *const name, char *const filename, TERMTYPE *const tp) { return(*(int *)0); } /* ./tinfo/read_termcap.c */ +#include <sys/types.h> + #undef _nc_read_termcap_entry int _nc_read_termcap_entry( const char *const tn, @@ -3015,6 +3155,12 @@ char *_nc_trace_buf( size_t want) { return(*(char **)0); } +#undef _nc_trace_bufcat +char *_nc_trace_bufcat( + int bufnum, + const char *value) + { return(*(char **)0); } + /* ./trace/trace_tries.c */ #undef _nc_trace_tries @@ -3022,6 +3168,35 @@ void _nc_trace_tries( struct tries *tree) { /* void */ } +/* ./base/tries.c */ + +#undef _nc_expand_try +char *_nc_expand_try( + struct tries *tree, + unsigned code, + int *count, + size_t len) + { return(*(char **)0); } + +#undef _nc_remove_key +int _nc_remove_key( + struct tries **tree, + unsigned code) + { return(*(int *)0); } + +#undef _nc_remove_string +int _nc_remove_string( + struct tries **tree, + const char *string) + { return(*(int *)0); } + +/* ./tinfo/trim_sgr0.c */ + +#undef _nc_trim_sgr0 +char *_nc_trim_sgr0( + TERMTYPE *tp) + { return(*(char **)0); } + /* ./unctrl.c */ #undef unctrl @@ -3042,6 +3217,25 @@ const char *_nc_visbuf( const char *buf) { return(*(const char **)0); } +#undef _nc_visbufn +const char *_nc_visbufn( + const char *buf, + int len) + { return(*(const char **)0); } + +#undef _nc_viscbuf2 +const char *_nc_viscbuf2( + int bufnum, + const chtype *buf, + int len) + { return(*(const char **)0); } + +#undef _nc_viscbuf +const char *_nc_viscbuf( + const chtype *buf, + int len) + { return(*(const char **)0); } + /* ./tinfo/write_entry.c */ #undef _nc_set_writedir @@ -3057,3 +3251,46 @@ void _nc_write_entry( #undef _nc_tic_written int _nc_tic_written(void) { return(*(int *)0); } + +/* ./base/define_key.c */ + +#undef define_key +int define_key( + const char *str, + int keycode) + { return(*(int *)0); } + +/* ./tinfo/hashed_db.c */ + +#undef _nc_hashed_db +void _nc_hashed_db(void) + { /* void */ } + +/* ./base/key_defined.c */ + +#undef key_defined +int key_defined( + const char *str) + { return(*(int *)0); } + +/* ./base/keybound.c */ + +#undef keybound +char *keybound( + int code, + int count) + { return(*(char **)0); } + +/* ./base/keyok.c */ + +#undef keyok +int keyok( + int c, + NCURSES_BOOL flag) + { return(*(int *)0); } + +/* ./base/version.c */ + +#undef curses_version +const char *curses_version(void) + { return(*(const char **)0); } diff --git a/contrib/ncurses/ncurses/llib-lncursesw b/contrib/ncurses/ncurses/llib-lncursesw index ffb0af650c61..86ef2845d1ff 100644 --- a/contrib/ncurses/ncurses/llib-lncursesw +++ b/contrib/ncurses/ncurses/llib-lncursesw @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2001,2002 Free Software Foundation, Inc. * + * Copyright (c) 2001-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,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey 2001,2002 * + * Author: Thomas E. Dickey 2001-2006 * ****************************************************************************/ /* LINTLIBRARY */ @@ -76,6 +76,12 @@ cchar_t _nc_render( cchar_t ch) { return(*(cchar_t *)0); } +#undef _nc_build_wch +int _nc_build_wch( + WINDOW *win, + cchar_t *ch) + { return(*(int *)0); } + #undef _nc_waddch_nosync int _nc_waddch_nosync( WINDOW *win, @@ -94,31 +100,19 @@ int wechochar( const chtype ch) { return(*(int *)0); } -#undef wadd_wch -int wadd_wch( - WINDOW *win, - const cchar_t *wch) - { return(*(int *)0); } - -#undef wecho_wchar -int wecho_wchar( - WINDOW *win, - const cchar_t *wch) - { return(*(int *)0); } - /* ./base/lib_addstr.c */ #undef waddnstr int waddnstr( WINDOW *win, - const char *const astr, + const char *astr, int n) { return(*(int *)0); } #undef waddchnstr int waddchnstr( WINDOW *win, - const chtype *const astr, + const chtype *astr, int n) { return(*(int *)0); } @@ -130,7 +124,7 @@ int _nc_wchstrlen( #undef wadd_wchnstr int wadd_wchnstr( WINDOW *win, - const cchar_t *const astr, + const cchar_t *astr, int n) { return(*(int *)0); } @@ -170,7 +164,7 @@ int wbkgrnd( #undef wbkgd int wbkgd( WINDOW *win, - const chtype ch) + chtype ch) { return(*(int *)0); } /* ./base/lib_box.c */ @@ -237,6 +231,10 @@ int COLOR_PAIRS; #undef COLORS int COLORS; +#undef _nc_reset_colors +NCURSES_BOOL _nc_reset_colors(void) + { return(*(NCURSES_BOOL *)0); } + #undef start_color int start_color(void) { return(*(int *)0); } @@ -281,8 +279,8 @@ int pair_content( #undef _nc_do_color void _nc_do_color( - int old_pair, - int pair, + short old_pair, + short pair, NCURSES_BOOL reverse, int (*outc)( int p1)) @@ -958,13 +956,6 @@ int untouchwin( WINDOW *z) { return(*(int *)0); } -#undef vid_attr -int vid_attr( - attr_t a1, - short a2, - void *z) - { return(*(int *)0); } - #undef vline int vline( chtype a1, @@ -974,7 +965,7 @@ int vline( #undef vw_printw int vw_printw( WINDOW *a1, - char *a2, + const char *a2, va_list z) { return(*(int *)0); } @@ -1075,6 +1066,46 @@ int wstandend( WINDOW *z) { return(*(int *)0); } +#undef getcurx +int getcurx( + const WINDOW *z) + { return(*(int *)0); } + +#undef getcury +int getcury( + const WINDOW *z) + { return(*(int *)0); } + +#undef getbegx +int getbegx( + const WINDOW *z) + { return(*(int *)0); } + +#undef getbegy +int getbegy( + const WINDOW *z) + { return(*(int *)0); } + +#undef getmaxx +int getmaxx( + const WINDOW *z) + { return(*(int *)0); } + +#undef getmaxy +int getmaxy( + const WINDOW *z) + { return(*(int *)0); } + +#undef getparx +int getparx( + const WINDOW *z) + { return(*(int *)0); } + +#undef getpary +int getpary( + const WINDOW *z) + { return(*(int *)0); } + #undef add_wch int add_wch( const cchar_t *z) @@ -1138,12 +1169,12 @@ int echo_wchar( #undef get_wch int get_wch( - wint_t *z) + wint_t *z) { return(*(int *)0); } #undef get_wstr int get_wstr( - wint_t *z) + wint_t *z) { return(*(int *)0); } #undef getbkgrnd @@ -1153,7 +1184,7 @@ int getbkgrnd( #undef getn_wstr int getn_wstr( - wint_t *a1, + wint_t *a1, int z) { return(*(int *)0); } @@ -1181,7 +1212,7 @@ int in_wchstr( #undef innwstr int innwstr( - wchar_t *a1, + wchar_t *a1, int z) { return(*(int *)0); } @@ -1203,7 +1234,7 @@ int ins_wstr( #undef inwstr int inwstr( - wchar_t *z) + wchar_t *z) { return(*(int *)0); } #undef mvadd_wch @@ -1247,21 +1278,21 @@ int mvaddwstr( int mvget_wch( int a1, int a2, - wint_t *z) + wint_t *z) { return(*(int *)0); } #undef mvget_wstr int mvget_wstr( int a1, int a2, - wint_t *z) + wint_t *z) { return(*(int *)0); } #undef mvgetn_wstr int mvgetn_wstr( int a1, int a2, - wint_t *a3, + wint_t *a3, int z) { return(*(int *)0); } @@ -1299,7 +1330,7 @@ int mvin_wchstr( int mvinnwstr( int a1, int a2, - wchar_t *a3, + wchar_t *a3, int z) { return(*(int *)0); } @@ -1329,7 +1360,7 @@ int mvins_wstr( int mvinwstr( int a1, int a2, - wchar_t *z) + wchar_t *z) { return(*(int *)0); } #undef mvvline_set @@ -1387,7 +1418,7 @@ int mvwget_wch( WINDOW *a1, int a2, int a3, - wint_t *z) + wint_t *z) { return(*(int *)0); } #undef mvwget_wstr @@ -1395,7 +1426,7 @@ int mvwget_wstr( WINDOW *a1, int a2, int a3, - wint_t *z) + wint_t *z) { return(*(int *)0); } #undef mvwgetn_wstr @@ -1403,7 +1434,7 @@ int mvwgetn_wstr( WINDOW *a1, int a2, int a3, - wint_t *a4, + wint_t *a4, int z) { return(*(int *)0); } @@ -1446,7 +1477,7 @@ int mvwinnwstr( WINDOW *a1, int a2, int a3, - wchar_t *a4, + wchar_t *a4, int z) { return(*(int *)0); } @@ -1480,7 +1511,7 @@ int mvwinwstr( WINDOW *a1, int a2, int a3, - wchar_t *z) + wchar_t *z) { return(*(int *)0); } #undef mvwvline_set @@ -1513,7 +1544,13 @@ int waddwstr( #undef wget_wstr int wget_wstr( WINDOW *a1, - wint_t *z) + wint_t *z) + { return(*(int *)0); } + +#undef wgetbkgrnd +int wgetbkgrnd( + WINDOW *a1, + cchar_t *z) { return(*(int *)0); } #undef win_wchstr @@ -1532,7 +1569,7 @@ int wins_wstr( NCURSES_BOOL mouse_trafo( int *a1, int *a2, - NCURSES_BOOL z) + NCURSES_BOOL z) { return(*(NCURSES_BOOL *)0); } /* ./base/lib_getch.c */ @@ -1597,6 +1634,12 @@ WINDOW *initscr(void) /* ./base/lib_insch.c */ +#undef _nc_insert_ch +int _nc_insert_ch( + WINDOW *win, + chtype ch) + { return(*(int *)0); } + #undef winsch int winsch( WINDOW *win, @@ -1611,7 +1654,7 @@ int winsdelln( int n) { return(*(int *)0); } -/* ./base/lib_insstr.c */ +/* ./base/lib_insnstr.c */ #undef winsnstr int winsnstr( @@ -1740,6 +1783,10 @@ int mvwin( void filter(void) { /* void */ } +#undef nofilter +void nofilter(void) + { /* void */ } + #undef newterm SCREEN *newterm( char *name, @@ -1875,14 +1922,14 @@ int pechochar( #undef printw int printw( - char *fmt, + const char *fmt, ...) { return(*(int *)0); } #undef wprintw int wprintw( WINDOW *win, - char *fmt, + const char *fmt, ...) { return(*(int *)0); } @@ -1890,7 +1937,7 @@ int wprintw( int mvprintw( int y, int x, - char *fmt, + const char *fmt, ...) { return(*(int *)0); } @@ -1899,14 +1946,14 @@ int mvwprintw( WINDOW *win, int y, int x, - char *fmt, + const char *fmt, ...) { return(*(int *)0); } #undef vwprintw int vwprintw( WINDOW *win, - char *fmt, + const char *fmt, va_list argp) { return(*(int *)0); } @@ -1981,8 +2028,6 @@ int mvwscanw( /* ./base/lib_screen.c */ -#include <time.h> - #undef getwin WINDOW *getwin( FILE *filep) @@ -2062,9 +2107,11 @@ void delscreen( #undef _nc_setupscreen int _nc_setupscreen( - short slines, - short const scolumns, - FILE *output) + int slines, + int scolumns, + FILE *output, + NCURSES_BOOL filtered, + int slk_format) { return(*(int *)0); } #undef _nc_ripoffline @@ -2173,6 +2220,8 @@ int slk_refresh(void) /* ./base/lib_slkset.c */ +#include <wctype.h> + #undef slk_set int slk_set( int i, @@ -2207,57 +2256,6 @@ int wtouchln( int changed) { return(*(int *)0); } -/* ./trace/lib_traceatr.c */ - -#undef _traceattr2 -char *_traceattr2( - int bufnum, - attr_t newmode) - { return(*(char **)0); } - -#undef _traceattr -char *_traceattr( - attr_t newmode) - { return(*(char **)0); } - -#undef _nc_retrace_attr_t -attr_t _nc_retrace_attr_t( - attr_t code) - { return(*(attr_t *)0); } - -#undef _nc_altcharset_name -const char *_nc_altcharset_name( - attr_t attr, - chtype ch) - { return(*(const char **)0); } - -#undef _tracechtype2 -char *_tracechtype2( - int bufnum, - chtype ch) - { return(*(char **)0); } - -#undef _tracechtype -char *_tracechtype( - chtype ch) - { return(*(char **)0); } - -#undef _nc_retrace_chtype -attr_t _nc_retrace_chtype( - attr_t code) - { return(*(attr_t *)0); } - -#undef _tracecchar_t2 -char *_tracecchar_t2( - int bufnum, - const cchar_t *ch) - { return(*(char **)0); } - -#undef _tracecchar_t -char *_tracecchar_t( - const cchar_t *ch) - { return(*(char **)0); } - /* ./trace/lib_tracedmp.c */ #undef _tracedump @@ -2275,7 +2273,6 @@ char *_tracemouse( /* ./tty/lib_tstp.c */ -#include <signal.h> #include <SigAction.h> #undef _nc_signal_handler @@ -2409,11 +2406,6 @@ char *_nc_printf_string( int doupdate(void) { return(*(int *)0); } -#undef _nc_outstr -void _nc_outstr( - const char *str) - { /* void */ } - #undef _nc_scrolln int _nc_scrolln( int n, @@ -2457,18 +2449,51 @@ char *_nc_varargs( void _nc_memmove(void) { /* void */ } -/* ./base/sigaction.c */ - -#undef _nc_sigaction -void _nc_sigaction(void) - { /* void */ } - /* ./base/vsscanf.c */ #undef _nc_vsscanf void _nc_vsscanf(void) { /* void */ } +/* ./base/lib_freeall.c */ + +#include <term_entry.h> + +#undef _nc_freeall +void _nc_freeall(void) + { /* void */ } + +/* ./widechar/charable.c */ + +#undef _nc_is_charable +NCURSES_BOOL _nc_is_charable( + wchar_t ch) + { return(*(NCURSES_BOOL *)0); } + +#undef _nc_to_char +int _nc_to_char( + wint_t ch) + { return(*(int *)0); } + +#undef _nc_to_widechar +wint_t _nc_to_widechar( + int ch) + { return(*(wint_t *)0); } + +/* ./widechar/lib_add_wch.c */ + +#undef wadd_wch +int wadd_wch( + WINDOW *win, + const cchar_t *wch) + { return(*(int *)0); } + +#undef wecho_wchar +int wecho_wchar( + WINDOW *win, + const cchar_t *wch) + { return(*(int *)0); } + /* ./widechar/lib_box_set.c */ #undef wborder_set @@ -2498,7 +2523,7 @@ int setcchar( #undef getcchar int getcchar( const cchar_t *wcval, - wchar_t *wch, + wchar_t *wch, attr_t *attrs, short *color_pair, void *opts) @@ -2509,7 +2534,19 @@ int getcchar( #undef wget_wch int wget_wch( WINDOW *win, - wint_t *result) + wint_t *result) + { return(*(int *)0); } + +/* ./widechar/lib_erasewchar.c */ + +#undef erasewchar +int erasewchar( + wchar_t *wch) + { return(*(int *)0); } + +#undef killwchar +int killwchar( + wchar_t *wch) { return(*(int *)0); } /* ./widechar/lib_get_wstr.c */ @@ -2517,7 +2554,7 @@ int wget_wch( #undef wgetn_wstr int wgetn_wstr( WINDOW *win, - wint_t *str, + wint_t *str, int maxlen) { return(*(int *)0); } @@ -2547,15 +2584,6 @@ int win_wchnstr( int n) { return(*(int *)0); } -/* ./widechar/lib_ins_nwstr.c */ - -#undef wins_nwstr -int wins_nwstr( - WINDOW *win, - const wchar_t *wstr, - int n) - { return(*(int *)0); } - /* ./widechar/lib_ins_wch.c */ #undef wins_wch @@ -2564,28 +2592,81 @@ int wins_wch( const cchar_t *wch) { return(*(int *)0); } +#undef wins_nwstr +int wins_nwstr( + WINDOW *win, + const wchar_t *wstr, + int n) + { return(*(int *)0); } + /* ./widechar/lib_inwstr.c */ #undef winnwstr int winnwstr( WINDOW *win, - wchar_t *wstr, + wchar_t *wstr, int n) { return(*(int *)0); } #undef winwstr int winwstr( WINDOW *win, - wchar_t *wstr) + wchar_t *wstr) + { return(*(int *)0); } + +/* ./widechar/lib_pecho_wchar.c */ + +#undef pecho_wchar +int pecho_wchar( + WINDOW *pad, + const cchar_t *wch) + { return(*(int *)0); } + +/* ./widechar/lib_slk_wset.c */ + +#undef slk_wset +int slk_wset( + int i, + const wchar_t *astr, + int format) { return(*(int *)0); } /* ./widechar/lib_unget_wch.c */ +#undef _nc_wcrtomb +size_t _nc_wcrtomb( + char *target, + wchar_t source, + mbstate_t *state) + { return(*(size_t *)0); } + #undef unget_wch int unget_wch( const wchar_t wch) { return(*(int *)0); } +/* ./widechar/lib_vid_attr.c */ + +#undef vid_puts +int vid_puts( + attr_t newmode, + short pair, + void *opts, + int (*outc)( + int p1)) + { return(*(int *)0); } + +#undef vid_attr +int vid_attr( + attr_t newmode, + short pair, + void *opts) + { return(*(int *)0); } + +#undef term_attrs +attr_t term_attrs(void) + { return(*(attr_t *)0); } + /* ./widechar/lib_vline_set.c */ #undef wvline_set @@ -2607,18 +2688,10 @@ void _nc_init_wacs(void) /* ./widechar/lib_wunctrl.c */ #undef wunctrl -wchar_t *wunctrl( +wchar_t *wunctrl( cchar_t *wc) { return(*(wchar_t **)0); } -/* ./base/define_key.c */ - -#undef define_key -int define_key( - char *str, - int keycode) - { return(*(int *)0); } - /* ./expanded.c */ #undef _nc_toggle_attr_on @@ -2645,23 +2718,14 @@ int _nc_InsCharCost( #undef _nc_UpdateAttrs void _nc_UpdateAttrs( - chtype c) + cchar_t c) { /* void */ } -/* ./base/keybound.c */ +/* ./base/legacy_coding.c */ -#undef keybound -char *keybound( - int code, - int count) - { return(*(char **)0); } - -/* ./base/keyok.c */ - -#undef keyok -int keyok( - int c, - NCURSES_BOOL flag) +#undef use_legacy_coding +int use_legacy_coding( + int level) { return(*(int *)0); } /* ./base/lib_dft_fgbg.c */ @@ -2676,14 +2740,6 @@ int assume_default_colors( int bg) { return(*(int *)0); } -/* ./base/lib_freeall.c */ - -#include <term_entry.h> - -#undef _nc_freeall -void _nc_freeall(void) - { /* void */ } - /* ./tinfo/lib_print.c */ #undef mcprint @@ -2719,34 +2775,6 @@ void _nc_trace_xnames( TERMTYPE *tp) { /* void */ } -/* ./base/tries.c */ - -#undef _nc_expand_try -char *_nc_expand_try( - struct tries *tree, - unsigned short code, - int *count, - size_t len) - { return(*(char **)0); } - -#undef _nc_remove_key -int _nc_remove_key( - struct tries **tree, - unsigned short code) - { return(*(int *)0); } - -#undef _nc_remove_string -int _nc_remove_string( - struct tries **tree, - char *string) - { return(*(int *)0); } - -/* ./base/version.c */ - -#undef curses_version -const char *curses_version(void) - { return(*(const char **)0); } - /* ./base/wresize.c */ #undef wresize @@ -2758,11 +2786,24 @@ int wresize( /* ./tinfo/access.c */ +#include <sys/stat.h> +#include <nc_alloc.h> + #undef _nc_rootname char *_nc_rootname( char *path) { return(*(char **)0); } +#undef _nc_is_abs_path +NCURSES_BOOL _nc_is_abs_path( + const char *path) + { return(*(NCURSES_BOOL *)0); } + +#undef _nc_pathlast +unsigned _nc_pathlast( + const char *path) + { return(*(unsigned *)0); } + #undef _nc_basename char *_nc_basename( char *path) @@ -2774,6 +2815,16 @@ int _nc_access( int mode) { return(*(int *)0); } +#undef _nc_is_dir_path +NCURSES_BOOL _nc_is_dir_path( + const char *path) + { return(*(NCURSES_BOOL *)0); } + +#undef _nc_is_file_path +NCURSES_BOOL _nc_is_file_path( + const char *path) + { return(*(NCURSES_BOOL *)0); } + #undef _nc_env_access int _nc_env_access(void) { return(*(int *)0); } @@ -2784,7 +2835,7 @@ int _nc_env_access(void) void _nc_add_to_try( struct tries **tree, const char *str, - unsigned short code) + unsigned code) { /* void */ } /* ./tinfo/alloc_entry.c */ @@ -2836,14 +2887,14 @@ void _nc_copy_termtype( char *_nc_captoinfo( const char *cap, const char *s, - int const parametrized) + int const parameterized) { return(*(char **)0); } #undef _nc_infotocap char *_nc_infotocap( const char *cap, const char *str, - int const parametrized) + int const parameterized) { return(*(char **)0); } /* ./codes.c */ @@ -2887,6 +2938,10 @@ int _nc_curr_line; #undef _nc_curr_col int _nc_curr_col; +#undef _nc_get_source +const char *_nc_get_source(void) + { return(*(const char **)0); } + #undef _nc_set_source void _nc_set_source( const char *const name) @@ -2948,6 +3003,10 @@ struct name_table_entry const *_nc_find_type_entry( /* ./tinfo/comp_parse.c */ +#undef _nc_check_termtype2 +void (*_nc_check_termtype2)( + TERMTYPE *p1, + NCURSES_BOOL p2); #undef _nc_check_termtype void (*_nc_check_termtype)( TERMTYPE *p1); @@ -2961,6 +3020,18 @@ void _nc_free_entries( ENTRY *headp) { /* void */ } +#undef _nc_delink_entry +ENTRY *_nc_delink_entry( + ENTRY *headp, + TERMTYPE *tterm) + { return(*(ENTRY **)0); } + +#undef _nc_free_entry +void _nc_free_entry( + ENTRY *headp, + TERMTYPE *tterm) + { /* void */ } + #undef _nc_entry_match NCURSES_BOOL _nc_entry_match( char *n1, @@ -2977,6 +3048,12 @@ void _nc_read_entry_source( ENTRY *p1)) { /* void */ } +#undef _nc_resolve_uses2 +int _nc_resolve_uses2( + NCURSES_BOOL fullresolve, + NCURSES_BOOL literal) + { return(*(int *)0); } + #undef _nc_resolve_uses int _nc_resolve_uses( NCURSES_BOOL fullresolve) @@ -2999,16 +3076,22 @@ struct token _nc_curr_token; #undef _nc_disable_period NCURSES_BOOL _nc_disable_period; +#undef _nc_reset_input +void _nc_reset_input( + FILE *fp, + char *buf) + { /* void */ } + #undef _nc_get_token int _nc_get_token( NCURSES_BOOL silent) { return(*(int *)0); } #undef _nc_trans_string -char _nc_trans_string( +int _nc_trans_string( char *ptr, char *last) - { return(*(char *)0); } + { return(*(int *)0); } #undef _nc_push_token void _nc_push_token( @@ -3020,10 +3103,32 @@ void _nc_panic_mode( char ch) { /* void */ } -#undef _nc_reset_input -void _nc_reset_input( - FILE *fp, - char *buf) +/* ./tinfo/db_iterator.c */ + +#undef _nc_tic_dir +const char *_nc_tic_dir( + const char *path) + { return(*(const char **)0); } + +#undef _nc_keep_tic_dir +void _nc_keep_tic_dir( + const char *path) + { /* void */ } + +#undef _nc_last_db +void _nc_last_db(void) + { /* void */ } + +#undef _nc_next_db +const char *_nc_next_db( + DBDIRS *state, + int *offset) + { return(*(const char **)0); } + +#undef _nc_first_db +void _nc_first_db( + DBDIRS *state, + int *offset) { /* void */ } /* ./tinfo/doalloc.c */ @@ -3087,7 +3192,7 @@ void _nc_init_keytry(void) /* ./tinfo/lib_acs.c */ #undef acs_map -chtype acs_map[128 ]; +chtype acs_map[128]; #undef _nc_init_acs void _nc_init_acs(void) @@ -3098,8 +3203,8 @@ void _nc_init_acs(void) #include <termcap.h> struct speed { - int s; - int sp; + int s; + int sp; }; #undef _nc_baudrate @@ -3180,7 +3285,7 @@ char *keyname( #undef key_name char *key_name( - wchar_t c) + wchar_t c) { return(*(char **)0); } /* ./tinfo/lib_longname.c */ @@ -3191,6 +3296,8 @@ char *longname(void) /* ./tinfo/lib_napms.c */ +#include <time.h> + #undef napms int napms( int ms) @@ -3299,13 +3406,12 @@ int intrflush( /* ./tinfo/lib_setup.c */ +#include <locale.h> #include <sys/ioctl.h> +#include <langinfo.h> -#undef use_env -void use_env( - NCURSES_BOOL f) - { /* void */ } - +#undef ttytype +char ttytype[256]; #undef LINES int LINES; #undef COLS @@ -3313,12 +3419,39 @@ int COLS; #undef TABSIZE int TABSIZE; +#undef _nc_handle_sigwinch +int _nc_handle_sigwinch( + int enable) + { return(*(int *)0); } + +#undef use_env +void use_env( + NCURSES_BOOL f) + { /* void */ } + #undef _nc_update_screensize void _nc_update_screensize(void) { /* void */ } -#undef ttytype -char ttytype[256 ]; +#undef _nc_get_locale +char *_nc_get_locale(void) + { return(*(char **)0); } + +#undef _nc_unicode_locale +int _nc_unicode_locale(void) + { return(*(int *)0); } + +#undef _nc_locale_breaks_acs +int _nc_locale_breaks_acs(void) + { return(*(int *)0); } + +#undef _nc_setupterm +int _nc_setupterm( + char *tname, + int Filedes, + int *errret, + NCURSES_BOOL reuse) + { return(*(int *)0); } #undef setupterm int setupterm( @@ -3398,15 +3531,22 @@ char *tigetstr( typedef struct { union { - unsigned int num; - char *str; + int num; + char *str; } data; - NCURSES_BOOL num_type; + NCURSES_BOOL num_type; } stack_frame; #undef _nc_tparm_err int _nc_tparm_err; +#undef _nc_tparm_analyze +int _nc_tparm_analyze( + const char *string, + char *p_is_s[9], + int *popcount) + { return(*(int *)0); } + #undef tparm char *tparm( char *string, @@ -3418,7 +3558,7 @@ char *tparm( #undef PC char PC; #undef ospeed -short ospeed; +NCURSES_OSPEED ospeed; #undef _nc_nulls_sent int _nc_nulls_sent; @@ -3469,16 +3609,41 @@ void _tracef( ...) { /* void */ } +#undef _nc_retrace_bool +NCURSES_BOOL _nc_retrace_bool( + NCURSES_BOOL code) + { return(*(NCURSES_BOOL *)0); } + #undef _nc_retrace_int int _nc_retrace_int( int code) { return(*(int *)0); } +#undef _nc_retrace_unsigned +unsigned _nc_retrace_unsigned( + unsigned code) + { return(*(unsigned *)0); } + #undef _nc_retrace_ptr char *_nc_retrace_ptr( char *code) { return(*(char **)0); } +#undef _nc_retrace_cptr +const char *_nc_retrace_cptr( + const char *code) + { return(*(const char **)0); } + +#undef _nc_retrace_cvoid_ptr +void *_nc_retrace_cvoid_ptr( + void *code) + { return(*(void **)0); } + +#undef _nc_retrace_void_ptr +void *_nc_retrace_void_ptr( + void *code) + { return(*(void **)0); } + #undef _nc_retrace_sp SCREEN *_nc_retrace_sp( SCREEN *code) @@ -3489,6 +3654,57 @@ WINDOW *_nc_retrace_win( WINDOW *code) { return(*(WINDOW **)0); } +/* ./trace/lib_traceatr.c */ + +#undef _traceattr2 +char *_traceattr2( + int bufnum, + chtype newmode) + { return(*(char **)0); } + +#undef _traceattr +char *_traceattr( + attr_t newmode) + { return(*(char **)0); } + +#undef _nc_retrace_attr_t +attr_t _nc_retrace_attr_t( + attr_t code) + { return(*(attr_t *)0); } + +#undef _nc_altcharset_name +const char *_nc_altcharset_name( + attr_t attr, + chtype ch) + { return(*(const char **)0); } + +#undef _tracechtype2 +char *_tracechtype2( + int bufnum, + chtype ch) + { return(*(char **)0); } + +#undef _tracechtype +char *_tracechtype( + chtype ch) + { return(*(char **)0); } + +#undef _nc_retrace_chtype +chtype _nc_retrace_chtype( + chtype code) + { return(*(chtype *)0); } + +#undef _tracecchar_t2 +char *_tracecchar_t2( + int bufnum, + const cchar_t *ch) + { return(*(char **)0); } + +#undef _tracecchar_t +char *_tracecchar_t( + const cchar_t *ch) + { return(*(char **)0); } + /* ./trace/lib_tracebits.c */ typedef struct { @@ -3496,6 +3712,11 @@ typedef struct { const char *name; } BITNAMES; +#undef _nc_trace_ttymode +char *_nc_trace_ttymode( + struct termios *tty) + { return(*(char **)0); } + #undef _nc_tracebits char *_nc_tracebits(void) { return(*(char **)0); } @@ -3603,15 +3824,14 @@ typedef struct { /* ./tinfo/read_entry.c */ -#undef _nc_tic_dir -const char *_nc_tic_dir( - const char *path) - { return(*(const char **)0); } +#include <hashed_db.h> -#undef _nc_keep_tic_dir -void _nc_keep_tic_dir( - const char *path) - { /* void */ } +#undef _nc_read_termtype +int _nc_read_termtype( + TERMTYPE *ptr, + char *buffer, + int limit) + { return(*(int *)0); } #undef _nc_read_file_entry int _nc_read_file_entry( @@ -3621,13 +3841,15 @@ int _nc_read_file_entry( #undef _nc_read_entry int _nc_read_entry( - const char *const tn, + const char *const name, char *const filename, TERMTYPE *const tp) { return(*(int *)0); } /* ./tinfo/read_termcap.c */ +#include <sys/types.h> + #undef _nc_read_termcap_entry int _nc_read_termcap_entry( const char *const tn, @@ -3688,6 +3910,12 @@ char *_nc_trace_buf( size_t want) { return(*(char **)0); } +#undef _nc_trace_bufcat +char *_nc_trace_bufcat( + int bufnum, + const char *value) + { return(*(char **)0); } + /* ./trace/trace_tries.c */ #undef _nc_trace_tries @@ -3695,6 +3923,35 @@ void _nc_trace_tries( struct tries *tree) { /* void */ } +/* ./base/tries.c */ + +#undef _nc_expand_try +char *_nc_expand_try( + struct tries *tree, + unsigned code, + int *count, + size_t len) + { return(*(char **)0); } + +#undef _nc_remove_key +int _nc_remove_key( + struct tries **tree, + unsigned code) + { return(*(int *)0); } + +#undef _nc_remove_string +int _nc_remove_string( + struct tries **tree, + const char *string) + { return(*(int *)0); } + +/* ./tinfo/trim_sgr0.c */ + +#undef _nc_trim_sgr0 +char *_nc_trim_sgr0( + TERMTYPE *tp) + { return(*(char **)0); } + /* ./unctrl.c */ #undef unctrl @@ -3715,6 +3972,12 @@ const char *_nc_visbuf( const char *buf) { return(*(const char **)0); } +#undef _nc_visbufn +const char *_nc_visbufn( + const char *buf, + int len) + { return(*(const char **)0); } + #undef _nc_viswbuf2 const char *_nc_viswbuf2( int bufnum, @@ -3726,6 +3989,17 @@ const char *_nc_viswbuf( const wchar_t *buf) { return(*(const char **)0); } +#undef _nc_viswbufn +const char *_nc_viswbufn( + const wchar_t *buf, + int len) + { return(*(const char **)0); } + +#undef _nc_viswibuf +const char *_nc_viswibuf( + const wint_t *buf) + { return(*(const char **)0); } + #undef _nc_viscbuf2 const char *_nc_viscbuf2( int bufnum, @@ -3754,3 +4028,46 @@ void _nc_write_entry( #undef _nc_tic_written int _nc_tic_written(void) { return(*(int *)0); } + +/* ./base/define_key.c */ + +#undef define_key +int define_key( + const char *str, + int keycode) + { return(*(int *)0); } + +/* ./tinfo/hashed_db.c */ + +#undef _nc_hashed_db +void _nc_hashed_db(void) + { /* void */ } + +/* ./base/key_defined.c */ + +#undef key_defined +int key_defined( + const char *str) + { return(*(int *)0); } + +/* ./base/keybound.c */ + +#undef keybound +char *keybound( + int code, + int count) + { return(*(char **)0); } + +/* ./base/keyok.c */ + +#undef keyok +int keyok( + int c, + NCURSES_BOOL flag) + { return(*(int *)0); } + +/* ./base/version.c */ + +#undef curses_version +const char *curses_version(void) + { return(*(const char **)0); } diff --git a/contrib/ncurses/ncurses/modules b/contrib/ncurses/ncurses/modules index 541df6f2493c..2e863dad0c38 100644 --- a/contrib/ncurses/ncurses/modules +++ b/contrib/ncurses/ncurses/modules @@ -1,6 +1,6 @@ -# $Id: modules,v 1.90 2002/05/11 20:14:41 tom Exp $ +# $Id: modules,v 1.107 2006/08/12 14:19:44 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"), # @@ -27,7 +27,7 @@ # authorization. # ############################################################################## # -# Author: Thomas E. Dickey <dickey@clark.net> 1996-1998, etc. +# Author: Thomas E. Dickey 1996-on # @ base @@ -61,7 +61,7 @@ lib_inchstr lib $(base) lib_initscr lib $(base) $(INCDIR)/tic.h lib_insch lib $(base) lib_insdel lib $(base) -lib_insstr lib $(base) +lib_insnstr lib $(base) lib_instr lib $(base) lib_isendwin lib $(base) lib_leaveok lib $(base) @@ -98,10 +98,9 @@ lib_slkrefr lib $(base) ../include/term.h lib_slkset lib $(base) lib_slktouch lib $(base) lib_touch lib $(base) -lib_traceatr lib $(trace) ../include/term.h lib_tracedmp lib $(trace) lib_tracemse lib $(trace) -lib_tstp lib $(serial) +lib_tstp lib $(serial) $(srcdir)/SigAction.h lib_ungetch lib $(base) lib_vidattr lib $(serial) ../include/term.h lib_vline lib $(base) @@ -117,11 +116,15 @@ varargs lib $(trace) # Modules for porting memmove lib $(base) -sigaction lib $(base) vsscanf lib $(base) +# actually an extension, but with its own configure option (--disable-leaks) +lib_freeall lib $(base) + # XSI extensions to the base library (wide-character) @ widechar +charable lib $(wide) +lib_add_wch lib $(wide) lib_box_set lib $(wide) lib_cchar lib $(wide) lib_get_wch lib $(wide) @@ -130,9 +133,10 @@ lib_get_wstr lib $(wide) lib_hline_set lib $(wide) lib_in_wch lib $(wide) lib_in_wchnstr lib $(wide) -lib_ins_nwstr lib $(wide) lib_ins_wch lib $(wide) lib_inwstr lib $(wide) +lib_pecho_wchar lib $(wide) +lib_slk_wset lib $(wide) lib_unget_wch lib $(wide) lib_vid_attr lib $(wide) ../include/term.h lib_vline_set lib $(wide) @@ -141,17 +145,12 @@ lib_wunctrl lib $(wide) # Extensions to the base library @ ext_funcs -define_key lib $(base) expanded lib . -keybound lib $(base) -keyok lib $(base) +legacy_coding lib $(base) ../include/term.h lib_dft_fgbg lib $(base) ../include/term.h -lib_freeall lib $(base) lib_print lib $(tinfo) ../include/term.h resizeterm lib $(base) ../include/term.h trace_xnames lib $(trace) ../include/term.h $(INCDIR)/term_entry.h -tries lib $(base) -version lib $(base) wresize lib $(base) ../include/term.h # Support for termcap (and tic, etc.), which can be a separate library @@ -168,6 +167,7 @@ comp_expand lib $(tinfo) $(INCDIR)/tic.h comp_hash lib $(tinfo) ../include/term.h $(INCDIR)/tic.h ../include/hashsize.h comp_parse lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h comp_scan lib $(tinfo) $(INCDIR)/tic.h +db_iterator lib $(tinfo) $(INCDIR)/tic.h doalloc lib $(tinfo) fallback lib . ../include/term.h $(INCDIR)/tic.h free_ttype lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h @@ -193,6 +193,7 @@ lib_ti lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h lib_tparm lib $(tinfo) ../include/term.h $(INCDIR)/tic.h lib_tputs lib $(tinfo) ../include/term.h $(INCDIR)/tic.h lib_trace lib $(trace) $(INCDIR)/tic.h +lib_traceatr lib $(trace) ../include/term.h lib_tracebits lib $(trace) ../include/term.h lib_tracechr lib $(trace) lib_ttyflags lib $(tinfo) ../include/term.h @@ -206,6 +207,17 @@ setbuf lib $(tinfo) strings lib $(tinfo) trace_buf lib $(trace) trace_tries lib $(trace) +tries lib $(base) +trim_sgr0 lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h unctrl lib . visbuf lib $(trace) $(INCDIR)/tic.h write_entry lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h + +# Extensions to the termlib library +@ ext_tinfo +define_key lib $(base) +hashed_db lib $(tinfo) +key_defined lib $(base) +keybound lib $(base) +keyok lib $(base) +version lib $(base) diff --git a/contrib/ncurses/ncurses/tinfo/MKcaptab.awk b/contrib/ncurses/ncurses/tinfo/MKcaptab.awk index ff9601ba62c5..57087b820e3b 100644 --- a/contrib/ncurses/ncurses/tinfo/MKcaptab.awk +++ b/contrib/ncurses/ncurses/tinfo/MKcaptab.awk @@ -1,5 +1,32 @@ #!/bin/sh -# $Id: MKcaptab.awk,v 1.12 2000/12/10 00:14:12 tom Exp $ +############################################################################## +# Copyright (c) 1998-2000,2006 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +# $Id: MKcaptab.awk,v 1.13 2006/04/22 21:46:17 tom Exp $ AWK=${1-awk} DATA=${2-../include/Caps} diff --git a/contrib/ncurses/ncurses/tinfo/MKfallback.sh b/contrib/ncurses/ncurses/tinfo/MKfallback.sh index d1abcd2eed3f..9feab3507cc0 100755 --- a/contrib/ncurses/ncurses/tinfo/MKfallback.sh +++ b/contrib/ncurses/ncurses/tinfo/MKfallback.sh @@ -1,5 +1,32 @@ #!/bin/sh -# $Id: MKfallback.sh,v 1.11 2001/12/02 01:55:30 tom Exp $ +############################################################################## +# Copyright (c) 1998-2001,2006 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +# $Id: MKfallback.sh,v 1.13 2006/07/15 16:54:20 tom Exp $ # # MKfallback.sh -- create fallback table for entry reads # @@ -25,7 +52,7 @@ if test $# != 0 ; then TERMINFO_DIRS=$TERMINFO:$terminfo_dir export TERMINFO_DIRS - tic $terminfo_src >&2 + tic -x $terminfo_src >&2 else tmp_info= fi diff --git a/contrib/ncurses/ncurses/tinfo/MKkeys_list.sh b/contrib/ncurses/ncurses/tinfo/MKkeys_list.sh index 98d5b1379a1c..14017b016896 100755 --- a/contrib/ncurses/ncurses/tinfo/MKkeys_list.sh +++ b/contrib/ncurses/ncurses/tinfo/MKkeys_list.sh @@ -1,7 +1,7 @@ #! /bin/sh -# $Id: MKkeys_list.sh,v 1.2 2001/06/16 16:50:35 tom Exp $ +# $Id: MKkeys_list.sh,v 1.4 2003/10/25 16:19:54 tom Exp $ ############################################################################## -# Copyright (c) 2001 Free Software Foundation, Inc. # +# Copyright (c) 2001,2003 Free Software Foundation, Inc. # # # # Permission is hereby granted, free of charge, to any person obtaining a # # copy of this software and associated documentation files (the "Software"), # @@ -30,7 +30,7 @@ # # MKkey_defs.sh -- generate list of function-keys for terminfo database # -# Author: Thomas E. Dickey <dickey@herndon4.his.com> 2001 +# Author: Thomas E. Dickey 2001 # # Extract function-key names from the Caps file # @@ -39,7 +39,7 @@ DATA=${1-../../include/Caps} data=data$$ trap 'rm -f $data' 0 1 2 5 15 -sed -e 's/[ ]\+/ /g' < $DATA >$data +sed -e 's/[ ][ ]*/ /g' < $DATA >$data cat <<EOF # These definitions were generated by $0 $DATA diff --git a/contrib/ncurses/ncurses/tinfo/MKnames.awk b/contrib/ncurses/ncurses/tinfo/MKnames.awk index 455efc01dea3..6be00ad4488d 100644 --- a/contrib/ncurses/ncurses/tinfo/MKnames.awk +++ b/contrib/ncurses/ncurses/tinfo/MKnames.awk @@ -1,4 +1,31 @@ -# $Id: MKnames.awk,v 1.11 2000/12/09 23:46:13 tom Exp $ +############################################################################## +# Copyright (c) 1998-2000,2006 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +# $Id: MKnames.awk,v 1.12 2006/04/22 21:46:17 tom Exp $ BEGIN { print "/* This file was generated by MKnames.awk */" > "namehdr" print "" > "namehdr" diff --git a/contrib/ncurses/ncurses/tinfo/README b/contrib/ncurses/ncurses/tinfo/README index 8b092c1ba41c..14c4220c4431 100644 --- a/contrib/ncurses/ncurses/tinfo/README +++ b/contrib/ncurses/ncurses/tinfo/README @@ -1,4 +1,32 @@ --- $Id: README,v 1.1 1998/11/07 22:59:07 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 files in this directory (tinfo) are those that support the terminfo database and interfaces for ncurses. The terminfo library can be built diff --git a/contrib/ncurses/ncurses/tinfo/access.c b/contrib/ncurses/ncurses/tinfo/access.c index f5240c121c26..c10b7e0af556 100644 --- a/contrib/ncurses/ncurses/tinfo/access.c +++ b/contrib/ncurses/ncurses/tinfo/access.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * Copyright (c) 1998-2003,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -27,14 +27,17 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1998,2000,2001 * + * Author: Thomas E. Dickey * ****************************************************************************/ #include <curses.priv.h> + +#include <sys/stat.h> + #include <tic.h> #include <nc_alloc.h> -MODULE_ID("$Id: access.c,v 1.9 2001/06/23 22:11:49 tom Exp $") +MODULE_ID("$Id: access.c,v 1.12 2006/08/05 17:18:14 tom Exp $") #define LOWERCASE(c) ((isalpha(UChar(c)) && isupper(UChar(c))) ? tolower(UChar(c)) : (c)) @@ -64,19 +67,43 @@ _nc_rootname(char *path) return result; } -NCURSES_EXPORT(char *) -_nc_basename(char *path) +/* + * Check if a string appears to be an absolute pathname. + */ +NCURSES_EXPORT(bool) +_nc_is_abs_path(const char *path) { - char *result = strrchr(path, '/'); +#if defined(__EMX__) || defined(__DJGPP__) +#define is_pathname(s) ((((s) != 0) && ((s)[0] == '/')) \ + || (((s)[0] != 0) && ((s)[1] == ':'))) +#else +#define is_pathname(s) ((s) != 0 && (s)[0] == '/') +#endif + return is_pathname(path); +} + +/* + * Return index of the basename + */ +NCURSES_EXPORT(unsigned) +_nc_pathlast(const char *path) +{ + const char *test = strrchr(path, '/'); #ifdef __EMX__ - if (result == 0) - result = strrchr(path, '\\'); + if (test == 0) + test = strrchr(path, '\\'); #endif - if (result == 0) - result = path; + if (test == 0) + test = path; else - result++; - return result; + test++; + return (test - path); +} + +NCURSES_EXPORT(char *) +_nc_basename(char *path) +{ + return path + _nc_pathlast(path); } NCURSES_EXPORT(int) @@ -102,6 +129,32 @@ _nc_access(const char *path, int mode) return 0; } +NCURSES_EXPORT(bool) +_nc_is_dir_path(const char *path) +{ + bool result = FALSE; + struct stat sb; + + if (stat(path, &sb) == 0 + && (sb.st_mode & S_IFMT) == S_IFDIR) { + result = TRUE; + } + return result; +} + +NCURSES_EXPORT(bool) +_nc_is_file_path(const char *path) +{ + bool result = FALSE; + struct stat sb; + + if (stat(path, &sb) == 0 + && (sb.st_mode & S_IFMT) == S_IFREG) { + result = TRUE; + } + return result; +} + #ifndef USE_ROOT_ENVIRON /* * Returns true if we allow application to use environment variables that are diff --git a/contrib/ncurses/ncurses/tinfo/add_tries.c b/contrib/ncurses/ncurses/tinfo/add_tries.c index f83249ccf01a..46c93b8fecc7 100644 --- a/contrib/ncurses/ncurses/tinfo/add_tries.c +++ b/contrib/ncurses/ncurses/tinfo/add_tries.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 * @@ -39,13 +39,13 @@ #include <curses.priv.h> -MODULE_ID("$Id: add_tries.c,v 1.4 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: add_tries.c,v 1.5 2005/11/20 01:32:48 tom Exp $") #define SET_TRY(dst,src) if ((dst->ch = *src++) == 128) dst->ch = '\0' #define CMP_TRY(a,b) ((a)? (a == b) : (b == 128)) NCURSES_EXPORT(void) -_nc_add_to_try(struct tries **tree, const char *str, unsigned short code) +_nc_add_to_try(struct tries **tree, const char *str, unsigned code) { static bool out_of_memory = FALSE; struct tries *ptr, *savedptr; diff --git a/contrib/ncurses/ncurses/tinfo/alloc_entry.c b/contrib/ncurses/ncurses/tinfo/alloc_entry.c index 5c064cfd8246..1496752f1956 100644 --- a/contrib/ncurses/ncurses/tinfo/alloc_entry.c +++ b/contrib/ncurses/ncurses/tinfo/alloc_entry.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 * ****************************************************************************/ /* @@ -47,7 +48,7 @@ #include <tic.h> #include <term_entry.h> -MODULE_ID("$Id: alloc_entry.c,v 1.36 2001/09/22 21:10:26 tom Exp $") +MODULE_ID("$Id: alloc_entry.c,v 1.47 2006/12/16 19:06:58 tom Exp $") #define ABSENT_OFFSET -1 #define CANCELLED_OFFSET -2 @@ -58,13 +59,20 @@ static char *stringbuf; /* buffer for string capabilities */ static size_t next_free; /* next free character in stringbuf */ NCURSES_EXPORT(void) -_nc_init_entry(TERMTYPE * const tp) +_nc_init_entry(TERMTYPE *const tp) /* initialize a terminal type data block */ { - int i; + unsigned i; + +#if NO_LEAKS + if (tp == 0 && stringbuf != 0) { + FreeAndNull(stringbuf); + return; + } +#endif if (stringbuf == 0) - stringbuf = malloc(MAX_STRTAB); + stringbuf = (char *) malloc(MAX_STRTAB); #if NCURSES_XNAMES tp->num_Booleans = BOOLCOUNT; @@ -75,7 +83,7 @@ _nc_init_entry(TERMTYPE * const tp) tp->ext_Strings = 0; #endif if (tp->Booleans == 0) - tp->Booleans = typeMalloc(char, BOOLCOUNT); + tp->Booleans = typeMalloc(NCURSES_SBOOL, BOOLCOUNT); if (tp->Numbers == 0) tp->Numbers = typeMalloc(short, NUMCOUNT); if (tp->Strings == 0) @@ -105,20 +113,32 @@ _nc_copy_entry(ENTRY * oldp) return newp; } +/* save a copy of string in the string buffer */ NCURSES_EXPORT(char *) _nc_save_str(const char *const string) -/* save a copy of string in the string buffer */ { + char *result = 0; size_t old_next_free = next_free; size_t len = strlen(string) + 1; - if (next_free + len < MAX_STRTAB) { + if (len == 1 && next_free != 0) { + /* + * Cheat a little by making an empty string point to the end of the + * previous string. + */ + if (next_free < MAX_STRTAB) { + result = (stringbuf + next_free - 1); + } + } else if (next_free + len < MAX_STRTAB) { strcpy(&stringbuf[next_free], string); DEBUG(7, ("Saved string %s", _nc_visbuf(string))); DEBUG(7, ("at location %d", (int) next_free)); next_free += len; + result = (stringbuf + old_next_free); + } else { + _nc_warning("Too much data, some is lost"); } - return (stringbuf + old_next_free); + return result; } NCURSES_EXPORT(void) @@ -126,7 +146,8 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings) /* copy the string parts to allocated storage, preserving pointers to it */ { int offsets[MAX_ENTRY_SIZE / 2], useoffsets[MAX_USES]; - int i, n; + unsigned i, n; + unsigned nuses = ep->nuses; TERMTYPE *tp = &(ep->tterm); if (copy_strings) { @@ -141,7 +162,7 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings) } } - for (i = 0; i < ep->nuses; i++) { + for (i = 0; i < nuses; i++) { if (ep->uses[i].name == 0) { ep->uses[i].name = _nc_save_str(ep->uses[i].name); } @@ -160,7 +181,7 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings) offsets[i] = tp->Strings[i] - stringbuf; } - for (i = 0; i < ep->nuses; i++) { + for (i = 0; i < nuses; i++) { if (ep->uses[i].name == 0) useoffsets[i] = ABSENT_OFFSET; else @@ -168,7 +189,7 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings) } if ((tp->str_table = typeMalloc(char, next_free)) == (char *) 0) - _nc_err_abort("Out of memory"); + _nc_err_abort(MSG_NO_MEMORY); (void) memcpy(tp->str_table, stringbuf, next_free); tp->term_names = tp->str_table + n; @@ -190,7 +211,7 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings) offsets[i] = tp->ext_Names[i] - stringbuf; } if ((tp->ext_str_table = typeMalloc(char, length)) == 0) - _nc_err_abort("Out of memory"); + _nc_err_abort(MSG_NO_MEMORY); for (i = 0, length = 0; i < n; i++) { tp->ext_Names[i] = tp->ext_str_table + length; strcpy(tp->ext_Names[i], stringbuf + offsets[i]); @@ -200,7 +221,7 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings) } #endif - for (i = 0; i < ep->nuses; i++) { + for (i = 0; i < nuses; i++) { if (useoffsets[i] == ABSENT_OFFSET) ep->uses[i].name = 0; else @@ -209,31 +230,34 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings) } NCURSES_EXPORT(void) -_nc_merge_entry -(TERMTYPE * const to, TERMTYPE * const from) +_nc_merge_entry(TERMTYPE *const to, TERMTYPE *const from) /* merge capabilities from `from' entry into `to' entry */ { - int i; + unsigned i; #if NCURSES_XNAMES _nc_align_termtype(to, from); #endif for_each_boolean(i, from) { - int mergebool = from->Booleans[i]; + if (to->Booleans[i] != (char) CANCELLED_BOOLEAN) { + int mergebool = from->Booleans[i]; - if (mergebool == CANCELLED_BOOLEAN) - to->Booleans[i] = FALSE; - else if (mergebool == TRUE) - to->Booleans[i] = mergebool; + if (mergebool == CANCELLED_BOOLEAN) + to->Booleans[i] = FALSE; + else if (mergebool == TRUE) + to->Booleans[i] = mergebool; + } } for_each_number(i, from) { - int mergenum = from->Numbers[i]; + if (to->Numbers[i] != CANCELLED_NUMERIC) { + int mergenum = from->Numbers[i]; - if (mergenum == CANCELLED_NUMERIC) - to->Numbers[i] = ABSENT_NUMERIC; - else if (mergenum != ABSENT_NUMERIC) - to->Numbers[i] = mergenum; + if (mergenum == CANCELLED_NUMERIC) + to->Numbers[i] = ABSENT_NUMERIC; + else if (mergenum != ABSENT_NUMERIC) + to->Numbers[i] = mergenum; + } } /* @@ -242,11 +266,24 @@ _nc_merge_entry * we ever want to deallocate entries. */ for_each_string(i, from) { - char *mergestring = from->Strings[i]; + if (to->Strings[i] != CANCELLED_STRING) { + char *mergestring = from->Strings[i]; - if (mergestring == CANCELLED_STRING) - to->Strings[i] = ABSENT_STRING; - else if (mergestring != ABSENT_STRING) - to->Strings[i] = mergestring; + if (mergestring == CANCELLED_STRING) + to->Strings[i] = ABSENT_STRING; + else if (mergestring != ABSENT_STRING) + to->Strings[i] = mergestring; + } + } +} + +#if NO_LEAKS +NCURSES_EXPORT(void) +_nc_alloc_entry_leaks(void) +{ + if (stringbuf != 0) { + FreeAndNull(stringbuf); } + next_free = 0; } +#endif diff --git a/contrib/ncurses/ncurses/tinfo/alloc_ttype.c b/contrib/ncurses/ncurses/tinfo/alloc_ttype.c index c13c5d6c29ed..9f31ed3ffab7 100644 --- a/contrib/ncurses/ncurses/tinfo/alloc_ttype.c +++ b/contrib/ncurses/ncurses/tinfo/alloc_ttype.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1999-2003,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -27,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + * Author: Thomas E. Dickey <dickey@clark.net> 1999-on * ****************************************************************************/ /* @@ -43,7 +43,7 @@ #include <tic.h> #include <term_entry.h> -MODULE_ID("$Id: alloc_ttype.c,v 1.12 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: alloc_ttype.c,v 1.16 2006/07/08 19:18:38 tom Exp $") #if NCURSES_XNAMES /* @@ -92,15 +92,17 @@ find_name(char **table, int length, char *name) } static void -realign_data(TERMTYPE * to, char **ext_Names, int ext_Booleans, int - ext_Numbers, int ext_Strings) +realign_data(TERMTYPE *to, char **ext_Names, + int ext_Booleans, + int ext_Numbers, + int ext_Strings) { int n, m, base; int limit = (to->ext_Booleans + to->ext_Numbers + to->ext_Strings); if (to->ext_Booleans != ext_Booleans) { to->num_Booleans += (ext_Booleans - to->ext_Booleans); - to->Booleans = typeRealloc(char, to->num_Booleans, to->Booleans); + to->Booleans = typeRealloc(NCURSES_SBOOL, to->num_Booleans, to->Booleans); for (n = to->ext_Booleans - 1, m = ext_Booleans - 1, base = to->num_Booleans - (m + 1); m >= 0; m--) { @@ -146,7 +148,7 @@ realign_data(TERMTYPE * to, char **ext_Names, int ext_Booleans, int * Returns the first index in ext_Names[] for the given token-type */ static int -_nc_first_ext_name(TERMTYPE * tp, int token_type) +_nc_first_ext_name(TERMTYPE *tp, int token_type) { int first; @@ -171,7 +173,7 @@ _nc_first_ext_name(TERMTYPE * tp, int token_type) * Returns the last index in ext_Names[] for the given token-type */ static int -_nc_last_ext_name(TERMTYPE * tp, int token_type) +_nc_last_ext_name(TERMTYPE *tp, int token_type) { int last; @@ -194,7 +196,7 @@ _nc_last_ext_name(TERMTYPE * tp, int token_type) * Lookup an entry from extended-names, returning -1 if not found */ static int -_nc_find_ext_name(TERMTYPE * tp, char *name, int token_type) +_nc_find_ext_name(TERMTYPE *tp, char *name, int token_type) { unsigned j; unsigned first = _nc_first_ext_name(tp, token_type); @@ -213,7 +215,7 @@ _nc_find_ext_name(TERMTYPE * tp, char *name, int token_type) * (e.g., Booleans[]). */ static int -_nc_ext_data_index(TERMTYPE * tp, int n, int token_type) +_nc_ext_data_index(TERMTYPE *tp, int n, int token_type) { switch (token_type) { case BOOLEAN: @@ -236,7 +238,7 @@ _nc_ext_data_index(TERMTYPE * tp, int n, int token_type) * data. */ static bool -_nc_del_ext_name(TERMTYPE * tp, char *name, int token_type) +_nc_del_ext_name(TERMTYPE *tp, char *name, int token_type) { int j; int first, last; @@ -280,7 +282,7 @@ _nc_del_ext_name(TERMTYPE * tp, char *name, int token_type) * index into the corresponding data array is returned. */ static int -_nc_ins_ext_name(TERMTYPE * tp, char *name, int token_type) +_nc_ins_ext_name(TERMTYPE *tp, char *name, int token_type) { unsigned first = _nc_first_ext_name(tp, token_type); unsigned last = _nc_last_ext_name(tp, token_type); @@ -291,7 +293,7 @@ _nc_ins_ext_name(TERMTYPE * tp, char *name, int token_type) int cmp = strcmp(name, tp->ext_Names[j]); if (cmp == 0) /* already present */ - return _nc_ext_data_index(tp, j, token_type); + return _nc_ext_data_index(tp, (int) j, token_type); if (cmp < 0) { break; } @@ -301,13 +303,13 @@ _nc_ins_ext_name(TERMTYPE * tp, char *name, int token_type) for (k = total - 1; k > j; k--) tp->ext_Names[k] = tp->ext_Names[k - 1]; tp->ext_Names[j] = name; - j = _nc_ext_data_index(tp, j, token_type); + j = _nc_ext_data_index(tp, (int) j, token_type); switch (token_type) { case BOOLEAN: tp->ext_Booleans += 1; tp->num_Booleans += 1; - tp->Booleans = typeRealloc(char, tp->num_Booleans, tp->Booleans); + tp->Booleans = typeRealloc(NCURSES_SBOOL, tp->num_Booleans, tp->Booleans); for (k = tp->num_Booleans - 1; k > j; k--) tp->Booleans[k] = tp->Booleans[k - 1]; break; @@ -335,7 +337,7 @@ _nc_ins_ext_name(TERMTYPE * tp, char *name, int token_type) * cancellation of a name that is inherited from another entry. */ static void -adjust_cancels(TERMTYPE * to, TERMTYPE * from) +adjust_cancels(TERMTYPE *to, TERMTYPE *from) { int first = to->ext_Booleans + to->ext_Numbers; int last = first + to->ext_Strings; @@ -371,8 +373,7 @@ adjust_cancels(TERMTYPE * to, TERMTYPE * from) } NCURSES_EXPORT(void) -_nc_align_termtype -(TERMTYPE * to, TERMTYPE * from) +_nc_align_termtype(TERMTYPE *to, TERMTYPE *from) { int na = NUM_EXT_NAMES(to); int nb = NUM_EXT_NAMES(from); @@ -380,6 +381,7 @@ _nc_align_termtype bool same; char **ext_Names; int ext_Booleans, ext_Numbers, ext_Strings; + bool used_ext_Names = FALSE; DEBUG(2, ("align_termtype to(%d:%s), from(%d:%s)", na, to->term_names, nb, from->term_names)); @@ -443,6 +445,7 @@ _nc_align_termtype to->ext_Names = ext_Names; DEBUG(2, ("realigned %d extended names for '%s' (to)", NUM_EXT_NAMES(to), to->term_names)); + used_ext_Names = TRUE; } if (nb != (ext_Booleans + ext_Numbers + ext_Strings)) { nb = (ext_Booleans + ext_Numbers + ext_Strings); @@ -452,18 +455,19 @@ _nc_align_termtype DEBUG(2, ("realigned %d extended names for '%s' (from)", NUM_EXT_NAMES(from), from->term_names)); } + if (!used_ext_Names) + free(ext_Names); } } #endif NCURSES_EXPORT(void) -_nc_copy_termtype -(TERMTYPE * dst, TERMTYPE * src) +_nc_copy_termtype(TERMTYPE *dst, TERMTYPE *src) { - int i; + unsigned i; *dst = *src; /* ...to copy the sizes and string-tables */ - dst->Booleans = typeMalloc(char, NUM_BOOLEANS(dst)); + dst->Booleans = typeMalloc(NCURSES_SBOOL, NUM_BOOLEANS(dst)); dst->Numbers = typeMalloc(short, NUM_NUMBERS(dst)); dst->Strings = typeMalloc(char *, NUM_STRINGS(dst)); diff --git a/contrib/ncurses/ncurses/tinfo/captoinfo.c b/contrib/ncurses/ncurses/tinfo/captoinfo.c index bf3116ae24f9..0e3baa845693 100644 --- a/contrib/ncurses/ncurses/tinfo/captoinfo.c +++ b/contrib/ncurses/ncurses/tinfo/captoinfo.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 * ****************************************************************************/ /* @@ -39,7 +40,7 @@ * * There is just one entry point: * - * char *_nc_captoinfo(n, s, parametrized) + * char *_nc_captoinfo(n, s, parameterized) * * Convert value s for termcap string capability named n into terminfo * format. @@ -92,7 +93,7 @@ #include <ctype.h> #include <tic.h> -MODULE_ID("$Id: captoinfo.c,v 1.41 2001/06/02 22:50:31 skimo Exp $") +MODULE_ID("$Id: captoinfo.c,v 1.49 2006/12/16 19:16:53 tom Exp $") #define MAX_PUSHED 16 /* max # args we can push onto the stack */ @@ -115,7 +116,7 @@ init_string(void) if (my_string == 0) my_string = typeMalloc(char, my_length = 256); if (my_string == 0) - _nc_err_abort("Out of memory"); + _nc_err_abort(MSG_NO_MEMORY); *my_string = '\0'; return my_string; @@ -129,18 +130,18 @@ save_string(char *d, const char *const s) if (need > my_length) { my_string = (char *) realloc(my_string, my_length = (need + need)); if (my_string == 0) - _nc_err_abort("Out of memory"); + _nc_err_abort(MSG_NO_MEMORY); d = my_string + have; } (void) strcpy(d, s); return d + strlen(d); } -static inline char * -save_char(char *s, char c) +static NCURSES_INLINE char * +save_char(char *s, int c) { static char temp[2]; - temp[0] = c; + temp[0] = (char) c; return save_string(s, temp); } @@ -272,12 +273,12 @@ getparm(int parm, int n) * Convert a termcap string to terminfo format. * 'cap' is the relevant terminfo capability index. * 's' is the string value of the capability. - * 'parametrized' tells what type of translations to do: + * 'parameterized' tells what type of translations to do: * % translations if 1 * pad translations if >=0 */ -char * -_nc_captoinfo(const char *cap, const char *s, int const parametrized) +NCURSES_EXPORT(char *) +_nc_captoinfo(const char *cap, const char *s, int const parameterized) { const char *capstart; @@ -294,7 +295,7 @@ _nc_captoinfo(const char *cap, const char *s, int const parametrized) capstart = 0; if (s == 0) s = ""; - if (parametrized >= 0 && isdigit(UChar(*s))) + if (parameterized >= 0 && isdigit(UChar(*s))) for (capstart = s;; s++) if (!(isdigit(UChar(*s)) || *s == '*' || *s == '.')) break; @@ -303,7 +304,7 @@ _nc_captoinfo(const char *cap, const char *s, int const parametrized) switch (*s) { case '%': s++; - if (parametrized < 1) { + if (parameterized < 1) { dp = save_char(dp, '%'); break; } @@ -464,7 +465,7 @@ _nc_captoinfo(const char *cap, const char *s, int const parametrized) dp = save_char(dp, '%'); s--; _nc_warning("unknown %% code %s (%#x) in %s", - unctrl((chtype) * s), UChar(*s), cap); + unctrl((chtype) *s), UChar(*s), cap); break; } break; @@ -636,8 +637,8 @@ save_tc_inequality(char *bufptr, int c1, int c2) * Convert a terminfo string to termcap format. Parameters are as in * _nc_captoinfo(). */ -char * -_nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parametrized) +NCURSES_EXPORT(char *) +_nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameterized) { int seenone = 0, seentwo = 0, saw_m = 0, saw_n = 0; const char *padding; @@ -649,11 +650,11 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parametrize /* we may have to move some trailing mandatory padding up front */ padding = str + strlen(str) - 1; - if (*padding == '>' && *--padding == '/') { + if (padding > str && *padding == '>' && *--padding == '/') { --padding; while (isdigit(UChar(*padding)) || *padding == '.' || *padding == '*') padding--; - if (*padding == '<' && *--padding == '$') + if (padding > str && *padding == '<' && *--padding == '$') trimmed = padding; padding += 2; @@ -678,7 +679,8 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parametrize --str; } else if (str[0] == '%' && str[1] == '%') { /* escaped '%' */ bufptr = save_string(bufptr, "%%"); - } else if (*str != '%' || (parametrized < 1)) { + ++str; + } else if (*str != '%' || (parameterized < 1)) { bufptr = save_char(bufptr, *str); } else if (sscanf(str, "%%?%%{%d}%%>%%t%%{%d}%%+%%;", &c1, &c2) == 2) { str = strchr(str, ';'); @@ -833,4 +835,13 @@ main(int argc, char *argv[]) } #endif /* MAIN */ -/* captoinfo.c ends here */ +#if NO_LEAKS +NCURSES_EXPORT(void) +_nc_captoinfo_leaks(void) +{ + if (my_string != 0) { + FreeAndNull(my_string); + } + my_length = 0; +} +#endif diff --git a/contrib/ncurses/ncurses/tinfo/comp_error.c b/contrib/ncurses/ncurses/tinfo/comp_error.c index e67cb795dd33..015f34886eb1 100644 --- a/contrib/ncurses/ncurses/tinfo/comp_error.c +++ b/contrib/ncurses/ncurses/tinfo/comp_error.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000,2001 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,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 <tic.h> -MODULE_ID("$Id: comp_error.c,v 1.23 2001/09/23 00:58:30 tom Exp $") +MODULE_ID("$Id: comp_error.c,v 1.30 2005/11/26 15:28:47 tom Exp $") NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings = FALSE; NCURSES_EXPORT_VAR(int) _nc_curr_line = 0; /* current line # in input */ @@ -49,6 +50,12 @@ NCURSES_EXPORT_VAR(int) _nc_curr_col = 0; /* current column # in input */ static const char *sourcename; static char *termtype; +NCURSES_EXPORT(const char *) +_nc_get_source(void) +{ + return sourcename; +} + NCURSES_EXPORT(void) _nc_set_source(const char *const name) { @@ -59,19 +66,28 @@ NCURSES_EXPORT(void) _nc_set_type(const char *const name) { if (termtype == 0) - termtype = _nc_doalloc(termtype, MAX_NAME_SIZE + 1); - termtype[0] = '\0'; - if (name) - strncat(termtype, name, MAX_NAME_SIZE); + termtype = typeMalloc(char, MAX_NAME_SIZE + 1); + if (termtype != 0) { + termtype[0] = '\0'; + if (name) + strncat(termtype, name, MAX_NAME_SIZE); + } } NCURSES_EXPORT(void) _nc_get_type(char *name) { - strcpy(name, termtype != 0 ? termtype : ""); +#if NO_LEAKS + if (name == 0 && termtype != 0) { + FreeAndNull(termtype); + return; + } +#endif + if (name != 0) + strcpy(name, termtype != 0 ? termtype : ""); } -static inline void +static NCURSES_INLINE void where_is_problem(void) { fprintf(stderr, "\"%s\"", sourcename); diff --git a/contrib/ncurses/ncurses/tinfo/comp_expand.c b/contrib/ncurses/ncurses/tinfo/comp_expand.c index 7ba438aff8e2..ef419d84cd2c 100644 --- a/contrib/ncurses/ncurses/tinfo/comp_expand.c +++ b/contrib/ncurses/ncurses/tinfo/comp_expand.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 * @@ -35,7 +35,7 @@ #include <ctype.h> #include <tic.h> -MODULE_ID("$Id: comp_expand.c,v 1.17 2001/09/22 19:16:52 tom Exp $") +MODULE_ID("$Id: comp_expand.c,v 1.18 2006/06/17 19:37:14 tom Exp $") static int trailing_spaces(const char *src) @@ -50,8 +50,7 @@ trailing_spaces(const char *src) #define REALPRINT(s) (UChar(*(s)) < 127 && isprint(UChar(*(s)))) NCURSES_EXPORT(char *) -_nc_tic_expand -(const char *srcp, bool tic_format, int numbers) +_nc_tic_expand(const char *srcp, bool tic_format, int numbers) { static char *buffer; static size_t length; @@ -62,6 +61,15 @@ _nc_tic_expand size_t need = (2 + strlen(str)) * 4; int ch; +#if NO_LEAKS + if (srcp == 0) { + if (buffer != 0) { + FreeAndNull(buffer); + length = 0; + } + return 0; + } +#endif if (buffer == 0 || need > length) { if ((buffer = typeRealloc(char, length = need, buffer)) == 0) return 0; diff --git a/contrib/ncurses/ncurses/tinfo/comp_hash.c b/contrib/ncurses/ncurses/tinfo/comp_hash.c index 9f2ee71041e4..d4d9eaa62e13 100644 --- a/contrib/ncurses/ncurses/tinfo/comp_hash.c +++ b/contrib/ncurses/ncurses/tinfo/comp_hash.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-on * ****************************************************************************/ /* @@ -37,6 +38,7 @@ * */ +#define USE_TERMLIB 1 #include <curses.priv.h> #include <tic.h> @@ -48,7 +50,7 @@ #define DEBUG(level, params) /*nothing */ #endif -MODULE_ID("$Id: comp_hash.c,v 1.25 2001/06/02 22:50:42 skimo Exp $") +MODULE_ID("$Id: comp_hash.c,v 1.28 2005/08/20 19:58:18 tom Exp $") static int hash_function(const char *); @@ -97,12 +99,11 @@ _nc_make_hash_table(struct name_table_entry *table, * Computes the hashing function on the given string. * * The current hash function is the sum of each consectutive pair - * of characters, taken as two-byte integers, mod Hashtabsize. + * of characters, taken as two-byte integers, mod HASHTABSIZE. * */ -static -int +static int hash_function(const char *string) { long sum = 0; @@ -128,8 +129,8 @@ hash_function(const char *string) #ifndef MAIN_PROGRAM NCURSES_EXPORT(struct name_table_entry const *) -_nc_find_entry -(const char *string, const struct name_table_entry *const *hash_table) +_nc_find_entry(const char *string, + const struct name_table_entry *const *hash_table) { int hashvalue; struct name_table_entry const *ptr; @@ -159,10 +160,9 @@ _nc_find_entry */ NCURSES_EXPORT(struct name_table_entry const *) -_nc_find_type_entry -(const char *string, - int type, - const struct name_table_entry *table) +_nc_find_type_entry(const char *string, + int type, + const struct name_table_entry *table) { struct name_table_entry const *ptr; diff --git a/contrib/ncurses/ncurses/tinfo/comp_parse.c b/contrib/ncurses/ncurses/tinfo/comp_parse.c index f11843828e09..667b3257f25a 100644 --- a/contrib/ncurses/ncurses/tinfo/comp_parse.c +++ b/contrib/ncurses/ncurses/tinfo/comp_parse.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,18 +29,19 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* * comp_parse.c -- parser driver loop and use handling. * * _nc_read_entry_source(FILE *, literal, bool, bool (*hook)()) - * _nc_resolve_uses(void) + * _nc_resolve_uses2(void) * _nc_free_entries(void) * * Use this code by calling _nc_read_entry_source() on as many source * files as you like (either terminfo or termcap syntax). If you - * want use-resolution, call _nc_resolve_uses(). To free the list + * want use-resolution, call _nc_resolve_uses2(). To free the list * storage, do _nc_free_entries(). * */ @@ -52,8 +53,12 @@ #include <tic.h> #include <term_entry.h> -MODULE_ID("$Id: comp_parse.c,v 1.50 2001/06/16 17:52:18 tom Exp $") +MODULE_ID("$Id: comp_parse.c,v 1.63 2006/07/08 18:55:14 tom Exp $") +static void sanity_check2(TERMTYPE *, bool); +NCURSES_IMPEXP void NCURSES_API(*_nc_check_termtype2) (TERMTYPE *, bool) = sanity_check2; + +/* obsolete: 20040705 */ static void sanity_check(TERMTYPE *); NCURSES_IMPEXP void NCURSES_API(*_nc_check_termtype) (TERMTYPE *) = sanity_check; @@ -81,14 +86,14 @@ NCURSES_IMPEXP void NCURSES_API(*_nc_check_termtype) (TERMTYPE *) = sanity_check NCURSES_EXPORT_VAR(ENTRY *) _nc_head = 0; NCURSES_EXPORT_VAR(ENTRY *) _nc_tail = 0; - static void - enqueue(ENTRY * ep) +static void +enqueue(ENTRY * ep) /* add an entry to the in-core list */ { ENTRY *newp = _nc_copy_entry(ep); if (newp == 0) - _nc_err_abort("Out of memory"); + _nc_err_abort(MSG_NO_MEMORY); newp->last = _nc_tail; _nc_tail = newp; @@ -102,24 +107,44 @@ NCURSES_EXPORT(void) _nc_free_entries(ENTRY * headp) /* free the allocated storage consumed by list entries */ { - ENTRY *ep, *next; + (void) headp; /* unused - _nc_head is altered here! */ - for (ep = headp; ep; ep = next) { - /* - * This conditional lets us disconnect storage from the list. - * To do this, copy an entry out of the list, then null out - * the string-table member in the original and any use entries - * it references. - */ - FreeIfNeeded(ep->tterm.str_table); + while (_nc_head != 0) { + _nc_free_termtype(&(_nc_head->tterm)); + } +} + +NCURSES_EXPORT(ENTRY *) +_nc_delink_entry(ENTRY * headp, TERMTYPE *tterm) +/* delink the allocated storage for the given list entry */ +{ + ENTRY *ep, *last; + + for (last = 0, ep = headp; ep != 0; last = ep, ep = ep->next) { + if (&(ep->tterm) == tterm) { + if (last != 0) { + last->next = ep->next; + } + if (ep == _nc_head) { + _nc_head = ep->next; + } + if (ep == _nc_tail) { + _nc_tail = last; + } + break; + } + } + return ep; +} - next = ep->next; +NCURSES_EXPORT(void) +_nc_free_entry(ENTRY * headp, TERMTYPE *tterm) +/* free the allocated storage consumed by the given list entry */ +{ + ENTRY *ep; + if ((ep = _nc_delink_entry(headp, tterm)) != 0) { free(ep); - if (ep == _nc_head) - _nc_head = 0; - if (ep == _nc_tail) - _nc_tail = 0; } } @@ -163,7 +188,7 @@ _nc_entry_match(char *n1, char *n2) ****************************************************************************/ NCURSES_EXPORT(void) -_nc_read_entry_source(FILE * fp, char *buf, +_nc_read_entry_source(FILE *fp, char *buf, int literal, bool silent, bool(*hook) (ENTRY *)) /* slurp all entries in the given file into core */ @@ -184,14 +209,25 @@ _nc_read_entry_source(FILE * fp, char *buf, _nc_err_abort("terminal names must start with letter or digit"); /* - * This can be used for immediate compilation of entries with no - * use references to disk, so as to avoid chewing up a lot of - * core when the resolution code could fetch entries off disk. + * This can be used for immediate compilation of entries with no "use=" + * references to disk. That avoids consuming a lot of memory when the + * resolution code could fetch entries off disk. */ - if (hook != NULLHOOK && (*hook) (&thisentry)) + if (hook != NULLHOOK && (*hook) (&thisentry)) { immediate++; - else + } else { enqueue(&thisentry); + /* + * The enqueued entry is copied with _nc_copy_termtype(), so we can + * free some of the data from thisentry, i.e., the arrays. + */ + FreeIfNeeded(thisentry.tterm.Booleans); + FreeIfNeeded(thisentry.tterm.Numbers); + FreeIfNeeded(thisentry.tterm.Strings); +#if NCURSES_XNAMES + FreeIfNeeded(thisentry.tterm.ext_Names); +#endif + } } if (_nc_tail) { @@ -211,12 +247,12 @@ _nc_read_entry_source(FILE * fp, char *buf, } NCURSES_EXPORT(int) -_nc_resolve_uses(bool fullresolve) +_nc_resolve_uses2(bool fullresolve, bool literal) /* try to resolve all use capabilities */ { ENTRY *qp, *rp, *lastread = 0; bool keepgoing; - int i, j, unresolved, total_unresolved, multiples; + int i, unresolved, total_unresolved, multiples; DEBUG(2, ("RESOLUTION BEGINNING")); @@ -289,7 +325,7 @@ _nc_resolve_uses(bool fullresolve) rp = typeMalloc(ENTRY, 1); if (rp == 0) - _nc_err_abort("Out of memory"); + _nc_err_abort(MSG_NO_MEMORY); rp->tterm = thisterm; rp->nuses = 0; rp->next = lastread; @@ -320,8 +356,8 @@ _nc_resolve_uses(bool fullresolve) DEBUG(2, ("NAME RESOLUTION COMPLETED OK")); /* - * OK, at this point all (char *) references in `name' mwmbers - * have been successfully converred to (ENTRY *) pointers in + * OK, at this point all (char *) references in `name' members + * have been successfully converted to (ENTRY *) pointers in * `link' members. Time to do the actual merges. */ if (fullresolve) { @@ -347,10 +383,10 @@ _nc_resolve_uses(bool fullresolve) } /* - * First, make sure there's no garbage in the - * merge block. as a side effect, copy into - * the merged entry the name field and string - * table pointer. + * First, make sure there is no garbage in the + * merge block. As a side effect, copy into + * the merged entry the name field and string + * table pointer. */ _nc_copy_termtype(&merged, &(qp->tterm)); @@ -373,6 +409,9 @@ _nc_resolve_uses(bool fullresolve) FreeIfNeeded(qp->tterm.Booleans); FreeIfNeeded(qp->tterm.Numbers); FreeIfNeeded(qp->tterm.Strings); +#if NCURSES_XNAMES + FreeIfNeeded(qp->tterm.ext_Names); +#endif qp->tterm = merged; _nc_wrap_entry(qp, TRUE); @@ -389,26 +428,6 @@ _nc_resolve_uses(bool fullresolve) (keepgoing); DEBUG(2, ("MERGES COMPLETED OK")); - - /* - * The exit condition of the loop above is such that all entries - * must now be resolved. Now handle cancellations. In a resolved - * entry there should be no cancellation markers. - */ - for_entry_list(qp) { - for_each_boolean(j, &(qp->tterm)) { - if ((int) qp->tterm.Booleans[j] == CANCELLED_BOOLEAN) - qp->tterm.Booleans[j] = ABSENT_BOOLEAN; - } - for_each_number(j, &(qp->tterm)) { - if (qp->tterm.Numbers[j] == CANCELLED_NUMERIC) - qp->tterm.Numbers[j] = ABSENT_NUMERIC; - } - for_each_string(j, &(qp->tterm)) { - if (qp->tterm.Strings[j] == CANCELLED_STRING) - qp->tterm.Strings[j] = ABSENT_STRING; - } - } } /* @@ -426,7 +445,7 @@ _nc_resolve_uses(bool fullresolve) for_entry_list(qp) { _nc_curr_line = qp->startline; _nc_set_type(_nc_first_name(qp->tterm.term_names)); - _nc_check_termtype(&qp->tterm); + _nc_check_termtype2(&qp->tterm, literal); } DEBUG(2, ("SANITY CHECK FINISHED")); } @@ -434,6 +453,13 @@ _nc_resolve_uses(bool fullresolve) return (TRUE); } +/* obsolete: 20040705 */ +NCURSES_EXPORT(int) +_nc_resolve_uses(bool fullresolve) +{ + return _nc_resolve_uses2(fullresolve, FALSE); +} + /* * This bit of legerdemain turns all the terminfo variable names into * references to locations in the arrays Booleans, Numbers, and Strings --- @@ -444,7 +470,7 @@ _nc_resolve_uses(bool fullresolve) #define CUR tp-> static void -sanity_check(TERMTYPE * tp) +sanity_check2(TERMTYPE *tp, bool literal) { if (!PRESENT(exit_attribute_mode)) { #ifdef __UNUSED__ /* this casts too wide a net */ @@ -461,22 +487,24 @@ sanity_check(TERMTYPE * tp) || PRESENT(enter_reverse_mode))) _nc_warning("no exit_attribute_mode"); #endif /* __UNUSED__ */ - PAIRED(enter_standout_mode, exit_standout_mode) - PAIRED(enter_underline_mode, exit_underline_mode) + PAIRED(enter_standout_mode, exit_standout_mode); + PAIRED(enter_underline_mode, exit_underline_mode); } /* we do this check/fix in postprocess_termcap(), but some packagers * prefer to bypass it... */ - if (acs_chars == 0 - && enter_alt_charset_mode != 0 - && exit_alt_charset_mode != 0) - acs_chars = strdup(VT_ACSC); + if (!literal) { + if (acs_chars == 0 + && enter_alt_charset_mode != 0 + && exit_alt_charset_mode != 0) + acs_chars = strdup(VT_ACSC); + ANDMISSING(enter_alt_charset_mode, acs_chars); + ANDMISSING(exit_alt_charset_mode, acs_chars); + } /* listed in structure-member order of first argument */ PAIRED(enter_alt_charset_mode, exit_alt_charset_mode); - ANDMISSING(enter_alt_charset_mode, acs_chars); - ANDMISSING(exit_alt_charset_mode, acs_chars); ANDMISSING(enter_blink_mode, exit_attribute_mode); ANDMISSING(enter_bold_mode, exit_attribute_mode); PAIRED(exit_ca_mode, enter_ca_mode); @@ -499,3 +527,10 @@ sanity_check(TERMTYPE * tp) #endif ANDMISSING(set_color_pair, initialize_pair); } + +/* obsolete: 20040705 */ +static void +sanity_check(TERMTYPE *tp) +{ + sanity_check2(tp, FALSE); +} diff --git a/contrib/ncurses/ncurses/tinfo/comp_scan.c b/contrib/ncurses/ncurses/tinfo/comp_scan.c index 52fb13a7f76e..e937f7eb5ada 100644 --- a/contrib/ncurses/ncurses/tinfo/comp_scan.c +++ b/contrib/ncurses/ncurses/tinfo/comp_scan.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 * ****************************************************************************/ /* @@ -50,7 +51,7 @@ #include <term_entry.h> #include <tic.h> -MODULE_ID("$Id: comp_scan.c,v 1.59 2001/09/23 00:56:29 tom Exp $") +MODULE_ID("$Id: comp_scan.c,v 1.78 2006/12/16 19:17:01 tom Exp $") /* * Maximum length of string capability we'll accept before raising an error. @@ -84,6 +85,7 @@ _nc_curr_token = *****************************************************************************/ static bool first_column; /* See 'next_char()' below */ +static bool had_newline; static char separator; /* capability separator */ static int pushtype; /* type of pushback token */ static char *pushname; @@ -93,14 +95,196 @@ NCURSES_EXPORT_VAR(bool) _nc_disable_period = FALSE; /* used by tic -a option */ #endif -static int last_char(void); -static int next_char(void); -static long stream_pos(void); -static bool end_of_stream(void); -static void push_back(char c); +/***************************************************************************** + * + * Character-stream handling + * + *****************************************************************************/ + +#define LEXBUFSIZ 1024 + +static char *bufptr; /* otherwise, the input buffer pointer */ +static char *bufstart; /* start of buffer so we can compute offsets */ +static FILE *yyin; /* scanner's input file descriptor */ + +/* + * _nc_reset_input() + * + * Resets the input-reading routines. Used on initialization, + * or after a seek has been done. Exactly one argument must be + * non-null. + */ + +NCURSES_EXPORT(void) +_nc_reset_input(FILE *fp, char *buf) +{ + pushtype = NO_PUSHBACK; + if (pushname != 0) + pushname[0] = '\0'; + yyin = fp; + bufstart = bufptr = buf; + _nc_curr_file_pos = 0L; + if (fp != 0) + _nc_curr_line = 0; + _nc_curr_col = 0; +} + +/* + * int last_char() + * + * Returns the final nonblank character on the current input buffer + */ +static int +last_char(void) +{ + size_t len = strlen(bufptr); + while (len--) { + if (!isspace(UChar(bufptr[len]))) + return bufptr[len]; + } + return 0; +} + +/* + * int next_char() + * + * Returns the next character in the input stream. Comments and leading + * white space are stripped. + * + * The global state variable 'firstcolumn' is set TRUE if the character + * returned is from the first column of the input line. + * + * The global variable _nc_curr_line is incremented for each new line. + * The global variable _nc_curr_file_pos is set to the file offset of the + * beginning of each line. + */ + +static int +next_char(void) +{ + static char *result; + static size_t allocated; + int the_char; + + if (!yyin) { + if (result != 0) { + FreeAndNull(result); + FreeAndNull(pushname); + allocated = 0; + } + /* + * An string with an embedded null will truncate the input. This is + * intentional (we don't read binary files here). + */ + if (bufptr == 0 || *bufptr == '\0') + return (EOF); + if (*bufptr == '\n') { + _nc_curr_line++; + _nc_curr_col = 0; + } else if (*bufptr == '\t') { + _nc_curr_col = (_nc_curr_col | 7); + } + } else if (!bufptr || !*bufptr) { + /* + * In theory this could be recoded to do its I/O one character at a + * time, saving the buffer space. In practice, this turns out to be + * quite hard to get completely right. Try it and see. If you + * succeed, don't forget to hack push_back() correspondingly. + */ + size_t used; + size_t len; + + do { + bufstart = 0; + used = 0; + do { + if (used + (LEXBUFSIZ / 4) >= allocated) { + allocated += (allocated + LEXBUFSIZ); + result = typeRealloc(char, allocated, result); + if (result == 0) + return (EOF); + } + if (used == 0) + _nc_curr_file_pos = ftell(yyin); + + if (fgets(result + used, (int) (allocated - used), yyin) != 0) { + bufstart = result; + if (used == 0) { + _nc_curr_line++; + _nc_curr_col = 0; + } + } else { + if (used != 0) + strcat(result, "\n"); + } + if ((bufptr = bufstart) != 0) { + used = strlen(bufptr); + while (iswhite(*bufptr)) { + if (*bufptr == '\t') { + _nc_curr_col = (_nc_curr_col | 7) + 1; + } else { + _nc_curr_col++; + } + bufptr++; + } + + /* + * Treat a trailing <cr><lf> the same as a <newline> so we + * can read files on OS/2, etc. + */ + if ((len = strlen(bufptr)) > 1) { + if (bufptr[len - 1] == '\n' + && bufptr[len - 2] == '\r') { + len--; + bufptr[len - 1] = '\n'; + bufptr[len] = '\0'; + } + } + } else { + return (EOF); + } + } while (bufptr[len - 1] != '\n'); /* complete a line */ + } while (result[0] == '#'); /* ignore comments */ + } else if (*bufptr == '\t') { + _nc_curr_col = (_nc_curr_col | 7); + } + + first_column = (bufptr == bufstart); + if (first_column) + had_newline = FALSE; + + _nc_curr_col++; + the_char = *bufptr++; + return UChar(the_char); +} + +static void +push_back(char c) +/* push a character back onto the input stream */ +{ + if (bufptr == bufstart) + _nc_syserr_abort("Can't backspace off beginning of line"); + *--bufptr = c; + _nc_curr_col--; +} + +static long +stream_pos(void) +/* return our current character position in the input stream */ +{ + return (yyin ? ftell(yyin) : (bufptr ? bufptr - bufstart : 0)); +} + +static bool +end_of_stream(void) +/* are we at end of input? */ +{ + return ((yyin ? feof(yyin) : (bufptr && *bufptr == '\0')) + ? TRUE : FALSE); +} /* Assume we may be looking at a termcap-style continuation */ -static inline int +static NCURSES_INLINE int eat_escaped_newline(int ch) { if (ch == '\\') @@ -148,8 +332,11 @@ _nc_get_token(bool silent) static const char terminfo_punct[] = "@%&*!#"; static char *buffer; + char *after_list; + char *after_name; char *numchk; char *ptr; + char *s; char numbuf[80]; int ch; int dot_flag = FALSE; @@ -157,6 +344,10 @@ _nc_get_token(bool silent) long number; long token_start; unsigned found; +#ifdef TRACE + int old_line; + int old_col; +#endif if (pushtype != NO_PUSHBACK) { int retval = pushtype; @@ -173,16 +364,31 @@ _nc_get_token(bool silent) return (retval); } - if (end_of_stream()) + if (end_of_stream()) { + yyin = 0; + next_char(); /* frees its allocated memory */ + if (buffer != 0) { + if (_nc_curr_token.tk_name == buffer) + _nc_curr_token.tk_name = 0; + FreeAndNull(buffer); + } return (EOF); + } start_token: token_start = stream_pos(); - while ((ch = next_char()) == '\n' || iswhite(ch)) + while ((ch = next_char()) == '\n' || iswhite(ch)) { + if (ch == '\n') + had_newline = TRUE; continue; + } ch = eat_escaped_newline(ch); +#ifdef TRACE + old_line = _nc_curr_line; + old_col = _nc_curr_col; +#endif if (ch == EOF) type = EOF; else { @@ -208,36 +414,44 @@ _nc_get_token(bool silent) } /* have to make some punctuation chars legal for terminfo */ - if (!isalnum(ch) + if (!isalnum(UChar(ch)) #if NCURSES_EXT_FUNCS && !(ch == '.' && _nc_disable_period) #endif && !strchr(terminfo_punct, (char) ch)) { if (!silent) - _nc_warning("Illegal character (expected alphanumeric or %s) - %s", + _nc_warning("Illegal character (expected alphanumeric or %s) - '%s'", terminfo_punct, unctrl((chtype) ch)); _nc_panic_mode(separator); goto start_token; } if (buffer == 0) - buffer = _nc_doalloc(buffer, MAX_ENTRY_SIZE); + buffer = typeMalloc(char, MAX_ENTRY_SIZE); +#ifdef TRACE + old_line = _nc_curr_line; + old_col = _nc_curr_col; +#endif ptr = buffer; *(ptr++) = ch; if (first_column) { - char *desc; - _nc_comment_start = token_start; _nc_comment_end = _nc_curr_file_pos; _nc_start_line = _nc_curr_line; _nc_syntax = ERR; + after_name = 0; + after_list = 0; while ((ch = next_char()) != '\n') { - if (ch == EOF) - _nc_err_abort("premature EOF"); - else if (ch == ':' && last_char() != ',') { + if (ch == EOF) { + _nc_err_abort(MSG_NO_INPUTS); + } else if (ch == '|') { + after_list = ptr; + if (after_name == 0) + after_name = ptr; + } else if (ch == ':' && last_char() != ',') { _nc_syntax = SYN_TERMCAP; separator = ':'; break; @@ -245,14 +459,18 @@ _nc_get_token(bool silent) _nc_syntax = SYN_TERMINFO; separator = ','; /* - * Fall-through here is not an accident. The idea is that - * if we see a comma, we figure this is terminfo unless we - * subsequently run into a colon -- but we don't stop - * looking for that colon until hitting a newline. This + * If we did not see a '|', then we found a name with no + * aliases or description. + */ + if (after_name == 0) + break; + /* + * If we see a comma, we assume this is terminfo unless we + * subsequently run into a colon. But we don't stop + * looking for a colon until hitting a newline. This * allows commas to be embedded in description fields of * either syntax. */ - /* FALLTHRU */ } else ch = eat_escaped_newline(ch); @@ -277,58 +495,62 @@ _nc_get_token(bool silent) /* * This is the soonest we have the terminal name fetched. Set up - * for following warning messages. + * for following warning messages. If there's no '|', then there + * is no description. */ - ptr = strchr(buffer, '|'); - if (ptr == (char *) NULL) - ptr = buffer + strlen(buffer); - ch = *ptr; - *ptr = '\0'; - _nc_set_type(buffer); - *ptr = ch; + if (after_name != 0) { + ch = *after_name; + *after_name = '\0'; + _nc_set_type(buffer); + *after_name = ch; + } /* * Compute the boundary between the aliases and the description * field for syntax-checking purposes. */ - desc = strrchr(buffer, '|'); - if (!silent && desc) { - if (*desc == '\0') - _nc_warning("empty longname field"); - else if (strchr(desc, ' ') == (char *) NULL) - _nc_warning("older tic versions may treat the description field as an alias"); + if (after_list != 0) { + if (!silent) { + if (*after_list == '\0') + _nc_warning("empty longname field"); + else if (strchr(after_list, ' ') == 0) + _nc_warning("older tic versions may treat the description field as an alias"); + } + } else { + after_list = buffer + strlen(buffer); + DEBUG(1, ("missing description")); } - if (!desc) - desc = buffer + strlen(buffer); /* * Whitespace in a name field other than the long name can confuse * rdist and some termcap tools. Slashes are a no-no. Other * special characters can be dangerous due to shell expansion. */ - for (ptr = buffer; ptr < desc; ptr++) { - if (isspace(UChar(*ptr))) { + for (s = buffer; s < after_list; ++s) { + if (isspace(UChar(*s))) { if (!silent) _nc_warning("whitespace in name or alias field"); break; - } else if (*ptr == '/') { + } else if (*s == '/') { if (!silent) _nc_warning("slashes aren't allowed in names or aliases"); break; - } else if (strchr("$[]!*?", *ptr)) { + } else if (strchr("$[]!*?", *s)) { if (!silent) - _nc_warning("dubious character `%c' in name or alias field", *ptr); + _nc_warning("dubious character `%c' in name or alias field", *s); break; } } - ptr = buffer; - _nc_curr_token.tk_name = buffer; type = NAMES; } else { + if (had_newline && _nc_syntax == SYN_TERMCAP) { + _nc_warning("Missing backslash before newline"); + had_newline = FALSE; + } while ((ch = next_char()) != EOF) { - if (!isalnum(ch)) { + if (!isalnum(UChar(ch))) { if (_nc_syntax == SYN_TERMINFO) { if (ch != '_') break; @@ -393,7 +615,7 @@ _nc_get_token(bool silent) /* just to get rid of the compiler warning */ type = UNDEF; if (!silent) - _nc_warning("Illegal character - %s", unctrl((chtype) ch)); + _nc_warning("Illegal character - '%s'", unctrl((chtype) ch)); } } /* end else (first_column == FALSE) */ } /* end else (ch != EOF) */ @@ -404,6 +626,11 @@ _nc_get_token(bool silent) if (dot_flag == TRUE) DEBUG(8, ("Commented out ")); + if (_nc_tracing >= DEBUG_LEVEL(8)) { + _tracef("parsed %d.%d to %d.%d", + old_line, old_col, + _nc_curr_line, _nc_curr_col); + } if (_nc_tracing >= DEBUG_LEVEL(7)) { switch (type) { case BOOLEAN: @@ -448,8 +675,9 @@ _nc_get_token(bool silent) type = _nc_get_token(silent); DEBUG(3, ("token: `%s', class %d", - _nc_curr_token.tk_name != 0 ? _nc_curr_token.tk_name : - "<null>", + ((_nc_curr_token.tk_name != 0) + ? _nc_curr_token.tk_name + : "<null>"), type)); return (type); @@ -474,7 +702,7 @@ _nc_get_token(bool silent) * */ -NCURSES_EXPORT(char) +NCURSES_EXPORT(int) _nc_trans_string(char *ptr, char *last) { int count = 0; @@ -492,10 +720,10 @@ _nc_trans_string(char *ptr, char *last) if (ch == '^' && last_ch != '%') { ch = c = next_char(); if (c == EOF) - _nc_err_abort("Premature EOF"); + _nc_err_abort(MSG_NO_INPUTS); if (!(is7bits(ch) && isprint(ch))) { - _nc_warning("Illegal ^ character - %s", unctrl(ch)); + _nc_warning("Illegal ^ character - '%s'", unctrl(ch)); } if (ch == '?') { *(ptr++) = '\177'; @@ -509,14 +737,14 @@ _nc_trans_string(char *ptr, char *last) } else if (ch == '\\') { ch = c = next_char(); if (c == EOF) - _nc_err_abort("Premature EOF"); + _nc_err_abort(MSG_NO_INPUTS); if (ch >= '0' && ch <= '7') { number = ch - '0'; for (i = 0; i < 2; i++) { ch = c = next_char(); if (c == EOF) - _nc_err_abort("Premature EOF"); + _nc_err_abort(MSG_NO_INPUTS); if (c < '0' || c > '7') { if (isdigit(c)) { @@ -590,21 +818,31 @@ _nc_trans_string(char *ptr, char *last) continue; default: - _nc_warning("Illegal character %s in \\ sequence", + _nc_warning("Illegal character '%s' in \\ sequence", unctrl(ch)); + /* FALLTHRU */ + case '|': *(ptr++) = (char) ch; } /* endswitch (ch) */ } /* endelse (ch < '0' || ch > '7') */ } /* end else if (ch == '\\') */ else if (ch == '\n' && (_nc_syntax == SYN_TERMINFO)) { - /* newlines embedded in a terminfo string are ignored */ + /* + * Newlines embedded in a terminfo string are ignored, provided + * that the next line begins with whitespace. + */ ignored = TRUE; } else { *(ptr++) = (char) ch; } if (!ignored) { + if (_nc_curr_col <= 1) { + push_back(ch); + ch = '\n'; + break; + } last_ch = ch; count++; } @@ -639,11 +877,14 @@ _nc_push_token(int tokclass) */ pushtype = tokclass; if (pushname == 0) - pushname = _nc_doalloc(pushname, MAX_NAME_SIZE + 1); + pushname = typeMalloc(char, MAX_NAME_SIZE + 1); _nc_get_type(pushname); DEBUG(3, ("pushing token: `%s', class %d", - _nc_curr_token.tk_name, pushtype)); + ((_nc_curr_token.tk_name != 0) + ? _nc_curr_token.tk_name + : "<null>"), + pushtype)); } /* @@ -663,169 +904,12 @@ _nc_panic_mode(char ch) } } -/***************************************************************************** - * - * Character-stream handling - * - *****************************************************************************/ - -#define LEXBUFSIZ 1024 - -static char *bufptr; /* otherwise, the input buffer pointer */ -static char *bufstart; /* start of buffer so we can compute offsets */ -static FILE *yyin; /* scanner's input file descriptor */ - -/* - * _nc_reset_input() - * - * Resets the input-reading routines. Used on initialization, - * or after a seek has been done. Exactly one argument must be - * non-null. - */ - +#if NO_LEAKS NCURSES_EXPORT(void) -_nc_reset_input(FILE * fp, char *buf) -{ - pushtype = NO_PUSHBACK; - if (pushname != 0) - pushname[0] = '\0'; - yyin = fp; - bufstart = bufptr = buf; - _nc_curr_file_pos = 0L; - if (fp != 0) - _nc_curr_line = 0; - _nc_curr_col = 0; -} - -/* - * int last_char() - * - * Returns the final nonblank character on the current input buffer - */ -static int -last_char(void) +_nc_comp_scan_leaks(void) { - size_t len = strlen(bufptr); - while (len--) { - if (!isspace(UChar(bufptr[len]))) - return bufptr[len]; - } - return 0; -} - -/* - * int next_char() - * - * Returns the next character in the input stream. Comments and leading - * white space are stripped. - * - * The global state variable 'firstcolumn' is set TRUE if the character - * returned is from the first column of the input line. - * - * The global variable _nc_curr_line is incremented for each new line. - * The global variable _nc_curr_file_pos is set to the file offset of the - * beginning of each line. - */ - -static int -next_char(void) -{ - if (!yyin) { - /* - * An string with an embedded null will truncate the input. This is - * intentional (we don't read binary files here). - */ - if (*bufptr == '\0') - return (EOF); - if (*bufptr == '\n') { - _nc_curr_line++; - _nc_curr_col = 0; - } - } else if (!bufptr || !*bufptr) { - /* - * In theory this could be recoded to do its I/O one character at a - * time, saving the buffer space. In practice, this turns out to be - * quite hard to get completely right. Try it and see. If you - * succeed, don't forget to hack push_back() correspondingly. - */ - static char *result; - static size_t allocated; - size_t used; - size_t len; - - do { - bufstart = 0; - used = 0; - do { - if (used + (LEXBUFSIZ / 4) >= allocated) { - allocated += (allocated + LEXBUFSIZ); - result = _nc_doalloc(result, allocated); - if (result == 0) - return (EOF); - } - if (used == 0) - _nc_curr_file_pos = ftell(yyin); - - if (fgets(result + used, allocated - used, yyin) != NULL) { - bufstart = result; - if (used == 0) { - _nc_curr_line++; - _nc_curr_col = 0; - } - } else { - if (used != 0) - strcat(result, "\n"); - } - if ((bufptr = bufstart) != 0) { - used = strlen(bufptr); - while (iswhite(*bufptr)) - bufptr++; - - /* - * Treat a trailing <cr><lf> the same as a <newline> so we - * can read files on OS/2, etc. - */ - if ((len = strlen(bufptr)) > 1) { - if (bufptr[len - 1] == '\n' - && bufptr[len - 2] == '\r') { - len--; - bufptr[len - 1] = '\n'; - bufptr[len] = '\0'; - } - } - } else { - return (EOF); - } - } while (bufptr[len - 1] != '\n'); /* complete a line */ - } while (result[0] == '#'); /* ignore comments */ + if (pushname != 0) { + FreeAndNull(pushname); } - - first_column = (bufptr == bufstart); - - _nc_curr_col++; - return (*bufptr++); -} - -static void -push_back(char c) -/* push a character back onto the input stream */ -{ - if (bufptr == bufstart) - _nc_syserr_abort("Can't backspace off beginning of line"); - *--bufptr = c; -} - -static long -stream_pos(void) -/* return our current character position in the input stream */ -{ - return (yyin ? ftell(yyin) : (bufptr ? bufptr - bufstart : 0)); -} - -static bool -end_of_stream(void) -/* are we at end of input? */ -{ - return ((yyin ? feof(yyin) : (bufptr && *bufptr == '\0')) - ? TRUE : FALSE); } +#endif diff --git a/contrib/ncurses/ncurses/tinfo/db_iterator.c b/contrib/ncurses/ncurses/tinfo/db_iterator.c new file mode 100644 index 000000000000..e69aa5e18834 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/db_iterator.c @@ -0,0 +1,227 @@ +/**************************************************************************** + * Copyright (c) 2006 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey 2006 * + ****************************************************************************/ + +/* + * Iterators for terminal databases. + */ + +#include <curses.priv.h> + +#include <tic.h> + +MODULE_ID("$Id: db_iterator.c,v 1.5 2006/12/16 19:06:42 tom Exp $") + +static bool have_tic_directory = FALSE; +static bool keep_tic_directory = FALSE; + +/* + * Record the "official" location of the terminfo directory, according to + * the place where we're writing to, or the normal default, if not. + */ +NCURSES_EXPORT(const char *) +_nc_tic_dir(const char *path) +{ + static const char *result = TERMINFO; + + if (!keep_tic_directory) { + if (path != 0) { + result = path; + have_tic_directory = TRUE; + } else if (!have_tic_directory && use_terminfo_vars()) { + char *envp; + if ((envp = getenv("TERMINFO")) != 0) + return _nc_tic_dir(envp); + } + } + return result; +} + +/* + * Special fix to prevent the terminfo directory from being moved after tic + * has chdir'd to it. If we let it be changed, then if $TERMINFO has a + * relative path, we'll lose track of the actual directory. + */ +NCURSES_EXPORT(void) +_nc_keep_tic_dir(const char *path) +{ + _nc_tic_dir(path); + keep_tic_directory = TRUE; +} + +/* + * Process the list of :-separated directories, looking for the terminal type. + * We don't use strtok because it does not show us empty tokens. + */ + +static char *this_db_list = 0; +static int size_db_list; + +/* + * Cleanup. + */ +NCURSES_EXPORT(void) +_nc_last_db(void) +{ + if (this_db_list != 0) { + FreeAndNull(this_db_list); + } + size_db_list = 0; +} + +/* The TERMINFO_DIRS value, if defined by the configure script, begins with a + * ":", which will be interpreted as TERMINFO. + */ +static const char * +next_list_item(const char *source, int *offset) +{ + if (source != 0) { + FreeIfNeeded(this_db_list); + this_db_list = strdup(source); + size_db_list = strlen(source); + } + + if (this_db_list != 0 && size_db_list && *offset < size_db_list) { + static char system_db[] = TERMINFO; + char *result = this_db_list + *offset; + char *marker = strchr(result, NCURSES_PATHSEP); + + /* + * Put a null on the marker if a separator was found. Set the offset + * to the next position after the marker so we can call this function + * again, using the data at the offset. + */ + if (marker == 0) { + *offset += strlen(result) + 1; + marker = result + *offset; + } else { + *marker++ = 0; + *offset = marker - this_db_list; + } + if (*result == 0 && result != (this_db_list + size_db_list)) + result = system_db; + return result; + } + return 0; +} + +#define NEXT_DBD(var, offset) next_list_item((*offset == 0) ? var : 0, offset) + +/* + * This is a simple iterator which allows the caller to step through the + * possible locations for a terminfo directory. ncurses uses this to find + * terminfo files to read. + */ +NCURSES_EXPORT(const char *) +_nc_next_db(DBDIRS * state, int *offset) +{ + const char *result; + char *envp; + + while (*state < dbdLAST) { + DBDIRS next = (DBDIRS) ((int) (*state) + 1); + + result = 0; + + switch (*state) { + case dbdTIC: + if (have_tic_directory) + result = _nc_tic_dir(0); + break; +#if USE_DATABASE + case dbdEnvOnce: + if (use_terminfo_vars()) { + if ((envp = getenv("TERMINFO")) != 0) + result = _nc_tic_dir(envp); + } + break; + case dbdHome: + if (use_terminfo_vars()) { + result = _nc_home_terminfo(); + } + break; + case dbdEnvList: + if (use_terminfo_vars()) { + if ((result = NEXT_DBD(getenv("TERMINFO_DIRS"), offset)) != 0) + next = *state; + } + break; + case dbdCfgList: +#ifdef TERMINFO_DIRS + if ((result = NEXT_DBD(TERMINFO_DIRS, offset)) != 0) + next = *state; +#endif + break; + case dbdCfgOnce: +#ifndef TERMINFO_DIRS + result = TERMINFO; +#endif + break; +#endif /* USE_DATABASE */ +#if USE_TERMCAP + case dbdEnvOnce2: + if (use_terminfo_vars()) { + if ((envp = getenv("TERMCAP")) != 0) + result = _nc_tic_dir(envp); + } + break; + case dbdEnvList2: + if (use_terminfo_vars()) { + if ((result = NEXT_DBD(getenv("TERMPATH"), offset)) != 0) + next = *state; + } + break; + case dbdCfgList2: + if ((result = NEXT_DBD(TERMPATH, offset)) != 0) + next = *state; + break; +#endif /* USE_TERMCAP */ + case dbdLAST: + break; + } + if (*state != next) { + *state = next; + *offset = 0; + _nc_last_db(); + } + if (result != 0) { + return result; + } + } + return 0; +} + +NCURSES_EXPORT(void) +_nc_first_db(DBDIRS * state, int *offset) +{ + *state = dbdTIC; + *offset = 0; +} diff --git a/contrib/ncurses/ncurses/tinfo/doalloc.c b/contrib/ncurses/ncurses/tinfo/doalloc.c index 634469cdf4ac..fe2a009d19b4 100644 --- a/contrib/ncurses/ncurses/tinfo/doalloc.c +++ b/contrib/ncurses/ncurses/tinfo/doalloc.c @@ -39,7 +39,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: doalloc.c,v 1.7 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: doalloc.c,v 1.8 2002/08/31 21:48:11 Philippe.Blain Exp $") NCURSES_EXPORT(void *) _nc_doalloc(void *oldp, size_t amount) @@ -52,7 +52,7 @@ _nc_doalloc(void *oldp, size_t amount) errno = ENOMEM; /* just in case 'free' reset */ } } else { - newp = typeMalloc(char, amount); + newp = malloc(amount); } return newp; } diff --git a/contrib/ncurses/ncurses/tinfo/free_ttype.c b/contrib/ncurses/ncurses/tinfo/free_ttype.c index df604e41a681..fa0fff1b83fb 100644 --- a/contrib/ncurses/ncurses/tinfo/free_ttype.c +++ b/contrib/ncurses/ncurses/tinfo/free_ttype.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,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + * Author: Thomas E. Dickey 1999-on * ****************************************************************************/ /* @@ -43,13 +43,14 @@ #include <tic.h> #include <term_entry.h> -MODULE_ID("$Id: free_ttype.c,v 1.7 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: free_ttype.c,v 1.13 2006/06/25 10:46:02 tom Exp $") NCURSES_EXPORT(void) -_nc_free_termtype(TERMTYPE * ptr) +_nc_free_termtype(TERMTYPE *ptr) { + T(("_nc_free_termtype(%s)", ptr->term_names)); + FreeIfNeeded(ptr->str_table); - FreeIfNeeded(ptr->term_names); FreeIfNeeded(ptr->Booleans); FreeIfNeeded(ptr->Numbers); FreeIfNeeded(ptr->Strings); @@ -58,6 +59,7 @@ _nc_free_termtype(TERMTYPE * ptr) FreeIfNeeded(ptr->ext_Names); #endif memset(ptr, 0, sizeof(TERMTYPE)); + _nc_free_entry(_nc_head, ptr); } #if NCURSES_XNAMES @@ -67,7 +69,9 @@ NCURSES_EXPORT(int) use_extended_names(bool flag) { int oldflag = _nc_user_definable; + + T((T_CALLED("use_extended_names(%d)"), flag)); _nc_user_definable = flag; - return oldflag; + returnBool(oldflag); } #endif diff --git a/contrib/ncurses/ncurses/tinfo/hashed_db.c b/contrib/ncurses/ncurses/tinfo/hashed_db.c new file mode 100644 index 000000000000..3fc04eae3cca --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/hashed_db.c @@ -0,0 +1,260 @@ +/**************************************************************************** + * Copyright (c) 2006 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey 2006 * + ****************************************************************************/ + +#include <curses.priv.h> +#include <tic.h> +#include <hashed_db.h> + +#if USE_HASHED_DB + +MODULE_ID("$Id: hashed_db.c,v 1.13 2006/08/19 19:48:38 tom Exp $") + +#if HASHED_DB_API >= 2 +static DBC *cursor; +#endif + +/* + * Open the database. + */ +NCURSES_EXPORT(DB *) +_nc_db_open(const char *path, bool modify) +{ + DB *result = 0; + +#if HASHED_DB_API >= 4 + db_create(&result, NULL, 0); + result->open(result, + NULL, + path, + NULL, + DB_HASH, + modify ? DB_CREATE : DB_RDONLY, + 0644); +#elif HASHED_DB_API >= 3 + db_create(&result, NULL, 0); + result->open(result, + path, + NULL, + DB_HASH, + modify ? DB_CREATE : DB_RDONLY, + 0644); +#elif HASHED_DB_API >= 2 + int code; + + if ((code = db_open(path, + DB_HASH, + modify ? DB_CREATE : DB_RDONLY, + 0644, + (DB_ENV *) 0, + (DB_INFO *) 0, + &result)) != 0) { + T(("cannot open %s: %s", path, strerror(code))); + result = 0; + } else { + T(("opened %s", path)); + } +#else + result = dbopen(path, + modify ? (O_CREAT | O_RDWR) : O_RDONLY, + 0644, + DB_HASH, + NULL); + if (result != 0) { + T(("opened %s", path)); + } +#endif + return result; +} + +/* + * Close the database. Do not attempt to use the 'db' handle after this call. + */ +NCURSES_EXPORT(int) +_nc_db_close(DB * db) +{ + int result; + +#if HASHED_DB_API >= 2 + result = db->close(db, 0); +#else + result = db->close(db); +#endif + return result; +} + +/* + * Write a record to the database. + * + * Returns 0 on success. + * + * FIXME: the FreeBSD cap_mkdb program assumes the database could have + * duplicates. There appears to be no good reason for that (review/fix). + */ +NCURSES_EXPORT(int) +_nc_db_put(DB * db, DBT * key, DBT * data) +{ + int result; +#if HASHED_DB_API >= 2 + /* remove any pre-existing value, since we do not want duplicates */ + (void) db->del(db, NULL, key, 0); + result = db->put(db, NULL, key, data, DB_NOOVERWRITE); +#else + result = db->put(db, key, data, R_NOOVERWRITE); +#endif + return result; +} + +/* + * Read a record from the database. + * + * Returns 0 on success. + */ +NCURSES_EXPORT(int) +_nc_db_get(DB * db, DBT * key, DBT * data) +{ + int result; + + memset(data, 0, sizeof(*data)); +#if HASHED_DB_API >= 2 + result = db->get(db, NULL, key, data, 0); +#else + result = db->get(db, key, data, 0); +#endif + return result; +} + +/* + * Read the first record from the database, ignoring order. + * + * Returns 0 on success. + */ +NCURSES_EXPORT(int) +_nc_db_first(DB * db, DBT * key, DBT * data) +{ + int result; + + memset(key, 0, sizeof(*key)); + memset(data, 0, sizeof(*data)); +#if HASHED_DB_API >= 2 + if ((result = db->cursor(db, NULL, &cursor, 0)) == 0) { + result = cursor->c_get(cursor, key, data, DB_FIRST); + } +#else + result = db->seq(db, key, data, 0); +#endif + return result; +} + +/* + * Read the next record from the database, ignoring order. + * + * Returns 0 on success. + */ +NCURSES_EXPORT(int) +_nc_db_next(DB * db, DBT * key, DBT * data) +{ + int result; + +#if HASHED_DB_API >= 2 + (void) db; + if (cursor != 0) { + result = cursor->c_get(cursor, key, data, DB_NEXT); + } else { + result = -1; + } +#else + result = db->seq(db, key, data, 0); +#endif + return result; +} + +/* + * Check if a record is a terminfo index record. Index records are those that + * contain only an alias pointing to a list of aliases. + */ +NCURSES_EXPORT(bool) +_nc_db_have_index(DBT * key, DBT * data, char **buffer, int *size) +{ + bool result = FALSE; + int used = data->size - 1; + char *have = (char *) data->data; + + (void) key; + if (*have++ == 2) { + result = TRUE; + } + /* + * Update params in any case for consistency with _nc_db_have_data(). + */ + *buffer = have; + *size = used; + return result; +} + +/* + * Check if a record is the terminfo data record. Ignore index records, e.g., + * those that contain only an alias pointing to a list of aliases. + */ +NCURSES_EXPORT(bool) +_nc_db_have_data(DBT * key, DBT * data, char **buffer, int *size) +{ + bool result = FALSE; + int used = data->size - 1; + char *have = (char *) data->data; + + if (*have++ == 0) { + if (data->size > key->size + && IS_TIC_MAGIC(have)) { + result = TRUE; + } + } + /* + * Update params in any case to make it simple to follow a index record + * to the data record. + */ + *buffer = have; + *size = used; + return result; +} + +#else + +extern +NCURSES_EXPORT(void) +_nc_hashed_db(void); + +NCURSES_EXPORT(void) +_nc_hashed_db(void) +{ +} + +#endif /* USE_HASHED_DB */ diff --git a/contrib/ncurses/ncurses/tinfo/home_terminfo.c b/contrib/ncurses/ncurses/tinfo/home_terminfo.c index 47b3e382ef7e..ce6576a82f82 100644 --- a/contrib/ncurses/ncurses/tinfo/home_terminfo.c +++ b/contrib/ncurses/ncurses/tinfo/home_terminfo.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,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,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1998,2000 * + * Author: Thomas E. Dickey 1998,2000,2004,2005 * ****************************************************************************/ /* @@ -37,7 +37,7 @@ #include <curses.priv.h> #include <tic.h> -MODULE_ID("$Id: home_terminfo.c,v 1.6 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: home_terminfo.c,v 1.9 2005/07/02 19:43:38 tom Exp $") #define my_length (strlen(home) + sizeof(PRIVATE_INFO)) @@ -46,6 +46,8 @@ MODULE_ID("$Id: home_terminfo.c,v 1.6 2000/12/10 02:55:07 tom Exp $") NCURSES_EXPORT(char *) _nc_home_terminfo(void) { + char *result = 0; +#ifdef USE_HOME_TERMINFO char *home; static char *temp = 0; @@ -55,11 +57,12 @@ _nc_home_terminfo(void) && my_length <= PATH_MAX) { temp = typeMalloc(char, my_length); if (temp == 0) - _nc_err_abort("Out of memory"); + _nc_err_abort(MSG_NO_MEMORY); (void) sprintf(temp, PRIVATE_INFO, home); } } - return temp; + result = temp; } - return 0; +#endif + return result; } diff --git a/contrib/ncurses/ncurses/tinfo/init_keytry.c b/contrib/ncurses/ncurses/tinfo/init_keytry.c index cf840e8e93b3..3461dd4d5e51 100644 --- a/contrib/ncurses/ncurses/tinfo/init_keytry.c +++ b/contrib/ncurses/ncurses/tinfo/init_keytry.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 * @@ -28,11 +28,15 @@ #include <curses.priv.h> -#include <term.h> /* keypad_xmit, keypad_local, meta_on, meta_off */ - /* cursor_visible,cursor_normal,cursor_invisible */ +#include <term.h> +/* keypad_xmit, keypad_local, meta_on, meta_off */ +/* cursor_visible,cursor_normal,cursor_invisible */ + #include <tic.h> /* struct tinfo_fkeys */ -MODULE_ID("$Id: init_keytry.c,v 1.5 2000/12/10 02:55:07 tom Exp $") +#include <term_entry.h> + +MODULE_ID("$Id: init_keytry.c,v 1.8 2006/01/21 23:43:28 tom Exp $") /* ** _nc_init_keytry() @@ -69,12 +73,38 @@ _nc_init_keytry(void) * mouse_activate() (which will call keyok()) are first called. */ - for (n = 0; _nc_tinfo_fkeys[n].code; n++) - if (_nc_tinfo_fkeys[n].offset < STRCOUNT) - _nc_add_to_try(&(SP->_keytry), - CUR Strings[_nc_tinfo_fkeys[n].offset], - _nc_tinfo_fkeys[n].code); + if (SP != 0) { + for (n = 0; _nc_tinfo_fkeys[n].code; n++) { + if (_nc_tinfo_fkeys[n].offset < STRCOUNT) { + _nc_add_to_try(&(SP->_keytry), + CUR Strings[_nc_tinfo_fkeys[n].offset], + _nc_tinfo_fkeys[n].code); + } + } +#if NCURSES_XNAMES + /* + * Add any of the extended strings to the tries if their name begins + * with 'k', i.e., they follow the convention of other terminfo key + * names. + */ + { + TERMTYPE *tp = &(SP->_term->type); + for (n = STRCOUNT; n < NUM_STRINGS(tp); ++n) { + const char *name = ExtStrname(tp, n, strnames); + char *value = tp->Strings[n]; + if (name != 0 + && *name == 'k' + && value != 0 + && key_defined(value) == 0) { + _nc_add_to_try(&(SP->_keytry), + value, + n - STRCOUNT + KEY_MAX); + } + } + } +#endif #ifdef TRACE - _nc_trace_tries(SP->_keytry); + _nc_trace_tries(SP->_keytry); #endif + } } diff --git a/contrib/ncurses/ncurses/tinfo/lib_acs.c b/contrib/ncurses/ncurses/tinfo/lib_acs.c index b84d8e262a2f..2719795d9d4f 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_acs.c +++ b/contrib/ncurses/ncurses/tinfo/lib_acs.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,12 +29,13 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ #include <curses.priv.h> #include <term.h> /* ena_acs, acs_chars */ -MODULE_ID("$Id: lib_acs.c,v 1.21 2001/12/23 00:15:10 tom Exp $") +MODULE_ID("$Id: lib_acs.c,v 1.30 2006/01/07 21:27:15 tom Exp $") #if BROKEN_LINKER NCURSES_EXPORT_VAR(chtype *) @@ -55,98 +56,120 @@ NCURSES_EXPORT_VAR(chtype) acs_map[ACS_LEN] = NCURSES_EXPORT(void) _nc_init_acs(void) { + chtype *fake_map = acs_map; + chtype *real_map = SP != 0 ? SP->_acs_map : fake_map; + int j; + T(("initializing ACS map")); /* + * If we're using this from curses (rather than terminfo), we are storing + * the mapping information in the SCREEN struct so we can decide how to + * render it. + */ + if (real_map != fake_map) { + for (j = 1; j < ACS_LEN; ++j) { + real_map[j] = 0; + fake_map[j] = A_ALTCHARSET | j; + SP->_screen_acs_map[j] = FALSE; + } + } else { + for (j = 1; j < ACS_LEN; ++j) { + real_map[j] = 0; + } + } + + /* * Initializations for a UNIX-like multi-terminal environment. Use * ASCII chars and count on the terminfo description to do better. */ - ACS_ULCORNER = '+'; /* should be upper left corner */ - ACS_LLCORNER = '+'; /* should be lower left corner */ - ACS_URCORNER = '+'; /* should be upper right corner */ - ACS_LRCORNER = '+'; /* should be lower right corner */ - ACS_RTEE = '+'; /* should be tee pointing left */ - ACS_LTEE = '+'; /* should be tee pointing right */ - ACS_BTEE = '+'; /* should be tee pointing up */ - ACS_TTEE = '+'; /* should be tee pointing down */ - ACS_HLINE = '-'; /* should be horizontal line */ - ACS_VLINE = '|'; /* should be vertical line */ - ACS_PLUS = '+'; /* should be large plus or crossover */ - ACS_S1 = '~'; /* should be scan line 1 */ - ACS_S9 = '_'; /* should be scan line 9 */ - ACS_DIAMOND = '+'; /* should be diamond */ - ACS_CKBOARD = ':'; /* should be checker board (stipple) */ - ACS_DEGREE = '\''; /* should be degree symbol */ - ACS_PLMINUS = '#'; /* should be plus/minus */ - ACS_BULLET = 'o'; /* should be bullet */ - ACS_LARROW = '<'; /* should be arrow pointing left */ - ACS_RARROW = '>'; /* should be arrow pointing right */ - ACS_DARROW = 'v'; /* should be arrow pointing down */ - ACS_UARROW = '^'; /* should be arrow pointing up */ - ACS_BOARD = '#'; /* should be board of squares */ - ACS_LANTERN = '#'; /* should be lantern symbol */ - ACS_BLOCK = '#'; /* should be solid square block */ + real_map['l'] = '+'; /* should be upper left corner */ + real_map['m'] = '+'; /* should be lower left corner */ + real_map['k'] = '+'; /* should be upper right corner */ + real_map['j'] = '+'; /* should be lower right corner */ + real_map['u'] = '+'; /* should be tee pointing left */ + real_map['t'] = '+'; /* should be tee pointing right */ + real_map['v'] = '+'; /* should be tee pointing up */ + real_map['w'] = '+'; /* should be tee pointing down */ + real_map['q'] = '-'; /* should be horizontal line */ + real_map['x'] = '|'; /* should be vertical line */ + real_map['n'] = '+'; /* should be large plus or crossover */ + real_map['o'] = '~'; /* should be scan line 1 */ + real_map['s'] = '_'; /* should be scan line 9 */ + real_map['`'] = '+'; /* should be diamond */ + real_map['a'] = ':'; /* should be checker board (stipple) */ + real_map['f'] = '\''; /* should be degree symbol */ + real_map['g'] = '#'; /* should be plus/minus */ + real_map['~'] = 'o'; /* should be bullet */ + real_map[','] = '<'; /* should be arrow pointing left */ + real_map['+'] = '>'; /* should be arrow pointing right */ + real_map['.'] = 'v'; /* should be arrow pointing down */ + real_map['-'] = '^'; /* should be arrow pointing up */ + real_map['h'] = '#'; /* should be board of squares */ + real_map['i'] = '#'; /* should be lantern symbol */ + real_map['0'] = '#'; /* should be solid square block */ /* these defaults were invented for ncurses */ - ACS_S3 = '-'; /* should be scan line 3 */ - ACS_S7 = '-'; /* should be scan line 7 */ - ACS_LEQUAL = '<'; /* should be less-than-or-equal-to */ - ACS_GEQUAL = '>'; /* should be greater-than-or-equal-to */ - ACS_PI = '*'; /* should be greek pi */ - ACS_NEQUAL = '!'; /* should be not-equal */ - ACS_STERLING = 'f'; /* should be pound-sterling symbol */ + real_map['p'] = '-'; /* should be scan line 3 */ + real_map['r'] = '-'; /* should be scan line 7 */ + real_map['y'] = '<'; /* should be less-than-or-equal-to */ + real_map['z'] = '>'; /* should be greater-than-or-equal-to */ + real_map['{'] = '*'; /* should be greek pi */ + real_map['|'] = '!'; /* should be not-equal */ + real_map['}'] = 'f'; /* should be pound-sterling symbol */ + +#if !USE_WIDEC_SUPPORT + if (_nc_unicode_locale() && _nc_locale_breaks_acs()) { + acs_chars = NULL; + ena_acs = NULL; + enter_alt_charset_mode = NULL; + exit_alt_charset_mode = NULL; + set_attributes = NULL; + } +#endif if (ena_acs != NULL) { TPUTS_TRACE("ena_acs"); putp(ena_acs); } -#define ALTCHAR(c) ((chtype)(((unsigned char)(c)) | A_ALTCHARSET)) +#if NCURSES_EXT_FUNCS + /* + * Linux console "supports" the "PC ROM" character set by the coincidence + * that smpch/rmpch and smacs/rmacs have the same values. ncurses has + * no codepage support (see SCO Merge for an example). Outside of the + * values defined in acsc, there are no definitions for the "PC ROM" + * character set (assumed by some applications to be codepage 437), but we + * allow those applications to use those codepoints. + * + * test/blue.c uses this feature. + */ +#define PCH_KLUDGE(a,b) (a != 0 && b != 0 && !strcmp(a,b)) + if (PCH_KLUDGE(enter_pc_charset_mode, enter_alt_charset_mode) && + PCH_KLUDGE(exit_pc_charset_mode, exit_alt_charset_mode)) { + size_t i; + for (i = 1; i < ACS_LEN; ++i) { + if (real_map[i] == 0) { + real_map[i] = i; + if (real_map != fake_map) { + if (SP != 0) + SP->_screen_acs_map[i] = TRUE; + } + } + } + } +#endif if (acs_chars != NULL) { size_t i = 0; size_t length = strlen(acs_chars); - while (i < length) - switch (acs_chars[i]) { - case 'l': - case 'm': - case 'k': - case 'j': - case 'u': - case 't': - case 'v': - case 'w': - case 'q': - case 'x': - case 'n': - case 'o': - case 's': - case '`': - case 'a': - case 'f': - case 'g': - case '~': - case ',': - case '+': - case '.': - case '-': - case 'h': - case 'i': - case '0': - case 'p': - case 'r': - case 'y': - case 'z': - case '{': - case '|': - case '}': - acs_map[(unsigned int) acs_chars[i]] = - ALTCHAR(acs_chars[i + 1]); - i++; - /* FALLTHRU */ - default: - i++; - break; + while (i + 1 < length) { + if (acs_chars[i] != 0 && UChar(acs_chars[i]) < ACS_LEN) { + real_map[UChar(acs_chars[i])] = UChar(acs_chars[i + 1]) | A_ALTCHARSET; + if (SP != 0) + SP->_screen_acs_map[UChar(acs_chars[i])] = TRUE; } + i += 2; + } } #ifdef TRACE /* Show the equivalent mapping, noting if it does not match the @@ -154,14 +177,18 @@ _nc_init_acs(void) */ if (_nc_tracing & TRACE_CALLS) { size_t n, m; - char show[ACS_LEN + 1]; + char show[ACS_LEN * 2 + 1]; for (n = 1, m = 0; n < ACS_LEN; n++) { - if (acs_map[n] != 0) { + if (real_map[n] != 0) { show[m++] = (char) n; - show[m++] = ChCharOf(acs_map[n]); + show[m++] = ChCharOf(real_map[n]); } } show[m] = 0; + if (acs_chars == NULL || strcmp(acs_chars, show)) + _tracef("%s acs_chars %s", + (acs_chars == NULL) ? "NULL" : "READ", + _nc_visbuf(acs_chars)); _tracef("%s acs_chars %s", (acs_chars == NULL) ? "NULL" diff --git a/contrib/ncurses/ncurses/tinfo/lib_cur_term.c b/contrib/ncurses/ncurses/tinfo/lib_cur_term.c index 8f269e591d0c..8fccc2f88d08 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_cur_term.c +++ b/contrib/ncurses/ncurses/tinfo/lib_cur_term.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,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 * @@ -40,7 +40,7 @@ #include <term_entry.h> /* TTY, cur_term */ #include <termcap.h> /* ospeed */ -MODULE_ID("$Id: lib_cur_term.c,v 1.11 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: lib_cur_term.c,v 1.13 2003/12/27 18:21:30 tom Exp $") NCURSES_EXPORT_VAR(TERMINAL *) cur_term = 0; @@ -49,11 +49,14 @@ set_curterm(TERMINAL * termp) { TERMINAL *oldterm = cur_term; + T((T_CALLED("set_curterm(%p)"), termp)); + if ((cur_term = termp) != 0) { ospeed = _nc_ospeed(cur_term->_baudrate); PC = (pad_char != NULL) ? pad_char[0] : 0; } - return oldterm; + T((T_RETURN("%p"), oldterm)); + return (oldterm); } NCURSES_EXPORT(int) @@ -63,6 +66,7 @@ del_curterm(TERMINAL * termp) if (termp != 0) { _nc_free_termtype(&(termp->type)); + FreeIfNeeded(termp->_termname); free(termp); if (termp == cur_term) cur_term = 0; diff --git a/contrib/ncurses/ncurses/tinfo/lib_data.c b/contrib/ncurses/ncurses/tinfo/lib_data.c index 87d60edf6ed9..34f033a79021 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_data.c +++ b/contrib/ncurses/ncurses/tinfo/lib_data.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,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 * ****************************************************************************/ /* @@ -40,18 +41,15 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_data.c,v 1.16 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: lib_data.c,v 1.17 2005/01/22 17:39:22 tom Exp $") /* * OS/2's native linker complains if we don't initialize public data when * constructing a dll (reported by J.J.G.Ripoll). */ -NCURSES_EXPORT_VAR(WINDOW *) -stdscr = 0; -NCURSES_EXPORT_VAR(WINDOW *) -curscr = 0; -NCURSES_EXPORT_VAR(WINDOW *) -newscr = 0; +NCURSES_EXPORT_VAR(WINDOW *) stdscr = 0; +NCURSES_EXPORT_VAR(WINDOW *) curscr = 0; +NCURSES_EXPORT_VAR(WINDOW *) newscr = 0; NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain = 0; @@ -66,7 +64,7 @@ NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain = 0; * module coupling that increases the size of the executable. */ #if BROKEN_LINKER - static SCREEN *my_screen; +static SCREEN *my_screen; NCURSES_EXPORT(SCREEN *) _nc_screen(void) @@ -81,11 +79,11 @@ _nc_alloc_screen(void) } NCURSES_EXPORT(void) -_nc_set_screen(SCREEN * sp) +_nc_set_screen(SCREEN *sp) { my_screen = sp; } #else -NCURSES_EXPORT_VAR(SCREEN *) SP = NULL; /* Some linkers require initialized data... */ +NCURSES_EXPORT_VAR(SCREEN *) SP = NULL; /* Some linkers require initialized data... */ #endif diff --git a/contrib/ncurses/ncurses/tinfo/lib_has_cap.c b/contrib/ncurses/ncurses/tinfo/lib_has_cap.c index 6fb7b3a9c8c0..0dc66bd9b918 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_has_cap.c +++ b/contrib/ncurses/ncurses/tinfo/lib_has_cap.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 * @@ -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 * ****************************************************************************/ /* @@ -42,7 +43,7 @@ #include <term.h> -MODULE_ID("$Id: lib_has_cap.c,v 1.3 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: lib_has_cap.c,v 1.4 2003/10/25 19:43:55 tom Exp $") NCURSES_EXPORT(bool) has_ic(void) diff --git a/contrib/ncurses/ncurses/tinfo/lib_kernel.c b/contrib/ncurses/ncurses/tinfo/lib_kernel.c index b4d3c7f45aca..89dc1e80ea8e 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_kernel.c +++ b/contrib/ncurses/ncurses/tinfo/lib_kernel.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2000,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 * @@ -48,13 +48,13 @@ #include <curses.priv.h> #include <term.h> /* cur_term */ -MODULE_ID("$Id: lib_kernel.c,v 1.22 2002/05/11 20:32:18 tom Exp $") +MODULE_ID("$Id: lib_kernel.c,v 1.24 2004/05/08 17:11:21 tom Exp $") static int _nc_vdisable(void) { - int value; -#if defined(_POSIX_VDISABLE) && defined(HAVE_UNISTD_H) + int value = -1; +#if defined(_POSIX_VDISABLE) && HAVE_UNISTD_H value = _POSIX_VDISABLE; #endif #if defined(_PC_VDISABLE) diff --git a/contrib/ncurses/ncurses/tinfo/lib_napms.c b/contrib/ncurses/ncurses/tinfo/lib_napms.c index 20537be4dfe0..926afa836db4 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_napms.c +++ b/contrib/ncurses/ncurses/tinfo/lib_napms.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,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 * @@ -36,6 +36,8 @@ * * The routine napms. * + * (This file was originally written by Eric Raymond; however except for + * comments, none of the original code remains - T.Dickey). */ #include <curses.priv.h> @@ -47,7 +49,7 @@ #endif #endif -MODULE_ID("$Id: lib_napms.c,v 1.12 2001/12/22 22:20:40 tom Exp $") +MODULE_ID("$Id: lib_napms.c,v 1.15 2005/04/03 13:58:14 tom Exp $") NCURSES_EXPORT(int) napms(int ms) @@ -56,13 +58,16 @@ napms(int ms) #if HAVE_NANOSLEEP { - struct timespec ts; - ts.tv_sec = ms / 1000; - ts.tv_nsec = (ms % 1000) * 1000000; - nanosleep(&ts, NULL); + struct timespec request, remaining; + request.tv_sec = ms / 1000; + request.tv_nsec = (ms % 1000) * 1000000; + while (nanosleep(&request, &remaining) == -1 + && errno == EINTR) { + request = remaining; + } } #else - _nc_timed_wait(0, ms, (int *) 0); + _nc_timed_wait(0, ms, (int *) 0 EVENTLIST_2nd(0)); #endif returnCode(OK); diff --git a/contrib/ncurses/ncurses/tinfo/lib_options.c b/contrib/ncurses/ncurses/tinfo/lib_options.c index 05bd47685dd6..bdb0b7024d7c 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_options.c +++ b/contrib/ncurses/ncurses/tinfo/lib_options.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000,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 * ****************************************************************************/ /* @@ -42,7 +43,7 @@ #include <term.h> -MODULE_ID("$Id: lib_options.c,v 1.46 2002/02/02 19:40:54 tom Exp $") +MODULE_ID("$Id: lib_options.c,v 1.49 2006/03/04 19:28:25 tom Exp $") NCURSES_EXPORT(int) idlok(WINDOW *win, bool flag) @@ -72,7 +73,7 @@ halfdelay(int t) { T((T_CALLED("halfdelay(%d)"), t)); - if (t < 1 || t > 255) + if (t < 1 || t > 255 || SP == 0) returnCode(ERR); cbreak(); @@ -98,7 +99,7 @@ nodelay(WINDOW *win, bool flag) NCURSES_EXPORT(int) notimeout(WINDOW *win, bool f) { - T((T_CALLED("notimout(%p,%d)"), win, f)); + T((T_CALLED("notimeout(%p,%d)"), win, f)); if (win) { win->_notimeout = f; @@ -133,19 +134,24 @@ keypad(WINDOW *win, bool flag) NCURSES_EXPORT(int) meta(WINDOW *win GCC_UNUSED, bool flag) { + int result = ERR; + /* Ok, we stay relaxed and don't signal an error if win is NULL */ T((T_CALLED("meta(%p,%d)"), win, flag)); - SP->_use_meta = flag; - - if (flag && meta_on) { - TPUTS_TRACE("meta_on"); - putp(meta_on); - } else if (!flag && meta_off) { - TPUTS_TRACE("meta_off"); - putp(meta_off); + if (SP != 0) { + SP->_use_meta = flag; + + if (flag && meta_on) { + TPUTS_TRACE("meta_on"); + putp(meta_on); + } else if (!flag && meta_off) { + TPUTS_TRACE("meta_off"); + putp(meta_off); + } + result = OK; } - returnCode(OK); + returnCode(result); } /* curs_set() moved here to narrow the kernel interface */ @@ -153,51 +159,56 @@ meta(WINDOW *win GCC_UNUSED, bool flag) NCURSES_EXPORT(int) curs_set(int vis) { - int cursor = SP->_cursor; + int result = ERR; T((T_CALLED("curs_set(%d)"), vis)); - - if (vis < 0 || vis > 2) - returnCode(ERR); - - if (vis == cursor) - returnCode(cursor); - - switch (vis) { - case 2: - if (cursor_visible) { - TPUTS_TRACE("cursor_visible"); - putp(cursor_visible); - } else - returnCode(ERR); - break; - case 1: - if (cursor_normal) { - TPUTS_TRACE("cursor_normal"); - putp(cursor_normal); - } else - returnCode(ERR); - break; - case 0: - if (cursor_invisible) { - TPUTS_TRACE("cursor_invisible"); - putp(cursor_invisible); - } else - returnCode(ERR); - break; + if (SP != 0 && vis >= 0 && vis <= 2) { + int cursor = SP->_cursor; + + if (vis == cursor) { + result = cursor; + } else { + result = (cursor == -1 ? 1 : cursor); + switch (vis) { + case 2: + if (cursor_visible) { + TPUTS_TRACE("cursor_visible"); + putp(cursor_visible); + } else + result = ERR; + break; + case 1: + if (cursor_normal) { + TPUTS_TRACE("cursor_normal"); + putp(cursor_normal); + } else + result = ERR; + break; + case 0: + if (cursor_invisible) { + TPUTS_TRACE("cursor_invisible"); + putp(cursor_invisible); + } else + result = ERR; + break; + } + SP->_cursor = vis; + _nc_flush(); + } } - SP->_cursor = vis; - _nc_flush(); - - returnCode(cursor == -1 ? 1 : cursor); + returnCode(result); } NCURSES_EXPORT(int) typeahead(int fd) { T((T_CALLED("typeahead(%d)"), fd)); - SP->_checkfd = fd; - returnCode(OK); + if (SP != 0) { + SP->_checkfd = fd; + returnCode(OK); + } else { + returnCode(ERR); + } } /* @@ -224,7 +235,7 @@ NCURSES_EXPORT(int) has_key(int keycode) { T((T_CALLED("has_key(%d)"), keycode)); - returnCode(has_key_internal(keycode, SP->_keytry)); + returnCode(SP != 0 ? has_key_internal(keycode, SP->_keytry) : FALSE); } #endif /* NCURSES_EXT_FUNCS */ @@ -248,10 +259,12 @@ _nc_keypad(bool flag) _nc_flush(); } - if (flag && !SP->_tried) { - _nc_init_keytry(); - SP->_tried = TRUE; + if (SP != 0) { + if (flag && !SP->_tried) { + _nc_init_keytry(); + SP->_tried = TRUE; + } + SP->_keypad_on = flag; } - SP->_keypad_on = flag; return (OK); } diff --git a/contrib/ncurses/ncurses/tinfo/lib_print.c b/contrib/ncurses/ncurses/tinfo/lib_print.c index 01540eacdc14..975b46d85773 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_print.c +++ b/contrib/ncurses/ncurses/tinfo/lib_print.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2000,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 * @@ -35,7 +35,7 @@ #include <term.h> -MODULE_ID("$Id: lib_print.c,v 1.14 2002/03/16 21:45:08 tom Exp $") +MODULE_ID("$Id: lib_print.c,v 1.16 2006/11/26 00:26:34 tom Exp $") NCURSES_EXPORT(int) mcprint(char *data, int len) @@ -51,7 +51,7 @@ mcprint(char *data, int len) } if (prtr_non) { - switchon = tparm(prtr_non, len); + switchon = TPARM_1(prtr_non, len); onsize = strlen(switchon); offsize = 0; } else { @@ -60,7 +60,8 @@ mcprint(char *data, int len) offsize = strlen(prtr_off); } - if ((mybuf = typeMalloc(char, onsize + len + offsize + 1)) == (char *) 0) { + if (switchon == 0 + || (mybuf = typeMalloc(char, onsize + len + offsize + 1)) == 0) { errno = ENOMEM; return (ERR); } diff --git a/contrib/ncurses/ncurses/tinfo/lib_raw.c b/contrib/ncurses/ncurses/tinfo/lib_raw.c index 97cf0cbd0249..aa09f52c8c8d 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_raw.c +++ b/contrib/ncurses/ncurses/tinfo/lib_raw.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,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 * @@ -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 1998 on * ****************************************************************************/ /* @@ -48,7 +49,7 @@ #include <curses.priv.h> #include <term.h> /* cur_term */ -MODULE_ID("$Id: lib_raw.c,v 1.12 2001/08/04 17:18:38 tom Exp $") +MODULE_ID("$Id: lib_raw.c,v 1.13 2002/07/06 22:00:45 tom Exp $") #if SVR4_TERMIO && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE @@ -60,6 +61,9 @@ MODULE_ID("$Id: lib_raw.c,v 1.12 2001/08/04 17:18:38 tom Exp $") #ifdef __EMX__ #include <io.h> +#define _nc_setmode(mode) setmode(SP->_ifd, mode) +#else +#define _nc_setmode(mode) /* nothing */ #endif #define COOKED_INPUT (IXON|BRKINT|PARMRK) @@ -75,162 +79,218 @@ MODULE_ID("$Id: lib_raw.c,v 1.12 2001/08/04 17:18:38 tom Exp $") NCURSES_EXPORT(int) raw(void) { + int result = ERR; + T((T_CALLED("raw()"))); - if (SP != 0 && cur_term != 0) { - SP->_raw = TRUE; - SP->_cbreak = 1; + if (SP != 0 && cur_term != 0) { + TTY buf; -#ifdef __EMX__ - setmode(SP->_ifd, O_BINARY); -#endif + BEFORE("raw"); + _nc_setmode(O_BINARY); + buf = cur_term->Nttyb; #ifdef TERMIOS - BEFORE("raw"); - cur_term->Nttyb.c_lflag &= ~(ICANON | ISIG | IEXTEN); - cur_term->Nttyb.c_iflag &= ~(COOKED_INPUT); - cur_term->Nttyb.c_cc[VMIN] = 1; - cur_term->Nttyb.c_cc[VTIME] = 0; - AFTER("raw"); + buf.c_lflag &= ~(ICANON | ISIG | IEXTEN); + buf.c_iflag &= ~(COOKED_INPUT); + buf.c_cc[VMIN] = 1; + buf.c_cc[VTIME] = 0; #else - cur_term->Nttyb.sg_flags |= RAW; + buf.sg_flags |= RAW; #endif - returnCode(_nc_set_tty_mode(&cur_term->Nttyb)); + if ((result = _nc_set_tty_mode(&buf)) == OK) { + SP->_raw = TRUE; + SP->_cbreak = 1; + cur_term->Nttyb = buf; + } + AFTER("raw"); } - returnCode(ERR); + returnCode(result); } NCURSES_EXPORT(int) cbreak(void) { + int result = ERR; + T((T_CALLED("cbreak()"))); - SP->_cbreak = 1; + if (SP != 0 && cur_term != 0) { + TTY buf; -#ifdef __EMX__ - setmode(SP->_ifd, O_BINARY); -#endif + BEFORE("cbreak"); + _nc_setmode(O_BINARY); + buf = cur_term->Nttyb; #ifdef TERMIOS - BEFORE("cbreak"); - cur_term->Nttyb.c_lflag &= ~ICANON; - cur_term->Nttyb.c_iflag &= ~ICRNL; - cur_term->Nttyb.c_lflag |= ISIG; - cur_term->Nttyb.c_cc[VMIN] = 1; - cur_term->Nttyb.c_cc[VTIME] = 0; - AFTER("cbreak"); + buf.c_lflag &= ~ICANON; + buf.c_iflag &= ~ICRNL; + buf.c_lflag |= ISIG; + buf.c_cc[VMIN] = 1; + buf.c_cc[VTIME] = 0; #else - cur_term->Nttyb.sg_flags |= CBREAK; + buf.sg_flags |= CBREAK; #endif - returnCode(_nc_set_tty_mode(&cur_term->Nttyb)); + if ((result = _nc_set_tty_mode(&buf)) == OK) { + SP->_cbreak = 1; + cur_term->Nttyb = buf; + } + AFTER("cbreak"); + } + returnCode(result); } +/* + * Note: + * this implementation may be wrong. See the comment under intrflush(). + */ NCURSES_EXPORT(void) qiflush(void) { + int result = ERR; + T((T_CALLED("qiflush()"))); - /* - * Note: this implementation may be wrong. See the comment under - * intrflush(). - */ + if (cur_term != 0) { + TTY buf; + BEFORE("qiflush"); + buf = cur_term->Nttyb; #ifdef TERMIOS - BEFORE("qiflush"); - cur_term->Nttyb.c_lflag &= ~(NOFLSH); - AFTER("qiflush"); - (void) _nc_set_tty_mode(&cur_term->Nttyb); + buf.c_lflag &= ~(NOFLSH); + result = _nc_set_tty_mode(&buf); +#else + /* FIXME */ #endif + if (result == OK) + cur_term->Nttyb = buf; + AFTER("qiflush"); + } returnVoid; } NCURSES_EXPORT(int) noraw(void) { + int result = ERR; + T((T_CALLED("noraw()"))); - SP->_raw = FALSE; - SP->_cbreak = 0; + if (SP != 0 && cur_term != 0) { + TTY buf; -#ifdef __EMX__ - setmode(SP->_ifd, O_TEXT); -#endif + BEFORE("noraw"); + _nc_setmode(O_TEXT); + buf = cur_term->Nttyb; #ifdef TERMIOS - BEFORE("noraw"); - cur_term->Nttyb.c_lflag |= ISIG | ICANON | - (cur_term->Ottyb.c_lflag & IEXTEN); - cur_term->Nttyb.c_iflag |= COOKED_INPUT; - AFTER("noraw"); + buf.c_lflag |= ISIG | ICANON | + (cur_term->Ottyb.c_lflag & IEXTEN); + buf.c_iflag |= COOKED_INPUT; #else - cur_term->Nttyb.sg_flags &= ~(RAW | CBREAK); + buf.sg_flags &= ~(RAW | CBREAK); #endif - returnCode(_nc_set_tty_mode(&cur_term->Nttyb)); + if ((result = _nc_set_tty_mode(&buf)) == OK) { + SP->_raw = FALSE; + SP->_cbreak = 0; + cur_term->Nttyb = buf; + } + AFTER("noraw"); + } + returnCode(result); } NCURSES_EXPORT(int) nocbreak(void) { + int result = ERR; + T((T_CALLED("nocbreak()"))); - SP->_cbreak = 0; + if (SP != 0 && cur_term != 0) { + TTY buf; -#ifdef __EMX__ - setmode(SP->_ifd, O_TEXT); -#endif + BEFORE("nocbreak"); + _nc_setmode(O_TEXT); + buf = cur_term->Nttyb; #ifdef TERMIOS - BEFORE("nocbreak"); - cur_term->Nttyb.c_lflag |= ICANON; - cur_term->Nttyb.c_iflag |= ICRNL; - AFTER("nocbreak"); + buf.c_lflag |= ICANON; + buf.c_iflag |= ICRNL; #else - cur_term->Nttyb.sg_flags &= ~CBREAK; + buf.sg_flags &= ~CBREAK; #endif - returnCode(_nc_set_tty_mode(&cur_term->Nttyb)); + if ((result = _nc_set_tty_mode(&buf)) == OK) { + SP->_cbreak = 0; + cur_term->Nttyb = buf; + } + AFTER("nocbreak"); + } + returnCode(result); } +/* + * Note: + * this implementation may be wrong. See the comment under intrflush(). + */ NCURSES_EXPORT(void) noqiflush(void) { + int result = ERR; + T((T_CALLED("noqiflush()"))); - /* - * Note: this implementation may be wrong. See the comment under - * intrflush(). - */ + if (cur_term != 0) { + TTY buf; + BEFORE("noqiflush"); + buf = cur_term->Nttyb; #ifdef TERMIOS - BEFORE("noqiflush"); - cur_term->Nttyb.c_lflag |= NOFLSH; - AFTER("noqiflush"); - (void) _nc_set_tty_mode(&cur_term->Nttyb); + buf.c_lflag |= NOFLSH; + result = _nc_set_tty_mode(&buf); +#else + /* FIXME */ #endif + if (result == OK) { + cur_term->Nttyb = buf; + } + AFTER("noqiflush"); + } returnVoid; } +/* + * This call does the same thing as the qiflush()/noqiflush() pair. We know + * for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the other hand, + * the match (in the SVr4 man pages) between the language describing NOFLSH in + * termio(7) and the language describing qiflush()/noqiflush() in + * curs_inopts(3x) is too exact to be coincidence. + */ NCURSES_EXPORT(int) intrflush(WINDOW *win GCC_UNUSED, bool flag) { + int result = ERR; + T((T_CALLED("intrflush(%d)"), flag)); - /* - * This call does the same thing as the qiflush()/noqiflush() pair. We - * know for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the - * other hand, the match (in the SVr4 man pages) between the language - * describing NOFLSH in termio(7) and the language describing - * qiflush()/noqiflush() in curs_inopts(3x) is too exact to be coincidence. - */ + if (cur_term != 0) { + TTY buf; + BEFORE("intrflush"); + buf = cur_term->Nttyb; #ifdef TERMIOS - BEFORE("intrflush"); - if (flag) - cur_term->Nttyb.c_lflag &= ~(NOFLSH); - else - cur_term->Nttyb.c_lflag |= (NOFLSH); - AFTER("intrflush"); - returnCode(_nc_set_tty_mode(&cur_term->Nttyb)); + if (flag) + buf.c_lflag &= ~(NOFLSH); + else + buf.c_lflag |= (NOFLSH); + result = _nc_set_tty_mode(&buf); #else - returnCode(ERR); + /* FIXME */ #endif + if (result == OK) { + cur_term->Nttyb = buf; + } + AFTER("intrflush"); + } + returnCode(result); } diff --git a/contrib/ncurses/ncurses/tinfo/lib_setup.c b/contrib/ncurses/ncurses/tinfo/lib_setup.c index 1e49b2b6ce07..350824208830 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_setup.c +++ b/contrib/ncurses/ncurses/tinfo/lib_setup.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-2003 * ****************************************************************************/ /* @@ -46,9 +47,13 @@ #define _POSIX_SOURCE #endif +#if HAVE_LOCALE_H +#include <locale.h> +#endif + #include <term.h> /* lines, columns, cur_term */ -MODULE_ID("$Id: lib_setup.c,v 1.68 2001/12/08 22:14:18 tom Exp $") +MODULE_ID("$Id: lib_setup.c,v 1.95 2006/07/28 22:58:13 tom Exp $") /**************************************************************************** * @@ -72,6 +77,10 @@ MODULE_ID("$Id: lib_setup.c,v 1.68 2001/12/08 22:14:18 tom Exp $") # include <sys/ptem.h> #endif +#if HAVE_LANGINFO_CODESET +#include <langinfo.h> +#endif + /* * SCO defines TIOCGSIZE and the corresponding struct. Other systems (SunOS, * Solaris, IRIX) define TIOCGWINSZ and struct winsize. @@ -90,9 +99,58 @@ MODULE_ID("$Id: lib_setup.c,v 1.68 2001/12/08 22:14:18 tom Exp $") # endif #endif +NCURSES_EXPORT_VAR(char) ttytype[NAMESIZE] = ""; +NCURSES_EXPORT_VAR(int) LINES = 0; +NCURSES_EXPORT_VAR(int) COLS = 0; +NCURSES_EXPORT_VAR(int) TABSIZE = 0; + static int _use_env = TRUE; -static void do_prototype(void); +#if USE_SIGWINCH +int +_nc_handle_sigwinch(int enable) +{ + static int have_sigwinch = 0; /* initially no SIGWINCH's */ + static int can_resizeall = 1; /* initially enabled */ + SCREEN *scan; + int result; + + switch (enable) { + default: + /* record a SIGWINCH */ + have_sigwinch = 1; + break; + case 0: + /* temporarily disable the next block */ + --can_resizeall; + break; + case 1: + /* temporarily enable the next block */ + ++can_resizeall; + break; + } + + /* + * If we have a pending SIGWINCH, set the flag in each screen. + * But do this only if the block is enabled. + */ + if (can_resizeall-- >= 0) { /* test and disable */ + if (have_sigwinch) { + scan = _nc_screen_chain; + while (scan) { + scan->_sig_winch = TRUE; + scan = scan->_next_screen; + } + have_sigwinch = 0; + } + } + result = can_resizeall + 1; /* reenable (unless disables are nested) */ + can_resizeall = result; + + return result; +} + +#endif NCURSES_EXPORT(void) use_env(bool f) @@ -102,10 +160,6 @@ use_env(bool f) returnVoid; } -NCURSES_EXPORT_VAR(int) LINES = 0; -NCURSES_EXPORT_VAR(int) COLS = 0; -NCURSES_EXPORT_VAR(int) TABSIZE = 0; - static void _nc_get_screensize(int *linep, int *colp) /* Obtain lines/columns values from the environment and/or terminfo entry */ @@ -113,6 +167,7 @@ _nc_get_screensize(int *linep, int *colp) /* figure out the size of the screen */ T(("screen size: terminfo lines = %d columns = %d", lines, columns)); + _nc_handle_sigwinch(0); if (!_use_env) { *linep = (int) lines; *colp = (int) columns; @@ -159,7 +214,7 @@ _nc_get_screensize(int *linep, int *colp) * environment variable. */ if (*linep <= 0) - *linep = WINSIZE_ROWS(size); + *linep = (SP != 0 && SP->_filtered) ? 1 : WINSIZE_ROWS(size); if (*colp <= 0) *colp = WINSIZE_COLS(size); } @@ -191,6 +246,7 @@ _nc_get_screensize(int *linep, int *colp) lines = (short) (*linep); columns = (short) (*colp); } + _nc_handle_sigwinch(1); T(("screen size is %dx%d", *linep, *colp)); @@ -199,18 +255,30 @@ _nc_get_screensize(int *linep, int *colp) else TABSIZE = 8; T(("TABSIZE = %d", TABSIZE)); - } #if USE_SIZECHANGE NCURSES_EXPORT(void) _nc_update_screensize(void) { - int my_lines, my_cols; + int old_lines = lines; + int new_lines; + int old_cols = columns; + int new_cols; - _nc_get_screensize(&my_lines, &my_cols); - if (SP != 0 && SP->_resize != 0) - SP->_resize(my_lines, my_cols); + _nc_get_screensize(&new_lines, &new_cols); + + /* + * See is_term_resized() and resizeterm(). + * We're doing it this way because those functions belong to the upper + * ncurses library, while this resides in the lower terminfo library. + */ + if (SP != 0 + && SP->_resize != 0) { + if ((new_lines != old_lines) || (new_cols != old_cols)) + SP->_resize(new_lines, new_cols); + SP->_sig_winch = FALSE; + } } #endif @@ -237,36 +305,15 @@ _nc_update_screensize(void) } #if USE_DATABASE || USE_TERMCAP +/* + * Return 1 if entry found, 0 if not found, -1 if database not accessible, + * just like tgetent(). + */ static int -grab_entry(const char *const tn, TERMTYPE * const tp) -/* return 1 if entry found, 0 if not found, -1 if database not accessible */ +grab_entry(const char *const tn, TERMTYPE *const tp) { char filename[PATH_MAX]; - int status; - - /* - * $TERM shouldn't contain pathname delimiters. - */ - if (strchr(tn, '/')) - return 0; - -#if USE_DATABASE - if ((status = _nc_read_entry(tn, filename, tp)) != 1) { - -#if !PURE_TERMINFO - /* - * Try falling back on the termcap file. - * Note: allowing this call links the entire terminfo/termcap - * compiler into the startup code. It's preferable to build a - * real terminfo database and use that. - */ - status = _nc_read_termcap_entry(tn, tp); -#endif /* PURE_TERMINFO */ - - } -#else - status = _nc_read_termcap_entry(tn, tp); -#endif + int status = _nc_read_entry(tn, filename, tp); /* * If we have an entry, force all of the cancelled strings to null @@ -274,8 +321,8 @@ grab_entry(const char *const tn, TERMTYPE * const tp) * (The terminfo compiler bypasses this logic, since it must know if * a string is cancelled, for merging entries). */ - if (status == 1) { - int n; + if (status == TGETENT_YES) { + unsigned n; for_each_boolean(n, tp) { if (!VALID_BOOLEAN(tp->Booleans[n])) tp->Booleans[n] = FALSE; @@ -289,139 +336,251 @@ grab_entry(const char *const tn, TERMTYPE * const tp) } #endif -NCURSES_EXPORT_VAR(char) ttytype[NAMESIZE] = ""; +/* +** do_prototype() +** +** Take the real command character out of the CC environment variable +** and substitute it in for the prototype given in 'command_character'. +*/ +static void +do_prototype(void) +{ + int i; + char CC; + char proto; + char *tmp; + + tmp = getenv("CC"); + CC = *tmp; + proto = *command_character; + + for_each_string(i, &(cur_term->type)) { + for (tmp = cur_term->type.Strings[i]; *tmp; tmp++) { + if (*tmp == proto) + *tmp = CC; + } + } +} /* - * setupterm(termname, Filedes, errret) - * - * Find and read the appropriate object file for the terminal - * Make cur_term point to the structure. - * + * Find the locale which is in effect. + */ +NCURSES_EXPORT(char *) +_nc_get_locale(void) +{ + char *env; +#if HAVE_LOCALE_H + /* + * This is preferable to using getenv() since it ensures that we are using + * the locale which was actually initialized by the application. + */ + env = setlocale(LC_CTYPE, 0); +#else + if (((env = getenv("LC_ALL")) != 0 && *env != '\0') + || ((env = getenv("LC_CTYPE")) != 0 && *env != '\0') + || ((env = getenv("LANG")) != 0 && *env != '\0')) { + ; + } +#endif + T(("_nc_get_locale %s", _nc_visbuf(env))); + return env; +} + +/* + * Check if we are running in a UTF-8 locale. */ +NCURSES_EXPORT(int) +_nc_unicode_locale(void) +{ + int result = 0; +#if HAVE_LANGINFO_CODESET + char *env = nl_langinfo(CODESET); + result = !strcmp(env, "UTF-8"); + T(("_nc_unicode_locale(%s) ->%d", env, result)); +#else + char *env = _nc_get_locale(); + if (env != 0) { + if (strstr(env, ".UTF-8") != 0) { + result = 1; + T(("_nc_unicode_locale(%s) ->%d", env, result)); + } + } +#endif + return result; +} +#define CONTROL_N(s) ((s) != 0 && strstr(s, "\016") != 0) +#define CONTROL_O(s) ((s) != 0 && strstr(s, "\017") != 0) + +/* + * Check for known broken cases where a UTF-8 locale breaks the alternate + * character set. + */ NCURSES_EXPORT(int) -setupterm(NCURSES_CONST char *tname, int Filedes, int *errret) +_nc_locale_breaks_acs(void) +{ + char *env; + + if ((env = getenv("NCURSES_NO_UTF8_ACS")) != 0) { + return atoi(env); + } else if ((env = getenv("TERM")) != 0) { + if (strstr(env, "linux")) + return 1; /* always broken */ + if (strstr(env, "screen") != 0 + && ((env = getenv("TERMCAP")) != 0 + && strstr(env, "screen") != 0) + && strstr(env, "hhII00") != 0) { + if (CONTROL_N(enter_alt_charset_mode) || + CONTROL_O(enter_alt_charset_mode) || + CONTROL_N(set_attributes) || + CONTROL_O(set_attributes)) + return 1; + } + } + return 0; +} + +/* + * This entrypoint is called from tgetent() to allow a special case of reusing + * the same TERMINAL data (see comment). + */ +NCURSES_EXPORT(int) +_nc_setupterm(NCURSES_CONST char *tname, int Filedes, int *errret, bool reuse) { - struct term *term_ptr; int status; + START_TRACE(); T((T_CALLED("setupterm(%s,%d,%p)"), _nc_visbuf(tname), Filedes, errret)); if (tname == 0) { tname = getenv("TERM"); if (tname == 0 || *tname == '\0') { - ret_error0(-1, "TERM environment variable not set.\n"); + ret_error0(TGETENT_ERR, "TERM environment variable not set.\n"); } } + if (strlen(tname) > MAX_NAME_SIZE) { - ret_error(-1, "TERM environment must be <= %d characters.\n", + ret_error(TGETENT_ERR, + "TERM environment must be <= %d characters.\n", MAX_NAME_SIZE); } T(("your terminal name is %s", tname)); - term_ptr = typeCalloc(TERMINAL, 1); + /* + * Allow output redirection. This is what SVr3 does. If stdout is + * directed to a file, screen updates go to standard error. + */ + if (Filedes == STDOUT_FILENO && !isatty(Filedes)) + Filedes = STDERR_FILENO; - if (term_ptr == 0) { - ret_error0(-1, "Not enough memory to create terminal structure.\n"); - } + /* + * Check if we have already initialized to use this terminal. If so, we + * do not need to re-read the terminfo entry, or obtain TTY settings. + * + * This is an improvement on SVr4 curses. If an application mixes curses + * and termcap calls, it may call both initscr and tgetent. This is not + * really a good thing to do, but can happen if someone tries using ncurses + * with the readline library. The problem we are fixing is that when + * tgetent calls setupterm, the resulting Ottyb struct in cur_term is + * zeroed. A subsequent call to endwin uses the zeroed terminal settings + * rather than the ones saved in initscr. So we check if cur_term appears + * to contain terminal settings for the same output file as our current + * call - and copy those terminal settings. (SVr4 curses does not do this, + * however applications that are working around the problem will still work + * properly with this feature). + */ + if (reuse + && cur_term != 0 + && cur_term->Filedes == Filedes + && cur_term->_termname != 0 + && !strcmp(cur_term->_termname, tname) + && _nc_name_match(cur_term->type.term_names, tname, "|")) { + T(("reusing existing terminal information and mode-settings")); + } else { + TERMINAL *term_ptr; + + term_ptr = typeCalloc(TERMINAL, 1); + + if (term_ptr == 0) { + ret_error0(TGETENT_ERR, + "Not enough memory to create terminal structure.\n"); + } #if USE_DATABASE || USE_TERMCAP - status = grab_entry(tname, &term_ptr->type); + status = grab_entry(tname, &term_ptr->type); #else - status = 0; + status = TGETENT_NO; #endif - /* try fallback list if entry on disk */ - if (status != 1) { - const TERMTYPE *fallback = _nc_fallback(tname); + /* try fallback list if entry on disk */ + if (status != TGETENT_YES) { + const TERMTYPE *fallback = _nc_fallback(tname); - if (fallback) { - term_ptr->type = *fallback; - status = 1; + if (fallback) { + term_ptr->type = *fallback; + status = TGETENT_YES; + } } - } - if (status == -1) { - ret_error0(-1, "terminals database is inaccessible\n"); - } else if (status == 0) { - ret_error(0, "'%s': unknown terminal type.\n", tname); - } + if (status != TGETENT_YES) { + del_curterm(term_ptr); + if (status == TGETENT_ERR) { + ret_error0(status, "terminals database is inaccessible\n"); + } else if (status == TGETENT_NO) { + ret_error(status, "'%s': unknown terminal type.\n", tname); + } + } - /* - * Improve on SVr4 curses. If an application mixes curses and termcap - * calls, it may call both initscr and tgetent. This is not really a - * good thing to do, but can happen if someone tries using ncurses with - * the readline library. The problem we are fixing is that when - * tgetent calls setupterm, the resulting Ottyb struct in cur_term is - * zeroed. A subsequent call to endwin uses the zeroed terminal - * settings rather than the ones saved in initscr. So we check if - * cur_term appears to contain terminal settings for the same output - * file as our current call - and copy those terminal settings. (SVr4 - * curses does not do this, however applications that are working - * around the problem will still work properly with this feature). - */ - if (cur_term != 0) { - if (cur_term->Filedes == Filedes) - term_ptr->Ottyb = cur_term->Ottyb; - } + set_curterm(term_ptr); + + if (command_character && getenv("CC")) + do_prototype(); - set_curterm(term_ptr); + strncpy(ttytype, cur_term->type.term_names, NAMESIZE - 1); + ttytype[NAMESIZE - 1] = '\0'; - if (command_character && getenv("CC")) - do_prototype(); + cur_term->Filedes = Filedes; + cur_term->_termname = strdup(tname); - strncpy(ttytype, cur_term->type.term_names, NAMESIZE - 1); - ttytype[NAMESIZE - 1] = '\0'; + /* + * If an application calls setupterm() rather than initscr() or + * newterm(), we will not have the def_prog_mode() call in + * _nc_setupscreen(). Do it now anyway, so we can initialize the + * baudrate. + */ + if (isatty(Filedes)) { + def_prog_mode(); + baudrate(); + } + } /* - * Allow output redirection. This is what SVr3 does. - * If stdout is directed to a file, screen updates go - * to standard error. + * We should always check the screensize, just in case. */ - if (Filedes == STDOUT_FILENO && !isatty(Filedes)) - Filedes = STDERR_FILENO; - cur_term->Filedes = Filedes; - _nc_get_screensize(&LINES, &COLS); if (errret) - *errret = 1; + *errret = TGETENT_YES; T((T_CREATE("screen %s %dx%d"), tname, LINES, COLS)); if (generic_type) { - ret_error(0, "'%s': I need something more specific.\n", tname); + ret_error(TGETENT_NO, "'%s': I need something more specific.\n", tname); } if (hard_copy) { - ret_error(1, "'%s': I can't handle hardcopy terminals.\n", tname); + ret_error(TGETENT_YES, "'%s': I can't handle hardcopy terminals.\n", tname); } returnCode(OK); } /* -** do_prototype() -** -** Take the real command character out of the CC environment variable -** and substitute it in for the prototype given in 'command_character'. -** -*/ - -static void -do_prototype(void) + * setupterm(termname, Filedes, errret) + * + * Find and read the appropriate object file for the terminal + * Make cur_term point to the structure. + */ +NCURSES_EXPORT(int) +setupterm(NCURSES_CONST char *tname, int Filedes, int *errret) { - int i; - char CC; - char proto; - char *tmp; - - tmp = getenv("CC"); - CC = *tmp; - proto = *command_character; - - for_each_string(i, &(cur_term->type)) { - for (tmp = cur_term->type.Strings[i]; *tmp; tmp++) { - if (*tmp == proto) - *tmp = CC; - } - } + return _nc_setupterm(tname, Filedes, errret, FALSE); } diff --git a/contrib/ncurses/ncurses/tinfo/lib_termcap.c b/contrib/ncurses/ncurses/tinfo/lib_termcap.c index c03a601f4968..33e15c55c179 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_termcap.c +++ b/contrib/ncurses/ncurses/tinfo/lib_termcap.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,9 +29,11 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * * * * some of the code in here was contributed by: * * Magnus Bengtsson, d6mbeng@dtek.chalmers.se (Nov'93) * + * (but it has changed a lot) * ****************************************************************************/ #define __INTERNAL_CAPS_VISIBLE @@ -43,66 +45,26 @@ #include <term_entry.h> -MODULE_ID("$Id: lib_termcap.c,v 1.43 2002/05/25 12:24:13 tom Exp $") - -#define CSI 233 -#define ESC 033 /* ^[ */ -#define L_BRACK '[' -#define SHIFT_OUT 017 /* ^N */ +MODULE_ID("$Id: lib_termcap.c,v 1.58 2006/09/02 19:39:46 Miroslav.Lichvar Exp $") NCURSES_EXPORT_VAR(char *) UP = 0; NCURSES_EXPORT_VAR(char *) BC = 0; -static char *fix_me = 0; - -static char * -set_attribute_9(int flag) -{ - const char *result; - - if ((result = tparm(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, flag)) == 0) - result = ""; - return strdup(result); -} - -static int -is_csi(char *s) -{ - if (UChar(s[0]) == CSI) - return 1; - else if (s[0] == ESC && s[1] == L_BRACK) - return 2; - return 0; -} +typedef struct { + long sequence; + char *fix_sgr0; /* this holds the filtered sgr0 string */ + char *last_bufp; /* help with fix_sgr0 leak */ + TERMINAL *last_term; +} CACHE; -static char * -skip_zero(char *s) -{ - if (s[0] == '0') { - if (s[1] == ';') - s += 2; - else if (isalpha(UChar(s[1]))) - s += 1; - } - return s; -} +#define MAX_CACHE 4 +static CACHE cache[MAX_CACHE]; +static int in_cache = 0; -static bool -similar_sgr(char *a, char *b) -{ - int csi_a = is_csi(a); - int csi_b = is_csi(b); - - if (csi_a != 0 && csi_b != 0 && csi_a == csi_b) { - a += csi_a; - b += csi_b; - if (*a != *b) { - a = skip_zero(a); - b = skip_zero(b); - } - } - return strcmp(a, b) == 0; -} +#define FIX_SGR0 cache[in_cache].fix_sgr0 +#define LAST_TRM cache[in_cache].last_term +#define LAST_BUF cache[in_cache].last_bufp +#define LAST_SEQ cache[in_cache].sequence /*************************************************************************** * @@ -120,18 +82,64 @@ similar_sgr(char *a, char *b) ***************************************************************************/ NCURSES_EXPORT(int) -tgetent(char *bufp GCC_UNUSED, const char *name) +tgetent(char *bufp, const char *name) { + static long sequence; + int errcode; + int n; + bool found_cache = FALSE; + START_TRACE(); T((T_CALLED("tgetent()"))); - setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode); + _nc_setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode, TRUE); + + /* + * In general we cannot tell if the fixed sgr0 is still used by the + * caller, but if tgetent() is called with the same buffer, that is + * good enough, since the previous data would be invalidated by the + * current call. + */ + for (n = 0; n < MAX_CACHE; ++n) { + bool same_result = (bufp != 0 && cache[n].last_bufp == bufp); + if (same_result) { + in_cache = n; + if (FIX_SGR0 != 0) { + FreeAndNull(FIX_SGR0); + } + /* + * Also free the terminfo data that we loaded (much bigger leak). + */ + if (LAST_TRM != 0 && LAST_TRM != cur_term) { + TERMINAL *trm = LAST_TRM; + del_curterm(LAST_TRM); + for (in_cache = 0; in_cache < MAX_CACHE; ++in_cache) + if (LAST_TRM == trm) + LAST_TRM = 0; + in_cache = n; + } + found_cache = TRUE; + break; + } + } + if (!found_cache) { + int best = 0; + + for (in_cache = 0; in_cache < MAX_CACHE; ++in_cache) { + if (LAST_SEQ < cache[best].sequence) { + best = in_cache; + } + } + in_cache = best; + } + LAST_TRM = cur_term; + LAST_SEQ = ++sequence; PC = 0; UP = 0; BC = 0; - fix_me = 0; + FIX_SGR0 = 0; /* don't free it - application may still use */ if (errcode == 1) { @@ -147,67 +155,15 @@ tgetent(char *bufp GCC_UNUSED, const char *name) if (backspace_if_not_bs != NULL) BC = backspace_if_not_bs; - /* - * While 'sgr0' is the "same" as termcap 'me', there is a compatibility - * issue. The sgr/sgr0 capabilities include setting/clearing alternate - * character set mode. A termcap application cannot use sgr, so sgr0 - * strings that reset alternate character set mode will be - * misinterpreted. Here, we remove those from the more common - * ISO/ANSI/VT100 entries, which have sgr0 agreeing with sgr. - */ - if (exit_attribute_mode != 0 - && set_attributes != 0) { - char *on = set_attribute_9(1); - char *off = set_attribute_9(0); - char *tmp; - size_t i, j, k; - - if (similar_sgr(off, exit_attribute_mode) - && !similar_sgr(off, on)) { - TR(TRACE_DATABASE, ("adjusting sgr0 : %s", _nc_visbuf(off))); - FreeIfNeeded(fix_me); - fix_me = off; - for (i = 0; off[i] != '\0'; ++i) { - if (on[i] != off[i]) { - j = strlen(off); - k = strlen(on); - while (j != 0 - && k != 0 - && off[j - 1] == on[k - 1]) { - --j, --k; - } - while (off[j] != '\0') { - off[i++] = off[j++]; - } - off[i] = '\0'; - break; - } - } - /* SGR 10 would reset to normal font */ - if ((i = is_csi(off)) != 0 - && off[strlen(off) - 1] == 'm') { - tmp = skip_zero(off + i); - if (tmp[0] == '1' - && skip_zero(tmp + 1) != tmp + 1) { - i = tmp - off; - if (off[i - 1] == ';') - i--; - j = skip_zero(tmp + 1) - off; - while (off[j] != '\0') { - off[i++] = off[j++]; - } - off[i] = '\0'; - } - } - TR(TRACE_DATABASE, ("...adjusted me : %s", _nc_visbuf(fix_me))); - if (!strcmp(fix_me, exit_attribute_mode)) { - TR(TRACE_DATABASE, ("...same result, discard")); - free(fix_me); - fix_me = 0; + if ((FIX_SGR0 = _nc_trim_sgr0(&(cur_term->type))) != 0) { + if (!strcmp(FIX_SGR0, exit_attribute_mode)) { + if (FIX_SGR0 != exit_attribute_mode) { + free(FIX_SGR0); } + FIX_SGR0 = 0; } - free(on); } + LAST_BUF = bufp; (void) baudrate(); /* sets ospeed as a side-effect */ @@ -233,7 +189,7 @@ tgetent(char *bufp GCC_UNUSED, const char *name) NCURSES_EXPORT(int) tgetflag(NCURSES_CONST char *id) { - int i; + unsigned i; T((T_CALLED("tgetflag(%s)"), id)); if (cur_term != 0) { @@ -261,7 +217,7 @@ tgetflag(NCURSES_CONST char *id) NCURSES_EXPORT(int) tgetnum(NCURSES_CONST char *id) { - int i; + unsigned i; T((T_CALLED("tgetnum(%s)"), id)); if (cur_term != 0) { @@ -290,7 +246,7 @@ tgetnum(NCURSES_CONST char *id) NCURSES_EXPORT(char *) tgetstr(NCURSES_CONST char *id, char **area) { - int i; + unsigned i; char *result = NULL; T((T_CALLED("tgetstr(%s,%p)"), id, area)); @@ -304,13 +260,14 @@ tgetstr(NCURSES_CONST char *id, char **area) /* setupterm forces canceled strings to null */ if (VALID_STRING(result)) { if (result == exit_attribute_mode - && fix_me != 0) { - result = fix_me; + && FIX_SGR0 != 0) { + result = FIX_SGR0; TR(TRACE_DATABASE, ("altered to : %s", _nc_visbuf(result))); } if (area != 0 && *area != 0) { (void) strcpy(*area, result); + result = *area; *area += strlen(*area) + 1; } } @@ -320,3 +277,14 @@ tgetstr(NCURSES_CONST char *id, char **area) } returnPtr(result); } + +#if NO_LEAKS +NCURSES_EXPORT(void) +_nc_tgetent_leaks(void) +{ + for (in_cache = 0; in_cache < MAX_CACHE; ++in_cache) { + FreeIfNeeded(FIX_SGR0); + del_curterm(LAST_TRM); + } +} +#endif diff --git a/contrib/ncurses/ncurses/tinfo/lib_termname.c b/contrib/ncurses/ncurses/tinfo/lib_termname.c index 57ce807a9e5f..713d0be8c360 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_termname.c +++ b/contrib/ncurses/ncurses/tinfo/lib_termname.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 * @@ -27,22 +27,18 @@ ****************************************************************************/ #include <curses.priv.h> -#include <tic.h> /* for MAX_ALIAS */ -MODULE_ID("$Id: lib_termname.c,v 1.7 2001/08/04 19:29:38 tom Exp $") +MODULE_ID("$Id: lib_termname.c,v 1.8 2003/12/27 18:23:01 tom Exp $") NCURSES_EXPORT(char *) termname(void) { - char *name = getenv("TERM"); - static char ret[MAX_ALIAS + 1]; + char *name = 0; T((T_CALLED("termname()"))); - if (name != 0) { - ret[0] = '\0'; - (void) strncat(ret, name, sizeof(ret) - 1); - name = ret; - } + if (cur_term != 0) + name = cur_term->_termname; + returnPtr(name); } diff --git a/contrib/ncurses/ncurses/tinfo/lib_tgoto.c b/contrib/ncurses/ncurses/tinfo/lib_tgoto.c index 17649d53f68f..37553f712394 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_tgoto.c +++ b/contrib/ncurses/ncurses/tinfo/lib_tgoto.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2000,2001 Free Software Foundation, Inc. * + * Copyright (c) 2000-2003,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -35,7 +35,7 @@ #include <ctype.h> #include <termcap.h> -MODULE_ID("$Id: lib_tgoto.c,v 1.8 2001/06/02 22:44:42 tom Exp $") +MODULE_ID("$Id: lib_tgoto.c,v 1.12 2006/11/26 00:26:24 tom Exp $") #if !PURE_TERMINFO static bool @@ -88,7 +88,7 @@ tgoto_internal(const char *string, int x, int y) while (*string != 0) { if ((used + need) > length) { length += (used + need); - if ((result = _nc_doalloc(result, length)) == 0) { + if ((result = typeRealloc(char, length, result)) == 0) { length = 0; break; } @@ -155,7 +155,7 @@ tgoto_internal(const char *string, int x, int y) *value = 16 * (*value / 10) + (*value % 10); break; case 'D': /* Reverse coding (Delta Data) */ - *value -= 2 * (*value / 16); + *value -= 2 * (*value % 16); break; } if (fmt != 0) { @@ -172,11 +172,13 @@ tgoto_internal(const char *string, int x, int y) } string++; } - if (need_BC) { - strcpy(result + used, BC); - used += strlen(BC); + if (result != 0) { + if (need_BC) { + strcpy(result + used, BC); + used += strlen(BC); + } + result[used] = '\0'; } - result[used] = '\0'; return result; } #endif @@ -186,8 +188,7 @@ tgoto_internal(const char *string, int x, int y) * the last two arguments when invoking tparm(). */ NCURSES_EXPORT(char *) -tgoto -(const char *string, int x, int y) +tgoto(const char *string, int x, int y) { char *result; @@ -197,6 +198,6 @@ tgoto result = tgoto_internal(string, x, y); else #endif - result = tparm((NCURSES_CONST char *) string, y, x); + result = TPARM_2((NCURSES_CONST char *) string, y, x); returnPtr(result); } diff --git a/contrib/ncurses/ncurses/tinfo/lib_ti.c b/contrib/ncurses/ncurses/tinfo/lib_ti.c index 8ef866588197..df460f953ea7 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_ti.c +++ b/contrib/ncurses/ncurses/tinfo/lib_ti.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,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 * @@ -36,12 +36,12 @@ #include <term_entry.h> #include <tic.h> -MODULE_ID("$Id: lib_ti.c,v 1.22 2000/12/10 02:55:08 tom Exp $") +MODULE_ID("$Id: lib_ti.c,v 1.23 2003/05/24 21:10:28 tom Exp $") NCURSES_EXPORT(int) tigetflag(NCURSES_CONST char *str) { - int i; + unsigned i; T((T_CALLED("tigetflag(%s)"), str)); @@ -62,7 +62,7 @@ tigetflag(NCURSES_CONST char *str) NCURSES_EXPORT(int) tigetnum(NCURSES_CONST char *str) { - int i; + unsigned i; T((T_CALLED("tigetnum(%s)"), str)); @@ -84,7 +84,7 @@ tigetnum(NCURSES_CONST char *str) NCURSES_EXPORT(char *) tigetstr(NCURSES_CONST char *str) { - int i; + unsigned i; T((T_CALLED("tigetstr(%s)"), str)); diff --git a/contrib/ncurses/ncurses/tinfo/lib_tparm.c b/contrib/ncurses/ncurses/tinfo/lib_tparm.c index 931669e933bd..cba31d9fd36b 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_tparm.c +++ b/contrib/ncurses/ncurses/tinfo/lib_tparm.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,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 * ****************************************************************************/ /* @@ -42,7 +43,7 @@ #include <term.h> #include <tic.h> -MODULE_ID("$Id: lib_tparm.c,v 1.53 2001/06/02 22:53:59 tom Exp $") +MODULE_ID("$Id: lib_tparm.c,v 1.71 2006/11/26 01:12:56 tom Exp $") /* * char * @@ -108,7 +109,7 @@ MODULE_ID("$Id: lib_tparm.c,v 1.53 2001/06/02 22:53:59 tom Exp $") typedef struct { union { - unsigned int num; + int num; char *str; } data; bool num_type; @@ -128,6 +129,9 @@ static char *out_buff; static size_t out_size; static size_t out_used; +static char *fmt_buff; +static size_t fmt_size; + #if NO_LEAKS NCURSES_EXPORT(void) _nc_free_tparm(void) @@ -136,28 +140,25 @@ _nc_free_tparm(void) FreeAndNull(out_buff); out_size = 0; out_used = 0; + FreeAndNull(fmt_buff); + fmt_size = 0; } } #endif -static void -really_get_space(size_t need) -{ - out_size = need * 2; - out_buff = typeRealloc(char, out_size, out_buff); - if (out_buff == 0) - _nc_err_abort("Out of memory"); -} - -static inline void +static NCURSES_INLINE void get_space(size_t need) { need += out_used; - if (need > out_size) - really_get_space(need); + if (need > out_size) { + out_size = need * 2; + out_buff = typeRealloc(char, out_size, out_buff); + if (out_buff == 0) + _nc_err_abort(MSG_NO_MEMORY); + } } -static inline void +static NCURSES_INLINE void save_text(const char *fmt, const char *s, int len) { size_t s_len = strlen(s); @@ -170,19 +171,19 @@ save_text(const char *fmt, const char *s, int len) out_used += strlen(out_buff + out_used); } -static inline void +static NCURSES_INLINE void save_number(const char *fmt, int number, int len) { if (len < 30) len = 30; /* actually log10(MAX_INT)+1 */ - get_space(len + 1); + get_space((unsigned) len + 1); (void) sprintf(out_buff + out_used, fmt, number); out_used += strlen(out_buff + out_used); } -static inline void +static NCURSES_INLINE void save_char(int c) { if (c == 0) @@ -191,7 +192,7 @@ save_char(int c) out_buff[out_used++] = c; } -static inline void +static NCURSES_INLINE void npush(int x) { if (stack_ptr < STACKSIZE) { @@ -204,7 +205,7 @@ npush(int x) } } -static inline int +static NCURSES_INLINE int npop(void) { int result = 0; @@ -219,7 +220,7 @@ npop(void) return result; } -static inline void +static NCURSES_INLINE void spush(char *x) { if (stack_ptr < STACKSIZE) { @@ -232,7 +233,7 @@ spush(char *x) } } -static inline char * +static NCURSES_INLINE char * spop(void) { static char dummy[] = ""; /* avoid const-cast */ @@ -248,152 +249,139 @@ spop(void) return result; } -static inline const char * +static NCURSES_INLINE const char * parse_format(const char *s, char *format, int *len) { - bool done = FALSE; - bool allowminus = FALSE; - bool dot = FALSE; - bool err = FALSE; - char *fmt = format; - int prec = 0; - int width = 0; - int value = 0; - *len = 0; - *format++ = '%'; - while (*s != '\0' && !done) { - switch (*s) { - case 'c': /* FALLTHRU */ - case 'd': /* FALLTHRU */ - case 'o': /* FALLTHRU */ - case 'x': /* FALLTHRU */ - case 'X': /* FALLTHRU */ - case 's': - *format++ = *s; - done = TRUE; - break; - case '.': - *format++ = *s++; - if (dot) { - err = TRUE; - } else { - dot = TRUE; - prec = value; - } - value = 0; - break; - case '#': - *format++ = *s++; - break; - case ' ': - *format++ = *s++; - break; - case ':': - s++; - allowminus = TRUE; - break; - case '-': - if (allowminus) { - *format++ = *s++; - } else { + if (format != 0) { + bool done = FALSE; + bool allowminus = FALSE; + bool dot = FALSE; + bool err = FALSE; + char *fmt = format; + int my_width = 0; + int my_prec = 0; + int value = 0; + + *len = 0; + *format++ = '%'; + while (*s != '\0' && !done) { + switch (*s) { + case 'c': /* FALLTHRU */ + case 'd': /* FALLTHRU */ + case 'o': /* FALLTHRU */ + case 'x': /* FALLTHRU */ + case 'X': /* FALLTHRU */ + case 's': + *format++ = *s; done = TRUE; - } - break; - default: - if (isdigit(UChar(*s))) { - value = (value * 10) + (*s - '0'); - if (value > 10000) + break; + case '.': + *format++ = *s++; + if (dot) { err = TRUE; + } else { /* value before '.' is the width */ + dot = TRUE; + my_width = value; + } + value = 0; + break; + case '#': *format++ = *s++; - } else { - done = TRUE; + break; + case ' ': + *format++ = *s++; + break; + case ':': + s++; + allowminus = TRUE; + break; + case '-': + if (allowminus) { + *format++ = *s++; + } else { + done = TRUE; + } + break; + default: + if (isdigit(UChar(*s))) { + value = (value * 10) + (*s - '0'); + if (value > 10000) + err = TRUE; + *format++ = *s++; + } else { + done = TRUE; + } } } - } - - /* - * If we found an error, ignore (and remove) the flags. - */ - if (err) { - prec = width = value = 0; - format = fmt; - *format++ = '%'; - *format++ = *s; - } - if (dot) - width = value; - else - prec = value; + /* + * If we found an error, ignore (and remove) the flags. + */ + if (err) { + my_width = my_prec = value = 0; + format = fmt; + *format++ = '%'; + *format++ = *s; + } - *format = '\0'; - /* return maximum string length in print */ - *len = (prec > width) ? prec : width; + /* + * Any value after '.' is the precision. If we did not see '.', then + * the value is the width. + */ + if (dot) + my_prec = value; + else + my_width = value; + + *format = '\0'; + /* return maximum string length in print */ + *len = (my_width > my_prec) ? my_width : my_prec; + } return s; } #define isUPPER(c) ((c) >= 'A' && (c) <= 'Z') #define isLOWER(c) ((c) >= 'a' && (c) <= 'z') -static inline char * -tparam_internal(const char *string, va_list ap) +/* + * Analyze the string to see how many parameters we need from the varargs list, + * and what their types are. We will only accept string parameters if they + * appear as a %l or %s format following an explicit parameter reference (e.g., + * %p2%s). All other parameters are numbers. + * + * 'number' counts coarsely the number of pop's we see in the string, and + * 'popcount' shows the highest parameter number in the string. We would like + * to simply use the latter count, but if we are reading termcap strings, there + * may be cases that we cannot see the explicit parameter numbers. + */ +NCURSES_EXPORT(int) +_nc_tparm_analyze(const char *string, char *p_is_s[NUM_PARM], int *popcount) { -#define NUM_VARS 26 - char *p_is_s[9]; - int param[9]; - int lastpop; - int popcount; - int number; - int len; - int level; - int x, y; - int i; size_t len2; - register const char *cp; - static size_t len_fmt; + int i; + int lastpop = -1; + int len; + int number = 0; + const char *cp = string; static char dummy[] = ""; - static char *format; - static int dynamic_var[NUM_VARS]; - static int static_vars[NUM_VARS]; - out_used = 0; - if (string == NULL) - return NULL; + if (cp == 0) + return 0; - if ((len2 = strlen(string)) > len_fmt) { - len_fmt = len2 + len_fmt + 2; - if ((format = typeRealloc(char, len_fmt, format)) == 0) + if ((len2 = strlen(cp)) > fmt_size) { + fmt_size = len2 + fmt_size + 2; + if ((fmt_buff = typeRealloc(char, fmt_size, fmt_buff)) == 0) return 0; } - /* - * Find the highest parameter-number referred to in the format string. - * Use this value to limit the number of arguments copied from the - * variable-length argument list. - */ - - number = 0; - lastpop = -1; - popcount = 0; - memset(p_is_s, 0, sizeof(p_is_s)); + memset(p_is_s, 0, sizeof(p_is_s[0]) * NUM_PARM); + *popcount = 0; - /* - * Analyze the string to see how many parameters we need from the varargs - * list, and what their types are. We will only accept string parameters - * if they appear as a %l or %s format following an explicit parameter - * reference (e.g., %p2%s). All other parameters are numbers. - * - * 'number' counts coarsely the number of pop's we see in the string, and - * 'popcount' shows the highest parameter number in the string. We would - * like to simply use the latter count, but if we are reading termcap - * strings, there may be cases that we cannot see the explicit parameter - * numbers. - */ - for (cp = string; (cp - string) < (int) len2;) { + while ((cp - string) < (int) len2) { if (*cp == '%') { cp++; - cp = parse_format(cp, format, &len); + cp = parse_format(cp, fmt_buff, &len); switch (*cp) { default: break; @@ -403,7 +391,8 @@ tparam_internal(const char *string, va_list ap) case 'x': /* FALLTHRU */ case 'X': /* FALLTHRU */ case 'c': /* FALLTHRU */ - number++; + if (lastpop <= 0) + number++; lastpop = -1; break; @@ -416,15 +405,19 @@ tparam_internal(const char *string, va_list ap) case 'p': cp++; - i = (*cp - '0'); - if (i >= 0 && i <= 9) { + i = (UChar(*cp) - '0'); + if (i >= 0 && i <= NUM_PARM) { lastpop = i; - if (lastpop > popcount) - popcount = lastpop; + if (lastpop > *popcount) + *popcount = lastpop; } break; case 'P': + ++number; + ++cp; + break; + case 'g': cp++; break; @@ -436,7 +429,7 @@ tparam_internal(const char *string, va_list ap) case L_BRACE: cp++; - while (*cp >= '0' && *cp <= '9') { + while (isdigit(UChar(*cp))) { cp++; } break; @@ -454,16 +447,18 @@ tparam_internal(const char *string, va_list ap) case '=': case '<': case '>': + lastpop = -1; + number += 2; + break; + case '!': case '~': lastpop = -1; - number += 2; + ++number; break; case 'i': - lastpop = -1; - if (popcount < 2) - popcount = 2; + /* will add 1 to first (usually two) parameters */ break; } } @@ -471,18 +466,55 @@ tparam_internal(const char *string, va_list ap) cp++; } - if (number > 9) - number = 9; + if (number > NUM_PARM) + number = NUM_PARM; + return number; +} + +static NCURSES_INLINE char * +tparam_internal(const char *string, va_list ap) +{ +#define NUM_VARS 26 + char *p_is_s[NUM_PARM]; + TPARM_ARG param[NUM_PARM]; + int popcount; + int number; + int len; + int level; + int x, y; + int i; + const char *cp = string; + size_t len2; + static int dynamic_var[NUM_VARS]; + static int static_vars[NUM_VARS]; + + if (cp == NULL) + return NULL; + + out_used = 0; + len2 = strlen(cp); + + /* + * Find the highest parameter-number referred to in the format string. + * Use this value to limit the number of arguments copied from the + * variable-length argument list. + */ + number = _nc_tparm_analyze(cp, p_is_s, &popcount); + if (fmt_buff == 0) + return NULL; + for (i = 0; i < max(popcount, number); i++) { /* * A few caps (such as plab_norm) have string-valued parms. * We'll have to assume that the caller knows the difference, since - * a char* and an int may not be the same size on the stack. + * a char* and an int may not be the same size on the stack. The + * normal prototype for this uses 9 long's, which is consistent with + * our va_arg() usage. */ if (p_is_s[i] != 0) { p_is_s[i] = va_arg(ap, char *); } else { - param[i] = va_arg(ap, int); + param[i] = va_arg(ap, TPARM_ARG); } } @@ -507,18 +539,18 @@ tparam_internal(const char *string, va_list ap) else save_number(", %d", param[i], 0); } - _tracef(T_CALLED("%s(%s%s)"), tname, _nc_visbuf(string), out_buff); + _tracef(T_CALLED("%s(%s%s)"), tname, _nc_visbuf(cp), out_buff); out_used = 0; } #endif /* TRACE */ - while (*string) { - if (*string != '%') { - save_char(*string); + while ((cp - string) < (int) len2) { + if (*cp != '%') { + save_char(UChar(*cp)); } else { - tparam_base = string++; - string = parse_format(string, format, &len); - switch (*string) { + tparam_base = cp++; + cp = parse_format(cp, fmt_buff, &len); + switch (*cp) { default: break; case '%': @@ -529,22 +561,25 @@ tparam_internal(const char *string, va_list ap) case 'o': /* FALLTHRU */ case 'x': /* FALLTHRU */ case 'X': /* FALLTHRU */ + save_number(fmt_buff, npop(), len); + break; + case 'c': /* FALLTHRU */ - save_number(format, npop(), len); + save_char(npop()); break; case 'l': - save_number("%d", strlen(spop()), 0); + save_number("%d", (int) strlen(spop()), 0); break; case 's': - save_text(format, spop(), len); + save_text(fmt_buff, spop(), len); break; case 'p': - string++; - i = (*string - '1'); - if (i >= 0 && i < 9) { + cp++; + i = (UChar(*cp) - '1'); + if (i >= 0 && i < NUM_PARM) { if (p_is_s[i]) spush(p_is_s[i]); else @@ -553,39 +588,39 @@ tparam_internal(const char *string, va_list ap) break; case 'P': - string++; - if (isUPPER(*string)) { - i = (*string - 'A'); + cp++; + if (isUPPER(*cp)) { + i = (UChar(*cp) - 'A'); static_vars[i] = npop(); - } else if (isLOWER(*string)) { - i = (*string - 'a'); + } else if (isLOWER(*cp)) { + i = (UChar(*cp) - 'a'); dynamic_var[i] = npop(); } break; case 'g': - string++; - if (isUPPER(*string)) { - i = (*string - 'A'); + cp++; + if (isUPPER(*cp)) { + i = (UChar(*cp) - 'A'); npush(static_vars[i]); - } else if (isLOWER(*string)) { - i = (*string - 'a'); + } else if (isLOWER(*cp)) { + i = (UChar(*cp) - 'a'); npush(dynamic_var[i]); } break; case S_QUOTE: - string++; - npush(*string); - string++; + cp++; + npush(UChar(*cp)); + cp++; break; case L_BRACE: number = 0; - string++; - while (*string >= '0' && *string <= '9') { - number = number * 10 + *string - '0'; - string++; + cp++; + while (isdigit(UChar(*cp))) { + number = (number * 10) + (UChar(*cp) - '0'); + cp++; } npush(number); break; @@ -676,38 +711,38 @@ tparam_internal(const char *string, va_list ap) x = npop(); if (!x) { /* scan forward for %e or %; at level zero */ - string++; + cp++; level = 0; - while (*string) { - if (*string == '%') { - string++; - if (*string == '?') + while (*cp) { + if (*cp == '%') { + cp++; + if (*cp == '?') level++; - else if (*string == ';') { + else if (*cp == ';') { if (level > 0) level--; else break; - } else if (*string == 'e' && level == 0) + } else if (*cp == 'e' && level == 0) break; } - if (*string) - string++; + if (*cp) + cp++; } } break; case 'e': /* scan forward for a %; at level zero */ - string++; + cp++; level = 0; - while (*string) { - if (*string == '%') { - string++; - if (*string == '?') + while (*cp) { + if (*cp == '%') { + cp++; + if (*cp == '?') level++; - else if (*string == ';') { + else if (*cp == ';') { if (level > 0) level--; else @@ -715,22 +750,22 @@ tparam_internal(const char *string, va_list ap) } } - if (*string) - string++; + if (*cp) + cp++; } break; case ';': break; - } /* endswitch (*string) */ - } /* endelse (*string == '%') */ + } /* endswitch (*cp) */ + } /* endelse (*cp == '%') */ - if (*string == '\0') + if (*cp == '\0') break; - string++; - } /* endwhile (*string) */ + cp++; + } /* endwhile (*cp) */ get_space(1); out_buff[out_used] = '\0'; @@ -739,9 +774,14 @@ tparam_internal(const char *string, va_list ap) return (out_buff); } +#if NCURSES_TPARM_VARARGS +#define tparm_varargs tparm +#else +#define tparm_proto tparm +#endif + NCURSES_EXPORT(char *) -tparm -(NCURSES_CONST char *string,...) +tparm_varargs(NCURSES_CONST char *string,...) { va_list ap; char *result; @@ -755,3 +795,20 @@ tparm va_end(ap); return result; } + +#if !NCURSES_TPARM_VARARGS +NCURSES_EXPORT(char *) +tparm_proto(NCURSES_CONST char *string, + TPARM_ARG a1, + TPARM_ARG a2, + TPARM_ARG a3, + TPARM_ARG a4, + TPARM_ARG a5, + TPARM_ARG a6, + TPARM_ARG a7, + TPARM_ARG a8, + TPARM_ARG a9) +{ + return tparm_varargs(string, a1, a2, a3, a4, a5, a6, a7, a8, a9); +} +#endif /* NCURSES_TPARM_VARARGS */ diff --git a/contrib/ncurses/ncurses/tinfo/lib_tputs.c b/contrib/ncurses/ncurses/tinfo/lib_tputs.c index 26d805ba4025..3a18ffd7404f 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_tputs.c +++ b/contrib/ncurses/ncurses/tinfo/lib_tputs.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000,2001 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 * @@ -45,16 +45,14 @@ #include <termcap.h> /* ospeed */ #include <tic.h> -MODULE_ID("$Id: lib_tputs.c,v 1.59 2001/09/22 18:35:23 tom Exp $") +MODULE_ID("$Id: lib_tputs.c,v 1.62 2003/08/23 21:39:20 tom Exp $") -NCURSES_EXPORT_VAR(char) -PC = 0; /* used by termcap library */ +NCURSES_EXPORT_VAR(char) PC = 0; /* used by termcap library */ NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed = 0; /* used by termcap library */ -NCURSES_EXPORT_VAR(int) -_nc_nulls_sent = 0; /* used by 'tack' program */ +NCURSES_EXPORT_VAR(int) _nc_nulls_sent = 0; /* used by 'tack' program */ - static int (*my_outch) (int c) = _nc_outch; +static int (*my_outch) (int c) = _nc_outch; NCURSES_EXPORT(int) delay_output(int ms) @@ -67,7 +65,7 @@ delay_output(int ms) } else { register int nullcount; - nullcount = (ms * _nc_baudrate(ospeed)) / 10000; + nullcount = (ms * _nc_baudrate(ospeed)) / (BAUDBYTE * 1000); for (_nc_nulls_sent += nullcount; nullcount > 0; nullcount--) my_outch(PC); if (my_outch == _nc_outch) @@ -86,9 +84,7 @@ _nc_flush(void) NCURSES_EXPORT(int) _nc_outch(int ch) { -#ifdef TRACE - _nc_outchars++; -#endif /* TRACE */ + TRACE_OUTCHARS(1); if (SP != 0 && SP->_cleanup) { @@ -111,8 +107,7 @@ putp(const char *string) } NCURSES_EXPORT(int) -tputs -(const char *string, int affcnt, int (*outc) (int)) +tputs(const char *string, int affcnt, int (*outc) (int)) { bool always_delay; bool normal_delay; diff --git a/contrib/ncurses/ncurses/tinfo/lib_ttyflags.c b/contrib/ncurses/ncurses/tinfo/lib_ttyflags.c index 385166e94fa7..77c35fa58426 100644 --- a/contrib/ncurses/ncurses/tinfo/lib_ttyflags.c +++ b/contrib/ncurses/ncurses/tinfo/lib_ttyflags.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 * @@ -38,42 +38,56 @@ #include <curses.priv.h> #include <term.h> /* cur_term */ -MODULE_ID("$Id: lib_ttyflags.c,v 1.7 2002/05/25 14:50:00 tom Exp $") - -#undef tabs - -#ifdef TAB3 -# define tabs TAB3 -#else -# ifdef XTABS -# define tabs XTABS -# else -# ifdef OXTABS -# define tabs OXTABS -# else -# define tabs 0 -# endif -# endif -#endif +MODULE_ID("$Id: lib_ttyflags.c,v 1.13 2006/12/10 01:31:54 tom Exp $") NCURSES_EXPORT(int) _nc_get_tty_mode(TTY * buf) { - if (cur_term == 0 - || GET_TTY(cur_term->Filedes, buf) != 0) - return (ERR); - TR(TRACE_BITS, ("_nc_get_tty_mode: %s", _nc_trace_ttymode(buf))); - return (OK); + int result = OK; + + if (cur_term == 0) { + result = ERR; + } else { + for (;;) { + if (GET_TTY(cur_term->Filedes, buf) != 0) { + if (errno == EINTR) + continue; + result = ERR; + } + break; + } + } + + if (result == ERR) + memset(buf, 0, sizeof(*buf)); + + TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s", + cur_term->Filedes, _nc_trace_ttymode(buf))); + return (result); } NCURSES_EXPORT(int) _nc_set_tty_mode(TTY * buf) { - if (cur_term == 0 - || SET_TTY(cur_term->Filedes, buf) != 0) - return (ERR); - TR(TRACE_BITS, ("_nc_set_tty_mode: %s", _nc_trace_ttymode(buf))); - return (OK); + int result = OK; + + if (cur_term == 0) { + result = ERR; + } else { + for (;;) { + if (SET_TTY(cur_term->Filedes, buf) != 0) { + if (errno == EINTR) + continue; + if ((errno == ENOTTY) && (SP != 0)) + SP->_notty = TRUE; + result = ERR; + } + break; + } + } + TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s", + cur_term->Filedes, _nc_trace_ttymode(buf))); + return (result); } NCURSES_EXPORT(int) @@ -82,14 +96,13 @@ def_shell_mode(void) T((T_CALLED("def_shell_mode()"))); /* - * Turn off the XTABS bit in the tty structure if it was on. If XTABS - * was on, remove the tab and backtab capabilities. + * If XTABS was on, remove the tab and backtab capabilities. */ if (_nc_get_tty_mode(&cur_term->Ottyb) != OK) returnCode(ERR); #ifdef TERMIOS - if (cur_term->Ottyb.c_oflag & tabs) + if (cur_term->Ottyb.c_oflag & OFLAGS_TABS) tab = back_tab = NULL; #else if (cur_term->Ottyb.sg_flags & XTABS) @@ -103,10 +116,14 @@ def_prog_mode(void) { T((T_CALLED("def_prog_mode()"))); + /* + * Turn off the XTABS bit in the tty structure if it was on. + */ + if (_nc_get_tty_mode(&cur_term->Nttyb) != OK) returnCode(ERR); #ifdef TERMIOS - cur_term->Nttyb.c_oflag &= ~tabs; + cur_term->Nttyb.c_oflag &= ~OFLAGS_TABS; #else cur_term->Nttyb.sg_flags &= ~XTABS; #endif @@ -119,13 +136,14 @@ reset_prog_mode(void) T((T_CALLED("reset_prog_mode()"))); if (cur_term != 0) { - _nc_set_tty_mode(&cur_term->Nttyb); - if (SP) { - if (SP->_keypad_on) - _nc_keypad(TRUE); - NC_BUFFERED(TRUE); + if (_nc_set_tty_mode(&cur_term->Nttyb) == OK) { + if (SP) { + if (SP->_keypad_on) + _nc_keypad(TRUE); + NC_BUFFERED(TRUE); + } + returnCode(OK); } - returnCode(OK); } returnCode(ERR); } diff --git a/contrib/ncurses/ncurses/tinfo/make_keys.c b/contrib/ncurses/ncurses/tinfo/make_keys.c index 3c98da23e019..8f6243c93c75 100644 --- a/contrib/ncurses/ncurses/tinfo/make_keys.c +++ b/contrib/ncurses/ncurses/tinfo/make_keys.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 * @@ -35,9 +35,11 @@ * making the output show the indices into the TERMTYPE Strings array. Doing * it that way lets us cut down on the size of the init_keytry() function. */ + +#define USE_TERMLIB 1 #include <curses.priv.h> -MODULE_ID("$Id: make_keys.c,v 1.10 2000/12/10 02:55:08 tom Exp $") +MODULE_ID("$Id: make_keys.c,v 1.12 2005/08/20 19:58:18 tom Exp $") #include <names.c> @@ -66,7 +68,7 @@ lookup(const char *name) } static void -make_keys(FILE * ifp, FILE * ofp) +make_keys(FILE *ifp, FILE *ofp) { char buffer[BUFSIZ]; char from[BUFSIZ]; @@ -92,7 +94,7 @@ make_keys(FILE * ifp, FILE * ofp) } static void -write_list(FILE * ofp, const char **list) +write_list(FILE *ofp, const char **list) { while (*list != 0) fprintf(ofp, "%s\n", *list++); diff --git a/contrib/ncurses/ncurses/tinfo/name_match.c b/contrib/ncurses/ncurses/tinfo/name_match.c index e7205d5ec8ab..fee3ba3bc711 100644 --- a/contrib/ncurses/ncurses/tinfo/name_match.c +++ b/contrib/ncurses/ncurses/tinfo/name_match.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1999,2000,2001 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 * @@ -34,7 +34,7 @@ #include <term.h> #include <tic.h> -MODULE_ID("$Id: name_match.c,v 1.11 2001/09/22 21:11:34 tom Exp $") +MODULE_ID("$Id: name_match.c,v 1.15 2005/01/22 21:47:25 tom Exp $") /* * _nc_first_name(char *names) @@ -49,8 +49,16 @@ _nc_first_name(const char *const sp) static char *buf; register unsigned n; +#if NO_LEAKS + if (sp == 0) { + if (buf != 0) + FreeAndNull(buf); /* for leak-testing */ + return 0; + } +#endif + if (buf == 0) - buf = _nc_doalloc(buf, MAX_NAME_SIZE + 1); + buf = typeMalloc(char, MAX_NAME_SIZE + 1); for (n = 0; n < MAX_NAME_SIZE; n++) { if ((buf[n] = sp[n]) == '\0' || (buf[n] == '|')) @@ -67,8 +75,7 @@ _nc_first_name(const char *const sp) */ NCURSES_EXPORT(int) -_nc_name_match -(const char *const namelst, const char *const name, const char *const delim) +_nc_name_match(const char *const namelst, const char *const name, const char *const delim) { const char *s, *d, *t; int code, found; diff --git a/contrib/ncurses/ncurses/tinfo/parse_entry.c b/contrib/ncurses/ncurses/tinfo/parse_entry.c index 1c0ce850e42d..510b232c8b5c 100644 --- a/contrib/ncurses/ncurses/tinfo/parse_entry.c +++ b/contrib/ncurses/ncurses/tinfo/parse_entry.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 * ****************************************************************************/ /* @@ -47,7 +48,7 @@ #include <tic.h> #include <term_entry.h> -MODULE_ID("$Id: parse_entry.c,v 1.56 2002/05/25 12:23:51 tom Exp $") +MODULE_ID("$Id: parse_entry.c,v 1.63 2006/06/17 17:57:50 tom Exp $") #ifdef LINT static short const parametrized[] = @@ -141,7 +142,7 @@ _nc_extend_names(ENTRY * entryp, char *name, int token_type) case BOOLEAN: tp->ext_Booleans += 1; tp->num_Booleans += 1; - tp->Booleans = typeRealloc(char, tp->num_Booleans, tp->Booleans); + tp->Booleans = typeRealloc(NCURSES_SBOOL, tp->num_Booleans, tp->Booleans); for (last = tp->num_Booleans - 1; last > tindex; last--) tp->Booleans[last] = tp->Booleans[last - 1]; break; @@ -188,20 +189,24 @@ _nc_extend_names(ENTRY * entryp, char *name, int token_type) * if the token was not a name in column 1, complain and die * save names in entry's string table * while (get_token() is not EOF and not NAMES) - * check for existance and type-correctness + * check for existence and type-correctness * enter cap into structure * if STRING * save string in entry's string table * push back token */ +#define BAD_TC_USAGE if (!bad_tc_usage) \ + { bad_tc_usage = TRUE; \ + _nc_warning("Legacy termcap allows only a trailing tc= clause"); } + NCURSES_EXPORT(int) -_nc_parse_entry -(struct entry *entryp, int literal, bool silent) +_nc_parse_entry(struct entry *entryp, int literal, bool silent) { int token_type; struct name_table_entry const *entry_ptr; char *ptr, *base; + bool bad_tc_usage = FALSE; token_type = _nc_get_token(silent); @@ -217,11 +222,25 @@ _nc_parse_entry entryp->startline = _nc_start_line; DEBUG(2, ("Comment range is %ld to %ld", entryp->cstart, entryp->cend)); - /* junk the 2-character termcap name, if present */ + /* + * Strip off the 2-character termcap name, if present. Originally termcap + * used that as an indexing aid. We can retain 2-character terminfo names, + * but note that they would be lost if we translate to/from termcap. This + * feature is supposedly obsolete since "newer" BSD implementations do not + * use it; however our reference for this feature is SunOS 4.x, which + * implemented it. Note that the resulting terminal type was never the + * 2-character name, but was instead the first alias after that. + */ ptr = _nc_curr_token.tk_name; - if (ptr[2] == '|') { - ptr = _nc_curr_token.tk_name + 3; - _nc_curr_token.tk_name[2] = '\0'; + if (_nc_syntax == SYN_TERMCAP +#if NCURSES_XNAMES + && !_nc_user_definable +#endif + ) { + if (ptr[2] == '|') { + ptr += 3; + _nc_curr_token.tk_name[2] = '\0'; + } } entryp->tterm.str_table = entryp->tterm.term_names = _nc_save_str(ptr); @@ -252,11 +271,15 @@ _nc_parse_entry for (token_type = _nc_get_token(silent); token_type != EOF && token_type != NAMES; token_type = _nc_get_token(silent)) { - if (strcmp(_nc_curr_token.tk_name, "use") == 0 - || strcmp(_nc_curr_token.tk_name, "tc") == 0) { + bool is_use = (strcmp(_nc_curr_token.tk_name, "use") == 0); + bool is_tc = !is_use && (strcmp(_nc_curr_token.tk_name, "tc") == 0); + if (is_use || is_tc) { entryp->uses[entryp->nuses].name = _nc_save_str(_nc_curr_token.tk_valstring); entryp->uses[entryp->nuses].line = _nc_curr_line; entryp->nuses++; + if (entryp->nuses > 1 && is_tc) { + BAD_TC_USAGE + } } else { /* normal token lookup */ entry_ptr = _nc_find_entry(_nc_curr_token.tk_name, @@ -274,6 +297,9 @@ _nc_parse_entry const struct alias *ap; if (_nc_syntax == SYN_TERMCAP) { + if (entryp->nuses != 0) { + BAD_TC_USAGE + } for (ap = _nc_capalias_table; ap->from; ap++) if (strcmp(ap->from, _nc_curr_token.tk_name) == 0) { if (ap->to == (char *) 0) { @@ -345,22 +371,25 @@ _nc_parse_entry */ /* tell max_attributes from arrow_key_map */ - if (token_type == NUMBER && !strcmp("ma", _nc_curr_token.tk_name)) + if (token_type == NUMBER + && !strcmp("ma", _nc_curr_token.tk_name)) { entry_ptr = _nc_find_type_entry("ma", NUMBER, _nc_get_table(_nc_syntax != 0)); - /* map terminfo's string MT to MT */ - else if (token_type == STRING && !strcmp("MT", _nc_curr_token.tk_name)) + /* map terminfo's string MT to MT */ + } else if (token_type == STRING + && !strcmp("MT", _nc_curr_token.tk_name)) { entry_ptr = _nc_find_type_entry("MT", STRING, _nc_get_table(_nc_syntax != 0)); - /* treat strings without following "=" as empty strings */ - else if (token_type == BOOLEAN && entry_ptr->nte_type == STRING) + /* treat strings without following "=" as empty strings */ + } else if (token_type == BOOLEAN + && entry_ptr->nte_type == STRING) { token_type = STRING; - /* we couldn't recover; skip this token */ - else { + /* we couldn't recover; skip this token */ + } else { if (!silent) { const char *type_name; switch (entry_ptr->nte_type) { @@ -594,7 +623,7 @@ static const char C_HT[] = "\t"; #define CUR tp-> static void -postprocess_termcap(TERMTYPE * tp, bool has_base) +postprocess_termcap(TERMTYPE *tp, bool has_base) { char buf[MAX_LINE * 2 + 2]; string_desc result; @@ -869,13 +898,12 @@ postprocess_termcap(TERMTYPE * tp, bool has_base) } else if (acs_chars == 0 && enter_alt_charset_mode != 0 && exit_alt_charset_mode != 0) { - acs_chars = - _nc_save_str("``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"); + acs_chars = _nc_save_str(VT_ACSC); } } static void -postprocess_terminfo(TERMTYPE * tp) +postprocess_terminfo(TERMTYPE *tp) { /* * TERMINFO-TO-TERMINFO MAPPINGS FOR SOURCE TRANSLATION diff --git a/contrib/ncurses/ncurses/tinfo/read_entry.c b/contrib/ncurses/ncurses/tinfo/read_entry.c index 006e56c3ddb1..c6c327514d57 100644 --- a/contrib/ncurses/ncurses/tinfo/read_entry.c +++ b/contrib/ncurses/ncurses/tinfo/read_entry.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 * @@ -29,77 +29,24 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* * read_entry.c -- Routine for reading in a compiled terminfo file - * */ #include <curses.priv.h> +#include <hashed_db.h> #include <tic.h> #include <term_entry.h> -MODULE_ID("$Id: read_entry.c,v 1.72 2000/12/10 02:55:08 tom Exp $") - -#if !HAVE_TELL -#define tell(fd) 0 /* lseek() is POSIX, but not tell() - odd... */ -#endif - -/* - * int - * _nc_read_file_entry(filename, ptr) - * - * Read the compiled terminfo entry in the given file into the - * structure pointed to by ptr, allocating space for the string - * table. - */ - -#undef BYTE -#define BYTE(p,n) (unsigned char)((p)[n]) - -#define IS_NEG1(p) ((BYTE(p,0) == 0377) && (BYTE(p,1) == 0377)) -#define IS_NEG2(p) ((BYTE(p,0) == 0376) && (BYTE(p,1) == 0377)) -#define LOW_MSB(p) (BYTE(p,0) + 256*BYTE(p,1)) - -static bool have_tic_directory = FALSE; -static bool keep_tic_directory = FALSE; - -/* - * Record the "official" location of the terminfo directory, according to - * the place where we're writing to, or the normal default, if not. - */ -NCURSES_EXPORT(const char *) -_nc_tic_dir(const char *path) -{ - static const char *result = TERMINFO; - - if (!keep_tic_directory) { - if (path != 0) { - result = path; - have_tic_directory = TRUE; - } else if (!have_tic_directory && use_terminfo_vars()) { - char *envp; - if ((envp = getenv("TERMINFO")) != 0) - return _nc_tic_dir(envp); - } - } - return result; -} +MODULE_ID("$Id: read_entry.c,v 1.99 2006/08/19 15:58:50 tom Exp $") -/* - * Special fix to prevent the terminfo directory from being moved after tic - * has chdir'd to it. If we let it be changed, then if $TERMINFO has a - * relative path, we'll lose track of the actual directory. - */ -NCURSES_EXPORT(void) -_nc_keep_tic_dir(const char *path) -{ - _nc_tic_dir(path); - keep_tic_directory = TRUE; -} +#define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts)) +#if USE_DATABASE static void convert_shorts(char *buf, short *Numbers, int count) { @@ -145,30 +92,51 @@ convert_strings(char *buf, char **Strings, int count, int size, char *table) } } -#define read_shorts(fd, buf, count) (read(fd, buf, (count)*2) == (count)*2) +static int +fake_read(char *src, int *offset, int limit, char *dst, unsigned want) +{ + int have = (limit - *offset); + + if (have > 0) { + if ((int) want > have) + want = have; + memcpy(dst, src + *offset, want); + *offset += want; + } else { + want = 0; + } + return (int) want; +} + +#define Read(buf, count) fake_read(buffer, &offset, limit, buf, count) + +#define read_shorts(buf, count) \ + (Read(buf, (unsigned) (count)*2) == (int) (count)*2) #define even_boundary(value) \ - if ((value) % 2 != 0) read(fd, buf, 1) + if ((value) % 2 != 0) Read(buf, 1) -static int -read_termtype(int fd, TERMTYPE * ptr) +NCURSES_EXPORT(int) +_nc_read_termtype(TERMTYPE *ptr, char *buffer, int limit) /* return 1 if read, 0 if not found or garbled */ { + int offset = 0; int name_size, bool_count, num_count, str_count, str_size; int i; - char buf[MAX_ENTRY_SIZE]; + char buf[MAX_ENTRY_SIZE + 1]; + char *string_table; + unsigned want, have; - TR(TRACE_DATABASE, ("READ termtype header @%d", tell(fd))); + TR(TRACE_DATABASE, ("READ termtype header @%d", offset)); memset(ptr, 0, sizeof(*ptr)); /* grab the header */ - if (!read_shorts(fd, buf, 6) - || LOW_MSB(buf) != MAGIC) { - return (0); + if (!read_shorts(buf, 6) + || !IS_TIC_MAGIC(buf)) { + return (TGETENT_NO); } - _nc_free_termtype(ptr); name_size = LOW_MSB(buf + 2); bool_count = LOW_MSB(buf + 4); num_count = LOW_MSB(buf + 6); @@ -184,34 +152,41 @@ read_termtype(int fd, TERMTYPE * ptr) || num_count < 0 || str_count < 0 || str_size < 0) { - return (0); + return (TGETENT_NO); } + want = str_size + name_size + 1; if (str_size) { /* try to allocate space for the string table */ if (str_count * 2 >= (int) sizeof(buf) - || (ptr->str_table = typeMalloc(char, (unsigned) str_size)) == 0) { - return (0); + || (string_table = typeMalloc(char, want)) == 0) { + return (TGETENT_NO); } } else { str_count = 0; + if ((string_table = typeMalloc(char, want)) == 0) { + return (TGETENT_NO); + } } - /* grab the name (a null-terminate string) */ - read(fd, buf, min(MAX_NAME_SIZE, (unsigned) name_size)); - buf[MAX_NAME_SIZE] = '\0'; - ptr->term_names = typeCalloc(char, strlen(buf) + 1); - if (ptr->term_names == NULL) { - return (0); + /* grab the name (a null-terminated string) */ + want = min(MAX_NAME_SIZE, (unsigned) name_size); + ptr->str_table = string_table; + ptr->term_names = string_table; + if ((have = Read(ptr->term_names, want)) != want) { + memset(ptr->term_names + have, 0, want - have); } - (void) strcpy(ptr->term_names, buf); - if (name_size > MAX_NAME_SIZE) - lseek(fd, (off_t) (name_size - MAX_NAME_SIZE), 1); + ptr->term_names[want] = '\0'; + string_table += (want + 1); + + if (have > MAX_NAME_SIZE) + offset = (have - MAX_NAME_SIZE); /* grab the booleans */ - if ((ptr->Booleans = typeCalloc(char, max(BOOLCOUNT, bool_count))) == 0 - || read(fd, ptr->Booleans, (unsigned) bool_count) < bool_count) { - return (0); + if ((ptr->Booleans = TYPE_CALLOC(NCURSES_SBOOL, + max(BOOLCOUNT, bool_count))) == 0 + || Read(ptr->Booleans, (unsigned) bool_count) < bool_count) { + return (TGETENT_NO); } /* @@ -223,24 +198,24 @@ read_termtype(int fd, TERMTYPE * ptr) even_boundary(name_size + bool_count); /* grab the numbers */ - if ((ptr->Numbers = typeCalloc(short, max(NUMCOUNT, num_count))) == 0 - || !read_shorts(fd, buf, num_count)) { - return (0); + if ((ptr->Numbers = TYPE_CALLOC(short, max(NUMCOUNT, num_count))) == 0 + || !read_shorts(buf, num_count)) { + return (TGETENT_NO); } convert_shorts(buf, ptr->Numbers, num_count); - if ((ptr->Strings = typeCalloc(char *, max(STRCOUNT, str_count))) == 0) - return (0); + if ((ptr->Strings = TYPE_CALLOC(char *, max(STRCOUNT, str_count))) == 0) + return (TGETENT_NO); if (str_count) { /* grab the string offsets */ - if (!read_shorts(fd, buf, str_count)) { - return (0); + if (!read_shorts(buf, str_count)) { + return (TGETENT_NO); } /* finally, grab the string table itself */ - if (read(fd, ptr->str_table, (unsigned) str_size) != str_size) - return (0); - convert_strings(buf, ptr->Strings, str_count, str_size, ptr->str_table); + if (Read(string_table, (unsigned) str_size) != str_size) + return (TGETENT_NO); + convert_strings(buf, ptr->Strings, str_count, str_size, string_table); } #if NCURSES_XNAMES @@ -252,17 +227,17 @@ read_termtype(int fd, TERMTYPE * ptr) * Read extended entries, if any, after the normal end of terminfo data. */ even_boundary(str_size); - TR(TRACE_DATABASE, ("READ extended_header @%d", tell(fd))); - if (_nc_user_definable && read_shorts(fd, buf, 5)) { + TR(TRACE_DATABASE, ("READ extended_header @%d", offset)); + if (_nc_user_definable && read_shorts(buf, 5)) { int ext_bool_count = LOW_MSB(buf + 0); int ext_num_count = LOW_MSB(buf + 2); int ext_str_count = LOW_MSB(buf + 4); int ext_str_size = LOW_MSB(buf + 6); int ext_str_limit = LOW_MSB(buf + 8); - int need = (ext_bool_count + ext_num_count + ext_str_count); + unsigned need = (ext_bool_count + ext_num_count + ext_str_count); int base = 0; - if (need >= (int) sizeof(buf) + if (need >= sizeof(buf) || ext_str_size >= (int) sizeof(buf) || ext_str_limit >= (int) sizeof(buf) || ext_bool_count < 0 @@ -270,13 +245,13 @@ read_termtype(int fd, TERMTYPE * ptr) || ext_str_count < 0 || ext_str_size < 0 || ext_str_limit < 0) - return (0); + return (TGETENT_NO); ptr->num_Booleans = BOOLCOUNT + ext_bool_count; ptr->num_Numbers = NUMCOUNT + ext_num_count; ptr->num_Strings = STRCOUNT + ext_str_count; - ptr->Booleans = typeRealloc(char, ptr->num_Booleans, ptr->Booleans); + ptr->Booleans = typeRealloc(NCURSES_SBOOL, ptr->num_Booleans, ptr->Booleans); ptr->Numbers = typeRealloc(short, ptr->num_Numbers, ptr->Numbers); ptr->Strings = typeRealloc(char *, ptr->num_Strings, ptr->Strings); @@ -285,36 +260,36 @@ read_termtype(int fd, TERMTYPE * ptr) ext_str_size, ext_str_limit)); TR(TRACE_DATABASE, ("READ %d extended-booleans @%d", - ext_bool_count, tell(fd))); + ext_bool_count, offset)); if ((ptr->ext_Booleans = ext_bool_count) != 0) { - if (read(fd, ptr->Booleans + BOOLCOUNT, (unsigned) + if (Read(ptr->Booleans + BOOLCOUNT, (unsigned) ext_bool_count) != ext_bool_count) - return (0); + return (TGETENT_NO); } even_boundary(ext_bool_count); TR(TRACE_DATABASE, ("READ %d extended-numbers @%d", - ext_num_count, tell(fd))); + ext_num_count, offset)); if ((ptr->ext_Numbers = ext_num_count) != 0) { - if (!read_shorts(fd, buf, ext_num_count)) - return (0); + if (!read_shorts(buf, ext_num_count)) + return (TGETENT_NO); TR(TRACE_DATABASE, ("Before converting extended-numbers")); convert_shorts(buf, ptr->Numbers + NUMCOUNT, ext_num_count); } - TR(TRACE_DATABASE, ("READ extended-offsets @%d", tell(fd))); + TR(TRACE_DATABASE, ("READ extended-offsets @%d", offset)); if ((ext_str_count || need) - && !read_shorts(fd, buf, ext_str_count + need)) - return (0); + && !read_shorts(buf, ext_str_count + need)) + return (TGETENT_NO); TR(TRACE_DATABASE, ("READ %d bytes of extended-strings @%d", - ext_str_limit, tell(fd))); + ext_str_limit, offset)); if (ext_str_limit) { if ((ptr->ext_str_table = typeMalloc(char, ext_str_limit)) == 0) - return (0); - if (read(fd, ptr->ext_str_table, ext_str_limit) != ext_str_limit) - return (0); + return (TGETENT_NO); + if (Read(ptr->ext_str_table, (unsigned) ext_str_limit) != ext_str_limit) + return (TGETENT_NO); TR(TRACE_DATABASE, ("first extended-string is %s", _nc_visbuf(ptr->ext_str_table))); } @@ -338,12 +313,14 @@ read_termtype(int fd, TERMTYPE * ptr) } if (need) { - if ((ptr->ext_Names = typeCalloc(char *, need)) == 0) - return (0); + if ((ptr->ext_Names = TYPE_CALLOC(char *, need)) == 0) + return (TGETENT_NO); TR(TRACE_DATABASE, ("ext_NAMES starting @%d in extended_strings, first = %s", base, _nc_visbuf(ptr->ext_str_table + base))); - convert_strings(buf + (2 * ext_str_count), ptr->ext_Names, need, + convert_strings(buf + (2 * ext_str_count), + ptr->ext_Names, + (int) need, ext_str_limit, ptr->ext_str_table + base); } @@ -370,86 +347,160 @@ read_termtype(int fd, TERMTYPE * ptr) for (i = str_count; i < STRCOUNT; i++) ptr->Strings[i] = ABSENT_STRING; - return (1); + return (TGETENT_YES); } +/* + * int + * _nc_read_file_entry(filename, ptr) + * + * Read the compiled terminfo entry in the given file into the + * structure pointed to by ptr, allocating space for the string + * table. + */ NCURSES_EXPORT(int) -_nc_read_file_entry -(const char *const filename, TERMTYPE * ptr) +_nc_read_file_entry(const char *const filename, TERMTYPE *ptr) /* return 1 if read, 0 if not found or garbled */ { int code, fd = -1; + int limit; + char buffer[MAX_ENTRY_SIZE + 1]; if (_nc_access(filename, R_OK) < 0 || (fd = open(filename, O_RDONLY | O_BINARY)) < 0) { T(("cannot open terminfo %s (errno=%d)", filename, errno)); - return (0); - } + code = TGETENT_NO; + } else { + if ((limit = read(fd, buffer, sizeof(buffer))) > 0) { - T(("read terminfo %s", filename)); - if ((code = read_termtype(fd, ptr)) == 0) - _nc_free_termtype(ptr); - close(fd); + T(("read terminfo %s", filename)); + if ((code = _nc_read_termtype(ptr, buffer, limit)) == TGETENT_NO) { + _nc_free_termtype(ptr); + } + } else { + code = TGETENT_NO; + } + close(fd); + } return (code); } /* - * Build a terminfo pathname and try to read the data. Returns 1 on success, - * 0 on failure. + * Build a terminfo pathname and try to read the data. Returns TGETENT_YES on + * success, TGETENT_NO on failure. */ static int -_nc_read_tic_entry(char *const filename, - const char *const dir, const char *ttn, TERMTYPE * const tp) +_nc_read_tic_entry(char *filename, + unsigned limit, + const char *const path, + const char *name, + TERMTYPE *const tp) { -/* maximum safe length of terminfo root directory name */ -#define MAX_TPATH (PATH_MAX - MAX_ALIAS - 6) + int result = TGETENT_NO; - if (strlen(dir) > MAX_TPATH) - return 0; - (void) sprintf(filename, "%s/%s", dir, ttn); - return _nc_read_file_entry(filename, tp); -} + /* + * If we are looking in a directory, assume the entry is a file under that, + * according to the normal rules. + * + * FIXME - add caseless-filename fixup. + */ + if (_nc_is_dir_path(path)) { + unsigned need = 4 + strlen(path) + strlen(name); -/* - * Process the list of :-separated directories, looking for the terminal type. - * We don't use strtok because it does not show us empty tokens. - */ -static int -_nc_read_terminfo_dirs(const char *dirs, char *const filename, const char *const - ttn, TERMTYPE * const tp) -{ - char *list, *a; - const char *b; - int code = 0; - - /* we'll modify the argument, so we must copy */ - if ((b = a = list = strdup(dirs)) == NULL) - return (0); - - for (;;) { - int c = *a; - if (c == 0 || c == NCURSES_PATHSEP) { - *a = 0; - if ((b + 1) >= a) - b = TERMINFO; - if (_nc_read_tic_entry(filename, b, ttn, tp) == 1) { - code = 1; - break; + if (need <= limit) { + (void) sprintf(filename, "%s/%c/%s", path, *name, name); + result = _nc_read_file_entry(filename, tp); + } + } +#if USE_HASHED_DB + else { + static const char suffix[] = DBM_SUFFIX; + DB *capdbp; + unsigned lens = sizeof(suffix) - 1; + unsigned size = strlen(path); + unsigned need = lens + size; + + if (need <= limit) { + if (size >= lens + && !strcmp(path + size - lens, suffix)) + (void) strcpy(filename, path); + else + (void) sprintf(filename, "%s%s", path, suffix); + + /* + * It would be nice to optimize the dbopen/close activity, as + * done in the cgetent implementation for tc= clauses. However, + * since we support multiple database locations, we cannot do + * that. + */ + if ((capdbp = _nc_db_open(filename, FALSE)) != 0) { + DBT key, data; + int reccnt = 0; + char *save = strdup(name); + + memset(&key, 0, sizeof(key)); + key.data = save; + key.size = strlen(save); + + /* + * This lookup could return termcap data, which we do not want. + * We are looking for compiled (binary) terminfo data. + * + * cgetent uses a two-level lookup. On the first it uses the + * given name to return a record containing only the aliases + * for an entry. On the second (using that list of aliases as + * a key), it returns the content of the terminal description. + * We expect second lookup to return data beginning with the + * same set of aliases. + * + * For compiled terminfo, the list of aliases in the second + * case will be null-terminated. A termcap entry will not be, + * and will run on into the description. So we can easily + * distinguish between the two (source/binary) by checking the + * lengths. + */ + while (_nc_db_get(capdbp, &key, &data) == 0) { + int used = data.size - 1; + char *have = (char *) data.data; + + if (*have++ == 0) { + if (data.size > key.size + && IS_TIC_MAGIC(have)) { + result = _nc_read_termtype(tp, have, used); + if (result == TGETENT_NO) { + _nc_free_termtype(tp); + } + } + break; + } + + /* + * Just in case we have a corrupt database, do not waste + * time with it. + */ + if (++reccnt >= 3) + break; + + /* + * Prepare for the second level. + */ + key.data = have; + key.size = used; + } + + _nc_db_close(capdbp); + free(save); } - b = a + 1; - if (c == 0) - break; } - a++; } - - free(list); - return (code); +#endif + return result; } +#endif /* USE_DATABASE */ /* - * _nc_read_entry(char *tn, char *filename, TERMTYPE *tp) + * _nc_read_entry(char *name, char *filename, TERMTYPE *tp) * * Find and read the compiled entry for a given terminal type, * if it exists. We take pains here to make sure no combination @@ -458,46 +509,36 @@ _nc_read_terminfo_dirs(const char *dirs, char *const filename, const char *const */ NCURSES_EXPORT(int) -_nc_read_entry -(const char *const tn, char *const filename, TERMTYPE * const tp) +_nc_read_entry(const char *const name, char *const filename, TERMTYPE *const tp) { - char *envp; - char ttn[MAX_ALIAS + 3]; - - /* truncate the terminal name to prevent dangerous buffer airline */ - (void) sprintf(ttn, "%c/%.*s", *tn, MAX_ALIAS, tn); - - /* This is System V behavior, in conjunction with our requirements for - * writing terminfo entries. - */ - if (have_tic_directory - && _nc_read_tic_entry(filename, _nc_tic_dir(0), ttn, tp) == 1) - return 1; - - if (use_terminfo_vars()) { - if ((envp = getenv("TERMINFO")) != 0 - && _nc_read_tic_entry(filename, _nc_tic_dir(envp), ttn, tp) == 1) - return 1; - - /* this is an ncurses extension */ - if ((envp = _nc_home_terminfo()) != 0) { - if (_nc_read_tic_entry(filename, envp, ttn, tp) == 1) { - return (1); + int code = TGETENT_NO; + + if (strlen(name) == 0 + || strcmp(name, ".") == 0 + || strcmp(name, "..") == 0 + || _nc_pathlast(name) != 0 + || strchr(name, NCURSES_PATHSEP) != 0) { + T(("illegal or missing entry name '%s'", name)); + } else { +#if USE_DATABASE + DBDIRS state = dbdTIC; + int offset = 0; + const char *path; + + while ((path = _nc_next_db(&state, &offset)) != 0) { + code = _nc_read_tic_entry(filename, PATH_MAX, path, name, tp); + if (code == TGETENT_YES) { + _nc_last_db(); + break; } } - - /* this is an ncurses extension */ - if ((envp = getenv("TERMINFO_DIRS")) != 0) - return _nc_read_terminfo_dirs(envp, filename, ttn, tp); - } - - /* Try the system directory. Note that the TERMINFO_DIRS value, if - * defined by the configure script, begins with a ":", which will be - * interpreted as TERMINFO. - */ -#ifdef TERMINFO_DIRS - return _nc_read_terminfo_dirs(TERMINFO_DIRS, filename, ttn, tp); -#else - return _nc_read_tic_entry(filename, TERMINFO, ttn, tp); #endif +#if USE_TERMCAP + if (code != TGETENT_YES) { + code = _nc_read_termcap_entry(name, tp); + sprintf(filename, "%.*s", PATH_MAX - 1, _nc_get_source()); + } +#endif + } + return code; } diff --git a/contrib/ncurses/ncurses/tinfo/read_termcap.c b/contrib/ncurses/ncurses/tinfo/read_termcap.c index c6e7e358ad91..d94d1a42466d 100644 --- a/contrib/ncurses/ncurses/tinfo/read_termcap.c +++ b/contrib/ncurses/ncurses/tinfo/read_termcap.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 * ****************************************************************************/ /* @@ -57,27 +58,20 @@ #include <tic.h> #include <term_entry.h> -MODULE_ID("$Id: read_termcap.c,v 1.58 2001/10/28 01:11:34 tom Exp $") +MODULE_ID("$Id: read_termcap.c,v 1.71 2006/07/29 12:06:51 tom Exp $") #if !PURE_TERMINFO -#ifdef __EMX__ -#define is_pathname(s) ((((s) != 0) && ((s)[0] == '/')) \ - || (((s)[0] != 0) && ((s)[1] == ':'))) -#else -#define is_pathname(s) ((s) != 0 && (s)[0] == '/') -#endif - #define TC_SUCCESS 0 -#define TC_UNRESOLVED -1 -#define TC_NOT_FOUND -2 -#define TC_SYS_ERR -3 -#define TC_REF_LOOP -4 +#define TC_NOT_FOUND -1 +#define TC_SYS_ERR -2 +#define TC_REF_LOOP -3 +#define TC_UNRESOLVED -4 /* this is not returned by BSD cgetent */ -static char * +static NCURSES_CONST char * get_termpath(void) { - char *result; + NCURSES_CONST char *result; if (!use_terminfo_vars() || (result = getenv("TERMPATH")) == 0) result = TERMPATH; @@ -231,10 +225,10 @@ _nc_cgetcap(char *buf, const char *cap, int type) * Returns: * * positive # on success (i.e., the index in db_array) - * TC_UNRESOLVED if we had too many recurrences to resolve * TC_NOT_FOUND if the requested record couldn't be found * TC_SYS_ERR if a system error was encountered (e.g.,couldn't open a file) * TC_REF_LOOP if a potential reference loop is detected + * TC_UNRESOLVED if we had too many recurrences to resolve */ static int _nc_cgetent(char **buf, int *oline, char **db_array, const char *name) @@ -720,7 +714,7 @@ get_tc_token(char **srcp, int *endp) if (*s == '\0') { break; } else if (*s++ == '\n') { - while (isspace(*s)) + while (isspace(UChar(*s))) s++; } else { found = TRUE; @@ -734,7 +728,7 @@ get_tc_token(char **srcp, int *endp) break; } base = s; - } else if (isgraph(ch)) { + } else if (isgraph(UChar(ch))) { found = TRUE; } } @@ -754,7 +748,7 @@ copy_tc_token(char *dst, const char *src, size_t len) while ((ch = *src++) != '\0') { if (ch == '\\' && *src == '\n') { - while (isspace(*src)) + while (isspace(UChar(*src))) src++; continue; } @@ -784,7 +778,7 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name) char pathbuf[PBUFSIZ]; /* holds raw path of filenames */ char *pathvec[PVECSIZ]; /* to point to names in pathbuf */ char **pvec; /* holds usable tail of path vector */ - char *termpath; + NCURSES_CONST char *termpath; string_desc desc; fname = pathvec; @@ -805,7 +799,7 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name) _nc_str_init(&desc, pathbuf, sizeof(pathbuf)); if (cp == NULL) { _nc_safe_strcpy(&desc, get_termpath()); - } else if (!is_pathname(cp)) { /* TERMCAP holds an entry */ + } else if (!_nc_is_abs_path(cp)) { /* TERMCAP holds an entry */ if ((termpath = get_termpath()) != 0) { _nc_safe_strcat(&desc, termpath); } else { @@ -843,7 +837,7 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name) } } *fname = 0; /* mark end of vector */ - if (is_pathname(cp)) { + if (_nc_is_abs_path(cp)) { if (_nc_cgetset(cp) < 0) { return (TC_SYS_ERR); } @@ -896,8 +890,21 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name) * cgetent, then it is the actual filename). */ if (i >= 0) { +#if HAVE_BSD_CGETENT + char temp[PATH_MAX]; + + _nc_str_init(&desc, temp, sizeof(temp)); + _nc_safe_strcpy(&desc, pathvec[i]); + _nc_safe_strcat(&desc, ".db"); + if (_nc_access(temp, R_OK) == 0) { + _nc_safe_strcpy(&desc, pathvec[i]); + } + if ((the_source = strdup(temp)) != 0) + *sourcename = the_source; +#else if ((the_source = strdup(pathvec[i])) != 0) *sourcename = the_source; +#endif } return (i); @@ -932,29 +939,39 @@ add_tc(char *termpaths[], char *path, int count) #endif /* !USE_GETCAP */ NCURSES_EXPORT(int) -_nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp) +_nc_read_termcap_entry(const char *const tn, TERMTYPE *const tp) { - int found = FALSE; + int found = TGETENT_NO; ENTRY *ep; #if USE_GETCAP_CACHE char cwd_buf[PATH_MAX]; #endif #if USE_GETCAP char *p, tc[TBUFSIZ]; + int status; static char *source; static int lineno; T(("read termcap entry for %s", tn)); + + if (strlen(tn) == 0 + || strcmp(tn, ".") == 0 + || strcmp(tn, "..") == 0 + || _nc_pathlast(tn) != 0) { + T(("illegal or missing entry name '%s'", tn)); + return TGETENT_NO; + } + if (use_terminfo_vars() && (p = getenv("TERMCAP")) != 0 - && !is_pathname(p) && _nc_name_match(p, tn, "|:")) { + && !_nc_is_abs_path(p) && _nc_name_match(p, tn, "|:")) { /* TERMCAP holds a termcap entry */ strncpy(tc, p, sizeof(tc) - 1); tc[sizeof(tc) - 1] = '\0'; _nc_set_source("TERMCAP"); } else { /* we're using getcap(3) */ - if (_nc_tgetent(tc, &source, &lineno, tn) < 0) - return (ERR); + if ((status = _nc_tgetent(tc, &source, &lineno, tn)) < 0) + return (status == TC_NOT_FOUND ? TGETENT_NO : TGETENT_ERR); _nc_curr_line = lineno; _nc_set_source(source); @@ -1001,7 +1018,7 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp) termpaths[filecount] = 0; if (use_terminfo_vars() && (tc = getenv("TERMCAP")) != 0) { - if (is_pathname(tc)) { /* interpret as a filename */ + if (_nc_is_abs_path(tc)) { /* interpret as a filename */ ADD_TC(tc, 0); normal = FALSE; } else if (_nc_name_match(tc, tn, "|:")) { /* treat as a capability file */ @@ -1038,7 +1055,7 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp) * Probably /etc/termcap is a symlink to /usr/share/misc/termcap. * Avoid reading the same file twice. */ -#ifdef HAVE_LINK +#if HAVE_LINK for (j = 0; j < filecount; j++) { bool omit = FALSE; if (stat(termpaths[j], &test_stat[j]) != 0 @@ -1100,10 +1117,10 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp) #endif /* USE_GETCAP */ if (_nc_head == 0) - return (ERR); + return (TGETENT_ERR); /* resolve all use references */ - _nc_resolve_uses(TRUE); + _nc_resolve_uses2(TRUE, FALSE); /* find a terminal matching tn, if we can */ #if USE_GETCAP_CACHE @@ -1113,13 +1130,12 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp) for_entry_list(ep) { if (_nc_name_match(ep->tterm.term_names, tn, "|:")) { /* - * Make a local copy of the terminal capabilities. Free all - * entry storage except the string table for the loaded type - * (which we disconnected from the list by NULLing out - * ep->tterm.str_table above). + * Make a local copy of the terminal capabilities, delinked + * from the list. */ *tp = ep->tterm; - ep->tterm.str_table = (char *) 0; + _nc_delink_entry(_nc_head, &(ep->tterm)); + free(ep); /* * OK, now try to write the type to user's terminfo directory. @@ -1136,7 +1152,7 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp) #if USE_GETCAP_CACHE (void) _nc_write_entry(tp); #endif - found = TRUE; + found = TGETENT_YES; break; } } @@ -1145,7 +1161,6 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp) } #endif - _nc_free_entries(_nc_head); return (found); } #else diff --git a/contrib/ncurses/ncurses/tinfo/setbuf.c b/contrib/ncurses/ncurses/tinfo/setbuf.c index 6d0201bfb2aa..94bb6d3463c5 100644 --- a/contrib/ncurses/ncurses/tinfo/setbuf.c +++ b/contrib/ncurses/ncurses/tinfo/setbuf.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 * @@ -40,7 +40,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: setbuf.c,v 1.7 2000/12/10 02:55:08 tom Exp $") +MODULE_ID("$Id: setbuf.c,v 1.12 2003/11/15 23:55:34 tom Exp $") /* * If the output file descriptor is connected to a tty (the typical case) it @@ -98,47 +98,53 @@ MODULE_ID("$Id: setbuf.c,v 1.7 2000/12/10 02:55:08 tom Exp $") * buffer. So we disable this by default (there may yet be a workaround). */ NCURSES_EXPORT(void) -_nc_set_buffer(FILE * ofp, bool buffered) +_nc_set_buffer(FILE *ofp, bool buffered) { /* optional optimization hack -- do before any output to ofp */ #if HAVE_SETVBUF || HAVE_SETBUFFER - unsigned buf_len; - char *buf_ptr; + if (SP->_buffered != (int)buffered) { + unsigned buf_len; + char *buf_ptr; - if (getenv("NCURSES_NO_SETBUF") != 0) - return; + if (getenv("NCURSES_NO_SETBUF") != 0) + return; - fflush(ofp); - if ((SP->_buffered = buffered) != 0) { - buf_len = min(LINES * (COLS + 6), 2800); - if ((buf_ptr = SP->_setbuf) == 0) { - if ((buf_ptr = typeMalloc(char, buf_len)) == NULL) - return; - SP->_setbuf = buf_ptr; - /* Don't try to free this! */ - } + fflush(ofp); +#ifdef __DJGPP__ + setmode(ofp, O_BINARY); +#endif + if (buffered != 0) { + buf_len = min(LINES * (COLS + 6), 2800); + if ((buf_ptr = SP->_setbuf) == 0) { + if ((buf_ptr = typeMalloc(char, buf_len)) == NULL) + return; + SP->_setbuf = buf_ptr; + /* Don't try to free this! */ + } #if !USE_SETBUF_0 - else - return; + else + return; #endif - } else { + } else { #if !USE_SETBUF_0 - return; + return; #else - buf_len = 0; - buf_ptr = 0; + buf_len = 0; + buf_ptr = 0; #endif - } + } #if HAVE_SETVBUF #ifdef SETVBUF_REVERSED /* pre-svr3? */ - (void) setvbuf(ofp, buf_ptr, buf_len, buf_len ? _IOFBF : _IOLBF); + (void) setvbuf(ofp, buf_ptr, buf_len, buf_len ? _IOFBF : _IOLBF); #else - (void) setvbuf(ofp, buf_ptr, buf_len ? _IOFBF : _IOLBF, buf_len); + (void) setvbuf(ofp, buf_ptr, buf_len ? _IOFBF : _IOLBF, buf_len); #endif #elif HAVE_SETBUFFER - (void) setbuffer(ofp, buf_ptr, (int) buf_len); + (void) setbuffer(ofp, buf_ptr, (int) buf_len); #endif + SP->_buffered = buffered; + } #endif /* HAVE_SETVBUF || HAVE_SETBUFFER */ } diff --git a/contrib/ncurses/ncurses/tinfo/strings.c b/contrib/ncurses/ncurses/tinfo/strings.c index 5fa68caf7534..d5377fe07a51 100644 --- a/contrib/ncurses/ncurses/tinfo/strings.c +++ b/contrib/ncurses/ncurses/tinfo/strings.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2000 Free Software Foundation, Inc. * + * Copyright (c) 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 * @@ -36,7 +36,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: strings.c,v 1.3 2000/12/10 02:55:08 tom Exp $") +MODULE_ID("$Id: strings.c,v 1.5 2003/08/16 23:46:00 tom Exp $") /**************************************************************************** * Useful string functions (especially for mvcur) @@ -44,8 +44,7 @@ MODULE_ID("$Id: strings.c,v 1.3 2000/12/10 02:55:08 tom Exp $") #if !HAVE_STRSTR NCURSES_EXPORT(char *) -_nc_strstr -(const char *haystack, const char *needle) +_nc_strstr(const char *haystack, const char *needle) { size_t len1 = strlen(haystack); size_t len2 = strlen(needle); @@ -63,16 +62,18 @@ _nc_strstr #endif /* - * Initialize the descriptor so we can append to it. + * Initialize the descriptor so we can append to it. Note that 'src' may + * be a null pointer (see _nc_str_null), so the corresponding strcat and + * strcpy calls have to allow for this. */ NCURSES_EXPORT(string_desc *) -_nc_str_init -(string_desc * dst, char *src, size_t len) +_nc_str_init(string_desc * dst, char *src, size_t len) { if (dst != 0) { dst->s_head = src; dst->s_tail = src; dst->s_size = len - 1; + dst->s_init = dst->s_size; if (src != 0) *src = 0; } @@ -83,8 +84,7 @@ _nc_str_init * Initialize the descriptor for only tracking the amount of memory used. */ NCURSES_EXPORT(string_desc *) -_nc_str_null -(string_desc * dst, size_t len) +_nc_str_null(string_desc * dst, size_t len) { return _nc_str_init(dst, 0, len); } @@ -93,8 +93,7 @@ _nc_str_null * Copy a descriptor */ NCURSES_EXPORT(string_desc *) -_nc_str_copy -(string_desc * dst, string_desc * src) +_nc_str_copy(string_desc * dst, string_desc * src) { *dst = *src; return dst; @@ -135,7 +134,7 @@ _nc_safe_strcpy(string_desc * dst, const char *src) strcpy(dst->s_head, src); dst->s_tail = dst->s_head + len; } - dst->s_size -= len; + dst->s_size = dst->s_init - len; return TRUE; } } diff --git a/contrib/ncurses/ncurses/tinfo/trim_sgr0.c b/contrib/ncurses/ncurses/tinfo/trim_sgr0.c new file mode 100644 index 000000000000..3ce18e070b06 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/trim_sgr0.c @@ -0,0 +1,328 @@ +/**************************************************************************** + * 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 Dickey * + ****************************************************************************/ + +#include <curses.priv.h> + +#include <ctype.h> + +#include <tic.h> +#include <term_entry.h> + +MODULE_ID("$Id: trim_sgr0.c,v 1.7 2006/12/02 19:37:57 tom Exp $") + +#undef CUR +#define CUR tp-> + +#define CSI 233 +#define ESC 033 /* ^[ */ +#define L_BRACK '[' + +static char * +set_attribute_9(TERMTYPE *tp, int flag) +{ + const char *result; + + if ((result = tparm(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, flag)) == 0) + result = ""; + return strdup(result); +} + +static int +is_csi(const char *s) +{ + if (UChar(s[0]) == CSI) + return 1; + else if (s[0] == ESC && s[1] == L_BRACK) + return 2; + return 0; +} + +static char * +skip_zero(char *s) +{ + if (s[0] == '0') { + if (s[1] == ';') + s += 2; + else if (isalpha(UChar(s[1]))) + s += 1; + } + return s; +} + +static const char * +skip_delay(const char *s) +{ + if (s[0] == '$' && s[1] == '<') { + s += 2; + while (isdigit(UChar(*s)) || *s == '/') + ++s; + if (*s == '>') + ++s; + } + return s; +} + +/* + * Improve similar_sgr a little by moving the attr-string from the beginning + * to the end of the s-string. + */ +static bool +rewrite_sgr(char *s, char *attr) +{ + if (PRESENT(s)) { + if (PRESENT(attr)) { + unsigned len_s = strlen(s); + unsigned len_a = strlen(attr); + + if (len_s > len_a && !strncmp(attr, s, len_a)) { + unsigned n; + TR(TRACE_DATABASE, ("rewrite:\n\t%s", s)); + for (n = 0; n < len_s - len_a; ++n) { + s[n] = s[n + len_a]; + } + strcpy(s + n, attr); + TR(TRACE_DATABASE, ("to:\n\t%s", s)); + } + } + return TRUE; + } + return FALSE; /* oops */ +} + +static bool +similar_sgr(char *a, char *b) +{ + bool result = FALSE; + int csi_a = is_csi(a); + int csi_b = is_csi(b); + unsigned len_a; + unsigned len_b; + + TR(TRACE_DATABASE, ("similar_sgr:\n\t%s\n\t%s", + _nc_visbuf2(1, a), + _nc_visbuf2(2, b))); + if (csi_a != 0 && csi_b != 0 && csi_a == csi_b) { + a += csi_a; + b += csi_b; + if (*a != *b) { + a = skip_zero(a); + b = skip_zero(b); + } + } + len_a = strlen(a); + len_b = strlen(b); + if (len_a && len_b) { + if (len_a > len_b) + result = (strncmp(a, b, len_b) == 0); + else + result = (strncmp(a, b, len_a) == 0); + } + TR(TRACE_DATABASE, ("...similar_sgr: %d\n\t%s\n\t%s", result, + _nc_visbuf2(1, a), + _nc_visbuf2(2, b))); + return result; +} + +static unsigned +chop_out(char *string, unsigned i, unsigned j) +{ + TR(TRACE_DATABASE, ("chop_out %d..%d from %s", i, j, _nc_visbuf(string))); + while (string[j] != '\0') { + string[i++] = string[j++]; + } + string[i] = '\0'; + return i; +} + +/* + * Compare, ignoring delays. Some of the delay values are inconsistent, and + * we do not want to be stopped by that. + * + * Returns the number of chars from 'full' that we matched. If any mismatch + * occurs, return zero. + */ +static int +compare_part(const char *part, const char *full) +{ + const char *next_part; + const char *next_full; + int used_full = 0; + int used_delay = 0; + + while (*part != 0) { + if (*part != *full) { + used_full = 0; + break; + } + + /* + * Adjust the return-value to allow the rare case of + * string<delay>string + * to remove the whole piece. The most common case is a delay at the + * end of the string. The adjusted string will retain the delay, which + * is conservative. + */ + if (used_delay != 0) { + used_full += used_delay; + used_delay = 0; + } + if (*part == '$' && *full == '$') { + next_part = skip_delay(part); + next_full = skip_delay(full); + if (next_part != part && next_full != full) { + used_delay += (next_full - full); + full = next_full; + part = next_part; + continue; + } + } + ++used_full; + ++part; + ++full; + } + return used_full; +} + +/* + * While 'sgr0' is the "same" as termcap 'me', there is a compatibility issue. + * The sgr/sgr0 capabilities include setting/clearing alternate character set + * mode. A termcap application cannot use sgr, so sgr0 strings that reset + * alternate character set mode will be misinterpreted. Here, we remove those + * from the more common ISO/ANSI/VT100 entries, which have sgr0 agreeing with + * sgr. + * + * This function returns the modified sgr0 if it can be modified, a null if + * an error occurs, or the original sgr0 if no change is needed. + */ +NCURSES_EXPORT(char *) +_nc_trim_sgr0(TERMTYPE *tp) +{ + char *result = exit_attribute_mode; + + T((T_CALLED("_nc_trim_sgr0()"))); + + if (PRESENT(exit_attribute_mode) + && PRESENT(set_attributes)) { + bool found = FALSE; + char *on = set_attribute_9(tp, 1); + char *off = set_attribute_9(tp, 0); + char *end = strdup(exit_attribute_mode); + char *tmp; + size_t i, j, k; + + TR(TRACE_DATABASE, ("checking if we can trim sgr0 based on sgr")); + TR(TRACE_DATABASE, ("sgr0 %s", _nc_visbuf(end))); + TR(TRACE_DATABASE, ("sgr(9:off) %s", _nc_visbuf(off))); + TR(TRACE_DATABASE, ("sgr(9:on) %s", _nc_visbuf(on))); + + if (!rewrite_sgr(on, enter_alt_charset_mode) + || !rewrite_sgr(off, exit_alt_charset_mode) + || !rewrite_sgr(end, exit_alt_charset_mode)) { + FreeIfNeeded(on); + FreeIfNeeded(off); + FreeIfNeeded(end); + } else if (similar_sgr(off, end) + && !similar_sgr(off, on)) { + TR(TRACE_DATABASE, ("adjusting sgr(9:off) : %s", _nc_visbuf(off))); + result = off; + /* + * If rmacs is a substring of sgr(0), remove that chunk. + */ + if (exit_alt_charset_mode != 0) { + TR(TRACE_DATABASE, ("scan for rmacs %s", _nc_visbuf(exit_alt_charset_mode))); + j = strlen(off); + k = strlen(exit_alt_charset_mode); + if (j > k) { + for (i = 0; i <= (j - k); ++i) { + int k2 = compare_part(exit_alt_charset_mode, off + i); + if (k2 != 0) { + found = TRUE; + chop_out(off, i, i + k2); + break; + } + } + } + } + /* + * SGR 10 would reset to normal font. + */ + if (!found) { + if ((i = is_csi(off)) != 0 + && off[strlen(off) - 1] == 'm') { + TR(TRACE_DATABASE, ("looking for SGR 10 in %s", + _nc_visbuf(off))); + tmp = skip_zero(off + i); + if (tmp[0] == '1' + && skip_zero(tmp + 1) != tmp + 1) { + i = tmp - off; + if (off[i - 1] == ';') + i--; + j = skip_zero(tmp + 1) - off; + i = chop_out(off, i, j); + found = TRUE; + } + } + } + if (!found + && (tmp = strstr(end, off)) != 0 + && strcmp(end, off) != 0) { + i = tmp - end; + j = strlen(off); + tmp = strdup(end); + chop_out(tmp, i, j); + free(off); + result = tmp; + } + TR(TRACE_DATABASE, ("...adjusted sgr0 : %s", _nc_visbuf(result))); + if (!strcmp(result, exit_attribute_mode)) { + TR(TRACE_DATABASE, ("...same result, discard")); + free(result); + result = exit_attribute_mode; + } + } else { + /* + * Either the sgr does not reference alternate character set, + * or it is incorrect. That's too hard to decide right now. + */ + free(off); + } + free(end); + free(on); + } else { + /* + * Possibly some applications are confused if sgr0 contains rmacs, + * but that would be a different bug report -TD + */ + } + + returnPtr(result); +} diff --git a/contrib/ncurses/ncurses/tinfo/write_entry.c b/contrib/ncurses/ncurses/tinfo/write_entry.c index 9750dffd5ffe..5426f1fc40d0 100644 --- a/contrib/ncurses/ncurses/tinfo/write_entry.c +++ b/contrib/ncurses/ncurses/tinfo/write_entry.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2000,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 * @@ -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 * ****************************************************************************/ /* @@ -36,6 +37,7 @@ */ #include <curses.priv.h> +#include <hashed_db.h> #include <sys/stat.h> @@ -46,21 +48,27 @@ #define S_ISDIR(mode) ((mode & S_IFMT) == S_IFDIR) #endif -#if 0 +#if 1 #define TRACE_OUT(p) DEBUG(2, p) #else #define TRACE_OUT(p) /*nothing */ #endif -MODULE_ID("$Id: write_entry.c,v 1.58 2002/04/21 20:35:08 tom Exp $") +MODULE_ID("$Id: write_entry.c,v 1.68 2006/10/14 20:45:16 tom Exp $") static int total_written; -static int write_object(FILE *, TERMTYPE *); +static int make_db_root(const char *); +static int write_object(TERMTYPE *, char *, unsigned *, unsigned); +#if !USE_HASHED_DB static void -write_file(char *filename, TERMTYPE * tp) +write_file(char *filename, TERMTYPE *tp) { + char buffer[MAX_ENTRY_SIZE]; + unsigned limit = sizeof(buffer); + unsigned offset = 0; + FILE *fp = (_nc_access(filename, W_OK) == 0) ? fopen(filename, "wb") : 0; if (fp == 0) { perror(filename); @@ -68,50 +76,118 @@ write_file(char *filename, TERMTYPE * tp) } DEBUG(1, ("Created %s", filename)); - if (write_object(fp, tp) == ERR) { + if (write_object(tp, buffer, &offset, limit) == ERR + || fwrite(buffer, sizeof(char), offset, fp) != offset) { _nc_syserr_abort("error writing %s/%s", _nc_tic_dir(0), filename); } + fclose(fp); } /* - * make_directory(char *path) + * Check for access rights to destination directories + * Create any directories which don't exist. * - * Make a directory if it doesn't exist. + * Note: there's no reason to return the result of make_db_root(), since + * this function is called only in instances where that has to succeed. */ +static void +check_writeable(int code) +{ + static const char dirnames[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + static bool verified[sizeof(dirnames)]; + + char dir[2]; + char *s = 0; + + if (code == 0 || (s = strchr(dirnames, code)) == 0) + _nc_err_abort("Illegal terminfo subdirectory \"%c\"", code); + + if (verified[s - dirnames]) + return; + + dir[0] = code; + dir[1] = '\0'; + if (make_db_root(dir) < 0) { + _nc_err_abort("%s/%s: permission denied", _nc_tic_dir(0), dir); + } + + verified[s - dirnames] = TRUE; +} +#endif /* !USE_HASHED_DB */ + static int -make_directory(const char *path) +make_db_path(char *dst, const char *src, unsigned limit) { - int rc; - struct stat statbuf; - char fullpath[PATH_MAX]; - const char *destination = _nc_tic_dir(0); + int rc = -1; + const char *top = _nc_tic_dir(0); - if (path == destination || *path == '/') { - if (strlen(path) + 1 > sizeof(fullpath)) - return (-1); - (void) strcpy(fullpath, path); + if (src == top || _nc_is_abs_path(src)) { + if (strlen(src) + 1 <= limit) { + (void) strcpy(dst, src); + rc = 0; + } } else { - if (strlen(destination) + strlen(path) + 2 > sizeof(fullpath)) - return (-1); - (void) sprintf(fullpath, "%s/%s", destination, path); + if (strlen(top) + strlen(src) + 2 <= limit) { + (void) sprintf(dst, "%s/%s", top, src); + rc = 0; + } } +#if USE_HASHED_DB + if (rc == 0) { + if (_nc_is_dir_path(dst)) { + rc = -1; + } else { + unsigned have = strlen(dst); + if (have > 3 && strcmp(dst + have - 3, DBM_SUFFIX)) { + if (have + 3 <= limit) + strcat(dst, DBM_SUFFIX); + else + rc = -1; + } + } + } +#endif + return rc; +} - if ((rc = stat(path, &statbuf)) < 0) { - rc = mkdir(path, 0777); - } else { - if (_nc_access(path, R_OK | W_OK | X_OK) < 0) { +/* + * Make a database-root if it doesn't exist. + */ +static int +make_db_root(const char *path) +{ + int rc; + char fullpath[PATH_MAX]; + + if ((rc = make_db_path(fullpath, path, sizeof(fullpath))) == 0) { +#if USE_HASHED_DB + DB *capdbp; + + if ((capdbp = _nc_db_open(fullpath, TRUE)) == NULL) + rc = -1; + else if (_nc_db_close(capdbp) < 0) + rc = -1; +#else + struct stat statbuf; + + if ((rc = stat(path, &statbuf)) < 0) { + rc = mkdir(path, 0777); + } else if (_nc_access(path, R_OK | W_OK | X_OK) < 0) { rc = -1; /* permission denied */ } else if (!(S_ISDIR(statbuf.st_mode))) { rc = -1; /* not a directory */ } +#endif } return rc; } +/* + * Set the write directory for compiled entries. + */ NCURSES_EXPORT(void) _nc_set_writedir(char *dir) -/* set the write directory for compiled entries */ { const char *destination; char actual[PATH_MAX]; @@ -124,12 +200,12 @@ _nc_set_writedir(char *dir) (void) _nc_tic_dir(dir); destination = _nc_tic_dir(0); - if (make_directory(destination) < 0) { + if (make_db_root(destination) < 0) { char *home = _nc_home_terminfo(); if (home != 0) { destination = home; - if (make_directory(destination) < 0) + if (make_db_root(destination) < 0) _nc_err_abort("%s: permission denied (errno %d)", destination, errno); } @@ -139,51 +215,17 @@ _nc_set_writedir(char *dir) * Note: because of this code, this logic should be exercised * *once only* per run. */ +#if USE_HASHED_DB + make_db_path(actual, destination, sizeof(actual)); +#else if (chdir(_nc_tic_dir(destination)) < 0 || getcwd(actual, sizeof(actual)) == 0) _nc_err_abort("%s: not a directory", destination); +#endif _nc_keep_tic_dir(strdup(actual)); } /* - * check_writeable(char code) - * - * Miscellaneous initialisations - * - * Check for access rights to destination directories - * Create any directories which don't exist. - * Note: there's no reason to return the result of make_directory(), since - * this function is called only in instances where that has to succeed. - * - */ - -static void -check_writeable(int code) -{ - static const char dirnames[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - static bool verified[sizeof(dirnames)]; - - char dir[2]; - char *s = 0; - - if (code == 0 || (s = strchr(dirnames, code)) == 0) - _nc_err_abort("Illegal terminfo subdirectory \"%c\"", code); - - if (verified[s - dirnames]) - return; - - dir[0] = code; - dir[1] = '\0'; - if (make_directory(dir) < 0) { - _nc_err_abort("%s/%s: permission denied", _nc_tic_dir(0), dir); - } - - verified[s - dirnames] = TRUE; -} - -/* - * _nc_write_entry() - * * Save the compiled version of a description in the filesystem. * * make a copy of the name-list @@ -203,13 +245,18 @@ check_writeable(int code) * _nc_curr_line is properly set before the write_entry() call. */ -void -_nc_write_entry(TERMTYPE * const tp) +NCURSES_EXPORT(void) +_nc_write_entry(TERMTYPE *const tp) { +#if USE_HASHED_DB + + char buffer[MAX_ENTRY_SIZE + 1]; + unsigned limit = sizeof(buffer); + unsigned offset = 0; + +#else /* !USE_HASHED_DB */ + struct stat statbuf; - char name_list[MAX_TERMINFO_LENGTH]; - char *first_name, *other_names; - char *ptr; char filename[PATH_MAX]; char linkname[PATH_MAX]; #if USE_SYMLINKS @@ -219,12 +266,15 @@ _nc_write_entry(TERMTYPE * const tp) #define HAVE_LINK 1 #endif #endif /* USE_SYMLINKS */ + static int call_count; static time_t start_time; /* time at start of writes */ - if (call_count++ == 0) { - start_time = 0; - } +#endif /* USE_HASHED_DB */ + + char name_list[MAX_TERMINFO_LENGTH]; + char *first_name, *other_names; + char *ptr; (void) strcpy(name_list, tp->term_names); DEBUG(7, ("Name list = '%s'", name_list)); @@ -256,6 +306,55 @@ _nc_write_entry(TERMTYPE * const tp) _nc_set_type(first_name); +#if USE_HASHED_DB + if (write_object(tp, buffer + 1, &offset, limit - 1) != ERR) { + DB *capdb = _nc_db_open(_nc_tic_dir(0), TRUE); + DBT key, data; + + if (capdb != 0) { + buffer[0] = 0; + + memset(&key, 0, sizeof(key)); + key.data = tp->term_names; + key.size = strlen(tp->term_names); + + memset(&data, 0, sizeof(data)); + data.data = buffer; + data.size = offset + 1; + + _nc_db_put(capdb, &key, &data); + + buffer[0] = 2; + + key.data = name_list; + key.size = strlen(name_list); + + strcpy(buffer + 1, tp->term_names); + data.size = strlen(tp->term_names) + 1; + + _nc_db_put(capdb, &key, &data); + + while (*other_names != '\0') { + ptr = other_names++; + while (*other_names != '|' && *other_names != '\0') + other_names++; + + if (*other_names != '\0') + *(other_names++) = '\0'; + + key.data = ptr; + key.size = strlen(ptr); + + _nc_db_put(capdb, &key, &data); + } + _nc_db_close(capdb); + } + } +#else /* !USE_HASHED_DB */ + if (call_count++ == 0) { + start_time = 0; + } + if (strlen(first_name) > sizeof(filename) - 3) _nc_warning("terminal name too long."); @@ -355,14 +454,39 @@ _nc_write_entry(TERMTYPE * const tp) write_file(linkname, tp); #endif /* HAVE_LINK */ } +#endif /* USE_HASHED_DB */ } +static unsigned +fake_write(char *dst, + unsigned *offset, + unsigned limit, + char *src, + unsigned want, + unsigned size) +{ + int have = (limit - *offset); + + want *= size; + if (have > 0) { + if ((int) want > have) + want = have; + memcpy(dst + *offset, src, want); + *offset += want; + } else { + want = 0; + } + return (int) (want / size); +} + +#define Write(buf, size, count) fake_write(buffer, offset, limit, (char *) buf, count, size) + #undef LITTLE_ENDIAN /* BSD/OS defines this as a feature macro */ #define HI(x) ((x) / 256) #define LO(x) ((x) % 256) #define LITTLE_ENDIAN(p, x) (p)[0] = LO(x), (p)[1] = HI(x) -#define WRITE_STRING(str) (fwrite(str, sizeof(char), strlen(str) + 1, fp) == strlen(str) + 1) +#define WRITE_STRING(str) (Write(str, sizeof(char), strlen(str) + 1) == strlen(str) + 1) static int compute_offsets(char **Strings, unsigned strmax, short *offsets) @@ -402,10 +526,68 @@ convert_shorts(unsigned char *buf, short *Numbers, unsigned count) } #define even_boundary(value) \ - ((value) % 2 != 0 && fwrite(&zero, sizeof(char), 1, fp) != 1) + ((value) % 2 != 0 && Write(&zero, sizeof(char), 1) != 1) + +#if NCURSES_XNAMES +static unsigned +extended_Booleans(TERMTYPE *tp) +{ + unsigned short result = 0; + unsigned short i; + + for (i = 0; i < tp->ext_Booleans; ++i) { + if (tp->Booleans[BOOLCOUNT + i] == TRUE) + result = (i + 1); + } + return result; +} + +static unsigned +extended_Numbers(TERMTYPE *tp) +{ + unsigned short result = 0; + unsigned short i; + + for (i = 0; i < tp->ext_Numbers; ++i) { + if (tp->Numbers[NUMCOUNT + i] != ABSENT_NUMERIC) + result = (i + 1); + } + return result; +} + +static unsigned +extended_Strings(TERMTYPE *tp) +{ + unsigned short result = 0; + unsigned short i; + + for (i = 0; i < tp->ext_Strings; ++i) { + if (tp->Strings[STRCOUNT + i] != ABSENT_STRING) + result = (i + 1); + } + return result; +} + +/* + * _nc_align_termtype() will extend entries that are referenced in a use= + * clause - discard the unneeded data. + */ +static bool +extended_object(TERMTYPE *tp) +{ + bool result = FALSE; + + if (_nc_user_definable) { + result = ((extended_Booleans(tp) + + extended_Numbers(tp) + + extended_Strings(tp)) != 0); + } + return result; +} +#endif static int -write_object(FILE * fp, TERMTYPE * tp) +write_object(TERMTYPE *tp, char *buffer, unsigned *offset, unsigned limit) { char *namelist; size_t namelen, boolmax, nummax, strmax; @@ -464,9 +646,9 @@ write_object(FILE * fp, TERMTYPE * tp) LITTLE_ENDIAN(buf + 10, nextfree); /* write out the header */ - TRACE_OUT(("Header of %s @%ld", namelist, ftell(fp))); - if (fwrite(buf, 12, 1, fp) != 1 - || fwrite(namelist, sizeof(char), namelen, fp) != namelen) + TRACE_OUT(("Header of %s @%d", namelist, *offset)); + if (Write(buf, 12, 1) != 1 + || Write(namelist, sizeof(char), namelen) != namelen) return (ERR); for (i = 0; i < boolmax; i++) @@ -474,27 +656,27 @@ write_object(FILE * fp, TERMTYPE * tp) buf[i] = TRUE; else buf[i] = FALSE; - if (fwrite(buf, sizeof(char), boolmax, fp) != boolmax) + if (Write(buf, sizeof(char), boolmax) != boolmax) return (ERR); if (even_boundary(namelen + boolmax)) return (ERR); - TRACE_OUT(("Numerics begin at %04lx", ftell(fp))); + TRACE_OUT(("Numerics begin at %04x", *offset)); /* the numerics */ convert_shorts(buf, tp->Numbers, nummax); - if (fwrite(buf, 2, nummax, fp) != nummax) + if (Write(buf, 2, nummax) != nummax) return (ERR); - TRACE_OUT(("String offsets begin at %04lx", ftell(fp))); + TRACE_OUT(("String offsets begin at %04x", *offset)); /* the string offsets */ convert_shorts(buf, offsets, strmax); - if (fwrite(buf, 2, strmax, fp) != strmax) + if (Write(buf, 2, strmax) != strmax) return (ERR); - TRACE_OUT(("String table begins at %04lx", ftell(fp))); + TRACE_OUT(("String table begins at %04x", *offset)); /* the strings */ for (i = 0; i < strmax; i++) @@ -503,7 +685,7 @@ write_object(FILE * fp, TERMTYPE * tp) return (ERR); #if NCURSES_XNAMES - if (NUM_EXT_NAMES(tp)) { + if (extended_object(tp)) { unsigned extcnt = NUM_EXT_NAMES(tp); if (even_boundary(nextfree)) @@ -523,23 +705,23 @@ write_object(FILE * fp, TERMTYPE * tp) LITTLE_ENDIAN(buf + 4, tp->ext_Strings); LITTLE_ENDIAN(buf + 6, strmax); LITTLE_ENDIAN(buf + 8, nextfree); - TRACE_OUT(("WRITE extended-header @%ld", ftell(fp))); - if (fwrite(buf, 10, 1, fp) != 1) + TRACE_OUT(("WRITE extended-header @%d", *offset)); + if (Write(buf, 10, 1) != 1) return (ERR); - TRACE_OUT(("WRITE %d booleans @%ld", tp->ext_Booleans, ftell(fp))); + TRACE_OUT(("WRITE %d booleans @%d", tp->ext_Booleans, *offset)); if (tp->ext_Booleans - && fwrite(tp->Booleans + BOOLCOUNT, sizeof(char), - tp->ext_Booleans, fp) != tp->ext_Booleans) + && Write(tp->Booleans + BOOLCOUNT, sizeof(char), + tp->ext_Booleans) != tp->ext_Booleans) return (ERR); if (even_boundary(tp->ext_Booleans)) return (ERR); - TRACE_OUT(("WRITE %d numbers @%ld", tp->ext_Numbers, ftell(fp))); + TRACE_OUT(("WRITE %d numbers @%d", tp->ext_Numbers, *offset)); if (tp->ext_Numbers) { convert_shorts(buf, tp->Numbers + NUMCOUNT, tp->ext_Numbers); - if (fwrite(buf, 2, tp->ext_Numbers, fp) != tp->ext_Numbers) + if (Write(buf, 2, tp->ext_Numbers) != tp->ext_Numbers) return (ERR); } @@ -548,8 +730,8 @@ write_object(FILE * fp, TERMTYPE * tp) * in that order. */ convert_shorts(buf, offsets, strmax); - TRACE_OUT(("WRITE offsets @%ld", ftell(fp))); - if (fwrite(buf, 2, strmax, fp) != strmax) + TRACE_OUT(("WRITE offsets @%d", *offset)); + if (Write(buf, 2, strmax) != strmax) return (ERR); /* diff --git a/contrib/ncurses/ncurses/trace/README b/contrib/ncurses/ncurses/trace/README index a627a537a3d1..e658feccb873 100644 --- a/contrib/ncurses/ncurses/trace/README +++ b/contrib/ncurses/ncurses/trace/README @@ -1,4 +1,32 @@ --- $Id: README,v 1.1 1998/11/08 00:11:01 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 files in this directory (trace) support both the terminfo and ncurses libraries. Most of the functions are linked in only when the libraries diff --git a/contrib/ncurses/ncurses/trace/lib_trace.c b/contrib/ncurses/ncurses/trace/lib_trace.c index 29eecc0a2764..7f7812217999 100644 --- a/contrib/ncurses/ncurses/trace/lib_trace.c +++ b/contrib/ncurses/ncurses/trace/lib_trace.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,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,10 +29,16 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* * lib_trace.c - Tracing/Debugging routines + * + * The _tracef() function is originally from pcurses (by Pavel Curtis) in 1982. + * pcurses allowed one to enable/disable tracing using traceon() and traceoff() + * functions. ncurses provides a trace() function which allows one to + * selectively enable or disable several tracing features. */ #include <curses.priv.h> @@ -40,32 +46,38 @@ #include <ctype.h> -MODULE_ID("$Id: lib_trace.c,v 1.48 2001/10/20 20:35:25 tom Exp $") +MODULE_ID("$Id: lib_trace.c,v 1.59 2006/08/19 12:05:25 tom Exp $") -NCURSES_EXPORT_VAR(unsigned) -_nc_tracing = 0; /* always define this */ +NCURSES_EXPORT_VAR(unsigned) _nc_tracing = 0; /* always define this */ #ifdef TRACE -NCURSES_EXPORT_VAR(const char *) -_nc_tputs_trace = ""; -NCURSES_EXPORT_VAR(long) -_nc_outchars = 0; +NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace = ""; +NCURSES_EXPORT_VAR(long) _nc_outchars = 0; - static FILE *tracefp; /* default to writing to stderr */ +static FILE *tracefp = 0; /* default to writing to stderr */ NCURSES_EXPORT(void) -trace(const unsigned int tracelevel GCC_UNUSED) +trace(const unsigned int tracelevel) { static bool been_here = FALSE; - static char my_name[] = "trace"; + static char my_name[PATH_MAX]; - if (!been_here && tracelevel) { - been_here = TRUE; + if ((tracefp == 0) && tracelevel) { + const char *mode = been_here ? "ab" : "wb"; + + if (*my_name == '\0') { + if (getcwd(my_name, sizeof(my_name) - 10) == 0) { + perror("curses: Can't get working directory"); + exit(EXIT_FAILURE); + } + strcat(my_name, "/trace"); + } + been_here = TRUE; _nc_tracing = tracelevel; if (_nc_access(my_name, W_OK) < 0 - || (tracefp = fopen(my_name, "wb")) == 0) { - perror("curses: Can't open 'trace' file: "); + || (tracefp = fopen(my_name, mode)) == 0) { + perror("curses: Can't open 'trace' file"); exit(EXIT_FAILURE); } /* Try to set line-buffered mode, or (failing that) unbuffered, @@ -77,8 +89,16 @@ trace(const unsigned int tracelevel GCC_UNUSED) #elif HAVE_SETBUF /* POSIX */ (void) setbuffer(tracefp, (char *) 0); #endif - _tracef("TRACING NCURSES version %s (tracelevel=%#x)", - curses_version(), tracelevel); + _tracef("TRACING NCURSES version %s.%d (tracelevel=%#x)", + NCURSES_VERSION, + NCURSES_VERSION_PATCH, + tracelevel); + } else if (tracelevel == 0) { + if (tracefp != 0) { + fclose(tracefp); + tracefp = 0; + } + _nc_tracing = tracelevel; } else if (_nc_tracing != tracelevel) { _nc_tracing = tracelevel; _tracef("tracelevel=%#x", tracelevel); @@ -94,7 +114,7 @@ _tracef(const char *fmt,...) va_list ap; bool before = FALSE; bool after = FALSE; - int doit = _nc_tracing; + unsigned doit = _nc_tracing; int save_err = errno; if (strlen(fmt) >= sizeof(Called) - 1) { @@ -133,6 +153,14 @@ _tracef(const char *fmt,...) errno = save_err; } +/* Trace 'bool' return-values */ +NCURSES_EXPORT(NCURSES_BOOL) +_nc_retrace_bool(NCURSES_BOOL code) +{ + T((T_RETURN("%s"), code ? "TRUE" : "FALSE")); + return code; +} + /* Trace 'int' return-values */ NCURSES_EXPORT(int) _nc_retrace_int(int code) @@ -141,6 +169,14 @@ _nc_retrace_int(int code) return code; } +/* Trace 'unsigned' return-values */ +NCURSES_EXPORT(unsigned) +_nc_retrace_unsigned(unsigned code) +{ + T((T_RETURN("%#x"), code)); + return code; +} + /* Trace 'char*' return-values */ NCURSES_EXPORT(char *) _nc_retrace_ptr(char *code) @@ -149,9 +185,33 @@ _nc_retrace_ptr(char *code) return code; } +/* Trace 'const char*' return-values */ +NCURSES_EXPORT(const char *) +_nc_retrace_cptr(const char *code) +{ + T((T_RETURN("%s"), _nc_visbuf(code))); + return code; +} + +/* Trace 'NCURSES_CONST void*' return-values */ +NCURSES_EXPORT(NCURSES_CONST void *) +_nc_retrace_cvoid_ptr(NCURSES_CONST void *code) +{ + T((T_RETURN("%p"), code)); + return code; +} + +/* Trace 'void*' return-values */ +NCURSES_EXPORT(void *) +_nc_retrace_void_ptr(void *code) +{ + T((T_RETURN("%p"), code)); + return code; +} + /* Trace 'SCREEN *' return-values */ NCURSES_EXPORT(SCREEN *) -_nc_retrace_sp(SCREEN * code) +_nc_retrace_sp(SCREEN *code) { T((T_RETURN("%p"), code)); return code; diff --git a/contrib/ncurses/ncurses/trace/lib_traceatr.c b/contrib/ncurses/ncurses/trace/lib_traceatr.c index 870624f3f514..ee6cf5f1f3d3 100644 --- a/contrib/ncurses/ncurses/trace/lib_traceatr.c +++ b/contrib/ncurses/ncurses/trace/lib_traceatr.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 * @@ -27,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas Dickey 1996-2001 * + * Author: Thomas Dickey 1996-on * * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ @@ -39,20 +39,40 @@ #include <curses.priv.h> #include <term.h> /* acs_chars */ -MODULE_ID("$Id: lib_traceatr.c,v 1.42 2002/06/16 00:35:01 tom Exp $") +MODULE_ID("$Id: lib_traceatr.c,v 1.56 2006/12/02 21:18:28 tom Exp $") -#define COLOR_OF(c) (c < 0 || c > 7 ? "default" : colors[c].name) +#define COLOR_OF(c) ((c < 0) ? "default" : (c > 7 ? color_of(c) : colors[c].name)) #ifdef TRACE static const char l_brace[] = {L_BRACE, 0}; static const char r_brace[] = {R_BRACE, 0}; +#ifndef USE_TERMLIB +static char * +color_of(int c) +{ + static char buffer[2][80]; + static int sel; + static int last = -1; + + if (c != last) { + last = c; + sel = !sel; + if (c == COLOR_DEFAULT) + strcpy(buffer[sel], "default"); + else + sprintf(buffer[sel], "color%d", c); + } + return buffer[sel]; +} +#endif /* !USE_TERMLIB */ + NCURSES_EXPORT(char *) -_traceattr2(int bufnum, attr_t newmode) +_traceattr2(int bufnum, chtype newmode) { char *buf = _nc_trace_buf(bufnum, BUFSIZ); - char *tmp = buf; + char temp[80]; static const struct { unsigned int val; const char *name; @@ -73,7 +93,9 @@ _traceattr2(int bufnum, attr_t newmode) { A_COLOR, "A_COLOR" }, /* *INDENT-ON* */ - }, + } +#ifndef USE_TERMLIB + , colors[] = { /* *INDENT-OFF* */ @@ -87,44 +109,51 @@ _traceattr2(int bufnum, attr_t newmode) { COLOR_WHITE, "COLOR_WHITE" }, /* *INDENT-ON* */ - }; + } +#endif /* !USE_TERMLIB */ + ; size_t n; unsigned save_nc_tracing = _nc_tracing; _nc_tracing = 0; - strcpy(tmp++, l_brace); + strcpy(buf, l_brace); for (n = 0; n < SIZEOF(names); n++) { if ((newmode & names[n].val) != 0) { if (buf[1] != '\0') - strcat(tmp, "|"); - strcat(tmp, names[n].name); - tmp += strlen(tmp); + buf = _nc_trace_bufcat(bufnum, "|"); + buf = _nc_trace_bufcat(bufnum, names[n].name); if (names[n].val == A_COLOR) { short pairnum = PAIR_NUMBER(newmode); +#ifdef USE_TERMLIB + /* pair_content lives in libncurses */ + (void) sprintf(temp, "{%d}", pairnum); +#else short fg, bg; - if (pair_content(pairnum, &fg, &bg) == OK) - (void) sprintf(tmp, + if (pair_content(pairnum, &fg, &bg) == OK) { + (void) sprintf(temp, "{%d = {%s, %s}}", pairnum, COLOR_OF(fg), - COLOR_OF(bg) - ); - else - (void) sprintf(tmp, "{%d}", pairnum); + COLOR_OF(bg)); + } else { + (void) sprintf(temp, "{%d}", pairnum); + } +#endif + buf = _nc_trace_bufcat(bufnum, temp); } } } if (ChAttrOf(newmode) == A_NORMAL) { if (buf[1] != '\0') - strcat(tmp, "|"); - strcat(tmp, "A_NORMAL"); + (void) _nc_trace_bufcat(bufnum, "|"); + (void) _nc_trace_bufcat(bufnum, "A_NORMAL"); } _nc_tracing = save_nc_tracing; - return (strcat(buf, r_brace)); + return (_nc_trace_bufcat(bufnum, r_brace)); } NCURSES_EXPORT(char *) @@ -146,7 +175,7 @@ _nc_altcharset_name(attr_t attr, chtype ch) { const char *result = 0; - if (attr & A_ALTCHARSET) { + if ((attr & A_ALTCHARSET) && (acs_chars != 0)) { char *cp; char *found = 0; static const struct { @@ -214,20 +243,21 @@ _nc_altcharset_name(attr_t attr, chtype ch) NCURSES_EXPORT(char *) _tracechtype2(int bufnum, chtype ch) { - char *buf = _nc_trace_buf(bufnum, BUFSIZ); const char *found; - strcpy(buf, l_brace); + strcpy(_nc_trace_buf(bufnum, BUFSIZ), l_brace); if ((found = _nc_altcharset_name(ChAttrOf(ch), ch)) != 0) { - (void) strcat(buf, found); + (void) _nc_trace_bufcat(bufnum, found); } else - (void) strcat(buf, _tracechar(ChCharOf(ch))); + (void) _nc_trace_bufcat(bufnum, _tracechar((int)ChCharOf(ch))); - if (ChAttrOf(ch) != A_NORMAL) - (void) sprintf(buf + strlen(buf), " | %s", + if (ChAttrOf(ch) != A_NORMAL) { + (void) _nc_trace_bufcat(bufnum, " | "); + (void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, ChAttrOf(ch))); + } - return (strcat(buf, r_brace)); + return (_nc_trace_bufcat(bufnum, r_brace)); } NCURSES_EXPORT(char *) @@ -237,8 +267,8 @@ _tracechtype (chtype ch) } /* Trace 'chtype' return-values */ -NCURSES_EXPORT(attr_t) -_nc_retrace_chtype (attr_t code) +NCURSES_EXPORT(chtype) +_nc_retrace_chtype (chtype code) { T((T_RETURN("%s"), _tracechtype(code))); return code; @@ -255,38 +285,45 @@ _tracecchar_t2 (int bufnum, const cchar_t *ch) strcpy(buf, l_brace); if (ch != 0) { attr = AttrOfD(ch); - if ((found = _nc_altcharset_name(attr, CharOfD(ch))) != 0) { - (void) strcat(buf, found); + if ((found = _nc_altcharset_name(attr, (chtype) CharOfD(ch))) != 0) { + (void) _nc_trace_bufcat(bufnum, found); attr &= ~A_ALTCHARSET; - } else if (!isnac(CHDEREF(ch))) { + } else if (isWidecExt(CHDEREF(ch))) { + (void) _nc_trace_bufcat(bufnum, "{NAC}"); + attr &= ~A_CHARTEXT; + } else { PUTC_DATA; int n; - memset (&PUT_st, '\0', sizeof (PUT_st)); - PUTC_i = 0; - (void) strcat(buf, "{ "); - do { - PUTC_ch = PUTC_i < CCHARW_MAX ? ch->chars[PUTC_i] : L'\0'; - PUTC_n = wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st); + PUTC_INIT; + (void) _nc_trace_bufcat(bufnum, "{ "); + for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { + PUTC_ch = ch->chars[PUTC_i]; if (PUTC_ch == L'\0') - --PUTC_n; - if (PUTC_n <= 0) break; + PUTC_n = wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st); + if (PUTC_n <= 0) { + if (PUTC_ch != L'\0') { + /* it could not be a multibyte sequence */ + (void) _nc_trace_bufcat(bufnum, _tracechar(UChar(ch->chars[PUTC_i]))); + } + break; + } for (n = 0; n < PUTC_n; n++) { if (n) - (void) strcat(buf, ", "); - (void) strcat(buf, _tracechar(UChar(PUTC_buf[n]))); + (void) _nc_trace_bufcat(bufnum, ", "); + (void) _nc_trace_bufcat(bufnum, _tracechar(UChar(PUTC_buf[n]))); } - ++PUTC_i; - } while (PUTC_ch != L'\0'); - (void) strcat(buf, " }"); + } + (void) _nc_trace_bufcat(bufnum, " }"); + } + if (attr != A_NORMAL) { + (void) _nc_trace_bufcat(bufnum, " | "); + (void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr)); } - if (attr != A_NORMAL) - (void) sprintf(buf + strlen(buf), " | %s", - _traceattr2(bufnum + 20, attr)); } - return (strcat(buf, r_brace)); + return (_nc_trace_bufcat(bufnum, r_brace)); } NCURSES_EXPORT(char *) diff --git a/contrib/ncurses/ncurses/trace/lib_tracebits.c b/contrib/ncurses/ncurses/trace/lib_tracebits.c index e681862649af..d9defd0cc9d6 100644 --- a/contrib/ncurses/ncurses/trace/lib_tracebits.c +++ b/contrib/ncurses/ncurses/trace/lib_tracebits.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 * @@ -29,12 +29,13 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ #include <curses.priv.h> #include <term.h> /* cur_term */ -MODULE_ID("$Id: lib_tracebits.c,v 1.12 2002/05/25 14:35:07 tom Exp $") +MODULE_ID("$Id: lib_tracebits.c,v 1.13 2006/12/10 01:33:00 tom Exp $") #if SVR4_TERMIO && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE @@ -106,6 +107,7 @@ _nc_trace_ttymode(TTY * tty) }, oflags[] = { {OPOST, "OPOST"}, + {OFLAGS_TABS, "XTABS"}, {0, NULL} #define ALLOUT (OPOST) }, cflags[] = diff --git a/contrib/ncurses/ncurses/trace/lib_tracechr.c b/contrib/ncurses/ncurses/trace/lib_tracechr.c index 2f33391b5505..34a2bb616f29 100644 --- a/contrib/ncurses/ncurses/trace/lib_tracechr.c +++ b/contrib/ncurses/ncurses/trace/lib_tracechr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2001,2002 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 * ****************************************************************************/ /* @@ -36,19 +37,36 @@ */ #include <curses.priv.h> -MODULE_ID("$Id: lib_tracechr.c,v 1.9 2002/05/25 23:34:19 tom Exp $") +#include <ctype.h> + +MODULE_ID("$Id: lib_tracechr.c,v 1.12 2005/04/16 16:55:46 tom Exp $") #ifdef TRACE NCURSES_EXPORT(char *) _tracechar(int ch) { - static char crep[40]; - (void) sprintf(crep, "'%.30s' = %#03o", - ((ch > KEY_MIN || ch < 0) - ? keyname(ch) - : unctrl(ch)), - ch); - return (crep); + static char result[40]; + NCURSES_CONST char *name; + + if (ch > KEY_MIN || ch < 0) { + name = keyname(ch); + if (name == 0 || *name == '\0') + name = "NULL"; + (void) sprintf(result, "'%.30s' = %#03o", name, ch); + } else if (!is8bits(ch) || !isprint(UChar(ch))) { + /* + * workaround for glibc bug: + * sprintf changes the result from unctrl() to an empty string if it + * does not correspond to a valid multibyte sequence. + */ + (void) sprintf(result, "%#03o", ch); + } else { + name = unctrl((chtype) ch); + if (name == 0 || *name == 0) + name = "null"; /* shouldn't happen */ + (void) sprintf(result, "'%.30s' = %#03o", name, ch); + } + return (result); } #else empty_module(_nc_lib_tracechr) diff --git a/contrib/ncurses/ncurses/trace/lib_tracedmp.c b/contrib/ncurses/ncurses/trace/lib_tracedmp.c index 8f8753640e0c..41739a92527c 100644 --- a/contrib/ncurses/ncurses/trace/lib_tracedmp.c +++ b/contrib/ncurses/ncurses/trace/lib_tracedmp.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 * @@ -27,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey 1996-2001 * + * Author: Thomas E. Dickey 1996-on * * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ @@ -39,7 +39,7 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$Id: lib_tracedmp.c,v 1.22 2001/11/03 15:45:35 tom Exp $") +MODULE_ID("$Id: lib_tracedmp.c,v 1.27 2006/10/14 20:43:31 tom Exp $") #ifdef TRACE NCURSES_EXPORT(void) @@ -53,9 +53,13 @@ _tracedump(const char *name, WINDOW *win) /* compute narrowest possible display width */ for (width = i = 0; i <= win->_maxy; ++i) { n = 0; - for (j = 0; j <= win->_maxx; ++j) - if (CharOf(win->_line[i].text[j]) != L(' ')) + for (j = 0; j <= win->_maxx; ++j) { + if (CharOf(win->_line[i].text[j]) != L(' ') + || AttrOf(win->_line[i].text[j]) != A_NORMAL + || GetPair(win->_line[i].text[j]) != 0) { n = j; + } + } if (n > width) width = n; @@ -64,7 +68,7 @@ _tracedump(const char *name, WINDOW *win) ++width; if (++width + 1 > (int) used) { used = 2 * (width + 1); - buf = _nc_doalloc(buf, used); + buf = typeRealloc(char, used, buf); } for (n = 0; n <= win->_maxy; ++n) { @@ -89,24 +93,34 @@ _tracedump(const char *name, WINDOW *win) : '?'; } ep[j] = '\0'; - _tracef("%s[%2d] %3d%3d ='%s'", + _tracef("%s[%2d] %3ld%3ld ='%s'", name, n, - win->_line[n].firstchar, - win->_line[n].lastchar, + (long) win->_line[n].firstchar, + (long) win->_line[n].lastchar, ep); /* dump A_COLOR part, will screw up if there are more than 96 */ havecolors = FALSE; for (j = 0; j < width; ++j) - if (AttrOf(win->_line[n].text[j]) & A_COLOR) { + if (GetPair(win->_line[n].text[j]) != 0) { havecolors = TRUE; break; } if (havecolors) { ep = buf; - for (j = 0; j < width; ++j) - ep[j] = UChar(CharOf(win->_line[n].text[j]) >> - NCURSES_ATTR_SHIFT) + ' '; + for (j = 0; j < width; ++j) { + int pair = GetPair(win->_line[n].text[j]); + if (pair >= 52) + ep[j] = '?'; + else if (pair >= 36) + ep[j] = pair + 'A'; + else if (pair >= 10) + ep[j] = pair + 'a'; + else if (pair >= 1) + ep[j] = pair + '0'; + else + ep[j] = ' '; + } ep[j] = '\0'; _tracef("%*s[%2d]%*s='%s'", (int) strlen(name), "colors", n, 8, " ", buf); @@ -135,6 +149,7 @@ _tracedump(const char *name, WINDOW *win) } #if NO_LEAKS free(buf); + buf = 0; used = 0; #endif } diff --git a/contrib/ncurses/ncurses/trace/lib_tracemse.c b/contrib/ncurses/ncurses/trace/lib_tracemse.c index f4a100b6eb43..98290a1efb0e 100644 --- a/contrib/ncurses/ncurses/trace/lib_tracemse.c +++ b/contrib/ncurses/ncurses/trace/lib_tracemse.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,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 * ****************************************************************************/ /* @@ -37,48 +38,81 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_tracemse.c,v 1.10 2002/01/12 22:32:25 tom Exp $") +MODULE_ID("$Id: lib_tracemse.c,v 1.12 2005/06/11 19:53:50 tom Exp $") #ifdef TRACE NCURSES_EXPORT(char *) _tracemouse(MEVENT const *ep) { - static char buf[80]; + /* + * hmm - format is no longer than 80 columns, there are 5 numbers that + * could at most have 10 digits, and the mask contains no more than 32 bits + * with each bit representing less than 15 characters. Usually the whole + * string is less than 80 columns, but this buffer size is an absolute + * limit. + */ + static char buf[80 + (5 * 10) + (32 * 15)]; (void) sprintf(buf, "id %2d at (%2d, %2d, %2d) state %4lx = {", - ep->id, ep->x, ep->y, ep->z, ep->bstate); + ep->id, + ep->x, + ep->y, + ep->z, + (unsigned long) ep->bstate); #define SHOW(m, s) if ((ep->bstate & m) == m) strcat(strcat(buf, s), ", ") + SHOW(BUTTON1_RELEASED, "release-1"); SHOW(BUTTON1_PRESSED, "press-1"); SHOW(BUTTON1_CLICKED, "click-1"); SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1"); SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1"); +#if NCURSES_MOUSE_VERSION == 1 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1"); +#endif + SHOW(BUTTON2_RELEASED, "release-2"); SHOW(BUTTON2_PRESSED, "press-2"); SHOW(BUTTON2_CLICKED, "click-2"); SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2"); SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2"); +#if NCURSES_MOUSE_VERSION == 1 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2"); +#endif + SHOW(BUTTON3_RELEASED, "release-3"); SHOW(BUTTON3_PRESSED, "press-3"); SHOW(BUTTON3_CLICKED, "click-3"); SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3"); SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3"); +#if NCURSES_MOUSE_VERSION == 1 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3"); +#endif + SHOW(BUTTON4_RELEASED, "release-4"); SHOW(BUTTON4_PRESSED, "press-4"); SHOW(BUTTON4_CLICKED, "click-4"); SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4"); SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4"); +#if NCURSES_MOUSE_VERSION == 1 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4"); +#endif + +#if NCURSES_MOUSE_VERSION == 2 + SHOW(BUTTON5_RELEASED, "release-5"); + SHOW(BUTTON5_PRESSED, "press-5"); + SHOW(BUTTON5_CLICKED, "click-5"); + SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5"); + SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5"); +#endif + SHOW(BUTTON_CTRL, "ctrl"); SHOW(BUTTON_SHIFT, "shift"); SHOW(BUTTON_ALT, "alt"); SHOW(ALL_MOUSE_EVENTS, "all-events"); SHOW(REPORT_MOUSE_POSITION, "position"); + #undef SHOW if (buf[strlen(buf) - 1] == ' ') diff --git a/contrib/ncurses/ncurses/trace/trace_buf.c b/contrib/ncurses/ncurses/trace/trace_buf.c index 15748d423d9e..85b4fbe682e8 100644 --- a/contrib/ncurses/ncurses/trace/trace_buf.c +++ b/contrib/ncurses/ncurses/trace/trace_buf.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 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 * @@ -35,21 +35,40 @@ #include <curses.priv.h> -MODULE_ID("$Id: trace_buf.c,v 1.10 2001/04/21 21:19:18 tom Exp $") +MODULE_ID("$Id: trace_buf.c,v 1.12 2003/03/15 21:21:36 tom Exp $") typedef struct { char *text; size_t size; } LIST; -NCURSES_EXPORT(char *) -_nc_trace_buf(int bufnum, size_t want) +static char * +_nc_trace_alloc(int bufnum, size_t want) { + char *result = 0; static LIST *list; static size_t have; + if (bufnum >= 0) { + if ((size_t) (bufnum + 1) > have) { + size_t need = (bufnum + 1) * 2; + if ((list = typeRealloc(LIST, need, list)) == 0) + return (0); + while (need > have) + list[have++].text = 0; + } + + if (list[bufnum].text == 0 + || want > list[bufnum].size) { + if ((list[bufnum].text = typeRealloc(char, want, list[bufnum].text)) + != 0) + list[bufnum].size = want; + } + + result = list[bufnum].text; + } #if NO_LEAKS - if (bufnum < 0) { + else { if (have) { while (have--) { if (list[have].text != 0) @@ -57,26 +76,34 @@ _nc_trace_buf(int bufnum, size_t want) } free(list); } - return 0; } #endif + return result; +} - if ((size_t) (bufnum + 1) > have) { - size_t need = (bufnum + 1) * 2; - if ((list = typeRealloc(LIST, need, list)) == 0) - return (0); - while (need > have) - list[have++].text = 0; - } +/* + * (re)Allocate a buffer big enough for the caller's wants. + */ +NCURSES_EXPORT(char *) +_nc_trace_buf(int bufnum, size_t want) +{ + char *result = _nc_trace_alloc(bufnum, want); + if (result != 0) + *result = '\0'; + return result; +} - if (list[bufnum].text == 0 - || want > list[bufnum].size) { - if ((list[bufnum].text = typeRealloc(char, want, list[bufnum].text)) - != 0) - list[bufnum].size = want; - } +/* + * Append a new string to an existing buffer. + */ +NCURSES_EXPORT(char *) +_nc_trace_bufcat(int bufnum, const char *value) +{ + char *buffer = _nc_trace_alloc(bufnum, 0); + size_t have = strlen(buffer); + + buffer = _nc_trace_alloc(bufnum, 1 + have + strlen(value)); + (void) strcpy(buffer + have, value); - if (list[bufnum].text != 0) - *(list[bufnum].text) = '\0'; - return list[bufnum].text; + return buffer; } diff --git a/contrib/ncurses/ncurses/trace/varargs.c b/contrib/ncurses/ncurses/trace/varargs.c index 7bcb7b55d42c..aee2010546a4 100644 --- a/contrib/ncurses/ncurses/trace/varargs.c +++ b/contrib/ncurses/ncurses/trace/varargs.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2001 Free Software Foundation, Inc. * + * Copyright (c) 2001-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 * @@ -34,17 +34,19 @@ #include <ctype.h> -MODULE_ID("$Id: varargs.c,v 1.2 2002/06/01 16:16:00 tom Exp $") +MODULE_ID("$Id: varargs.c,v 1.4 2003/05/24 21:10:28 tom Exp $") #ifdef TRACE +#define MAX_PARMS 10 + typedef enum { atUnknown = 0, atInteger, atFloat, atPoint, atString } ARGTYPE; #define VA_INT(type) ival = va_arg(ap, type) #define VA_FLT(type) fval = va_arg(ap, type) -#define VA_PTR(type) pval = (void *)va_arg(ap, type) +#define VA_PTR(type) pval = (char *)va_arg(ap, type) #define VA_STR(type) sval = va_arg(ap, type) /* @@ -58,6 +60,8 @@ _nc_varargs(const char *fmt, va_list ap) static size_t result_len; char buffer[BUFSIZ]; + const char *param; + int n; if (fmt == 0 || *fmt == '\0') return dummy; @@ -75,14 +79,16 @@ _nc_varargs(const char *fmt, va_list ap) int done = FALSE; int ival = 0; int type = 0; + ARGTYPE parm[MAX_PARMS]; + int parms = 0; ARGTYPE used = atUnknown; while (*++fmt != '\0' && !done) { if (*fmt == '*') { VA_INT(int); - used = atInteger; - break; + if (parms < MAX_PARMS) + parm[parms++] = atInteger; } else if (isalpha(UChar(*fmt))) { done = TRUE; switch (*fmt) { @@ -135,30 +141,34 @@ _nc_varargs(const char *fmt, va_list ap) } else if (*fmt == '%') { done = TRUE; } - if (used != atUnknown) { - const char *param = buffer; - switch (used) { - case atInteger: - sprintf(buffer, "%d", ival); - break; - case atFloat: - sprintf(buffer, "%f", fval); - break; - case atPoint: - sprintf(buffer, "%p", pval); - break; - case atString: - param = _nc_visbuf2(1, sval); - break; - default: - strcpy(buffer, "?"); - break; + if (used != atUnknown && parms < MAX_PARMS) { + parm[parms++] = used; + for (n = 0; n < parms; ++n) { + used = parm[n]; + param = buffer; + switch (used) { + case atInteger: + sprintf(buffer, "%d", ival); + break; + case atFloat: + sprintf(buffer, "%f", fval); + break; + case atPoint: + sprintf(buffer, "%p", pval); + break; + case atString: + param = _nc_visbuf2(1, sval); + break; + default: + strcpy(buffer, "?"); + break; + } + result_len += strlen(param) + 2; + result_buf = typeRealloc(char, result_len, result_buf); + sprintf(result_buf + strlen(result_buf), ", %s", param); } - result_len += strlen(param) + 2; - result_buf = typeRealloc(char, result_len, result_buf); - sprintf(result_buf + strlen(result_buf), ",%s", param); - used = atUnknown; } + used = atUnknown; } } else { fmt++; diff --git a/contrib/ncurses/ncurses/trace/visbuf.c b/contrib/ncurses/ncurses/trace/visbuf.c index 5f2460f3ed2c..0540ee6d8184 100644 --- a/contrib/ncurses/ncurses/trace/visbuf.c +++ b/contrib/ncurses/ncurses/trace/visbuf.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2001 Free Software Foundation, Inc. * + * Copyright (c) 2001-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,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey 1996-2001 * + * Author: Thomas E. Dickey 1996-on * * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ @@ -36,12 +36,17 @@ * visbuf.c - Tracing/Debugging support routines */ +#define NEED_NCURSES_CH_T #include <curses.priv.h> #include <tic.h> #include <ctype.h> -MODULE_ID("$Id: visbuf.c,v 1.3 2001/11/10 23:47:51 tom Exp $") +MODULE_ID("$Id: visbuf.c,v 1.21 2006/12/02 21:20:28 tom Exp $") + +static const char d_quote[] = {D_QUOTE, 0}; +static const char l_brace[] = {L_BRACE, 0}; +static const char r_brace[] = {R_BRACE, 0}; static char * _nc_vischar(char *tp, unsigned c) @@ -68,14 +73,15 @@ _nc_vischar(char *tp, unsigned c) *tp++ = '^'; *tp++ = '@' + c; } else { - sprintf(tp, "\\%03lo", ChCharOf(c)); + sprintf(tp, "\\%03lo", (unsigned long) ChCharOf(c)); tp += strlen(tp); } + *tp = 0; return tp; } -NCURSES_EXPORT(const char *) -_nc_visbuf2(int bufnum, const char *buf) +static const char * +_nc_visbuf2n(int bufnum, const char *buf, int len) { char *vbuf; char *tp; @@ -86,17 +92,20 @@ _nc_visbuf2(int bufnum, const char *buf) if (buf == CANCELLED_STRING) return ("(cancelled)"); + if (len < 0) + len = strlen(buf); + #ifdef TRACE - tp = vbuf = _nc_trace_buf(bufnum, (strlen(buf) * 4) + 5); + tp = vbuf = _nc_trace_buf(bufnum, (unsigned) (len * 4) + 5); #else { static char *mybuf[2]; - mybuf[bufnum] = _nc_doalloc(mybuf[bufnum], (strlen(buf) * 4) + 5); + mybuf[bufnum] = typeRealloc(char, (unsigned) (len * 4) + 5, mybuf[bufnum]); tp = vbuf = mybuf[bufnum]; } #endif *tp++ = D_QUOTE; - while ((c = *buf++) != '\0') { + while ((--len >= 0) && (c = *buf++) != '\0') { tp = _nc_vischar(tp, UChar(c)); } *tp++ = D_QUOTE; @@ -105,35 +114,72 @@ _nc_visbuf2(int bufnum, const char *buf) } NCURSES_EXPORT(const char *) +_nc_visbuf2(int bufnum, const char *buf) +{ + return _nc_visbuf2n(bufnum, buf, -1); +} + +NCURSES_EXPORT(const char *) _nc_visbuf(const char *buf) { return _nc_visbuf2(0, buf); } -#if USE_WIDEC_SUPPORT -#ifdef TRACE NCURSES_EXPORT(const char *) -_nc_viswbuf2(int bufnum, const wchar_t * buf) +_nc_visbufn(const char *buf, int len) +{ + return _nc_visbuf2n(0, buf, len); +} + +#ifdef TRACE +#if USE_WIDEC_SUPPORT + +#if defined(USE_TERMLIB) +#define _nc_wchstrlen _my_wchstrlen +static int +_nc_wchstrlen(const cchar_t *s) +{ + int result = 0; + while (CharOf(s[result]) != L'\0') { + result++; + } + return result; +} +#endif + +static const char * +_nc_viswbuf2n(int bufnum, const wchar_t *buf, int len) { char *vbuf; char *tp; - int c; + wchar_t c; if (buf == 0) return ("(null)"); + if (len < 0) + len = wcslen(buf); + #ifdef TRACE - tp = vbuf = _nc_trace_buf(bufnum, (wcslen(buf) * 4) + 5); + tp = vbuf = _nc_trace_buf(bufnum, (unsigned) (len * 4) + 5); #else { static char *mybuf[2]; - mybuf[bufnum] = _nc_doalloc(mybuf[bufnum], (wcslen(buf) * 4) + 5); + mybuf[bufnum] = typeRealloc(char, (unsigned) (len * 4) + 5, mybuf[bufnum]); tp = vbuf = mybuf[bufnum]; } #endif *tp++ = D_QUOTE; - while ((c = *buf++) != '\0') { - tp = _nc_vischar(tp, ChCharOf(c)); + while ((--len >= 0) && (c = *buf++) != '\0') { + char temp[CCHARW_MAX + 80]; + int j = wctomb(temp, c), k; + if (j <= 0) { + sprintf(temp, "\\u%08X", (wint_t) c); + j = strlen(temp); + } + for (k = 0; k < j; ++k) { + tp = _nc_vischar(tp, UChar(temp[k])); + } } *tp++ = D_QUOTE; *tp++ = '\0'; @@ -141,92 +187,125 @@ _nc_viswbuf2(int bufnum, const wchar_t * buf) } NCURSES_EXPORT(const char *) -_nc_viswbuf(const wchar_t * buf) +_nc_viswbuf2(int bufnum, const wchar_t *buf) +{ + return _nc_viswbuf2n(bufnum, buf, -1); +} + +NCURSES_EXPORT(const char *) +_nc_viswbuf(const wchar_t *buf) { return _nc_viswbuf2(0, buf); } NCURSES_EXPORT(const char *) -_nc_viscbuf2(int bufnum, const cchar_t * buf, int len) +_nc_viswbufn(const wchar_t *buf, int len) +{ + return _nc_viswbuf2n(0, buf, len); +} + +/* this special case is used for wget_wstr() */ +NCURSES_EXPORT(const char *) +_nc_viswibuf(const wint_t *buf) +{ + static wchar_t *mybuf; + static unsigned mylen; + unsigned n; + + for (n = 0; buf[n] != 0; ++n) ; + if (mylen < ++n) { + mylen = n + 80; + if (mybuf != 0) + mybuf = typeRealloc(wchar_t, mylen, mybuf); + else + mybuf = typeMalloc(wchar_t, mylen); + } + for (n = 0; buf[n] != 0; ++n) + mybuf[n] = (wchar_t) buf[n]; + + return _nc_viswbuf2(0, mybuf); +} +#endif /* USE_WIDEC_SUPPORT */ + +/* use these functions for displaying parts of a line within a window */ +NCURSES_EXPORT(const char *) +_nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len) { - size_t have = BUFSIZ; - char *result = _nc_trace_buf(bufnum, have); - char *tp = result; - int n; - bool same = TRUE; - attr_t attr = A_NORMAL; + char *result = _nc_trace_buf(bufnum, BUFSIZ); + int first; const char *found; +#if USE_WIDEC_SUPPORT if (len < 0) len = _nc_wchstrlen(buf); - - for (n = 1; n < len; n++) { - if (AttrOf(buf[n]) != AttrOf(buf[0])) { - same = FALSE; - break; - } - } +#endif /* USE_WIDEC_SUPPORT */ /* - * If the rendition is the same for the whole string, display it as a - * quoted string, followed by the rendition. Otherwise, use the more - * detailed trace function that displays each character separately. + * Display one or more strings followed by attributes. */ - if (same) { - *tp++ = D_QUOTE; - while (len-- > 0) { - if ((found = _nc_altcharset_name(attr, CharOfD(buf))) != 0) { - (void) strcpy(tp, found); - tp += strlen(tp); + first = 0; + while (first < len) { + attr_t attr = AttrOf(buf[first]); + int last = len - 1; + int j; + + for (j = first + 1; j < len; ++j) { + if (!SameAttrOf(buf[j], buf[first])) { + last = j - 1; + break; + } + } + + result = _nc_trace_bufcat(bufnum, l_brace); + result = _nc_trace_bufcat(bufnum, d_quote); + for (j = first; j <= last; ++j) { + if ((found = _nc_altcharset_name(attr, (chtype) CharOf(buf[j]))) != 0) { + result = _nc_trace_bufcat(bufnum, found); attr &= ~A_ALTCHARSET; - } else if (!isnac(CHDEREF(buf))) { + } else +#if USE_WIDEC_SUPPORT + if (!isWidecExt(buf[j])) { PUTC_DATA; - memset(&PUT_st, '\0', sizeof(PUT_st)); - PUTC_i = 0; - do { - PUTC_ch = PUTC_i < CCHARW_MAX ? buf->chars[PUTC_i] : L'\0'; - PUTC_n = wcrtomb(PUTC_buf, buf->chars[PUTC_i], &PUT_st); + PUTC_INIT; + for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { + int k; + + PUTC_ch = buf[j].chars[PUTC_i]; if (PUTC_ch == L'\0') - --PUTC_n; + break; + PUTC_n = wcrtomb(PUTC_buf, buf[j].chars[PUTC_i], &PUT_st); if (PUTC_n <= 0) break; - for (n = 0; n < PUTC_n; n++) { - tp = _nc_vischar(tp, UChar(PUTC_buf[n])); + for (k = 0; k < PUTC_n; k++) { + char temp[80]; + _nc_vischar(temp, UChar(PUTC_buf[k])); + result = _nc_trace_bufcat(bufnum, temp); } - ++PUTC_i; - } while (PUTC_ch != L'\0'); + } } - buf++; - } - *tp++ = D_QUOTE; - *tp++ = '\0'; - if (attr != A_NORMAL) - (void) sprintf(tp, " | %s", - _traceattr2(bufnum + 20, attr)); - } else { - *tp++ = L_BRACE; - while (len-- > 0) { - char *temp = _tracecchar_t2(bufnum + 20, buf++); - size_t used = (tp - result); - size_t want = strlen(temp) + 5 + used; - if (want > have) { - result = _nc_trace_buf(bufnum, have = want); - tp = result + used; +#else + { + char temp[80]; + _nc_vischar(temp, UChar(buf[j])); + result = _nc_trace_bufcat(bufnum, temp); } - (void) strcpy(tp, temp); - tp += strlen(tp); +#endif /* USE_WIDEC_SUPPORT */ + } + result = _nc_trace_bufcat(bufnum, d_quote); + if (attr != A_NORMAL) { + result = _nc_trace_bufcat(bufnum, " | "); + result = _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr)); } - *tp++ = R_BRACE; - *tp++ = '\0'; + result = _nc_trace_bufcat(bufnum, r_brace); + first = last + 1; } return result; } NCURSES_EXPORT(const char *) -_nc_viscbuf(const cchar_t * buf, int len) +_nc_viscbuf(const NCURSES_CH_T * buf, int len) { return _nc_viscbuf2(0, buf, len); } #endif /* TRACE */ -#endif /* USE_WIDEC_SUPPORT */ diff --git a/contrib/ncurses/ncurses/tty/MKexpanded.sh b/contrib/ncurses/ncurses/tty/MKexpanded.sh index 8e4a6c6c5f03..bf9acf21aa43 100755 --- a/contrib/ncurses/ncurses/tty/MKexpanded.sh +++ b/contrib/ncurses/ncurses/tty/MKexpanded.sh @@ -1,6 +1,6 @@ #! /bin/sh ############################################################################## -# 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 "Software"), # @@ -29,7 +29,7 @@ # # Author: Thomas E. Dickey <dickey@clark.net> 1997 # -# $Id: MKexpanded.sh,v 1.10 2000/12/10 00:24:33 tom Exp $ +# $Id: MKexpanded.sh,v 1.11 2005/01/02 01:06:40 tom Exp $ # # Script to generate 'expanded.c', a dummy source that contains functions # corresponding to complex macros used in this library. By making functions, @@ -84,7 +84,7 @@ NCURSES_EXPORT(int) _nc_InsCharCost (int count) { return InsCharCost(count); } -NCURSES_EXPORT(void) _nc_UpdateAttrs (chtype c) +NCURSES_EXPORT(void) _nc_UpdateAttrs (NCURSES_CH_T c) { UpdateAttrs(c); } diff --git a/contrib/ncurses/ncurses/tty/hashmap.c b/contrib/ncurses/ncurses/tty/hashmap.c index 1c30526069ba..1f482d4b6d0b 100644 --- a/contrib/ncurses/ncurses/tty/hashmap.c +++ b/contrib/ncurses/ncurses/tty/hashmap.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 * @@ -70,7 +70,7 @@ AUTHOR #include <curses.priv.h> #include <term.h> /* for back_color_erase */ -MODULE_ID("$Id: hashmap.c,v 1.45 2001/12/19 01:06:49 tom Exp $") +MODULE_ID("$Id: hashmap.c,v 1.49 2006/03/11 19:33:49 tom Exp $") #ifdef HASHDEBUG @@ -108,7 +108,9 @@ static chtype oldtext[MAXLINES][TEXTWIDTH], newtext[MAXLINES][TEXTWIDTH]; #define HASH_VAL(ch) (ch) #endif -static inline unsigned long +static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT); + +static NCURSES_INLINE unsigned long hash(NCURSES_CH_T * text) { int i; @@ -140,10 +142,10 @@ update_cost_from_blank(NCURSES_CH_T * to) { int cost = 0; int i; - NCURSES_CH_T blank = NewChar2(BLANK_TEXT, BLANK_ATTR); + NCURSES_CH_T blank = blankchar; if (back_color_erase) - AddAttr(blank, (AttrOf(stdscr->_nc_bkgd) & A_COLOR)); + SetPair(blank, GetPair(stdscr->_nc_bkgd)); for (i = TEXTWIDTH; i > 0; i--) if (!(CharEq(blank, *to++))) @@ -156,7 +158,7 @@ update_cost_from_blank(NCURSES_CH_T * to) * Returns true when moving line 'from' to line 'to' seems to be cost * effective. 'blank' indicates whether the line 'to' would become blank. */ -static inline bool +static NCURSES_INLINE bool cost_effective(const int from, const int to, const bool blank) { int new_from; @@ -294,9 +296,9 @@ _nc_hash_map(void) } else { /* re-hash all */ if (oldhash == 0) - oldhash = typeCalloc(unsigned long, screen_lines); + oldhash = typeCalloc(unsigned long, (unsigned) screen_lines); if (newhash == 0) - newhash = typeCalloc(unsigned long, screen_lines); + newhash = typeCalloc(unsigned long, (unsigned) screen_lines); if (!oldhash || !newhash) return; /* malloc failure */ for (i = 0; i < screen_lines; i++) { diff --git a/contrib/ncurses/ncurses/tty/lib_mvcur.c b/contrib/ncurses/ncurses/tty/lib_mvcur.c index 89b503f4aee6..4c0ef4a27e3e 100644 --- a/contrib/ncurses/ncurses/tty/lib_mvcur.c +++ b/contrib/ncurses/ncurses/tty/lib_mvcur.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 * ****************************************************************************/ /* @@ -108,7 +109,9 @@ * LONG_DIST and (b) further inward from the right or left edge than LONG_DIST, * we'll consider nonlocal. */ -#define NOT_LOCAL(fy, fx, ty, tx) ((tx > LONG_DIST) && (tx < screen_lines - 1 - LONG_DIST) && (abs(ty-fy) + abs(tx-fx) > LONG_DIST)) +#define NOT_LOCAL(fy, fx, ty, tx) ((tx > LONG_DIST) \ + && (tx < screen_columns - 1 - LONG_DIST) \ + && (abs(ty-fy) + abs(tx-fx) > LONG_DIST)) /**************************************************************************** * @@ -152,12 +155,8 @@ #include <term.h> #include <ctype.h> -MODULE_ID("$Id: lib_mvcur.c,v 1.85 2001/06/03 01:48:29 skimo Exp $") +MODULE_ID("$Id: lib_mvcur.c,v 1.107 2006/11/25 22:31:59 tom Exp $") -#define CURRENT_ROW SP->_cursrow /* phys cursor row */ -#define CURRENT_COLUMN SP->_curscol /* phys cursor column */ -#define CURRENT_ATTR SP->_current_attr /* current phys attribute */ -#define REAL_ATTR SP->_current_attr /* phys current attribute */ #define WANT_CHAR(y, x) SP->_newscr->_line[y].text[x] /* desired state */ #define BAUDRATE cur_term->_baudrate /* bits per second */ @@ -258,7 +257,7 @@ reset_scroll_region(void) { if (change_scroll_region) { TPUTS_TRACE("change_scroll_region"); - putp(tparm(change_scroll_region, 0, screen_lines - 1)); + putp(TPARM_2(change_scroll_region, 0, screen_lines - 1)); } } @@ -296,10 +295,11 @@ NCURSES_EXPORT(void) _nc_mvcur_init(void) /* initialize the cost structure */ { - /* - * 9 = 7 bits + 1 parity + 1 stop. - */ - SP->_char_padding = (9 * 1000 * 10) / (BAUDRATE > 0 ? BAUDRATE : 9600); + if (isatty(fileno(SP->_ofp))) + SP->_char_padding = ((BAUDBYTE * 1000 * 10) + / (BAUDRATE > 0 ? BAUDRATE : 9600)); + else + SP->_char_padding = 1; /* must be nonzero */ if (SP->_char_padding <= 0) SP->_char_padding = 1; /* must be nonzero */ TR(TRACE_CHARPUT | TRACE_MOVE, ("char_padding %d msecs", SP->_char_padding)); @@ -309,8 +309,13 @@ _nc_mvcur_init(void) SP->_home_cost = CostOf(cursor_home, 0); SP->_ll_cost = CostOf(cursor_to_ll, 0); #if USE_HARD_TABS - SP->_ht_cost = CostOf(tab, 0); - SP->_cbt_cost = CostOf(back_tab, 0); + if (getenv("NCURSES_NO_HARD_TABS") == 0) { + SP->_ht_cost = CostOf(tab, 0); + SP->_cbt_cost = CostOf(back_tab, 0); + } else { + SP->_ht_cost = INFINITY; + SP->_cbt_cost = INFINITY; + } #endif /* USE_HARD_TABS */ SP->_cub1_cost = CostOf(cursor_left, 0); SP->_cuf1_cost = CostOf(cursor_right, 0); @@ -356,13 +361,13 @@ _nc_mvcur_init(void) * All these averages depend on the assumption that all parameter values * are equally probable. */ - SP->_cup_cost = CostOf(tparm(SP->_address_cursor, 23, 23), 1); - SP->_cub_cost = CostOf(tparm(parm_left_cursor, 23), 1); - SP->_cuf_cost = CostOf(tparm(parm_right_cursor, 23), 1); - SP->_cud_cost = CostOf(tparm(parm_down_cursor, 23), 1); - SP->_cuu_cost = CostOf(tparm(parm_up_cursor, 23), 1); - SP->_hpa_cost = CostOf(tparm(column_address, 23), 1); - SP->_vpa_cost = CostOf(tparm(row_address, 23), 1); + SP->_cup_cost = CostOf(TPARM_2(SP->_address_cursor, 23, 23), 1); + SP->_cub_cost = CostOf(TPARM_1(parm_left_cursor, 23), 1); + SP->_cuf_cost = CostOf(TPARM_1(parm_right_cursor, 23), 1); + SP->_cud_cost = CostOf(TPARM_1(parm_down_cursor, 23), 1); + SP->_cuu_cost = CostOf(TPARM_1(parm_up_cursor, 23), 1); + SP->_hpa_cost = CostOf(TPARM_1(column_address, 23), 1); + SP->_vpa_cost = CostOf(TPARM_1(row_address, 23), 1); /* non-parameterized screen-update strings */ SP->_ed_cost = NormalizedCost(clr_eos, 1); @@ -371,15 +376,22 @@ _nc_mvcur_init(void) SP->_dch1_cost = NormalizedCost(delete_character, 1); SP->_ich1_cost = NormalizedCost(insert_character, 1); + /* + * If this is a bce-terminal, we want to bias the choice so we use clr_eol + * rather than spaces at the end of a line. + */ + if (back_color_erase) + SP->_el_cost = 0; + /* parameterized screen-update strings */ - SP->_dch_cost = NormalizedCost(tparm(parm_dch, 23), 1); - SP->_ich_cost = NormalizedCost(tparm(parm_ich, 23), 1); - SP->_ech_cost = NormalizedCost(tparm(erase_chars, 23), 1); - SP->_rep_cost = NormalizedCost(tparm(repeat_char, ' ', 23), 1); - - SP->_cup_ch_cost = NormalizedCost(tparm(SP->_address_cursor, 23, 23), 1); - SP->_hpa_ch_cost = NormalizedCost(tparm(column_address, 23), 1); - SP->_cuf_ch_cost = NormalizedCost(tparm(parm_right_cursor, 23), 1); + SP->_dch_cost = NormalizedCost(TPARM_1(parm_dch, 23), 1); + SP->_ich_cost = NormalizedCost(TPARM_1(parm_ich, 23), 1); + SP->_ech_cost = NormalizedCost(TPARM_1(erase_chars, 23), 1); + SP->_rep_cost = NormalizedCost(TPARM_2(repeat_char, ' ', 23), 1); + + SP->_cup_ch_cost = NormalizedCost(TPARM_2(SP->_address_cursor, 23, 23), 1); + SP->_hpa_ch_cost = NormalizedCost(TPARM_1(column_address, 23), 1); + SP->_cuf_ch_cost = NormalizedCost(TPARM_1(parm_right_cursor, 23), 1); SP->_inline_cost = min(SP->_cup_ch_cost, min(SP->_hpa_ch_cost, SP->_cuf_ch_cost)); @@ -441,7 +453,7 @@ _nc_mvcur_wrap(void) /* * Perform repeated-append, returning cost */ -static inline int +static NCURSES_INLINE int repeated_append(string_desc * target, int total, int num, int repeat, const char *src) { size_t need = repeat * strlen(src); @@ -484,7 +496,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int vcost = INFINITY; if (row_address != 0 - && _nc_safe_strcat(target, tparm(row_address, to_y))) { + && _nc_safe_strcat(target, TPARM_1(row_address, to_y))) { vcost = SP->_vpa_cost; } @@ -494,7 +506,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int if (parm_down_cursor && SP->_cud_cost < vcost && _nc_safe_strcat(_nc_str_copy(target, &save), - tparm(parm_down_cursor, n))) { + TPARM_1(parm_down_cursor, n))) { vcost = SP->_cud_cost; } @@ -508,10 +520,10 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int n = (from_y - to_y); if (parm_up_cursor - && SP->_cup_cost < vcost + && SP->_cuu_cost < vcost && _nc_safe_strcat(_nc_str_copy(target, &save), - tparm(parm_up_cursor, n))) { - vcost = SP->_cup_cost; + TPARM_1(parm_up_cursor, n))) { + vcost = SP->_cuu_cost; } if (cursor_up && (n * SP->_cuu1_cost < vcost)) { @@ -534,7 +546,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int if (column_address && _nc_safe_strcat(_nc_str_copy(target, &save), - tparm(column_address, to_x))) { + TPARM_1(column_address, to_x))) { hcost = SP->_hpa_cost; } @@ -544,7 +556,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int if (parm_right_cursor && SP->_cuf_cost < hcost && _nc_safe_strcat(_nc_str_copy(target, &save), - tparm(parm_right_cursor, n))) { + TPARM_1(parm_right_cursor, n))) { hcost = SP->_cuf_cost; } @@ -570,7 +582,6 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int } #endif /* USE_HARD_TABS */ -#if defined(REAL_ATTR) && defined(WANT_CHAR) if (n <= 0 || n >= (int) check.s_size) ovw = FALSE; #if BSD_TPUTS @@ -584,9 +595,11 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int && n > 0 && n < (int) check.s_size && vcost == 0 - && str[0] == '\0' - && isdigit(CharOf(WANT_CHAR(to_y, from_x)))) - ovw = FALSE; + && str[0] == '\0') { + int wanted = CharOf(WANT_CHAR(to_y, from_x)); + if (is8bits(wanted) && isdigit(wanted)) + ovw = FALSE; + } #endif /* * If we have no attribute changes, overwrite is cheaper. @@ -601,7 +614,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int for (i = 0; i < n; i++) { NCURSES_CH_T ch = WANT_CHAR(to_y, from_x + i); - if (AttrOf(ch) != CURRENT_ATTR + if (!SameAttrOf(ch, SCREEN_ATTRS(SP)) #if USE_WIDEC_SUPPORT || !Charable(ch) #endif @@ -619,9 +632,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int *check.s_tail = '\0'; check.s_size -= n; lhcost += n * SP->_char_padding; - } else -#endif /* defined(REAL_ATTR) && defined(WANT_CHAR) */ - { + } else { lhcost = repeated_append(&check, lhcost, SP->_cuf1_cost, n, cursor_right); } @@ -637,7 +648,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int if (parm_left_cursor && SP->_cub_cost < hcost && _nc_safe_strcat(_nc_str_copy(target, &save), - tparm(parm_left_cursor, n))) { + TPARM_1(parm_left_cursor, n))) { hcost = SP->_cub_cost; } @@ -689,7 +700,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int * the simpler method below. */ -static inline int +static NCURSES_INLINE int onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw) /* onscreen move from (yold, xold) to (ynew, xnew) */ { @@ -708,7 +719,7 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw) #define InitResult _nc_str_init(&result, buffer, sizeof(buffer)) /* tactic #0: use direct cursor addressing */ - if (_nc_safe_strcpy(InitResult, tparm(SP->_address_cursor, ynew, xnew))) { + if (_nc_safe_strcpy(InitResult, TPARM_2(SP->_address_cursor, ynew, xnew))) { tactic = 0; usecost = SP->_cup_cost; @@ -817,20 +828,22 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw) } #endif /* !NO_OPTIMIZE */ + nonlocal: #if defined(MAIN) || defined(NCURSES_TEST) gettimeofday(&after, NULL); diff = after.tv_usec - before.tv_usec + (after.tv_sec - before.tv_sec) * 1000000; if (!profiling) (void) fprintf(stderr, - "onscreen: %d msec, %f 28.8Kbps char-equivalents\n", + "onscreen: %d microsec, %f 28.8Kbps char-equivalents\n", (int) diff, diff / 288); #endif /* MAIN */ - nonlocal: if (usecost != INFINITY) { TPUTS_TRACE("mvcur"); tputs(buffer, 1, _nc_outch); + SP->_cursrow = ynew; + SP->_curscol = xnew; return (OK); } else return (ERR); @@ -840,72 +853,101 @@ NCURSES_EXPORT(int) mvcur(int yold, int xold, int ynew, int xnew) /* optimized cursor move from (yold, xold) to (ynew, xnew) */ { + NCURSES_CH_T oldattr; + int code; + TR(TRACE_CALLS | TRACE_MOVE, (T_CALLED("mvcur(%d,%d,%d,%d)"), yold, xold, ynew, xnew)); - if (SP == 0) - returnCode(ERR); + if (SP == 0) { + code = ERR; + } else if (yold == ynew && xold == xnew) { + code = OK; + } else { - if (yold == ynew && xold == xnew) - returnCode(OK); + /* + * Most work here is rounding for terminal boundaries getting the + * column position implied by wraparound or the lack thereof and + * rolling up the screen to get ynew on the screen. + */ + if (xnew >= screen_columns) { + ynew += xnew / screen_columns; + xnew %= screen_columns; + } - /* - * Most work here is rounding for terminal boundaries getting the - * column position implied by wraparound or the lack thereof and - * rolling up the screen to get ynew on the screen. - */ + /* + * Force restore even if msgr is on when we're in an alternate + * character set -- these have a strong tendency to screw up the CR & + * LF used for local character motions! + */ + oldattr = SCREEN_ATTRS(SP); + if ((AttrOf(oldattr) & A_ALTCHARSET) + || (AttrOf(oldattr) && !move_standout_mode)) { + TR(TRACE_CHARPUT, ("turning off (%#lx) %s before move", + (unsigned long) AttrOf(oldattr), + _traceattr(AttrOf(oldattr)))); + (void) VIDATTR(A_NORMAL, 0); + } - if (xnew >= screen_columns) { - ynew += xnew / screen_columns; - xnew %= screen_columns; - } - if (xold >= screen_columns) { - int l; - - if (SP->_nl) { - l = (xold + 1) / screen_columns; - yold += l; - if (yold >= screen_lines) - l -= (yold - screen_lines - 1); - - while (l > 0) { - if (newline) { - TPUTS_TRACE("newline"); - tputs(newline, 0, _nc_outch); - } else - putchar('\n'); - l--; - if (xold > 0) { + if (xold >= screen_columns) { + int l; + + if (SP->_nl) { + l = (xold + 1) / screen_columns; + yold += l; + if (yold >= screen_lines) + l -= (yold - screen_lines - 1); + + if (l > 0) { if (carriage_return) { TPUTS_TRACE("carriage_return"); - tputs(carriage_return, 0, _nc_outch); + putp(carriage_return); } else - putchar('\r'); + _nc_outch('\r'); xold = 0; + + while (l > 0) { + if (newline) { + TPUTS_TRACE("newline"); + putp(newline); + } else + _nc_outch('\n'); + l--; + } } + } else { + /* + * If caller set nonl(), we cannot really use newlines to + * position to the next row. + */ + xold = -1; + yold = -1; } - } else { - /* - * If caller set nonl(), we cannot really use newlines to position - * to the next row. - */ - xold = -1; - yold = -1; } - } - if (yold > screen_lines - 1) - yold = screen_lines - 1; - if (ynew > screen_lines - 1) - ynew = screen_lines - 1; + if (yold > screen_lines - 1) + yold = screen_lines - 1; + if (ynew > screen_lines - 1) + ynew = screen_lines - 1; + + /* destination location is on screen now */ + code = onscreen_mvcur(yold, xold, ynew, xnew, TRUE); - /* destination location is on screen now */ - returnCode(onscreen_mvcur(yold, xold, ynew, xnew, TRUE)); + /* + * Restore attributes if we disabled them before moving. + */ + if (!SameAttrOf(oldattr, SCREEN_ATTRS(SP))) { + TR(TRACE_CHARPUT, ("turning on (%#lx) %s after move", + (unsigned long) AttrOf(oldattr), + _traceattr(AttrOf(oldattr)))); + (void) VIDATTR(AttrOf(oldattr), GetPair(oldattr)); + } + } + returnCode(code); } #if defined(TRACE) || defined(NCURSES_TEST) -NCURSES_EXPORT_VAR(int) -_nc_optimize_enable = OPTIMIZE_ALL; +NCURSES_EXPORT_VAR(int) _nc_optimize_enable = OPTIMIZE_ALL; #endif #if defined(MAIN) || defined(NCURSES_TEST) @@ -918,10 +960,9 @@ _nc_optimize_enable = OPTIMIZE_ALL; #include <tic.h> #include <dump_entry.h> -NCURSES_EXPORT_VAR(const char *) -_nc_progname = "mvcur"; +NCURSES_EXPORT_VAR(const char *) _nc_progname = "mvcur"; - static unsigned long xmits; +static unsigned long xmits; /* these override lib_tputs.c */ NCURSES_EXPORT(int) @@ -948,17 +989,13 @@ _nc_outch(int ch) return OK; } -NCURSES_EXPORT_VAR(char) PC = 0; /* used by termcap library */ -NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed = 0; /* used by termcap library */ -NCURSES_EXPORT_VAR(int) _nc_nulls_sent = 0; /* used by 'tack' program */ - NCURSES_EXPORT(int) delay_output(int ms GCC_UNUSED) { return OK; } -static char tname[MAX_ALIAS]; +static char tname[PATH_MAX]; static void load_term(void) @@ -982,7 +1019,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) { (void) strcpy(tname, termname()); load_term(); - _nc_setupscreen(lines, columns, stdout); + _nc_setupscreen(lines, columns, stdout, FALSE, 0); baudrate(); _nc_mvcur_init(); @@ -1079,7 +1116,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) } } else if (buf[0] == 'i') { dump_init((char *) NULL, F_TERMINFO, S_TERMINFO, 70, 0, FALSE); - dump_entry(&cur_term->type, FALSE, TRUE, 0); + dump_entry(&cur_term->type, FALSE, TRUE, 0, 0, 0); putchar('\n'); } else if (buf[0] == 'o') { if (_nc_optimize_enable & OPTIMIZE_MVCUR) { diff --git a/contrib/ncurses/ncurses/tty/lib_tstp.c b/contrib/ncurses/ncurses/tty/lib_tstp.c index c850e41da2c2..4c9f9fbaf1b7 100644 --- a/contrib/ncurses/ncurses/tty/lib_tstp.c +++ b/contrib/ncurses/ncurses/tty/lib_tstp.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 * @@ -29,7 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * - * and: Thomas Dickey 1995-2001 * + * and: Thomas E. Dickey 1995-on * ****************************************************************************/ /* @@ -46,7 +46,7 @@ #define _POSIX_SOURCE #endif -MODULE_ID("$Id: lib_tstp.c,v 1.30 2002/05/18 19:55:38 tom Exp $") +MODULE_ID("$Id: lib_tstp.c,v 1.32 2006/04/01 19:31:34 tom Exp $") #if defined(SIGTSTP) && (HAVE_SIGACTION || HAVE_SIGVEC) #define USE_SIGTSTP 1 @@ -277,11 +277,7 @@ cleanup(int sig) static void sigwinch(int sig GCC_UNUSED) { - SCREEN *scan = _nc_screen_chain; - while (scan) { - scan->_sig_winch = TRUE; - scan = scan->_next_screen; - } + _nc_handle_sigwinch(-1); } #endif /* USE_SIGWINCH */ diff --git a/contrib/ncurses/ncurses/tty/lib_twait.c b/contrib/ncurses/ncurses/tty/lib_twait.c index 9829a7eec8ef..28e503f331f6 100644 --- a/contrib/ncurses/ncurses/tty/lib_twait.c +++ b/contrib/ncurses/ncurses/tty/lib_twait.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 * @@ -61,7 +61,7 @@ # endif #endif -MODULE_ID("$Id: lib_twait.c,v 1.44 2002/04/21 21:06:29 tom Exp $") +MODULE_ID("$Id: lib_twait.c,v 1.51 2006/05/27 21:57:43 tom Exp $") static long _nc_gettime(bool first) @@ -75,9 +75,16 @@ _nc_gettime(bool first) gettimeofday(&t1, (struct timezone *) 0); if (first) { t0 = t1; + res = 0; + } else { + /* .tv_sec and .tv_usec are unsigned, be careful when subtracting */ + if (t0.tv_usec > t1.tv_usec) { /* Convert 1s in 1e6 microsecs */ + t1.tv_usec += 1000000; + t1.tv_sec--; + } + res = (t1.tv_sec - t0.tv_sec) * 1000 + + (t1.tv_usec - t0.tv_usec) / 1000; } - res = (t1.tv_sec - t0.tv_sec) * 1000 - + (t1.tv_usec - t0.tv_usec) / 1000; #else # define PRECISE_GETTIME 0 static time_t t0; @@ -91,6 +98,29 @@ _nc_gettime(bool first) return res; } +#ifdef NCURSES_WGETCH_EVENTS +NCURSES_EXPORT(int) +_nc_eventlist_timeout(_nc_eventlist * evl) +{ + int event_delay = -1; + int n; + + if (evl != 0) { + + for (n = 0; n < evl->count; ++n) { + _nc_event *ev = evl->events[n]; + + if (ev->type == _NC_EVENT_TIMEOUT_MSEC) { + event_delay = ev->data.timeout_msec; + if (event_delay < 0) + event_delay = INT_MAX; /* FIXME Is this defined? */ + } + } + } + return event_delay; +} +#endif /* NCURSES_WGETCH_EVENTS */ + /* * Wait a specified number of milliseconds, returning nonzero if the timer * didn't expire before there is activity on the specified file descriptors. @@ -99,21 +129,35 @@ _nc_gettime(bool first) * 1 - ncurses' normal input-descriptor * 2 - mouse descriptor, if any * 3 - either input or mouse. + * + * Experimental: if NCURSES_WGETCH_EVENTS is defined, (mode & 4) determines + * whether to pay attention to evl argument. If set, the smallest of + * millisecond and of timeout of evl is taken. + * * We return a mask that corresponds to the mode (e.g., 2 for mouse activity). * * If the milliseconds given are -1, the wait blocks until activity on the * descriptors. */ NCURSES_EXPORT(int) -_nc_timed_wait(int mode, int milliseconds, int *timeleft) +_nc_timed_wait(int mode, + int milliseconds, + int *timeleft + EVENTLIST_2nd(_nc_eventlist * evl)) { int fd; int count; - int result; +#ifdef NCURSES_WGETCH_EVENTS + int timeout_is_event = 0; + int n; +#endif + #if USE_FUNC_POLL - struct pollfd fds[2]; +#define MIN_FDS 2 + struct pollfd fd_list[MIN_FDS]; + struct pollfd *fds = fd_list; #elif defined(__BEOS__) #elif HAVE_SELECT static fd_set set; @@ -121,11 +165,21 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft) long starttime, returntime; - if (milliseconds < 0) - milliseconds = 0; TR(TRACE_IEVENT, ("start twait: %d milliseconds, mode: %d", milliseconds, mode)); +#ifdef NCURSES_WGETCH_EVENTS + if (mode & 4) { + int event_delay = _nc_eventlist_timeout(evl); + + if (event_delay >= 0 + && (milliseconds >= event_delay || milliseconds < 0)) { + milliseconds = event_delay; + timeout_is_event = 1; + } + } +#endif + #if PRECISE_GETTIME retry: #endif @@ -133,8 +187,19 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft) count = 0; +#ifdef NCURSES_WGETCH_EVENTS + if ((mode & 4) && evl) + evl->result_flags = 0; +#endif + #if USE_FUNC_POLL - memset(fds, 0, sizeof(fds)); + memset(fd_list, 0, sizeof(fd_list)); + +#ifdef NCURSES_WGETCH_EVENTS + if ((mode & 4) && evl) + fds = typeMalloc(struct pollfd, MIN_FDS + evl->count); +#endif + if (mode & 1) { fds[count].fd = SP->_ifd; fds[count].events = POLLIN; @@ -146,7 +211,53 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft) fds[count].events = POLLIN; count++; } - result = poll(fds, count, milliseconds); +#ifdef NCURSES_WGETCH_EVENTS + if ((mode & 4) && evl) { + for (n = 0; n < evl->count; ++n) { + _nc_event *ev = evl->events[n]; + + if (ev->type == _NC_EVENT_FILE + && (ev->data.fev.flags & _NC_EVENT_FILE_READABLE)) { + fds[count].fd = ev->data.fev.fd; + fds[count].events = POLLIN; + count++; + } + } + } +#endif + + result = poll(fds, (unsigned) count, milliseconds); + +#ifdef NCURSES_WGETCH_EVENTS + if ((mode & 4) && evl) { + int c; + + if (!result) + count = 0; + + for (n = 0; n < evl->count; ++n) { + _nc_event *ev = evl->events[n]; + + if (ev->type == _NC_EVENT_FILE + && (ev->data.fev.flags & _NC_EVENT_FILE_READABLE)) { + ev->data.fev.result = 0; + for (c = 0; c < count; c++) + if (fds[c].fd == ev->data.fev.fd + && fds[c].revents & POLLIN) { + ev->data.fev.result |= _NC_EVENT_FILE_READABLE; + evl->result_flags |= _NC_EVENT_FILE_READABLE; + } + } else if (ev->type == _NC_EVENT_TIMEOUT_MSEC + && !result && timeout_is_event) { + evl->result_flags |= _NC_EVENT_TIMEOUT_MSEC; + } + } + } + + if (fds != fd_list) + free((char *) fds); + +#endif #elif defined(__BEOS__) /* @@ -157,26 +268,34 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft) * * FIXME: the return values from the ioctl aren't very clear if we get * interrupted. + * + * FIXME: this assumes mode&1 if milliseconds < 0 (see lib_getch.c). */ result = 0; if (mode & 1) { + int step = (milliseconds < 0) ? 0 : 5000; bigtime_t d; bigtime_t useconds = milliseconds * 1000; int n, howmany; - if (useconds == 0) /* we're here to go _through_ the loop */ + if (useconds <= 0) /* we're here to go _through_ the loop */ useconds = 1; - for (d = 0; d < useconds; d += 5000) { + for (d = 0; d < useconds; d += step) { n = 0; howmany = ioctl(0, 'ichr', &n); if (howmany >= 0 && n > 0) { result = 1; break; } - if (useconds > 1) - snooze(5000); - milliseconds -= 5; + if (useconds > 1 && step > 0) { + snooze(step); + milliseconds -= (step / 1000); + if (milliseconds <= 0) { + milliseconds = 0; + break; + } + } } } else if (milliseconds > 0) { snooze(milliseconds * 1000); @@ -198,6 +317,19 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft) FD_SET(fd, &set); count = max(fd, count) + 1; } +#ifdef NCURSES_WGETCH_EVENTS + if ((mode & 4) && evl) { + for (n = 0; n < evl->count; ++n) { + _nc_event *ev = evl->events[n]; + + if (ev->type == _NC_EVENT_FILE + && (ev->data.fev.flags & _NC_EVENT_FILE_READABLE)) { + FD_SET(ev->data.fev.fd, &set); + count = max(ev->data.fev.fd + 1, count); + } + } + } +#endif if (milliseconds >= 0) { struct timeval ntimeout; @@ -207,14 +339,53 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft) } else { result = select(count, &set, NULL, NULL, NULL); } + +#ifdef NCURSES_WGETCH_EVENTS + if ((mode & 4) && evl) { + evl->result_flags = 0; + for (n = 0; n < evl->count; ++n) { + _nc_event *ev = evl->events[n]; + + if (ev->type == _NC_EVENT_FILE + && (ev->data.fev.flags & _NC_EVENT_FILE_READABLE)) { + ev->data.fev.result = 0; + if (FD_ISSET(ev->data.fev.fd, &set)) { + ev->data.fev.result |= _NC_EVENT_FILE_READABLE; + evl->result_flags |= _NC_EVENT_FILE_READABLE; + } + } else if (ev->type == _NC_EVENT_TIMEOUT_MSEC + && !result && timeout_is_event) + evl->result_flags |= _NC_EVENT_TIMEOUT_MSEC; + } + } #endif +#endif /* USE_FUNC_POLL, etc */ + returntime = _nc_gettime(FALSE); if (milliseconds >= 0) milliseconds -= (returntime - starttime); -#if PRECISE_GETTIME +#ifdef NCURSES_WGETCH_EVENTS + if (evl) { + evl->result_flags = 0; + for (n = 0; n < evl->count; ++n) { + _nc_event *ev = evl->events[n]; + + if (ev->type == _NC_EVENT_TIMEOUT_MSEC) { + long diff = (returntime - starttime); + if (ev->data.timeout_msec <= diff) + ev->data.timeout_msec = 0; + else + ev->data.timeout_msec -= diff; + } + + } + } +#endif + +#if PRECISE_GETTIME && HAVE_NANOSLEEP /* * If the timeout hasn't expired, and we've gotten no data, * this is probably a system where 'select()' needs to be left @@ -222,7 +393,7 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft) * then come back for more. */ if (result == 0 && milliseconds > 100) { - napms(100); + napms(100); /* FIXME: this won't be right if I recur! */ milliseconds -= 100; goto retry; } @@ -245,7 +416,7 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft) if (result > 0) { result = 0; #if USE_FUNC_POLL - for (count = 0; count < 2; count++) { + for (count = 0; count < MIN_FDS; count++) { if ((mode & (1 << count)) && (fds[count].revents & POLLIN)) { result |= (1 << count); @@ -265,6 +436,10 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft) } else result = 0; } +#ifdef NCURSES_WGETCH_EVENTS + if ((mode & 4) && evl && evl->result_flags) + result |= 4; +#endif return (result); } diff --git a/contrib/ncurses/ncurses/tty/lib_vidattr.c b/contrib/ncurses/ncurses/tty/lib_vidattr.c index 00611f4e1501..dbbbc978a054 100644 --- a/contrib/ncurses/ncurses/tty/lib_vidattr.c +++ b/contrib/ncurses/ncurses/tty/lib_vidattr.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 * ****************************************************************************/ /* @@ -64,7 +65,7 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("$Id: lib_vidattr.c,v 1.39 2001/08/26 00:40:46 Philippe.Blain Exp $") +MODULE_ID("$Id: lib_vidattr.c,v 1.46 2006/01/21 23:39:40 tom Exp $") #define doPut(mode) TPUTS_TRACE(#mode); tputs(mode, 1, outc) @@ -87,8 +88,7 @@ MODULE_ID("$Id: lib_vidattr.c,v 1.39 2001/08/26 00:40:46 Philippe.Blain Exp $") } NCURSES_EXPORT(int) -vidputs -(chtype newmode, int (*outc) (int)) +vidputs(chtype newmode, int (*outc) (int)) { static attr_t previous_attr = A_NORMAL; attr_t turn_on, turn_off; @@ -105,15 +105,51 @@ vidputs /* this allows us to go on whether or not newterm() has been called */ if (SP) - previous_attr = SP->_current_attr; + previous_attr = AttrOf(SCREEN_ATTRS(SP)); TR(TRACE_ATTRS, ("previous attribute was %s", _traceattr(previous_attr))); -#if !USE_XMC_SUPPORT if ((SP != 0) - && (magic_cookie_glitch > 0)) + && (magic_cookie_glitch > 0)) { +#if USE_XMC_SUPPORT + static chtype table[] = + { + A_STANDOUT, + A_UNDERLINE, + A_REVERSE, + A_BLINK, + A_DIM, + A_BOLD, + A_INVIS, + A_PROTECT, + }; + unsigned n; + int used = 0; + int limit = (max_attributes <= 0) ? 1 : max_attributes; + chtype retain = 0; + + /* + * Limit the number of attribute bits set in the newmode according to + * the terminfo max_attributes value. + */ + for (n = 0; n < SIZEOF(table); ++n) { + if ((table[n] & SP->_ok_attributes) == 0) { + newmode &= ~table[n]; + } else if ((table[n] & newmode) != 0) { + if (used++ >= limit) { + newmode &= ~table[n]; + if (newmode == retain) + break; + } else { + retain = newmode; + } + } + } +#else newmode &= ~(SP->_xmc_suppress); #endif + TR(TRACE_ATTRS, ("suppressed attribute is %s", _traceattr(newmode))); + } /* * If we have a terminal that cannot combine color with video @@ -177,7 +213,7 @@ vidputs TurnOff(A_STANDOUT, exit_standout_mode); } } - previous_attr &= ~A_COLOR; + previous_attr &= ALL_BUT_COLOR; } SetColorsIf((pair != 0) || fix_pair0, previous_attr); @@ -194,7 +230,7 @@ vidputs (newmode & A_INVIS) != 0, (newmode & A_PROTECT) != 0, (newmode & A_ALTCHARSET) != 0), 1, outc); - previous_attr &= ~A_COLOR; + previous_attr &= ALL_BUT_COLOR; } SetColorsIf((pair != 0) || fix_pair0, previous_attr); } else { @@ -213,8 +249,8 @@ vidputs if (turn_off && exit_attribute_mode) { doPut(exit_attribute_mode); - turn_on |= (newmode & (chtype) (~A_COLOR)); - previous_attr &= ~A_COLOR; + turn_on |= (newmode & ALL_BUT_COLOR); + previous_attr &= ALL_BUT_COLOR; } SetColorsIf((pair != 0) || fix_pair0, previous_attr); @@ -229,22 +265,12 @@ vidputs TurnOn(A_PROTECT, enter_protected_mode); TurnOn(A_INVIS, enter_secure_mode); TurnOn(A_UNDERLINE, enter_underline_mode); -#ifdef enter_horizontal_hl_mode +#if USE_WIDEC_SUPPORT TurnOn(A_HORIZONTAL, enter_horizontal_hl_mode); -#endif -#ifdef enter_left_hl_mode TurnOn(A_LEFT, enter_left_hl_mode); -#endif -#ifdef enter_low_hl_mode TurnOn(A_LOW, enter_low_hl_mode); -#endif -#ifdef enter_right_hl_mode TurnOn(A_RIGHT, enter_right_hl_mode); -#endif -#ifdef enter_top_hl_mode TurnOn(A_TOP, enter_top_hl_mode); -#endif -#ifdef enter_vertical_hl_mode TurnOn(A_VERTICAL, enter_vertical_hl_mode); #endif /* *INDENT-ON* */ @@ -255,7 +281,7 @@ vidputs newmode |= A_REVERSE; if (SP) - SP->_current_attr = newmode; + SetAttr(SCREEN_ATTRS(SP), newmode); else previous_attr = newmode; diff --git a/contrib/ncurses/ncurses/tty/tty_display.h b/contrib/ncurses/ncurses/tty/tty_display.h index 8382c823f06a..4c45a08450ed 100644 --- a/contrib/ncurses/ncurses/tty/tty_display.h +++ b/contrib/ncurses/ncurses/tty/tty_display.h @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 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 * @@ -29,6 +29,9 @@ #ifndef TTY_DISPLAY_H #define TTY_DISPLAY_H 1 +/* + * $Id: tty_display.h,v 1.6 2005/01/01 23:41:12 tom Exp $ + */ extern NCURSES_EXPORT(bool) _nc_tty_beep (void); extern NCURSES_EXPORT(bool) _nc_tty_check_resize (void); extern NCURSES_EXPORT(bool) _nc_tty_cursor (int); @@ -111,11 +114,11 @@ struct tty_display_data { : ((enter_insert_mode && exit_insert_mode) \ ? D->_smir_cost + D->_rmir_cost + (D->_ip_cost * count) \ : ((insert_character != 0) \ - ? (D->_ich1_cost * count) \ + ? ((D->_ich1_cost + D->_ip_cost) * count) \ : INFINITY))) #if USE_XMC_SUPPORT -#define UpdateAttrs(c) if (D->_current_attr != AttrOf(c)) { \ +#define UpdateAttrs(c) if (!SameAttrOf(D->_current_attr, AttrOf(c))) { \ attr_t chg = D->_current_attr; \ vidattr(AttrOf(c)); \ if (magic_cookie_glitch > 0 \ @@ -128,7 +131,7 @@ struct tty_display_data { } \ } #else -#define UpdateAttrs(c) if (D->_current_attr != AttrOf(c)) \ +#define UpdateAttrs(c) if (!SameAttrOf(D->_current_attr, AttrOf(c))) \ vidattr(AttrOf(c)); #endif diff --git a/contrib/ncurses/ncurses/tty/tty_update.c b/contrib/ncurses/ncurses/tty/tty_update.c index e06de1b7da06..6926b56198d9 100644 --- a/contrib/ncurses/ncurses/tty/tty_update.c +++ b/contrib/ncurses/ncurses/tty/tty_update.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000,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,15 +29,16 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /*----------------------------------------------------------------- * * lib_doupdate.c * - * The routine doupdate() and its dependents. Also _nc_outstr(), - * so all physical output is concentrated here (except _nc_outch() - * in lib_tputs.c). + * The routine doupdate() and its dependents. + * All physical output is concentrated here (except _nc_outch() + * in lib_tputs.c). * *-----------------------------------------------------------------*/ @@ -70,9 +71,10 @@ #endif #endif +#include <ctype.h> #include <term.h> -MODULE_ID("$Id: tty_update.c,v 1.174 2002/04/21 21:04:16 tom Exp $") +MODULE_ID("$Id: tty_update.c,v 1.238 2006/11/25 22:33:21 tom Exp $") /* * This define controls the line-breakout optimization. Every once in a @@ -87,6 +89,9 @@ MODULE_ID("$Id: tty_update.c,v 1.174 2002/04/21 21:04:16 tom Exp $") #define FILL_BCE() (SP->_coloron && !SP->_default_color && !back_color_erase) +static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT); +static NCURSES_CH_T normal = NewChar(BLANK_TEXT); + /* * Enable checking to see if doupdate and friends are tracking the true * cursor position correctly. NOTE: this is a debugging hack which will @@ -94,7 +99,7 @@ MODULE_ID("$Id: tty_update.c,v 1.174 2002/04/21 21:04:16 tom Exp $") */ /* #define POSITION_DEBUG */ -static inline NCURSES_CH_T ClrBlank(WINDOW *win); +static NCURSES_INLINE NCURSES_CH_T ClrBlank(WINDOW *win); static int ClrBottom(int total); static void ClearScreen(NCURSES_CH_T blank); static void ClrUpdate(void); @@ -162,64 +167,131 @@ position_check(int expected_y, int expected_x, char *legend) * ****************************************************************************/ -static inline void +static NCURSES_INLINE void GoTo(int const row, int const col) { - attr_t oldattr = SP->_current_attr; - TR(TRACE_MOVE, ("GoTo(%d, %d) from (%d, %d)", row, col, SP->_cursrow, SP->_curscol)); position_check(SP->_cursrow, SP->_curscol, "GoTo"); - /* - * Force restore even if msgr is on when we're in an alternate - * character set -- these have a strong tendency to screw up the - * CR & LF used for local character motions! - */ - if ((oldattr & A_ALTCHARSET) - || (oldattr && !move_standout_mode)) { - TR(TRACE_CHARPUT, ("turning off (%#lx) %s before move", - oldattr, _traceattr(oldattr))); - vidattr(A_NORMAL); - } - mvcur(SP->_cursrow, SP->_curscol, row, col); - SP->_cursrow = row; - SP->_curscol = col; position_check(SP->_cursrow, SP->_curscol, "GoTo2"); } -static inline void +static NCURSES_INLINE void PutAttrChar(CARG_CH_T ch) { + int chlen = 1; + NCURSES_CH_T my_ch; PUTC_DATA; NCURSES_CH_T tilde; + NCURSES_CH_T attr = CHDEREF(ch); + TR(TRACE_CHARPUT, ("PutAttrChar(%s) at (%d, %d)", + _tracech_t(ch), + SP->_cursrow, SP->_curscol)); +#if USE_WIDEC_SUPPORT + /* + * If this is not a valid character, there is nothing more to do. + */ + if (isWidecExt(CHDEREF(ch))) { + TR(TRACE_CHARPUT, ("...skip")); + return; + } + /* + * Determine the number of character cells which the 'ch' value will use + * on the screen. It should be at least one. + */ + if ((chlen = wcwidth(CharOf(CHDEREF(ch)))) <= 0) { + static const NCURSES_CH_T blank = NewChar(BLANK_TEXT); + + /* + * If the character falls into any of these special cases, do + * not force the result to a blank: + * + * a) it is printable (this works around a bug in wcwidth()). + * b) use_legacy_coding() has been called to modify the treatment + * of codes 128-255. + * c) the acs_map[] has been initialized to allow codes 0-31 + * to be rendered. This supports Linux console's "PC" + * characters. Codes 128-255 are allowed though this is + * not checked. + */ + if (is8bits(CharOf(CHDEREF(ch))) + && (isprint(CharOf(CHDEREF(ch))) + || (SP->_legacy_coding > 0 && CharOf(CHDEREF(ch)) >= 160) + || (SP->_legacy_coding > 1 && CharOf(CHDEREF(ch)) >= 128) + || (AttrOf(attr) & A_ALTCHARSET + && ((CharOfD(ch) < ACS_LEN + && SP->_acs_map != 0 + && SP->_acs_map[CharOfD(ch)] != 0) + || (CharOfD(ch) >= 128))))) { + ; + } else { + ch = CHREF(blank); + TR(TRACE_CHARPUT, ("forced to blank")); + } + chlen = 1; + } +#endif + + if ((AttrOf(attr) & A_ALTCHARSET) + && SP->_acs_map != 0 + && CharOfD(ch) < ACS_LEN) { + my_ch = CHDEREF(ch); /* work around const param */ +#if USE_WIDEC_SUPPORT + /* + * This is crude & ugly, but works most of the time. It checks if the + * acs_chars string specified that we have a mapping for this + * character, and uses the wide-character mapping when we expect the + * normal one to be broken (by mis-design ;-). + */ + if (SP->_screen_acs_fix + && SP->_screen_acs_map[CharOf(my_ch)]) { + RemAttr(attr, A_ALTCHARSET); + my_ch = _nc_wacs[CharOf(my_ch)]; + } +#endif + /* + * If we (still) have alternate character set, it is the normal 8bit + * flavor. The _screen_acs_map[] array tells if the character was + * really in acs_chars, needed because of the way wide/normal line + * drawing flavors are integrated. + */ + if (AttrOf(attr) & A_ALTCHARSET) { + int j = CharOfD(ch); + chtype temp = UChar(SP->_acs_map[j]); + + if (!(SP->_screen_acs_map[j])) { + RemAttr(attr, A_ALTCHARSET); + if (temp == 0) + temp = ' '; + } + if (temp != 0) + SetChar(my_ch, temp, AttrOf(attr)); + } + ch = CHREF(my_ch); + } if (tilde_glitch && (CharOfD(ch) == L('~'))) { - SetChar(tilde, L('`'), AttrOfD(ch)); + SetChar(tilde, L('`'), AttrOf(attr)); ch = CHREF(tilde); } - TR(TRACE_CHARPUT, ("PutAttrChar(%s) at (%d, %d)", - _tracech_t(ch), - SP->_cursrow, SP->_curscol)); - UpdateAttrs(AttrOfD(ch)); + UpdateAttrs(attr); #if !USE_WIDEC_SUPPORT /* FIXME - we do this special case for signal handling, should see how to * make it work for wide characters. */ if (SP->_outch != 0) { - SP->_outch(ch); + SP->_outch(UChar(ch)); } else #endif { PUTC(CHDEREF(ch), SP->_ofp); /* macro's fastest... */ -#ifdef TRACE - _nc_outchars++; -#endif /* TRACE */ + TRACE_OUTCHARS(1); } - SP->_curscol++; + SP->_curscol += chlen; if (char_padding) { TPUTS_TRACE("char_padding"); putp(char_padding); @@ -311,38 +383,48 @@ PutCharLR(const ARG_CH_T ch) } } +/* + * Wrap the cursor position, i.e., advance to the beginning of the next line. + */ static void wrap_cursor(void) { if (eat_newline_glitch) { /* - * xenl can manifest two different ways. The vt100 - * way is that, when you'd expect the cursor to wrap, - * it stays hung at the right margin (on top of the - * character just emitted) and doesn't wrap until the - * *next* graphic char is emitted. The c100 way is - * to ignore LF received just after an am wrap. + * xenl can manifest two different ways. The vt100 way is that, when + * you'd expect the cursor to wrap, it stays hung at the right margin + * (on top of the character just emitted) and doesn't wrap until the + * *next* graphic char is emitted. The c100 way is to ignore LF + * received just after an am wrap. * - * An aggressive way to handle this would be to - * emit CR/LF after the char and then assume the wrap - * is done, you're on the first position of the next - * line, and the terminal out of its weird state. - * Here it's safe to just tell the code that the - * cursor is in hyperspace and let the next mvcur() - * call straighten things out. + * An aggressive way to handle this would be to emit CR/LF after the + * char and then assume the wrap is done, you're on the first position + * of the next line, and the terminal out of its weird state. Here + * it's safe to just tell the code that the cursor is in hyperspace and + * let the next mvcur() call straighten things out. */ SP->_curscol = -1; SP->_cursrow = -1; } else if (auto_right_margin) { SP->_curscol = 0; SP->_cursrow++; + /* + * We've actually moved - but may have to work around problems with + * video attributes not working. + */ + if (!move_standout_mode && AttrOf(SCREEN_ATTRS(SP))) { + TR(TRACE_CHARPUT, ("turning off (%#lx) %s before wrapping", + (unsigned long) AttrOf(SCREEN_ATTRS(SP)), + _traceattr(AttrOf(SCREEN_ATTRS(SP))))); + (void) VIDATTR(A_NORMAL, 0); + } } else { SP->_curscol--; } position_check(SP->_cursrow, SP->_curscol, "wrap_cursor"); } -static inline void +static NCURSES_INLINE void PutChar(const ARG_CH_T ch) /* insert character, handling automargin stuff */ { @@ -363,18 +445,20 @@ PutChar(const ARG_CH_T ch) * as A_REVERSE. All attribute flags which don't affect appearance of a space * or can be output by clearing (A_COLOR in case of bce-terminal) are excluded. */ -static inline bool +static NCURSES_INLINE bool can_clear_with(ARG_CH_T ch) { if (!back_color_erase && SP->_coloron) { #if NCURSES_EXT_FUNCS + int pair; + if (!SP->_default_color) return FALSE; if (SP->_default_fg != C_MASK || SP->_default_bg != C_MASK) return FALSE; - if (AttrOfD(ch) & A_COLOR) { + if ((pair = GetPair(CHDEREF(ch))) != 0) { short fg, bg; - pair_content(PAIR_NUMBER(AttrOfD(ch)), &fg, &bg); + pair_content(pair, &fg, &bg); if (fg != C_MASK || bg != C_MASK) return FALSE; } @@ -404,6 +488,8 @@ EmitRange(const NCURSES_CH_T * ntext, int num) { int i; + TR(TRACE_CHARPUT, ("EmitRange %d:%s", num, _nc_viscbuf(ntext, num))); + if (erase_chars || repeat_char) { while (num > 0) { int runcount; @@ -435,8 +521,8 @@ EmitRange(const NCURSES_CH_T * ntext, int num) if (erase_chars && runcount > SP->_ech_cost + SP->_cup_ch_cost && can_clear_with(CHREF(ntext0))) { - UpdateAttrs(AttrOf(ntext0)); - putp(tparm(erase_chars, runcount)); + UpdateAttrs(ntext0); + putp(TPARM_1(erase_chars, runcount)); /* * If this is the last part of the given interval, @@ -455,8 +541,9 @@ EmitRange(const NCURSES_CH_T * ntext, int num) if (wrap_possible) rep_count--; - UpdateAttrs(AttrOf(ntext0)); - putp(tparm(repeat_char, CharOf(ntext0), rep_count)); + UpdateAttrs(ntext0); + tputs(TPARM_2(repeat_char, CharOf(ntext0), rep_count), + rep_count, _nc_outch); SP->_curscol += rep_count; if (wrap_possible) @@ -485,33 +572,37 @@ EmitRange(const NCURSES_CH_T * ntext, int num) * Returns: same as EmitRange */ static int -PutRange( - const NCURSES_CH_T * otext, - const NCURSES_CH_T * ntext, - int row, - int first, int last) +PutRange(const NCURSES_CH_T * otext, + const NCURSES_CH_T * ntext, + int row, + int first, int last) { - int j, run; + int i, j, same; TR(TRACE_CHARPUT, ("PutRange(%p, %p, %d, %d, %d)", otext, ntext, row, first, last)); if (otext != ntext && (last - first + 1) > SP->_inline_cost) { - for (j = first, run = 0; j <= last; j++) { - if (!run && isnac(otext[j])) + for (j = first, same = 0; j <= last; j++) { + if (!same && isWidecExt(otext[j])) continue; if (CharEq(otext[j], ntext[j])) { - run++; + same++; } else { - if (run > SP->_inline_cost) { - int before_run = (j - run); - EmitRange(ntext + first, before_run - first); + if (same > SP->_inline_cost) { + EmitRange(ntext + first, j - same - first); GoTo(row, first = j); } - run = 0; + same = 0; } } + i = EmitRange(ntext + first, j - same - first); + /* + * Always return 1 for the next GoTo() after a PutRange() if we found + * identical characters at end of interval + */ + return (same == 0 ? i : 1); } return EmitRange(ntext + first, last - first + 1); } @@ -580,17 +671,15 @@ doupdate(void) #endif /* USE_TRACE_TIMES */ /* - * This is the support for magic-cookie terminals. The - * theory: we scan the virtual screen looking for attribute - * turnons. Where we find one, check to make sure it's - * realizable by seeing if the required number of - * un-attributed blanks are present before and after the - * attributed range; try to shift the range boundaries over - * blanks (not changing the screen display) so this becomes - * true. If it is, shift the beginning attribute change - * appropriately (the end one, if we've gotten this far, is - * guaranteed room for its cookie). If not, nuke the added - * attributes out of the span. + * This is the support for magic-cookie terminals. The theory: we scan + * the virtual screen looking for attribute turnons. Where we find one, + * check to make sure it's realizable by seeing if the required number of + * un-attributed blanks are present before and after the attributed range; + * try to shift the range boundaries over blanks (not changing the screen + * display) so this becomes true. If it is, shift the beginning attribute + * change appropriately (the end one, if we've gotten this far, is + * guaranteed room for its cookie). If not, nuke the added attributes out + * of the span. */ #if USE_XMC_SUPPORT if (magic_cookie_glitch > 0) { @@ -600,11 +689,13 @@ doupdate(void) for (i = 0; i < screen_lines; i++) { for (j = 0; j < screen_columns; j++) { bool failed = FALSE; - attr_t turnon = AttrOf(newscr->_line[i].text[j]) & ~rattr; + NCURSES_CH_T *thisline = newscr->_line[i].text; + attr_t thisattr = AttrOf(thisline[j]) & SP->_xmc_triggers; + attr_t turnon = thisattr & ~rattr; /* is an attribute turned on here? */ if (turnon == 0) { - rattr = AttrOf(newscr->_line[i].text[j]); + rattr = thisattr; continue; } @@ -612,23 +703,33 @@ doupdate(void) TR(TRACE_ATTRS, ("...to %s", _traceattr(turnon))); /* - * If the attribute change location is a blank with a - * "safe" attribute, undo the attribute turnon. This may - * ensure there's enough room to set the attribute before - * the first non-blank in the run. + * If the attribute change location is a blank with a "safe" + * attribute, undo the attribute turnon. This may ensure + * there's enough room to set the attribute before the first + * non-blank in the run. */ -#define SAFE(a) (!((a) & (attr_t)~NONBLANK_ATTR)) - if (ISBLANK(newscr->_line[i].text[j]) && SAFE(turnon)) { - RemAttr(newscr->_line[i].text[j], turnon); +#define SAFE(a) (!((a) & SP->_xmc_triggers)) + if (ISBLANK(thisline[j]) && SAFE(turnon)) { + RemAttr(thisline[j], turnon); continue; } /* check that there's enough room at start of span */ for (k = 1; k <= magic_cookie_glitch; k++) { if (j - k < 0 - || !ISBLANK(newscr->_line[i].text[j - k]) - || !SAFE(AttrOf(newscr->_line[i].text[j - k]))) + || !ISBLANK(thisline[j - k]) + || !SAFE(AttrOf(thisline[j - k]))) { failed = TRUE; + TR(TRACE_ATTRS, ("No room at start in %d,%d%s%s", + i, j - k, + (ISBLANK(thisline[j - k]) + ? "" + : ":nonblank"), + (SAFE(AttrOf(thisline[j - k])) + ? "" + : ":unsafe"))); + break; + } } if (!failed) { bool end_onscreen = FALSE; @@ -637,7 +738,8 @@ doupdate(void) /* find end of span, if it's onscreen */ for (m = i; m < screen_lines; m++) { for (; n < screen_columns; n++) { - if (AttrOf(newscr->_line[m].text[n]) == rattr) { + attr_t testattr = AttrOf(newscr->_line[m].text[n]); + if ((testattr & SP->_xmc_triggers) == rattr) { end_onscreen = TRUE; TR(TRACE_ATTRS, ("Range attributed with %s ends at (%d, %d)", @@ -656,22 +758,34 @@ doupdate(void) NCURSES_CH_T *lastline = newscr->_line[m].text; /* - * If there are safely-attributed blanks at the - * end of the range, shorten the range. This will - * help ensure that there is enough room at end - * of span. + * If there are safely-attributed blanks at the end of + * the range, shorten the range. This will help ensure + * that there is enough room at end of span. */ while (n >= 0 && ISBLANK(lastline[n]) - && SAFE(AttrOf(lastline[n]))) + && SAFE(AttrOf(lastline[n]))) { RemAttr(lastline[n--], turnon); + } /* check that there's enough room at end of span */ - for (k = 1; k <= magic_cookie_glitch; k++) + for (k = 1; k <= magic_cookie_glitch; k++) { if (n + k >= screen_columns || !ISBLANK(lastline[n + k]) - || !SAFE(AttrOf(lastline[n + k]))) + || !SAFE(AttrOf(lastline[n + k]))) { failed = TRUE; + TR(TRACE_ATTRS, + ("No room at end in %d,%d%s%s", + i, j - k, + (ISBLANK(lastline[n + k]) + ? "" + : ":nonblank"), + (SAFE(AttrOf(lastline[n + k])) + ? "" + : ":unsafe"))); + break; + } + } } } @@ -685,7 +799,8 @@ doupdate(void) /* turn off new attributes over span */ for (p = i; p < screen_lines; p++) { for (; q < screen_columns; q++) { - if (AttrOf(newscr->_line[p].text[q]) == rattr) + attr_t testattr = AttrOf(newscr->_line[p].text[q]); + if ((testattr & SP->_xmc_triggers) == rattr) goto foundend; RemAttr(newscr->_line[p].text[q], turnon); } @@ -698,14 +813,14 @@ doupdate(void) _traceattr(turnon), i, j)); /* - * back up the start of range so there's room - * for cookies before the first nonblank character + * Back up the start of range so there's room for cookies + * before the first nonblank character. */ for (k = 1; k <= magic_cookie_glitch; k++) - AddAttr(newscr->_line[i].text[j - k], turnon); + AddAttr(thisline[j - k], turnon); } - rattr = AttrOf(newscr->_line[i].text[j]); + rattr = thisattr; } } @@ -789,13 +904,18 @@ doupdate(void) cleanup: /* - * Keep the physical screen in normal mode in case we get other - * processes writing to the screen. + * We would like to keep the physical screen in normal mode in case we get + * other processes writing to the screen. This goal cannot be met for + * magic cookies since it interferes with attributes that may propagate + * past the current position. */ - UpdateAttrs(A_NORMAL); +#if USE_XMC_SUPPORT + if (magic_cookie_glitch != 0) +#endif + UpdateAttrs(normal); _nc_flush(); - curscr->_attrs = newscr->_attrs; + WINDOW_ATTRS(curscr) = WINDOW_ATTRS(newscr); #if USE_TRACE_TIMES (void) times(&after); @@ -824,10 +944,10 @@ doupdate(void) #define BCE_ATTRS (A_NORMAL|A_COLOR) #define BCE_BKGD(win) (((win) == curscr ? stdscr : (win))->_nc_bkgd) -static inline NCURSES_CH_T +static NCURSES_INLINE NCURSES_CH_T ClrBlank(WINDOW *win) { - NCURSES_CH_T blank = NewChar(BLANK_TEXT); + NCURSES_CH_T blank = blankchar; if (back_color_erase) AddAttr(blank, (AttrOf(BCE_BKGD(win)) & BCE_ATTRS)); return blank; @@ -887,14 +1007,14 @@ ClrToEOL(NCURSES_CH_T blank, bool needclear) } if (needclear) { - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); TPUTS_TRACE("clr_eol"); - if (SP->_el_cost > (screen_columns - SP->_curscol)) { + if (clr_eol && SP->_el_cost <= (screen_columns - SP->_curscol)) { + putp(clr_eol); + } else { int count = (screen_columns - SP->_curscol); while (count-- > 0) PutChar(CHREF(blank)); - } else { - putp(clr_eol); } } } @@ -913,7 +1033,7 @@ ClrToEOS(NCURSES_CH_T blank) row = SP->_cursrow; col = SP->_curscol; - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); TPUTS_TRACE("clr_eos"); tputs(clr_eos, screen_lines - row, _nc_outch); @@ -940,7 +1060,7 @@ ClrBottom(int total) int col; int top = total; int last = min(screen_columns, newscr->_maxx + 1); - NCURSES_CH_T blank = ClrBlank(stdscr); + NCURSES_CH_T blank = newscr->_line[total - 1].text[last - 1]; bool ok; if (clr_eos && can_clear_with(CHREF(blank))) { @@ -960,29 +1080,22 @@ ClrBottom(int total) } /* don't use clr_eos for just one line if clr_eol available */ - if (top < total - 1 || (top < total && !clr_eol && !clr_bol)) { + if (top < total) { GoTo(top, 0); ClrToEOS(blank); - total = top; if (SP->oldhash && SP->newhash) { for (row = top; row < screen_lines; row++) SP->oldhash[row] = SP->newhash[row]; } } } - return total; + return top; } #if USE_XMC_SUPPORT #if USE_WIDEC_SUPPORT -static inline bool -check_xmc_transition(NCURSES_CH_T * a, NCURSES_CH_T * b) -{ - if (((a->attr ^ b->attr) & ~(a->attr) & SP->_xmc_triggers) != 0) { - return TRUE; - } - return FALSE; -} +#define check_xmc_transition(a, b) \ + ((((a)->attr ^ (b)->attr) & ~((a)->attr) & SP->_xmc_triggers) != 0) #define xmc_turn_on(a,b) check_xmc_transition(&(a), &(b)) #else #define xmc_turn_on(a,b) ((((a)^(b)) & ~(a) & SP->_xmc_triggers) != 0) @@ -1019,14 +1132,12 @@ TransformLine(int const lineno) int n; bool attrchanged = FALSE; - TR(TRACE_UPDATE, ("TransformLine(%d) called", lineno)); + TR(TRACE_UPDATE, (T_CALLED("TransformLine(%d)"), lineno)); /* copy new hash value to old one */ if (SP->oldhash && SP->newhash) SP->oldhash[lineno] = SP->newhash[lineno]; -#define ColorOf(n) (AttrOf(n) & A_COLOR) -#define unColor(n) (AttrOf(n) & ALL_BUT_COLOR) /* * If we have colors, there is the possibility of having two color pairs * that display as the same colors. For instance, Lynx does this. Check @@ -1034,24 +1145,19 @@ TransformLine(int const lineno) * they are equivalent. */ if (SP->_coloron) { - attr_t oldColor; - attr_t newColor; int oldPair; int newPair; for (n = 0; n < screen_columns; n++) { if (!CharEq(newLine[n], oldLine[n])) { - oldColor = ColorOf(oldLine[n]); - newColor = ColorOf(newLine[n]); - if (oldColor != newColor + oldPair = GetPair(oldLine[n]); + newPair = GetPair(newLine[n]); + if (oldPair != newPair && unColor(oldLine[n]) == unColor(newLine[n])) { - oldPair = PAIR_NUMBER(oldColor); - newPair = PAIR_NUMBER(newColor); if (oldPair < COLOR_PAIRS && newPair < COLOR_PAIRS && SP->_color_pairs[oldPair] == SP->_color_pairs[newPair]) { - RemAttr(oldLine[n], A_COLOR); - AddAttr(oldLine[n], ColorOf(newLine[n])); + SetPair(oldLine[n], GetPair(newLine[n])); } } } @@ -1061,8 +1167,10 @@ TransformLine(int const lineno) if (ceol_standout_glitch && clr_eol) { firstChar = 0; while (firstChar < screen_columns) { - if (AttrOf(newLine[firstChar]) != AttrOf(oldLine[firstChar])) + if (!SameAttrOf(newLine[firstChar], oldLine[firstChar])) { attrchanged = TRUE; + break; + } firstChar++; } } @@ -1125,17 +1233,9 @@ TransformLine(int const lineno) } else { NCURSES_CH_T blank; - /* find the first differing character */ - while (firstChar < screen_columns && - CharEq(newLine[firstChar], oldLine[firstChar])) - firstChar++; - - /* if there wasn't one, we're done */ - if (firstChar >= screen_columns) - return; - /* it may be cheap to clear leading whitespace with clr_bol */ - if (clr_bol && (blank = newLine[0], can_clear_with(CHREF(blank)))) { + blank = newLine[0]; + if (clr_bol && can_clear_with(CHREF(blank))) { int oFirstChar, nFirstChar; for (oFirstChar = 0; oFirstChar < screen_columns; oFirstChar++) @@ -1145,25 +1245,44 @@ TransformLine(int const lineno) if (!CharEq(newLine[nFirstChar], blank)) break; - if (nFirstChar > oFirstChar + SP->_el1_cost) { - if (nFirstChar >= screen_columns && SP->_el_cost <= SP->_el1_cost) { - GoTo(lineno, 0); - UpdateAttrs(AttrOf(blank)); - TPUTS_TRACE("clr_eol"); - putp(clr_eol); - } else { - GoTo(lineno, nFirstChar - 1); - UpdateAttrs(AttrOf(blank)); - TPUTS_TRACE("clr_bol"); - putp(clr_bol); - } - - while (firstChar < nFirstChar) - oldLine[firstChar++] = blank; + if (nFirstChar == oFirstChar) { + firstChar = nFirstChar; + /* find the first differing character */ + while (firstChar < screen_columns + && CharEq(newLine[firstChar], oldLine[firstChar])) + firstChar++; + } else if (oFirstChar > nFirstChar) { + firstChar = nFirstChar; + } else { /* oFirstChar < nFirstChar */ + firstChar = oFirstChar; + if (SP->_el1_cost < nFirstChar - oFirstChar) { + if (nFirstChar >= screen_columns + && SP->_el_cost <= SP->_el1_cost) { + GoTo(lineno, 0); + UpdateAttrs(blank); + TPUTS_TRACE("clr_eol"); + putp(clr_eol); + } else { + GoTo(lineno, nFirstChar - 1); + UpdateAttrs(blank); + TPUTS_TRACE("clr_bol"); + putp(clr_bol); + } - if (firstChar >= screen_columns) - return; + while (firstChar < nFirstChar) + oldLine[firstChar++] = blank; + } } + } else { + /* find the first differing character */ + while (firstChar < screen_columns + && CharEq(newLine[firstChar], oldLine[firstChar])) + firstChar++; + } + /* if there wasn't one, we're done */ + if (firstChar >= screen_columns) { + TR(TRACE_UPDATE, (T_RETURN(""))); + return; } blank = newLine[screen_columns - 1]; @@ -1183,6 +1302,7 @@ TransformLine(int const lineno) newLine + firstChar, (nLastChar - firstChar + 1) * sizeof(NCURSES_CH_T)); } + TR(TRACE_UPDATE, (T_RETURN(""))); return; } @@ -1222,7 +1342,7 @@ TransformLine(int const lineno) /* can be -1 if no characters differ */ while (CharEq(newLine[nLastChar], oldLine[oLastChar])) { /* don't split a wide char */ - if (isnac(newLine[nLastChar]) && + if (isWidecExt(newLine[nLastChar]) && !CharEq(newLine[nLastChar - 1], oldLine[oLastChar - 1])) break; nLastChar--; @@ -1239,9 +1359,15 @@ TransformLine(int const lineno) if (oLastChar < nLastChar) { int m = max(nLastNonblank, oLastNonblank); +#if USE_WIDEC_SUPPORT + while (isWidecExt(newLine[n + 1]) && n) { + --n; + --oLastChar; + } +#endif GoTo(lineno, n + 1); - if (InsCharCost(nLastChar - oLastChar) - > (m - n)) { + if ((nLastChar < nLastNonblank) + || InsCharCost(nLastChar - oLastChar) > (m - n)) { PutRange(oldLine, newLine, lineno, n + 1, m); } else { InsStr(&newLine[n + 1], nLastChar - oLastChar); @@ -1263,7 +1389,7 @@ TransformLine(int const lineno) * setting the video attributes from * the last character on the row. */ - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); DelChar(oLastChar - nLastChar); } } @@ -1275,6 +1401,8 @@ TransformLine(int const lineno) memcpy(oldLine + firstChar, newLine + firstChar, (screen_columns - firstChar) * sizeof(NCURSES_CH_T)); + TR(TRACE_UPDATE, (T_RETURN(""))); + return; } /* @@ -1295,7 +1423,7 @@ ClearScreen(NCURSES_CH_T blank) #if NCURSES_EXT_FUNCS if (SP->_coloron && !SP->_default_color) { - _nc_do_color((int) COLOR_PAIR(SP->_current_attr), 0, FALSE, _nc_outch); + _nc_do_color(GET_SCREEN_PAIR(SP), 0, FALSE, _nc_outch); if (!back_color_erase) { fast_clear = FALSE; } @@ -1304,7 +1432,7 @@ ClearScreen(NCURSES_CH_T blank) if (fast_clear) { if (clear_screen) { - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); TPUTS_TRACE("clear_screen"); putp(clear_screen); SP->_cursrow = SP->_curscol = 0; @@ -1313,13 +1441,13 @@ ClearScreen(NCURSES_CH_T blank) SP->_cursrow = SP->_curscol = -1; GoTo(0, 0); - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); TPUTS_TRACE("clr_eos"); - putp(clr_eos); + tputs(clr_eos, screen_lines, _nc_outch); } else if (clr_eol) { SP->_cursrow = SP->_curscol = -1; - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); for (i = 0; i < screen_lines; i++) { GoTo(i, 0); TPUTS_TRACE("clr_eol"); @@ -1328,7 +1456,7 @@ ClearScreen(NCURSES_CH_T blank) GoTo(0, 0); } } else { - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); for (i = 0; i < screen_lines; i++) { GoTo(i, 0); for (j = 0; j < screen_columns; j++) @@ -1362,7 +1490,7 @@ InsStr(NCURSES_CH_T * line, int count) /* The order must match that of InsCharCost. */ if (parm_ich) { TPUTS_TRACE("parm_ich"); - tputs(tparm(parm_ich, count), count, _nc_outch); + tputs(TPARM_1(parm_ich, count), count, _nc_outch); while (count) { PutAttrChar(CHREF(*line)); line++; @@ -1410,12 +1538,14 @@ DelChar(int count) { int n; - TR(TRACE_UPDATE, ("DelChar(%d) called, position = (%d,%d)", count, - newscr->_cury, newscr->_curx)); + TR(TRACE_UPDATE, ("DelChar(%d) called, position = (%ld,%ld)", + count, + (long) newscr->_cury, + (long) newscr->_curx)); if (parm_dch) { TPUTS_TRACE("parm_dch"); - tputs(tparm(parm_dch, count), count, _nc_outch); + tputs(TPARM_1(parm_dch, count), count, _nc_outch); } else { for (n = 0; n < count; n++) { TPUTS_TRACE("delete_character"); @@ -1425,19 +1555,6 @@ DelChar(int count) } /* -** _nc_outstr(char *str) -** -** Emit a string without waiting for update. -*/ - -NCURSES_EXPORT(void) -_nc_outstr(const char *str) -{ - (void) putp(str); - _nc_flush(); -} - -/* * Physical-scrolling support * * This code was adapted from Keith Bostic's hardware scrolling @@ -1473,47 +1590,48 @@ _nc_outstr(const char *str) static int scroll_csr_forward(int n, int top, int bot, int miny, int maxy, NCURSES_CH_T blank) { - int i, j; + int i; if (n == 1 && scroll_forward && top == miny && bot == maxy) { GoTo(bot, 0); - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); TPUTS_TRACE("scroll_forward"); - tputs(scroll_forward, 0, _nc_outch); + putp(scroll_forward); } else if (n == 1 && delete_line && bot == maxy) { GoTo(top, 0); - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); TPUTS_TRACE("delete_line"); - tputs(delete_line, 0, _nc_outch); + putp(delete_line); } else if (parm_index && top == miny && bot == maxy) { GoTo(bot, 0); - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); TPUTS_TRACE("parm_index"); - tputs(tparm(parm_index, n, 0), n, _nc_outch); + tputs(TPARM_2(parm_index, n, 0), n, _nc_outch); } else if (parm_delete_line && bot == maxy) { GoTo(top, 0); - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); TPUTS_TRACE("parm_delete_line"); - tputs(tparm(parm_delete_line, n, 0), n, _nc_outch); + tputs(TPARM_2(parm_delete_line, n, 0), n, _nc_outch); } else if (scroll_forward && top == miny && bot == maxy) { GoTo(bot, 0); - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); for (i = 0; i < n; i++) { TPUTS_TRACE("scroll_forward"); - tputs(scroll_forward, 0, _nc_outch); + putp(scroll_forward); } } else if (delete_line && bot == maxy) { GoTo(top, 0); - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); for (i = 0; i < n; i++) { TPUTS_TRACE("delete_line"); - tputs(delete_line, 0, _nc_outch); + putp(delete_line); } } else return ERR; #if NCURSES_EXT_FUNCS if (FILL_BCE()) { + int j; for (i = 0; i < n; i++) { GoTo(bot - i, 0); for (j = 0; j < screen_columns; j++) @@ -1530,47 +1648,48 @@ static int scroll_csr_backward(int n, int top, int bot, int miny, int maxy, NCURSES_CH_T blank) { - int i, j; + int i; if (n == 1 && scroll_reverse && top == miny && bot == maxy) { GoTo(top, 0); - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); TPUTS_TRACE("scroll_reverse"); - tputs(scroll_reverse, 0, _nc_outch); + putp(scroll_reverse); } else if (n == 1 && insert_line && bot == maxy) { GoTo(top, 0); - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); TPUTS_TRACE("insert_line"); - tputs(insert_line, 0, _nc_outch); + putp(insert_line); } else if (parm_rindex && top == miny && bot == maxy) { GoTo(top, 0); - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); TPUTS_TRACE("parm_rindex"); - tputs(tparm(parm_rindex, n, 0), n, _nc_outch); + tputs(TPARM_2(parm_rindex, n, 0), n, _nc_outch); } else if (parm_insert_line && bot == maxy) { GoTo(top, 0); - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); TPUTS_TRACE("parm_insert_line"); - tputs(tparm(parm_insert_line, n, 0), n, _nc_outch); + tputs(TPARM_2(parm_insert_line, n, 0), n, _nc_outch); } else if (scroll_reverse && top == miny && bot == maxy) { GoTo(top, 0); - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); for (i = 0; i < n; i++) { TPUTS_TRACE("scroll_reverse"); - tputs(scroll_reverse, 0, _nc_outch); + putp(scroll_reverse); } } else if (insert_line && bot == maxy) { GoTo(top, 0); - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); for (i = 0; i < n; i++) { TPUTS_TRACE("insert_line"); - tputs(insert_line, 0, _nc_outch); + putp(insert_line); } } else return ERR; #if NCURSES_EXT_FUNCS if (FILL_BCE()) { + int j; for (i = 0; i < n; i++) { GoTo(top + i, 0); for (j = 0; j < screen_columns; j++) @@ -1592,41 +1711,48 @@ scroll_idl(int n, int del, int ins, NCURSES_CH_T blank) return ERR; GoTo(del, 0); - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); if (n == 1 && delete_line) { TPUTS_TRACE("delete_line"); - tputs(delete_line, 0, _nc_outch); + putp(delete_line); } else if (parm_delete_line) { TPUTS_TRACE("parm_delete_line"); - tputs(tparm(parm_delete_line, n, 0), n, _nc_outch); + tputs(TPARM_2(parm_delete_line, n, 0), n, _nc_outch); } else { /* if (delete_line) */ for (i = 0; i < n; i++) { TPUTS_TRACE("delete_line"); - tputs(delete_line, 0, _nc_outch); + putp(delete_line); } } GoTo(ins, 0); - UpdateAttrs(AttrOf(blank)); + UpdateAttrs(blank); if (n == 1 && insert_line) { TPUTS_TRACE("insert_line"); - tputs(insert_line, 0, _nc_outch); + putp(insert_line); } else if (parm_insert_line) { TPUTS_TRACE("parm_insert_line"); - tputs(tparm(parm_insert_line, n, 0), n, _nc_outch); + tputs(TPARM_2(parm_insert_line, n, 0), n, _nc_outch); } else { /* if (insert_line) */ for (i = 0; i < n; i++) { TPUTS_TRACE("insert_line"); - tputs(insert_line, 0, _nc_outch); + putp(insert_line); } } return OK; } +/* + * Note: some terminals require the cursor to be within the scrolling margins + * before setting them. Generally, the cursor must be at the appropriate end + * of the scrolling margins when issuing an indexing operation (it is not + * apparent whether it must also be at the left margin; we do this just to be + * safe). To make the related cursor movement a little faster, we use the + * save/restore cursor capabilities if the terminal has them. + */ NCURSES_EXPORT(int) -_nc_scrolln -(int n, int top, int bot, int maxy) +_nc_scrolln(int n, int top, int bot, int maxy) /* scroll region from top to bot by n lines */ { NCURSES_CH_T blank = ClrBlank(stdscr); @@ -1658,13 +1784,13 @@ _nc_scrolln && save_cursor && restore_cursor) { cursor_saved = TRUE; TPUTS_TRACE("save_cursor"); - tputs(save_cursor, 0, _nc_outch); + putp(save_cursor); } TPUTS_TRACE("change_scroll_region"); - tputs(tparm(change_scroll_region, top, bot), 0, _nc_outch); + putp(TPARM_2(change_scroll_region, top, bot)); if (cursor_saved) { TPUTS_TRACE("restore_cursor"); - tputs(restore_cursor, 0, _nc_outch); + putp(restore_cursor); } else { SP->_cursrow = SP->_curscol = -1; } @@ -1672,7 +1798,7 @@ _nc_scrolln res = scroll_csr_forward(n, top, bot, top, bot, blank); TPUTS_TRACE("change_scroll_region"); - tputs(tparm(change_scroll_region, 0, maxy), 0, _nc_outch); + putp(TPARM_2(change_scroll_region, 0, maxy)); SP->_cursrow = SP->_curscol = -1; } @@ -1684,9 +1810,9 @@ _nc_scrolln */ if (res != ERR && (non_dest_scroll_region || (memory_below && bot == maxy))) { - NCURSES_CH_T blank2 = NewChar(BLANK_TEXT); + static const NCURSES_CH_T blank2 = NewChar(BLANK_TEXT); if (bot == maxy && clr_eos) { - GoTo(bot - n, 0); + GoTo(bot - n + 1, 0); ClrToEOS(blank2); } else { for (i = 0; i < n; i++) { @@ -1704,13 +1830,13 @@ _nc_scrolln && save_cursor && restore_cursor) { cursor_saved = TRUE; TPUTS_TRACE("save_cursor"); - tputs(save_cursor, 0, _nc_outch); + putp(save_cursor); } TPUTS_TRACE("change_scroll_region"); - tputs(tparm(change_scroll_region, top, bot), 0, _nc_outch); + putp(TPARM_2(change_scroll_region, top, bot)); if (cursor_saved) { TPUTS_TRACE("restore_cursor"); - tputs(restore_cursor, 0, _nc_outch); + putp(restore_cursor); } else { SP->_cursrow = SP->_curscol = -1; } @@ -1718,7 +1844,7 @@ _nc_scrolln res = scroll_csr_backward(-n, top, bot, top, bot, blank); TPUTS_TRACE("change_scroll_region"); - tputs(tparm(change_scroll_region, 0, maxy), 0, _nc_outch); + putp(TPARM_2(change_scroll_region, 0, maxy)); SP->_cursrow = SP->_curscol = -1; } @@ -1730,7 +1856,7 @@ _nc_scrolln */ if (res != ERR && (non_dest_scroll_region || (memory_above && top == 0))) { - NCURSES_CH_T blank2 = NewChar(BLANK_TEXT); + static const NCURSES_CH_T blank2 = NewChar(BLANK_TEXT); for (i = 0; i < -n; i++) { GoTo(i + top, 0); ClrToEOL(blank2, FALSE); @@ -1753,11 +1879,27 @@ NCURSES_EXPORT(void) _nc_screen_resume(void) { /* make sure terminal is in a sane known state */ - SP->_current_attr = A_NORMAL; + SetAttr(SCREEN_ATTRS(SP), A_NORMAL); newscr->_clear = TRUE; - if (SP->_coloron == TRUE && orig_pair) - putp(orig_pair); + /* reset color pairs and definitions */ + if (SP->_coloron || SP->_color_defs) + _nc_reset_colors(); + + /* restore user-defined colors, if any */ + if (SP->_color_defs < 0) { + int n; + SP->_color_defs = -(SP->_color_defs); + for (n = 0; n < SP->_color_defs; ++n) { + if (SP->_color_table[n].init) { + init_color(n, + SP->_color_table[n].r, + SP->_color_table[n].g, + SP->_color_table[n].b); + } + } + } + if (exit_attribute_mode) putp(exit_attribute_mode); else { @@ -1785,29 +1927,30 @@ _nc_screen_init(void) NCURSES_EXPORT(void) _nc_screen_wrap(void) { - UpdateAttrs(A_NORMAL); + UpdateAttrs(normal); #if NCURSES_EXT_FUNCS if (SP->_coloron && !SP->_default_color) { - NCURSES_CH_T blank = NewChar(BLANK_TEXT); + static const NCURSES_CH_T blank = NewChar(BLANK_TEXT); SP->_default_color = TRUE; _nc_do_color(-1, 0, FALSE, _nc_outch); SP->_default_color = FALSE; mvcur(SP->_cursrow, SP->_curscol, screen_lines - 1, 0); - SP->_cursrow = screen_lines - 1; - SP->_curscol = 0; ClrToEOL(blank, TRUE); } #endif + if (SP->_color_defs) { + _nc_reset_colors(); + } } #if USE_XMC_SUPPORT NCURSES_EXPORT(void) _nc_do_xmc_glitch(attr_t previous) { - attr_t chg = XMC_CHANGES(previous ^ SP->_current_attr); + attr_t chg = XMC_CHANGES(previous ^ AttrOf(SCREEN_ATTRS(SP))); while (chg != 0) { if (chg & 1) { diff --git a/contrib/ncurses/ncurses/widechar/charable.c b/contrib/ncurses/ncurses/widechar/charable.c new file mode 100644 index 000000000000..cf7240780883 --- /dev/null +++ b/contrib/ncurses/ncurses/widechar/charable.c @@ -0,0 +1,80 @@ +/**************************************************************************** + * Copyright (c) 2003-2004,2005 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/* +** Support functions for wide/narrow conversion. +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: charable.c,v 1.4 2005/04/16 18:08:56 tom Exp $") + +NCURSES_EXPORT(bool) _nc_is_charable(wchar_t ch) +{ + bool result; +#if HAVE_WCTOB + result = (wctob((wint_t) ch) == ch); +#else + result = (_nc_to_char(ch) >= 0); +#endif + return result; +} + +NCURSES_EXPORT(int) _nc_to_char(wint_t ch) +{ + int result; +#if HAVE_WCTOB + result = wctob(ch); +#elif HAVE_WCTOMB + char temp[MB_LEN_MAX]; + result = wctomb(temp, ch); + if (strlen(temp) == 1) + result = UChar(temp[0]); + else + result = -1; +#endif + return result; +} + +NCURSES_EXPORT(wint_t) _nc_to_widechar(int ch) +{ + wint_t result; +#if HAVE_BTOWC + result = btowc(ch); +#elif HAVE_MBTOWC + wchar_t convert; + char temp[2]; + temp[0] = ch; + temp[1] = '\0'; + if (mbtowc(&convert, temp, 1) >= 0) + result = convert; + else + result = WEOF; +#endif + return result; +} diff --git a/contrib/ncurses/ncurses/widechar/lib_add_wch.c b/contrib/ncurses/ncurses/widechar/lib_add_wch.c new file mode 100644 index 000000000000..93b41bb4930c --- /dev/null +++ b/contrib/ncurses/ncurses/widechar/lib_add_wch.c @@ -0,0 +1,113 @@ +/**************************************************************************** + * Copyright (c) 2004,2006 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/* +** lib_add_wch.c +** +** The routine wadd_wch(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_add_wch.c,v 1.6 2006/12/02 21:19:17 tom Exp $") + +NCURSES_EXPORT(int) +wadd_wch(WINDOW *win, const cchar_t *wch) +{ + PUTC_DATA; + int n; + int code = ERR; + + TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wadd_wch(%p, %s)"), win, + _tracech_t(wch))); + + if (win != 0) { + PUTC_INIT; + for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { + attr_t attrs = (wch->attr & A_ATTRIBUTES); + + if ((PUTC_ch = wch->chars[PUTC_i]) == L'\0') + break; + if ((PUTC_n = wcrtomb(PUTC_buf, PUTC_ch, &PUT_st)) <= 0) { + code = ERR; + if (is8bits(PUTC_ch)) + code = waddch(win, UChar(PUTC_ch) | attrs); + break; + } + for (n = 0; n < PUTC_n; n++) { + if ((code = waddch(win, UChar(PUTC_buf[n]) | attrs)) == ERR) { + break; + } + } + if (code == ERR) + break; + } + } + + TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code)); + return (code); +} + +NCURSES_EXPORT(int) +wecho_wchar(WINDOW *win, const cchar_t *wch) +{ + PUTC_DATA; + int n; + int code = ERR; + + TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wecho_wchar(%p, %s)"), win, + _tracech_t(wch))); + + if (win != 0) { + PUTC_INIT; + for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { + attr_t attrs = (wch->attr & A_ATTRIBUTES); + + if ((PUTC_ch = wch->chars[PUTC_i]) == L'\0') + break; + if ((PUTC_n = wcrtomb(PUTC_buf, PUTC_ch, &PUT_st)) <= 0) { + code = ERR; + if (is8bits(PUTC_ch)) + code = waddch(win, UChar(PUTC_ch) | attrs); + break; + } + for (n = 0; n < PUTC_n; n++) { + if ((code = waddch(win, UChar(PUTC_buf[n]) | attrs)) == ERR) { + break; + } + } + if (code == ERR) + break; + } + wrefresh(win); + } + + TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code)); + return (code); +} diff --git a/contrib/ncurses/ncurses/widechar/lib_box_set.c b/contrib/ncurses/ncurses/widechar/lib_box_set.c index 7f69e5aa5113..35fce46d8d40 100644 --- a/contrib/ncurses/ncurses/widechar/lib_box_set.c +++ b/contrib/ncurses/ncurses/widechar/lib_box_set.c @@ -39,7 +39,7 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_box_set.c,v 1.2 2002/03/23 21:35:24 tom Exp $") +MODULE_ID("$Id: lib_box_set.c,v 1.4 2003/12/06 18:02:13 tom Exp $") NCURSES_EXPORT(int) wborder_set(WINDOW *win, @@ -66,7 +66,7 @@ wborder_set(WINDOW *win, if (!win) returnCode(ERR); -#define RENDER_WITH_DEFAULT(ch,def) w ##ch = (ch == 0) ? *def : *ch +#define RENDER_WITH_DEFAULT(ch,def) w ##ch = _nc_render(win, (ch == 0) ? *(const ARG_CH_T)def : *ch) RENDER_WITH_DEFAULT(ls, WACS_VLINE); RENDER_WITH_DEFAULT(rs, WACS_VLINE); diff --git a/contrib/ncurses/ncurses/widechar/lib_cchar.c b/contrib/ncurses/ncurses/widechar/lib_cchar.c index efbfc69b1c0f..b6458ee4a1f4 100644 --- a/contrib/ncurses/ncurses/widechar/lib_cchar.c +++ b/contrib/ncurses/ncurses/widechar/lib_cchar.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2001,2002 Free Software Foundation, Inc. * + * Copyright (c) 2001-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 * @@ -35,17 +35,20 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_cchar.c,v 1.5 2002/04/27 22:35:46 tom Exp $") +MODULE_ID("$Id: lib_cchar.c,v 1.11 2005/01/29 21:29:16 tom Exp $") /* * The SuSv2 description leaves some room for interpretation. We'll assume wch - * is L'\0' terminated, contains at most one character with strictly positive - * width, which must be the first, and contains no characters of negative - * width. + * points to a string which is L'\0' terminated, contains at least one + * character with strictly positive width, which must be the first, and + * contains no characters of negative width. */ NCURSES_EXPORT(int) -setcchar(cchar_t * wcval, const wchar_t * wch, const attr_t attrs, - short color_pair, const void *opts) +setcchar(cchar_t *wcval, + const wchar_t *wch, + const attr_t attrs, + short color_pair, + const void *opts) { int i; int len; @@ -54,27 +57,33 @@ setcchar(cchar_t * wcval, const wchar_t * wch, const attr_t attrs, TR(TRACE_CCALLS, (T_CALLED("setcchar(%p,%s,%ld,%d,%p)"), wcval, _nc_viswbuf(wch), attrs, color_pair, opts)); - if (opts != NULL || (len = wcslen(wch)) > CCHARW_MAX - || (len > 0 && wcwidth(wch[0]) < 0)) { + len = wcslen(wch); + if (opts != NULL + || (len > 1 && wcwidth(wch[0]) < 0)) { code = ERR; } else { + if (len > CCHARW_MAX) + len = CCHARW_MAX; + /* + * If we have a following spacing-character, stop at that point. We + * are only interested in adding non-spacing characters. + */ for (i = 1; i < len; ++i) { if (wcwidth(wch[i]) != 0) { - code = ERR; + len = i; break; } } - if (code != ERR) { - memset(wcval, 0, sizeof(*wcval)); + memset(wcval, 0, sizeof(*wcval)); - if (len != 0) { - SetAttr(*wcval, attrs | color_pair); - memcpy(&wcval->chars, wch, len * sizeof(wchar_t)); - TR(TRACE_CCALLS, ("copy %d wchars, first is %s", len, - _tracecchar_t(wcval))); - } + if (len != 0) { + SetAttr(*wcval, attrs | COLOR_PAIR(color_pair)); + SetPair(CHDEREF(wcval), color_pair); + memcpy(&wcval->chars, wch, len * sizeof(wchar_t)); + TR(TRACE_CCALLS, ("copy %d wchars, first is %s", len, + _tracecchar_t(wcval))); } } @@ -83,8 +92,11 @@ setcchar(cchar_t * wcval, const wchar_t * wch, const attr_t attrs, } NCURSES_EXPORT(int) -getcchar(const cchar_t * wcval, wchar_t * wch, attr_t * attrs, - short *color_pair, void *opts) +getcchar(const cchar_t *wcval, + wchar_t *wch, + attr_t *attrs, + short *color_pair, + void *opts) { wchar_t *wp; int len; @@ -100,9 +112,11 @@ getcchar(const cchar_t * wcval, wchar_t * wch, attr_t * attrs, if (wch == NULL) { code = len; + } else if (attrs == 0 || color_pair == 0) { + code = ERR; } else if (len >= 0) { *attrs = AttrOf(*wcval) & A_ATTRIBUTES; - *color_pair = AttrOf(*wcval) & A_COLOR; + *color_pair = GetPair(*wcval); wmemcpy(wch, wcval->chars, (unsigned) len); wch[len] = L'\0'; code = OK; diff --git a/contrib/ncurses/ncurses/widechar/lib_get_wch.c b/contrib/ncurses/ncurses/widechar/lib_get_wch.c index 21c40a506ccc..c73c363be531 100644 --- a/contrib/ncurses/ncurses/widechar/lib_get_wch.c +++ b/contrib/ncurses/ncurses/widechar/lib_get_wch.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2002 Free Software Foundation, Inc. * + * Copyright (c) 2002-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,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey 2002 * + * Author: Thomas E. Dickey 2002-on * ****************************************************************************/ /* @@ -38,28 +38,47 @@ */ #include <curses.priv.h> +#include <ctype.h> -MODULE_ID("$Id: lib_get_wch.c,v 1.3 2002/03/17 16:14:45 tom Exp $") +MODULE_ID("$Id: lib_get_wch.c,v 1.13 2006/06/03 17:27:57 tom Exp $") + +#if HAVE_MBTOWC && HAVE_MBLEN +#define reset_mbytes(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0) +#define count_mbytes(buffer,length,state) mblen(buffer,length) +#define check_mbytes(wch,buffer,length,state) \ + (int) mbtowc(&wch, buffer, length) +#define state_unused +#elif HAVE_MBRTOWC && HAVE_MBRLEN +#define reset_mbytes(state) init_mb(state) +#define count_mbytes(buffer,length,state) mbrlen(buffer,length,&state) +#define check_mbytes(wch,buffer,length,state) \ + (int) mbrtowc(&wch, buffer, length, &state) +#else +make an error +#endif NCURSES_EXPORT(int) -wget_wch(WINDOW *win, wint_t * result) +wget_wch(WINDOW *win, wint_t *result) { int code; - char buffer[(MB_CUR_MAX * 9) + 1]; /* allow some redundant shifts */ + char buffer[(MB_LEN_MAX * 9) + 1]; /* allow some redundant shifts */ int status; - mbstate_t state; size_t count = 0; unsigned long value; wchar_t wch; +#ifndef state_unused + mbstate_t state; +#endif T((T_CALLED("wget_wch(%p)"), win)); + /* * We can get a stream of single-byte characters and KEY_xxx codes from * _nc_wgetch(), while we want to return a wide character or KEY_xxx code. */ for (;;) { - T(("reading %d of %d", count + 1, sizeof(buffer))); - code = _nc_wgetch(win, &value, TRUE); + T(("reading %d of %d", count + 1, sizeof(buffer))); + code = _nc_wgetch(win, &value, TRUE EVENTLIST_2nd((_nc_eventlist *) 0)); if (code == ERR) { break; } else if (code == KEY_CODE_YES) { @@ -71,22 +90,23 @@ wget_wch(WINDOW *win, wint_t * result) * would be worth the effort. */ if (count != 0) { - ungetch(value); + ungetch((int) value); code = ERR; } break; } else if (count + 1 >= sizeof(buffer)) { - ungetch(value); + ungetch((int) value); code = ERR; break; } else { buffer[count++] = UChar(value); - memset(&state, 0, sizeof(state)); - status = mbrlen(buffer, count, &state); + reset_mbytes(state); + status = count_mbytes(buffer, count, state); if (status >= 0) { - memset(&state, 0, sizeof(state)); - if ((int) mbrtowc(&wch, buffer, count, &state) != status) { + reset_mbytes(state); + if (check_mbytes(wch, buffer, count, state) != status) { code = ERR; /* the two calls should match */ + ungetch((int) value); } value = wch; break; @@ -94,6 +114,6 @@ wget_wch(WINDOW *win, wint_t * result) } } *result = value; - T(("result %#o", value)); + T(("result %#lo", value)); returnCode(code); } diff --git a/contrib/ncurses/ncurses/widechar/lib_get_wstr.c b/contrib/ncurses/ncurses/widechar/lib_get_wstr.c index 426381cce0a5..bf39aa1a188b 100644 --- a/contrib/ncurses/ncurses/widechar/lib_get_wstr.c +++ b/contrib/ncurses/ncurses/widechar/lib_get_wstr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2002 Free Software Foundation, Inc. * + * Copyright (c) 2002-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 * @@ -27,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey 2002 * + * Author: Thomas E. Dickey * ****************************************************************************/ /* @@ -40,23 +40,38 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("$Id: lib_get_wstr.c,v 1.3 2002/05/11 22:29:43 tom Exp $") +MODULE_ID("$Id: lib_get_wstr.c,v 1.8 2004/10/16 21:55:36 tom Exp $") + +static int +wadd_wint(WINDOW *win, wint_t *src) +{ + cchar_t tmp; + wchar_t wch[2]; + + wch[0] = *src; + wch[1] = 0; + setcchar(&tmp, wch, A_NORMAL, 0, NULL); + return wadd_wch(win, &tmp); +} /* * This wipes out the last character, no matter whether it was a tab, control * or other character, and handles reverse wraparound. */ -static wchar_t * -WipeOut(WINDOW *win, int y, int x, wchar_t * first, wchar_t * last, bool echoed) +static wint_t * +WipeOut(WINDOW *win, int y, int x, wint_t *first, wint_t *last, bool echoed) { if (last > first) { *--last = '\0'; if (echoed) { int y1 = win->_cury; int x1 = win->_curx; + int n; wmove(win, y, x); - waddwstr(win, first); + for (n = 0; first[n] != 0; ++n) { + wadd_wint(win, first + n); + } getyx(win, y, x); while (win->_cury < y1 || (win->_cury == y1 && win->_curx < x1)) @@ -69,14 +84,14 @@ WipeOut(WINDOW *win, int y, int x, wchar_t * first, wchar_t * last, bool echoed) } NCURSES_EXPORT(int) -wgetn_wstr(WINDOW *win, wint_t * str, int maxlen) +wgetn_wstr(WINDOW *win, wint_t *str, int maxlen) { TTY buf; bool oldnl, oldecho, oldraw, oldcbreak; wint_t erasec; wint_t killc; - wchar_t *oldstr; - wchar_t *tmpstr; + wint_t *oldstr = str; + wint_t *tmpstr = str; wint_t ch; int y, x, code; @@ -99,16 +114,31 @@ wgetn_wstr(WINDOW *win, wint_t * str, int maxlen) erasec = erasechar(); killc = killchar(); - assert(sizeof(wchar_t) == sizeof(wint_t)); - oldstr = (wchar_t *) str; - tmpstr = (wchar_t *) str; - getyx(win, y, x); if (is_wintouched(win) || (win->_flags & _HASMOVED)) wrefresh(win); while ((code = wget_wch(win, &ch)) != ERR) { + /* + * Map special characters into key-codes. + */ + if (ch == '\r') + ch = '\n'; + if (ch == '\n') { + code = KEY_CODE_YES; + ch = KEY_ENTER; + } + if (ch < KEY_MIN) { + if (ch == erasec) { + ch = KEY_BACKSPACE; + code = KEY_CODE_YES; + } + if (ch == killc) { + ch = KEY_EOL; + code = KEY_CODE_YES; + } + } if (code == KEY_CODE_YES) { /* * Some terminals (the Wyse-50 is the most common) generate a \n @@ -116,21 +146,18 @@ wgetn_wstr(WINDOW *win, wint_t * str, int maxlen) * choice whether to set kcud=\n for wget_wch(); terminating * *getn_wstr() with \n should work either way. */ - if (ch == '\n' - || ch == '\r' - || ch == KEY_DOWN - || ch == KEY_ENTER) { + if (ch == KEY_DOWN || ch == KEY_ENTER) { if (oldecho == TRUE && win->_cury == win->_maxy && win->_scroll) wechochar(win, (chtype) '\n'); break; } - if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) { + if (ch == KEY_LEFT || ch == KEY_BACKSPACE) { if (tmpstr > oldstr) { tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho); } - } else if (ch == killc) { + } else if (ch == KEY_EOL) { while (tmpstr > oldstr) { tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho); } @@ -141,12 +168,11 @@ wgetn_wstr(WINDOW *win, wint_t * str, int maxlen) beep(); } else { *tmpstr++ = ch; + *tmpstr = 0; if (oldecho == TRUE) { int oldy = win->_cury; - cchar_t tmp; - setcchar(&tmp, tmpstr - 1, A_NORMAL, 0, NULL); - if (wadd_wch(win, &tmp) == ERR) { + if (wadd_wint(win, tmpstr - 1) == ERR) { /* * We can't really use the lower-right corner for input, * since it'll mess up bookkeeping for erases. @@ -188,18 +214,18 @@ wgetn_wstr(WINDOW *win, wint_t * str, int maxlen) SP->_raw = oldraw; SP->_cbreak = oldcbreak; - _nc_set_tty_mode(&buf); + (void) _nc_set_tty_mode(&buf); *tmpstr = 0; if (code == ERR) { if (tmpstr == oldstr) { - *tmpstr++ = (wchar_t)WEOF; + *tmpstr++ = WEOF; *tmpstr = 0; } returnCode(ERR); } - T(("wgetn_wstr returns %s", _nc_viswbuf(oldstr))); + T(("wgetn_wstr returns %s", _nc_viswibuf(oldstr))); returnCode(OK); } diff --git a/contrib/ncurses/ncurses/widechar/lib_in_wch.c b/contrib/ncurses/ncurses/widechar/lib_in_wch.c index 562fa82602fe..5cd92e382de4 100644 --- a/contrib/ncurses/ncurses/widechar/lib_in_wch.c +++ b/contrib/ncurses/ncurses/widechar/lib_in_wch.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2002 Free Software Foundation, Inc. * + * Copyright (c) 2002-2004,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -27,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas Dickey 2002 * + * Author: Thomas Dickey * ****************************************************************************/ /* @@ -39,10 +39,10 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_in_wch.c,v 1.1 2002/03/10 20:22:00 tom Exp $") +MODULE_ID("$Id: lib_in_wch.c,v 1.4 2006/09/03 15:41:22 tom Exp $") NCURSES_EXPORT(int) -win_wch(WINDOW *win, NCURSES_CONST cchar_t * wcval) +win_wch(WINDOW *win, cchar_t *wcval) { int row, col; int code = OK; @@ -53,8 +53,10 @@ win_wch(WINDOW *win, NCURSES_CONST cchar_t * wcval) getyx(win, row, col); *wcval = win->_line[row].text[col]; + TR(TRACE_CCALLS, ("data %s", _tracecchar_t(wcval))); } else { code = ERR; } - returnCode(code); + TR(TRACE_CCALLS, (T_RETURN("%d"), code)); + return (code); } diff --git a/contrib/ncurses/ncurses/widechar/lib_in_wchnstr.c b/contrib/ncurses/ncurses/widechar/lib_in_wchnstr.c index 42268ec3e025..41ba18ccdf00 100644 --- a/contrib/ncurses/ncurses/widechar/lib_in_wchnstr.c +++ b/contrib/ncurses/ncurses/widechar/lib_in_wchnstr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2002 Free Software Foundation, Inc. * + * Copyright (c) 2002,2004 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -27,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas Dickey 2002 * + * Author: Thomas Dickey 2002,2004 * ****************************************************************************/ /* @@ -39,22 +39,28 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_in_wchnstr.c,v 1.1 2002/04/13 19:33:57 tom Exp $") +MODULE_ID("$Id: lib_in_wchnstr.c,v 1.3 2004/05/16 00:12:30 tom Exp $") NCURSES_EXPORT(int) -win_wchnstr(WINDOW *win, NCURSES_CONST cchar_t * wchstr, int n) +win_wchnstr(WINDOW *win, cchar_t * wchstr, int n) { int code = OK; - TR(TRACE_CCALLS, (T_CALLED("win_wchnstr(%p,%p,%d)"), win, wchstr, n)); + TR(TRACE_CALLS, (T_CALLED("win_wchnstr(%p,%p,%d)"), win, wchstr, n)); if (win != 0 && wchstr != 0) { + int row, col; + int j; + + getyx(win, row, col); if (n < 0) { n = getmaxx(win) + 1 - getcurx(win); } - while (n-- > 0) - win_wch(win, wchstr++); + for (j = 0; j < n; ++j) { + wchstr[j] = win->_line[row].text[col + j]; + } + T(("result = %s", _nc_viscbuf(wchstr, n))); } else { code = ERR; } diff --git a/contrib/ncurses/ncurses/widechar/lib_ins_wch.c b/contrib/ncurses/ncurses/widechar/lib_ins_wch.c index 0821ee590bf8..c3d0420e53b8 100644 --- a/contrib/ncurses/ncurses/widechar/lib_ins_wch.c +++ b/contrib/ncurses/ncurses/widechar/lib_ins_wch.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2002 Free Software Foundation, Inc. * + * Copyright (c) 2002-2003,2005 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -39,27 +39,106 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_ins_wch.c,v 1.1 2002/03/10 22:25:06 tom Exp $") +MODULE_ID("$Id: lib_ins_wch.c,v 1.8 2005/12/03 20:24:19 tom Exp $") -NCURSES_EXPORT(int) -wins_wch(WINDOW *win, const cchar_t * wch) +/* + * Insert the given character, updating the current location to simplify + * inserting a string. + */ +static int +_nc_insert_wch(WINDOW *win, const cchar_t *wch) { - int code = ERR; + int cells = wcwidth(CharOf(CHDEREF(wch))); + int cell; - T((T_CALLED("wins_wch(%p, %s)"), win, _tracecchar_t(wch))); + if (cells <= 0) + cells = 1; - if (win) { + 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; + NCURSES_CH_T *temp2 = temp1 - cells; CHANGED_TO_EOL(line, win->_curx, win->_maxx); while (temp1 > end) *temp1-- = *temp2--; *temp1 = _nc_render(win, *wch); + for (cell = 1; cell < cells; ++cell) { + SetWidecExt(temp1[cell], cell); + } + + win->_curx++; + } + return OK; +} + +NCURSES_EXPORT(int) +wins_wch(WINDOW *win, const cchar_t *wch) +{ + NCURSES_SIZE_T oy; + NCURSES_SIZE_T ox; + int code = ERR; + + T((T_CALLED("wins_wch(%p, %s)"), win, _tracecchar_t(wch))); + + if (win != 0) { + oy = win->_cury; + ox = win->_curx; + + code = _nc_insert_wch(win, wch); + + win->_curx = ox; + win->_cury = oy; + _nc_synchook(win); + } + returnCode(code); +} + +NCURSES_EXPORT(int) +wins_nwstr(WINDOW *win, const wchar_t *wstr, int n) +{ + int code = ERR; + NCURSES_SIZE_T oy; + NCURSES_SIZE_T ox; + const wchar_t *cp; + + T((T_CALLED("wins_nwstr(%p,%s,%d)"), win, _nc_viswbufn(wstr, n), n)); + + if (win != 0 + && wstr != 0) { + if (n < 1) + n = wcslen(wstr); code = OK; + if (n > 0) { + oy = win->_cury; + ox = win->_curx; + for (cp = wstr; *cp && ((cp - wstr) < n); cp++) { + int len = wcwidth(*cp); + + if (len != 1 || !is8bits(*cp)) { + cchar_t tmp_cchar; + wchar_t tmp_wchar = *cp; + memset(&tmp_cchar, 0, sizeof(tmp_cchar)); + (void) setcchar(&tmp_cchar, + &tmp_wchar, + WA_NORMAL, + 0, + (void *) 0); + code = _nc_insert_wch(win, &tmp_cchar); + } else { + /* tabs, other ASCII stuff */ + code = _nc_insert_ch(win, (chtype) (*cp)); + } + if (code != OK) + break; + } + + win->_curx = ox; + win->_cury = oy; + _nc_synchook(win); + } } returnCode(code); } diff --git a/contrib/ncurses/ncurses/widechar/lib_inwstr.c b/contrib/ncurses/ncurses/widechar/lib_inwstr.c index c3c46fa9e554..2207a5f5d19f 100644 --- a/contrib/ncurses/ncurses/widechar/lib_inwstr.c +++ b/contrib/ncurses/ncurses/widechar/lib_inwstr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2002 Free Software Foundation, Inc. * + * Copyright (c) 2002,2004 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -27,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas Dickey 2002 * + * Author: Thomas Dickey * ****************************************************************************/ /* @@ -39,10 +39,10 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_inwstr.c,v 1.1 2002/03/10 00:25:27 tom Exp $") +MODULE_ID("$Id: lib_inwstr.c,v 1.4 2004/10/23 20:41:28 tom Exp $") NCURSES_EXPORT(int) -winnwstr(WINDOW *win, wchar_t * wstr, int n) +winnwstr(WINDOW *win, wchar_t *wstr, int n) { int row, col, inx; int count = 0; @@ -50,23 +50,25 @@ winnwstr(WINDOW *win, wchar_t * wstr, int n) cchar_t *text; wchar_t wch; - TR(TRACE_CCALLS, (T_CALLED("winnwstr(%p,%p,%d)"), win, wstr, n)); + T((T_CALLED("winnwstr(%p,%p,%d)"), win, wstr, n)); if (wstr != 0) { if (win) { getyx(win, row, col); text = win->_line[row].text; while (count < n && count != ERR) { - for (inx = 0; (inx < CCHARW_MAX) - && ((wch = text[col].chars[inx]) != 0); - ++inx) { - if (count + 1 >= n) { - if ((count = last) == 0) { - count = ERR; /* error if we t store nothing */ + if (!isWidecExt(text[col])) { + for (inx = 0; (inx < CCHARW_MAX) + && ((wch = text[col].chars[inx]) != 0); + ++inx) { + if (count + 1 > n) { + if ((count = last) == 0) { + count = ERR; /* error if we store nothing */ + } + break; } - break; + wstr[count++] = wch; } - wstr[count++] = wch; } last = count; if (++col > win->_maxx) { @@ -74,8 +76,10 @@ winnwstr(WINDOW *win, wchar_t * wstr, int n) } } } - if (count > 0) + if (count > 0) { wstr[count] = '\0'; + T(("winnwstr returns %s", _nc_viswbuf(wstr))); + } } returnCode(count); } @@ -86,10 +90,10 @@ winnwstr(WINDOW *win, wchar_t * wstr, int n) * it does not define what happens for a negative count with winnwstr(). */ NCURSES_EXPORT(int) -winwstr(WINDOW *win, wchar_t * wstr) +winwstr(WINDOW *win, wchar_t *wstr) { int result = OK; - TR(TRACE_CCALLS, (T_CALLED("winwstr(%p,%p)"), win, wstr)); + T((T_CALLED("winwstr(%p,%p)"), win, wstr)); if (winnwstr(win, wstr, CCHARW_MAX * (win->_maxx - win->_curx + 1)) == ERR) result = ERR; returnCode(result); diff --git a/contrib/ncurses/ncurses/widechar/lib_pecho_wchar.c b/contrib/ncurses/ncurses/widechar/lib_pecho_wchar.c new file mode 100644 index 000000000000..e61277574311 --- /dev/null +++ b/contrib/ncurses/ncurses/widechar/lib_pecho_wchar.c @@ -0,0 +1,57 @@ +/**************************************************************************** + * Copyright (c) 2004 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_pecho_wchar.c,v 1.1 2004/01/03 21:42:01 tom Exp $") + +NCURSES_EXPORT(int) +pecho_wchar(WINDOW *pad, const cchar_t * wch) +{ + T((T_CALLED("pecho_wchar(%p, %s)"), pad, _tracech_t(wch))); + + if (pad == 0) + returnCode(ERR); + + if (!(pad->_flags & _ISPAD)) + returnCode(wecho_wchar(pad, wch)); + + wadd_wch(pad, wch); + prefresh(pad, pad->_pad._pad_y, + pad->_pad._pad_x, + pad->_pad._pad_top, + pad->_pad._pad_left, + pad->_pad._pad_bottom, + pad->_pad._pad_right); + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/widechar/lib_slk_wset.c b/contrib/ncurses/ncurses/widechar/lib_slk_wset.c new file mode 100644 index 000000000000..646b5d9e2fa8 --- /dev/null +++ b/contrib/ncurses/ncurses/widechar/lib_slk_wset.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * Copyright (c) 2003-2004,2005 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey * + ****************************************************************************/ + +/* + * lib_slk_wset.c + * Set soft label text. + */ +#include <curses.priv.h> + +#if HAVE_WCTYPE_H +#include <wctype.h> +#endif + +MODULE_ID("$Id: lib_slk_wset.c,v 1.11 2005/01/16 01:03:53 tom Exp $") + +NCURSES_EXPORT(int) +slk_wset(int i, const wchar_t *astr, int format) +{ + int result = ERR; + size_t arglen; + const wchar_t *str; + char *mystr; + mbstate_t state; + + T((T_CALLED("slk_wset(%d, %s, %d)"), i, _nc_viswbuf(astr), format)); + + init_mb(state); + str = astr; + if ((arglen = wcsrtombs(NULL, &str, 0, &state)) != (size_t) -1) { + if ((mystr = (char *) _nc_doalloc(0, arglen + 1)) != 0) { + str = astr; + if (wcsrtombs(mystr, &str, arglen, &state) != (size_t) -1) { + /* glibc documentation claims that the terminating L'\0' + * is written, but it is not... + */ + mystr[arglen] = 0; + result = slk_set(i, mystr, format); + } + free(mystr); + } + } + returnCode(result); +} diff --git a/contrib/ncurses/ncurses/widechar/lib_unget_wch.c b/contrib/ncurses/ncurses/widechar/lib_unget_wch.c index b4b3433519c1..62ec89d75014 100644 --- a/contrib/ncurses/ncurses/widechar/lib_unget_wch.c +++ b/contrib/ncurses/ncurses/widechar/lib_unget_wch.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2002 Free Software Foundation, Inc. * + * Copyright (c) 2002-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 * @@ -39,7 +39,26 @@ #include <curses.priv.h> -MODULE_ID("$Id: lib_unget_wch.c,v 1.2 2002/03/17 00:01:38 tom Exp $") +MODULE_ID("$Id: lib_unget_wch.c,v 1.7 2004/12/05 01:21:31 tom Exp $") + +#ifdef linux +/* + * glibc's wcrtomb() function is broken - does not return the proper value + * when target is null (noted for glibc 2.3.2). This is a workaround. + */ +NCURSES_EXPORT(size_t) +_nc_wcrtomb(char *target, wchar_t source, mbstate_t * state) +{ + if (target == 0) { + wchar_t temp[2]; + const wchar_t *tempp = temp; + temp[0] = source; + temp[1] = 0; + return wcsrtombs(NULL, &tempp, 0, state); + } + return wcrtomb(target, source, state); +} +#endif NCURSES_EXPORT(int) unget_wch(const wchar_t wch) @@ -49,25 +68,29 @@ unget_wch(const wchar_t wch) size_t length; int n; - T((T_CALLED("unget_wch(%d)"), wch)); + T((T_CALLED("unget_wch(%#lx)"), (unsigned long) wch)); - memset(&state, 0, sizeof(state)); - length = wcrtomb(0, wch, &state); + init_mb(state); + length = _nc_wcrtomb(0, wch, &state); if (length != (size_t) (-1) && length != 0) { - char *string = malloc(length); + char *string; - memset(&state, 0, sizeof(state)); - wcrtomb(string, wch, &state); + if ((string = (char *) malloc(length)) != 0) { + init_mb(state); + wcrtomb(string, wch, &state); - for (n = (int) (length - 1); n >= 0; --n) { - if (ungetch(string[n]) != OK) { - result = ERR; - break; + for (n = (int) (length - 1); n >= 0; --n) { + if (ungetch(string[n]) != OK) { + result = ERR; + break; + } } + free(string); + } else { + result = ERR; } - free(string); } else { result = ERR; } diff --git a/contrib/ncurses/ncurses/widechar/lib_vid_attr.c b/contrib/ncurses/ncurses/widechar/lib_vid_attr.c index 06e7880dd4d0..2ba16b5cf924 100644 --- a/contrib/ncurses/ncurses/widechar/lib_vid_attr.c +++ b/contrib/ncurses/ncurses/widechar/lib_vid_attr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2002 Free Software Foundation, Inc. * + * Copyright (c) 2002-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,68 +27,248 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey 2002 * + * Author: Thomas E. Dickey * ****************************************************************************/ #include <curses.priv.h> #include <term.h> -MODULE_ID("$Id: lib_vid_attr.c,v 1.1 2002/05/11 20:55:26 tom Exp $") +MODULE_ID("$Id: lib_vid_attr.c,v 1.4 2006/11/26 00:26:00 tom Exp $") -#define set_color(mode, pair) mode &= ~A_COLOR; mode |= COLOR_PAIR(pair) +#define doPut(mode) TPUTS_TRACE(#mode); tputs(mode, 1, outc) + +#define TurnOn(mask,mode) \ + if ((turn_on & mask) && mode) { doPut(mode); } + +#define TurnOff(mask,mode) \ + if ((turn_off & mask) && mode) { doPut(mode); turn_off &= ~mask; } + + /* if there is no current screen, assume we *can* do color */ +#define SetColorsIf(why, old_attr, old_pair) \ + if (can_color && (why)) { \ + TR(TRACE_ATTRS, ("old pair = %d -- new pair = %d", old_pair, pair)); \ + if ((pair != old_pair) \ + || (fix_pair0 && (pair == 0)) \ + || (reverse ^ ((old_attr & A_REVERSE) != 0))) { \ + _nc_do_color(old_pair, pair, reverse, outc); \ + } \ + } + +#define set_color(mode, pair) mode &= ALL_BUT_COLOR; mode |= COLOR_PAIR(pair) NCURSES_EXPORT(int) vid_puts(attr_t newmode, short pair, void *opts GCC_UNUSED, int (*outc) (int)) { +#if NCURSES_EXT_COLORS + static attr_t previous_attr = A_NORMAL; + static int previous_pair = 0; + + attr_t turn_on, turn_off; + bool reverse = FALSE; + bool can_color = (SP == 0 || SP->_coloron); +#if NCURSES_EXT_FUNCS + bool fix_pair0 = (SP != 0 && SP->_coloron && !SP->_default_color); +#else +#define fix_pair0 FALSE +#endif + + T((T_CALLED("vid_puts(%s,%d)"), _traceattr(newmode), pair)); + + /* this allows us to go on whether or not newterm() has been called */ + if (SP) { + previous_attr = AttrOf(SCREEN_ATTRS(SP)); + previous_pair = GetPair(SCREEN_ATTRS(SP)); + } + + TR(TRACE_ATTRS, ("previous attribute was %s, %d", + _traceattr(previous_attr), previous_pair)); + +#if !USE_XMC_SUPPORT + if ((SP != 0) + && (magic_cookie_glitch > 0)) + newmode &= ~(SP->_xmc_suppress); +#endif + + /* + * If we have a terminal that cannot combine color with video + * attributes, use the colors in preference. + */ + if ((pair != 0 + || fix_pair0) + && (no_color_video > 0)) { + /* + * If we had chosen the A_xxx definitions to correspond to the + * no_color_video mask, we could simply shift it up and mask off the + * attributes. But we did not (actually copied Solaris' definitions). + * However, this is still simpler/faster than a lookup table. + * + * The 63 corresponds to A_STANDOUT, A_UNDERLINE, A_REVERSE, A_BLINK, + * A_DIM, A_BOLD which are 1:1 with no_color_video. The bits that + * correspond to A_INVIS, A_PROTECT (192) must be shifted up 1 and + * A_ALTCHARSET (256) down 2 to line up. We use the NCURSES_BITS + * macro so this will work properly for the wide-character layout. + */ + unsigned value = no_color_video; + attr_t mask = NCURSES_BITS((value & 63) + | ((value & 192) << 1) + | ((value & 256) >> 2), 8); + + if ((mask & A_REVERSE) != 0 + && (newmode & A_REVERSE) != 0) { + reverse = TRUE; + mask &= ~A_REVERSE; + } + newmode &= ~mask; + } + + if (newmode == previous_attr + && pair == previous_pair) + returnCode(OK); + + if (reverse) { + newmode &= ~A_REVERSE; + } + + turn_off = (~newmode & previous_attr) & ALL_BUT_COLOR; + turn_on = (newmode & ~previous_attr) & ALL_BUT_COLOR; + + SetColorsIf(((pair == 0) && !fix_pair0), previous_attr, previous_pair); + + if (newmode == A_NORMAL) { + if ((previous_attr & A_ALTCHARSET) && exit_alt_charset_mode) { + doPut(exit_alt_charset_mode); + previous_attr &= ~A_ALTCHARSET; + } + if (previous_attr) { + if (exit_attribute_mode) { + doPut(exit_attribute_mode); + } else { + if (!SP || SP->_use_rmul) { + TurnOff(A_UNDERLINE, exit_underline_mode); + } + if (!SP || SP->_use_rmso) { + TurnOff(A_STANDOUT, exit_standout_mode); + } + } + previous_attr &= ALL_BUT_COLOR; + previous_pair = 0; + } + + SetColorsIf((pair != 0) || fix_pair0, previous_attr, previous_pair); + } else if (set_attributes) { + if (turn_on || turn_off) { + TPUTS_TRACE("set_attributes"); + tputs(TPARM_9(set_attributes, + (newmode & A_STANDOUT) != 0, + (newmode & A_UNDERLINE) != 0, + (newmode & A_REVERSE) != 0, + (newmode & A_BLINK) != 0, + (newmode & A_DIM) != 0, + (newmode & A_BOLD) != 0, + (newmode & A_INVIS) != 0, + (newmode & A_PROTECT) != 0, + (newmode & A_ALTCHARSET) != 0), 1, outc); + previous_attr &= ALL_BUT_COLOR; + previous_pair = 0; + } + SetColorsIf((pair != 0) || fix_pair0, previous_attr, previous_pair); + } else { + + TR(TRACE_ATTRS, ("turning %s off", _traceattr(turn_off))); + + TurnOff(A_ALTCHARSET, exit_alt_charset_mode); + + if (!SP || SP->_use_rmul) { + TurnOff(A_UNDERLINE, exit_underline_mode); + } + + if (!SP || SP->_use_rmso) { + TurnOff(A_STANDOUT, exit_standout_mode); + } + + if (turn_off && exit_attribute_mode) { + doPut(exit_attribute_mode); + turn_on |= (newmode & ALL_BUT_COLOR); + previous_attr &= ALL_BUT_COLOR; + previous_pair = 0; + } + SetColorsIf((pair != 0) || fix_pair0, previous_attr, previous_pair); + + TR(TRACE_ATTRS, ("turning %s on", _traceattr(turn_on))); + /* *INDENT-OFF* */ + TurnOn(A_ALTCHARSET, enter_alt_charset_mode); + TurnOn(A_BLINK, enter_blink_mode); + TurnOn(A_BOLD, enter_bold_mode); + TurnOn(A_DIM, enter_dim_mode); + TurnOn(A_REVERSE, enter_reverse_mode); + TurnOn(A_STANDOUT, enter_standout_mode); + TurnOn(A_PROTECT, enter_protected_mode); + TurnOn(A_INVIS, enter_secure_mode); + TurnOn(A_UNDERLINE, enter_underline_mode); +#if USE_WIDEC_SUPPORT + TurnOn(A_HORIZONTAL, enter_horizontal_hl_mode); + TurnOn(A_LEFT, enter_left_hl_mode); + TurnOn(A_LOW, enter_low_hl_mode); + TurnOn(A_RIGHT, enter_right_hl_mode); + TurnOn(A_TOP, enter_top_hl_mode); + TurnOn(A_VERTICAL, enter_vertical_hl_mode); +#endif + /* *INDENT-ON* */ + + } + + if (reverse) + newmode |= A_REVERSE; + + if (SP) { + SetAttr(SCREEN_ATTRS(SP), newmode); + SetPair(SCREEN_ATTRS(SP), pair); + } else { + previous_attr = newmode; + previous_pair = pair; + } + + returnCode(OK); +#else T((T_CALLED("vid_puts(%s,%d)"), _traceattr(newmode), pair)); set_color(newmode, pair); returnCode(vidputs(newmode, outc)); +#endif } #undef vid_attr NCURSES_EXPORT(int) -vid_attr(attr_t newmode, short pair, void *opts GCC_UNUSED) +vid_attr(attr_t newmode, short pair, void *opts) { T((T_CALLED("vid_attr(%s,%d)"), _traceattr(newmode), pair)); - set_color(newmode, pair); - returnCode(vidputs(newmode, _nc_outch)); + returnCode(vid_puts(newmode, pair, opts, _nc_outch)); } +/* + * This implementation uses the same mask values for A_xxx and WA_xxx, so + * we can use termattrs() for part of the logic. + */ NCURSES_EXPORT(attr_t) term_attrs(void) { - attr_t attrs = WA_NORMAL; + attr_t attrs; T((T_CALLED("term_attrs()"))); - if (enter_alt_charset_mode) - attrs |= WA_ALTCHARSET; - - if (enter_blink_mode) - attrs |= WA_BLINK; - - if (enter_bold_mode) - attrs |= WA_BOLD; - - if (enter_dim_mode) - attrs |= WA_DIM; - - if (enter_reverse_mode) - attrs |= WA_REVERSE; - - if (enter_standout_mode) - attrs |= WA_STANDOUT; - - if (enter_protected_mode) - attrs |= WA_PROTECT; - - if (enter_secure_mode) - attrs |= WA_INVIS; - - if (enter_underline_mode) - attrs |= WA_UNDERLINE; + attrs = termattrs(); - if (SP->_coloron) - attrs |= A_COLOR; + /* these are only supported for wide-character mode */ + if (enter_horizontal_hl_mode) + attrs |= WA_HORIZONTAL; + if (enter_left_hl_mode) + attrs |= WA_LEFT; + if (enter_low_hl_mode) + attrs |= WA_LOW; + if (enter_right_hl_mode) + attrs |= WA_RIGHT; + if (enter_top_hl_mode) + attrs |= WA_TOP; + if (enter_vertical_hl_mode) + attrs |= WA_VERTICAL; returnAttr(attrs); } diff --git a/contrib/ncurses/ncurses/widechar/lib_wacs.c b/contrib/ncurses/ncurses/widechar/lib_wacs.c index 05fa329dd9fa..fe893b4d2f8b 100644 --- a/contrib/ncurses/ncurses/widechar/lib_wacs.c +++ b/contrib/ncurses/ncurses/widechar/lib_wacs.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2002 Free Software Foundation, Inc. * + * Copyright (c) 2002,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -33,23 +33,10 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("$Id: lib_wacs.c,v 1.2 2002/02/17 00:02:15 tom Exp $") +MODULE_ID("$Id: lib_wacs.c,v 1.7 2006/12/17 15:16:17 tom Exp $") NCURSES_EXPORT_VAR(cchar_t) * _nc_wacs = 0; -static int -_nc_unicode_locale(void) -{ - char *s; - if (((s = getenv("LC_ALL")) != 0 && *s != '\0') - || ((s = getenv("LC_ALL")) != 0 && *s != '\0') - || ((s = getenv("LC_ALL")) != 0 && *s != '\0')) { - if (strstr(s, ".UTF-8") != 0) - return 1; - } - return 0; -} - NCURSES_EXPORT(void) _nc_init_wacs(void) { @@ -72,7 +59,7 @@ _nc_init_wacs(void) { 'n', { '+', 0x253c }}, /* large plus or crossover */ { 'o', { '~', 0x23ba }}, /* scan line 1 */ { 's', { '_', 0x23bd }}, /* scan line 9 */ - { '\'', { '+', 0x25c6 }}, /* diamond */ + { '`', { '+', 0x25c6 }}, /* diamond */ { 'a', { ':', 0x2592 }}, /* checker board (stipple) */ { 'f', { '\'', 0x00b0 }}, /* degree symbol */ { 'g', { '#', 0x00b1 }}, /* plus/minus */ @@ -99,19 +86,29 @@ _nc_init_wacs(void) unsigned n, m; int active = _nc_unicode_locale(); + /* + * If we're running in a UTF-8 locale, will use the Unicode equivalents + * rather than the terminfo information. Actually the terminfo should + * be the rule, but there are people who are offended by the notion that + * a Unicode-capable terminal would have something resembling a mode. + * So the smacs/rmacs may be disabled -- sometime. + */ T(("initializing WIDE-ACS map (Unicode is%s active)", active ? "" : " not")); - if (active) { - enter_alt_charset_mode = ""; - exit_alt_charset_mode = ""; - acs_chars = ""; - ena_acs = ""; - } _nc_wacs = typeCalloc(cchar_t, ACS_LEN); for (n = 0; n < SIZEOF(table); ++n) { + int wide = wcwidth(table[n].value[active]); + m = table[n].map; - SetChar(_nc_wacs[m], table[n].value[active], A_NORMAL); + if (active && (wide == 1)) { + SetChar(_nc_wacs[m], table[n].value[active], A_NORMAL); + } else if (acs_map[m] & A_ALTCHARSET) { + SetChar(_nc_wacs[m], m, A_ALTCHARSET); + } else { + SetChar(_nc_wacs[m], table[n].value[0], A_NORMAL); + } + T(("#%d, SetChar(%c, %#04x) = %s", n, m, table[n].value[active], diff --git a/contrib/ncurses/ncurses/widechar/lib_wunctrl.c b/contrib/ncurses/ncurses/widechar/lib_wunctrl.c index f4887d125fcf..cd7c56ca73f4 100644 --- a/contrib/ncurses/ncurses/widechar/lib_wunctrl.c +++ b/contrib/ncurses/ncurses/widechar/lib_wunctrl.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2001 Free Software Foundation, Inc. * + * Copyright (c) 2001-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 * @@ -37,17 +37,18 @@ #if USE_WIDEC_SUPPORT -MODULE_ID("$Id: lib_wunctrl.c,v 1.6 2001/09/22 19:18:02 tom Exp $") +MODULE_ID("$Id: lib_wunctrl.c,v 1.8 2005/04/16 18:10:44 tom Exp $") NCURSES_EXPORT(wchar_t *) -wunctrl(cchar_t * wc) +wunctrl(cchar_t *wc) { static wchar_t str[5], *sp; if (Charable(*wc)) { - const char *p; - for (p = unctrl(wctob(CharOf(*wc))), sp = str; *p;) - *sp++ = btowc(*p++); + const char *p = unctrl((unsigned) _nc_to_char((wint_t) CharOf(*wc))); + + for (sp = str; *p;) + *sp++ = _nc_to_widechar(*p++); return str; } else return wc->chars; |