diff options
author | peter <peter@FreeBSD.org> | 1999-08-24 01:06:48 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1999-08-24 01:06:48 +0000 |
commit | bacd15cb1fff2dee94d390e0f84c147cd82ea148 (patch) | |
tree | ad214c5b2c8142ad6dc6d2ce3a9c83e6317d7f77 /contrib/ncurses/ncurses | |
download | FreeBSD-src-bacd15cb1fff2dee94d390e0f84c147cd82ea148.zip FreeBSD-src-bacd15cb1fff2dee94d390e0f84c147cd82ea148.tar.gz |
Import unmodified (but trimmed) ncurses 5.0 prerelease 990821.
This contains the full eti (panel, form, menu) extensions.
bmake glue to follow.
Obtained from: ftp://ftp.clark.net/pub/dickey/ncurses
Diffstat (limited to 'contrib/ncurses/ncurses')
157 files changed, 31427 insertions, 0 deletions
diff --git a/contrib/ncurses/ncurses/Makefile.in b/contrib/ncurses/ncurses/Makefile.in new file mode 100644 index 0000000..6550220 --- /dev/null +++ b/contrib/ncurses/ncurses/Makefile.in @@ -0,0 +1,248 @@ +# $Id: Makefile.in,v 1.62 1999/02/18 11:58:20 tom Exp $ +############################################################################## +# Copyright (c) 1998 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +# +# Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 +# +# Makefile for ncurses source code. +# +# This makes the following: +# programs +# includes +# libraries (normal/debug/profile/shared) +# +# The variable 'srcdir' refers to the source-distribution, and can be set with +# the configure script by "--srcdir=DIR". +# +# The rules are organized to produce the libraries for the configured models, +# and the programs with the configured default model. + +# turn off _all_ suffix rules; we'll generate our own +.SUFFIXES: + +SHELL = /bin/sh +THIS = Makefile + +x = @PROG_EXT@ + +CF_MFLAGS = @cf_cv_makeflags@ +@SET_MAKE@ + +MODEL = @DFT_LWR_MODEL@ +INSTALL_PREFIX = @INSTALL_PREFIX@ +srcdir = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ +libdir = @libdir@ +includedir = @includedir@ +datadir = @datadir@ + +ticdir = $(datadir)/terminfo + +INSTALL = @INSTALL@ +INSTALL_LIB = @INSTALL@ @INSTALL_LIB@ +INSTALL_DATA = @INSTALL_DATA@ + +AR = @AR@ +AR_OPTS = @AR_OPTS@ +AWK = @AWK@ +LD = @LD@ +LN_S = @LN_S@ + +CC = @CC@ +CPP = @CPP@ +CFLAGS = @CFLAGS@ + +INCDIR = $(srcdir)/../include +CPPFLAGS = -I../ncurses -I$(srcdir) @CPPFLAGS@ \ + -DHAVE_CONFIG_H -DTERMINFO=\"$(ticdir)\" + +CCFLAGS = $(CPPFLAGS) $(CFLAGS) + +HOSTCC = @BUILD_CC@ +HOSTCCFLAGS = @CFLAGS@ $(CPPFLAGS) +HOSTLDFLAGS = @LDFLAGS@ @LIBS@ + +CFLAGS_NORMAL = $(CCFLAGS) +CFLAGS_DEBUG = $(CCFLAGS) @CC_G_OPT@ -DTRACE +CFLAGS_PROFILE = $(CCFLAGS) -pg +CFLAGS_SHARED = $(CCFLAGS) @CC_SHARED_OPTS@ + +CFLAGS_DEFAULT = $(CFLAGS_@DFT_UPR_MODEL@) + +LINK = $(CC) +LDFLAGS = @LDFLAGS@ @LD_MODEL@ @LIBS@ + +SHLIB_DIRS = -L../lib -L$(libdir) +SHLIB_LIST = $(SHLIB_DIRS) @SHLIB_LIST@ +TINFO_LIST = $(SHLIB_DIRS) @TINFO_LIST@ + +MK_SHARED_LIB = @MK_SHARED_LIB@ + +REL_VERSION = @cf_cv_rel_version@ +ABI_VERSION = @cf_cv_abi_version@ + +RANLIB = @RANLIB@ + +LIBRARIES = @LIBS_TO_MAKE@ + +LINT = @LINT@ +LINT_OPTS = @LINT_OPTS@ +LINT_LIBS = -lncurses @LIBS@ + +FALLBACK_LIST = @FALLBACK_LIST@ + +AUTO_SRC = \ + ../include/nomacros.h \ + ./comp_captab.c \ + ./expanded.c \ + ./fallback.c \ + init_keytry.h \ + ./lib_keyname.c \ + ./lib_gen.c \ + ./codes.c \ + ./names.c \ + ./unctrl.c + +TEST_DEPS = @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_PROGS = \ + captoinfo$x \ + hardscroll$x \ + hashmap$x \ + lib_mvcur$x + +base = $(srcdir)/base +serial = $(srcdir)/tty +tinfo = $(srcdir)/tinfo +trace = $(srcdir)/trace + +################################################################################ +all :: $(AUTO_SRC) ../lib $(LIBRARIES) + +sources: $(AUTO_SRC) + +$(INSTALL_PREFIX)$(libdir) : + $(srcdir)/../mkinstalldirs $@ + +../lib : ; mkdir $@ + +./fallback.c : $(tinfo)/MKfallback.sh + sh $(tinfo)/MKfallback.sh $(FALLBACK_LIST) >$@ + +./lib_gen.c : $(base)/MKlib_gen.sh ../include/curses.h + sh $(base)/MKlib_gen.sh "$(CPP)" "$(AWK)" <../include/curses.h >$@ + +../include/nomacros.h : $(base)/MKlib_gen.sh ../include/curses.h + sh $(base)/MKlib_gen.sh "$(CPP)" "$(AWK)" <../include/curses.h | \ + fgrep undef >$@ + +init_keytry.h: make_keys$x $(tinfo)/keys.list + ./make_keys $(tinfo)/keys.list > $@ + +make_keys$x : \ + $(tinfo)/make_keys.c \ + ./names.c + $(HOSTCC) -o $@ $(HOSTCCFLAGS) $(tinfo)/make_keys.c $(HOSTLDFLAGS) + +make_hash$x : \ + $(tinfo)/comp_hash.c \ + ../include/hashsize.h + $(HOSTCC) -o $@ $(HOSTCCFLAGS) -DMAIN_PROGRAM $(tinfo)/comp_hash.c $(HOSTLDFLAGS) + +./expanded.c : $(serial)/MKexpanded.sh + sh $(serial)/MKexpanded.sh "$(CPP)" $(CPPFLAGS) > $@ + +./comp_captab.c: \ + make_hash$x \ + ../include/hashsize.h \ + $(tinfo)/MKcaptab.awk + sh $(tinfo)/MKcaptab.awk $(AWK) $(srcdir)/../include/Caps > $@ + +./lib_keyname.c: $(tinfo)/keys.list $(base)/MKkeyname.awk + $(AWK) -f $(base)/MKkeyname.awk $(tinfo)/keys.list > $@ + +./names.c ./codes.c: $(tinfo)/MKnames.awk + $(AWK) -f $(tinfo)/MKnames.awk $(srcdir)/../include/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 + +./unctrl.c: $(base)/MKunctrl.awk + echo | $(AWK) -f $(base)/MKunctrl.awk >$@ + +tags: + ctags *.[ch] + +TAGS: + etags *.[ch] + +mostlyclean :: + -rm -f core tags TAGS *~ *.ln *.atac trace + -rm -f $(TEST_PROGS) + +clean :: mostlyclean + -rm -f $(AUTO_SRC) + -rm -f make_keys + -rm -f make_hash + +distclean :: clean + -rm -f Makefile + +realclean :: distclean + +# These rules are used to allow "make -n" to work on a clean directory-tree +../include/hashsize.h \ +../include/parametrized.h \ +../include/term.h : + cd ../include; $(MAKE) $(CF_MFLAGS) + +# These rules build test-programs for the modules that have test-drivers +test_progs : $(TEST_PROGS) + +captoinfo$x : $(tinfo)/captoinfo.c $(TEST_DEPS) + @ECHO_LINK@ $(CC) -o $@ $(CFLAGS_DEFAULT) -DMAIN $(tinfo)/captoinfo.c $(TEST_LDFLAGS) + +hardscroll$x : $(serial)/hardscroll.c $(TEST_DEPS) + @ECHO_LINK@ $(CC) -o $@ $(CFLAGS_DEFAULT) -DSCROLLDEBUG $(serial)/hardscroll.c $(TEST_LDFLAGS) + +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: + 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 new file mode 100644 index 0000000..aade721 --- /dev/null +++ b/contrib/ncurses/ncurses/README @@ -0,0 +1,2 @@ +For discussion of the package internals, see hackguide.html in the misc +directory. diff --git a/contrib/ncurses/ncurses/SigAction.h b/contrib/ncurses/ncurses/SigAction.h new file mode 100644 index 0000000..9b5a31a --- /dev/null +++ b/contrib/ncurses/ncurses/SigAction.h @@ -0,0 +1,117 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * $Id: SigAction.h,v 1.5 1999/06/19 23:00:54 tom Exp $ + * + * This file exists to handle non-POSIX systems which don't have <unistd.h>, + * and usually no sigaction() nor <termios.h> + */ + +#ifndef _SIGACTION_H +#define _SIGACTION_H + +#ifndef HAVE_SIGACTION +#define HAVE_SIGACTION 0 +#endif + +#ifndef HAVE_SIGVEC +#define HAVE_SIGVEC 0 +#endif + +#if HAVE_SIGACTION + +#if !HAVE_TYPE_SIGACTION +typedef struct sigaction sigaction_t; +#endif + +#else /* !HAVE_SIGACTION */ + +#if HAVE_SIGVEC + +#if HAVE_LIBC_H +#include <libc.h> +#endif + +#undef SIG_BLOCK +#define SIG_BLOCK 00 + +#undef SIG_UNBLOCK +#define SIG_UNBLOCK 01 + +#undef SIG_SETMASK +#define SIG_SETMASK 02 + + /* + * <bsd/signal.h> is in the Linux 1.2.8 + gcc 2.7.0 configuration, + * and is useful for testing this header file. + */ +#if HAVE_BSD_SIGNAL_H +#include <bsd/signal.h> +#endif + +typedef struct sigvec sigaction_t; + +#define sigset_t _nc_sigset_t +typedef unsigned long sigset_t; + +#undef sa_mask +#define sa_mask sv_mask +#undef sa_handler +#define sa_handler sv_handler +#undef sa_flags +#define sa_flags sv_flags + +#undef sigaction +#define sigaction _nc_sigaction +#undef sigprocmask +#define sigprocmask _nc_sigprocmask +#undef sigemptyset +#define sigemptyset _nc_sigemptyset +#undef sigsuspend +#define sigsuspend _nc_sigsuspend +#undef sigdelset +#define sigdelset _nc_sigdelset +#undef sigaddset +#define sigaddset _nc_sigaddset + +extern int sigaction (int sig, sigaction_t * sigact, sigaction_t * osigact); +extern int sigprocmask (int how, sigset_t *mask, sigset_t *omask); +extern int sigemptyset (sigset_t *mask); +extern int sigsuspend (sigset_t *mask); +extern int sigdelset (sigset_t *mask, int sig); +extern int sigaddset (sigset_t *mask, int sig); + +#endif /* HAVE_SIGVEC */ +#endif /* HAVE_SIGACTION */ +#endif /* !defined(_SIGACTION_H) */ diff --git a/contrib/ncurses/ncurses/base/MKkeyname.awk b/contrib/ncurses/ncurses/base/MKkeyname.awk new file mode 100644 index 0000000..aaeb474 --- /dev/null +++ b/contrib/ncurses/ncurses/base/MKkeyname.awk @@ -0,0 +1,74 @@ +# $Id: MKkeyname.awk,v 1.17 1999/02/18 11:18:06 tom Exp $ +############################################################################## +# Copyright (c) 1999 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +BEGIN { + print "/* generated by MKkeyname.awk */" + print "" + print "#include <ncurses_cfg.h>" + print "#include <stdlib.h>" + print "#include <string.h>" + print "#include <curses.h>" + print "#include <tic.h>" + print "" + print "const struct kn _nc_key_names[] = {" +} + +/^[^#]/ { + printf "\t{ \"%s\", %s },\n", $1, $1; + } + +END { + printf "\t{ 0, 0 }};\n" + print "" + print "NCURSES_CONST char *keyname(int c)" + print "{" + print "int i;" + print "static char name[20];" + print "char *p;" + 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 >= 256) return \"UNKNOWN KEY\";" + print "\tp = name;" + print "\tif (c >= 128) {" + print "\t\tstrcpy(p, \"M-\");" + print "\t\tp += 2;" + print "\t\tc -= 128;" + print "\t}" + print "\tif (c < 0)" + print "\t\tsprintf(p, \"%d\", c);" + print "\telse if (c < 32)" + print "\t\tsprintf(p, \"^%c\", c + '@');" + print "\telse if (c == 127)" + print "\t\tstrcpy(p, \"^?\");" + print "\telse" + print "\t\tsprintf(p, \"%c\", c);" + print "\treturn (NCURSES_CONST char *)name;" + print "}" +} diff --git a/contrib/ncurses/ncurses/base/MKlib_gen.sh b/contrib/ncurses/ncurses/base/MKlib_gen.sh new file mode 100755 index 0000000..0a29c60 --- /dev/null +++ b/contrib/ncurses/ncurses/base/MKlib_gen.sh @@ -0,0 +1,254 @@ +#!/bin/sh +# +# MKlib_gen.sh -- generate sources from curses.h macro definitions +# +# ($Id: MKlib_gen.sh,v 1.11 1998/01/17 14:16:52 Juan.Jose.Garcia.Ripoll Exp $) +# +# The XSI Curses standard requires all curses entry points to exist as +# functions, even though many definitions would normally be shadowed +# by macros. Rather than hand-hack all that code, we actually +# generate functions from the macros. +# +# This script accepts a file of prototypes on standard input. It discards +# any that don't have a `generated' comment attached. It then parses each +# prototype (relying on the fact that none of the macros take function +# pointer or array arguments) and generates C source from it. +# +# Here is what the pipeline stages are doing: +# +# 1. sed: extract prototypes of generated functions +# 2. sed: decorate prototypes with generated arguments a1. a2,...z +# 3. awk: generate the calls with args matching the formals +# 4. sed: prefix function names in prototypes so the preprocessor won't expand +# them. +# 5. cpp: macro-expand the file so the macro calls turn into C calls +# 6. awk: strip the expansion junk off the front and add the new header +# 7. sed: squeeze spaces, strip off gen_ prefix, create needed #undef +# + +preprocessor="$1 -I../include" +AWK="$2" +ED1=sed1$$.sed +ED2=sed2$$.sed +ED3=sed3$$.sed +AW1=awk1$$.awk +TMP=gen$$.c +trap "rm -f $ED1 $ED2 $ED3 $AW1 $TMP" 0 1 2 5 15 + +(cat <<EOF +#include <ncurses_cfg.h> +#include <curses.h> + +DECLARATIONS + +EOF +cat >$ED1 <<EOF1 +/^extern.*generated/{ + h + s/^.*generated:\([^ *]*\).*/P_#if_USE_\1_SUPPORT/p + g + s/^extern \([^;]*\);.*/\1/p + g + s/^.*generated:\([^ *]*\).*/P_#endif/p +} +EOF1 + +cat >$ED2 <<EOF2 +/^P_/b nc +/(void)/b nc + s/,/ a1% / + s/,/ a2% / + s/,/ a3% / + s/,/ a4% / + s/,/ a5% / + s/,/ a6% / + s/,/ a7% / + s/,/ a8% / + s/,/ a9% / + s/,/ a10% / + s/,/ a11% / + s/,/ a12% / + s/,/ a13% / + s/,/ a14% / + s/,/ a15% / + s/*/ * /g + s/%/ , /g + s/)/ z)/ +:nc + /(/s// ( / + s/)/ )/ +EOF2 + +cat >$ED3 <<EOF3 +/^P_/{ + s/^P_#if_/#if / + s/^P_// + b done +} + s/ */ /g + s/ */ /g + s/ ,/,/g + s/ )/)/g + s/ gen_/ / + s/^M_/#undef / + /^%%/s// / +:done +EOF3 + +cat >$AW1 <<\EOF1 +BEGIN { + skip=0; + } + /^P_#if/ { + print "\n" + print $0 + skip=0; + } + /^P_#endif/ { + print $0 + skip=1; + } + $0 !~ /^P_/ { + if (skip) + print "\n" + skip=1; + + print "M_" $2 + print $0; + print "{"; + argcount = 1; + if (NF == 5 && $4 == "void") + argcount = 0; + if (argcount != 0) { + for (i = 1; i <= NF; i++) + if ($i == ",") + argcount++; + } + + # suppress trace-code for functions that we cannot do properly here, + # since they return data. + dotrace = 1; + if ($2 == "innstr") + dotrace = 0; + + call = "%%T((T_CALLED(\"" + args = "" + comma = "" + num = 0; + pointer = 0; + argtype = "" + for (i = 1; i <= NF; i++) { + ch = $i; + if ( ch == "*" ) + pointer = 1; + else if ( ch == "va_list" ) + pointer = 1; + else if ( ch == "char" ) + argtype = "char"; + else if ( ch == "int" ) + argtype = "int"; + else if ( ch == "short" ) + argtype = "short"; + else if ( ch == "chtype" ) + argtype = "chtype"; + else if ( ch == "attr_t" || ch == "NCURSES_ATTR_T" ) + argtype = "attr"; + + if ( ch == "," || ch == ")" ) { + if (pointer) { + if ( argtype == "char" ) { + call = call "%s" + comma = comma "_nc_visbuf2(" num "," + pointer = 0; + } else + call = call "%p" + } else if (argcount != 0) { + if ( argtype == "int" || argtype == "short" ) { + call = call "%d" + argtype = "" + } else if ( argtype != "" ) { + call = call "%s" + comma = comma "_trace" argtype "2(" num "," + } else { + call = call "%#lx" + comma = comma "(long)" + } + } + if (ch == ",") + args = args comma "a" ++num; + else if (argcount != 0) + args = args comma "z" + call = call ch + if (pointer == 0 && argcount != 0 && argtype != "" ) + args = args ")" + if (args != "") + comma = ", " + pointer = 0; + argtype = "" + } + if ( i == 2 || ch == "(" ) + call = call ch + } + call = call "\")" + if (args != "") + call = call ", " args + call = call ")); " + + if (dotrace) + printf "%s", call + + if (match($0, "^void")) + call = "" + else if (dotrace) + call = "returnCode( "; + else + call = "%%return "; + + call = call $2 "("; + for (i = 1; i < argcount; i++) + call = call "a" i ", "; + if (argcount != 0) + call = call "z"; + if (!match($0, "^void")) + call = call ") "; + if (dotrace) + call = call ")"; + print call ";" + + if (match($0, "^void")) + print "%%returnVoid;" + print "}"; +} +EOF1 + +sed -n -f $ED1 | sed -f $ED2 \ +| $AWK -f $AW1 ) \ +| sed \ + -e '/^\([a-z_][a-z_]*\) /s//\1 gen_/' >$TMP + $preprocessor $TMP 2>/dev/null \ +| $AWK ' +BEGIN { + print "/*" + print " * DO NOT EDIT THIS FILE BY HAND!" + print " * It is generated by MKlib_gen.sh." + print " *" + print " * This is a file of trivial functions generated from macro" + print " * definitions in curses.h to satisfy the XSI Curses requirement" + print " * that every macro also exist as a callable function." + print " *" + print " * It will never be linked unless you call one of the entry" + print " * points with its normal macro definition disabled. In that" + print " * case, if you have no shared libraries, it will indirectly" + print " * pull most of the rest of the library into your link image." + print " */" + print "#include <curses.priv.h>" + print "" + } +/^DECLARATIONS/ {start = 1; next;} + {if (start) print $0;} +' \ +| sed -f $ED3 \ +| sed \ + -e 's/^.*T_CALLED.*returnCode( \([a-z].*) \));/ return \1;/' \ + -e 's/^.*T_CALLED.*returnCode( \((wmove.*) \));/ return \1;/' + diff --git a/contrib/ncurses/ncurses/base/MKunctrl.awk b/contrib/ncurses/ncurses/base/MKunctrl.awk new file mode 100644 index 0000000..0f44192 --- /dev/null +++ b/contrib/ncurses/ncurses/base/MKunctrl.awk @@ -0,0 +1,67 @@ +# $Id: MKunctrl.awk,v 1.6 1998/06/06 18:18:07 tom Exp $ +############################################################################## +# Copyright (c) 1998 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +# +# Author: Thomas E. Dickey <dickey@clark.net> 1997 +# + +BEGIN { + print "/* generated by MKunctrl.awk */" + print "" + print "#include <curses.priv.h>" + print "" + print "#undef unctrl" + print "" + } +END { + print "NCURSES_CONST char *unctrl(register chtype ch)" + print "{" + printf "static const char* const table[] = {" + for ( ch = 0; ch < 256; ch++ ) { + gap = "," + if ((ch % 8) == 0) + printf "\n " + if (ch < 32) { + printf "\"^\\%03o\"", ch + 64 + } else if (ch == 127) { + printf "\"^?\"" + } else { + printf "\"\\%03o\"", ch + gap = gap " " + } + if (ch == 255) + gap = "\n" + else if (((ch + 1) % 8) != 0) + gap = gap " " + printf "%s", gap + } + print "};" + print "" + print "\treturn (NCURSES_CONST char *)table[TextOf(ch)];" + print "}" + } diff --git a/contrib/ncurses/ncurses/base/README b/contrib/ncurses/ncurses/base/README new file mode 100644 index 0000000..ffa1696 --- /dev/null +++ b/contrib/ncurses/ncurses/base/README @@ -0,0 +1,7 @@ +-- $Id: README,v 1.1 1998/11/14 22:58:22 tom Exp $ + +The functions in this directory are the generic (not device-specific) modules +of ncurses. + +As a rule, these modules should not depend directly on term.h references and +associated terminfo function and variables. diff --git a/contrib/ncurses/ncurses/base/define_key.c b/contrib/ncurses/ncurses/base/define_key.c new file mode 100644 index 0000000..52dc692 --- /dev/null +++ b/contrib/ncurses/ncurses/base/define_key.c @@ -0,0 +1,59 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: define_key.c,v 1.4 1999/02/21 13:03:55 tom Exp $") + +int +define_key(char *str, int keycode) +{ + int code = ERR; + + T((T_CALLED("define_key(%s,%d)"), _nc_visbuf(str), keycode)); + if (keycode > 0) { + if (str != 0) { + define_key(str, 0); + } else if (has_key(keycode)) { + while (_nc_remove_key(&(SP->_keytry), keycode)) + code = OK; + } + if (str != 0) { + (void) _nc_add_to_try(&(SP->_keytry), str, keycode); + code = OK; + } + } else { + while (_nc_remove_string(&(SP->_keytry), str)) + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/keybound.c b/contrib/ncurses/ncurses/base/keybound.c new file mode 100644 index 0000000..c9aa022 --- /dev/null +++ b/contrib/ncurses/ncurses/base/keybound.c @@ -0,0 +1,45 @@ +/**************************************************************************** + * Copyright (c) 1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: keybound.c,v 1.1 1999/02/19 11:55:56 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. + */ + +char *keybound(int code, int count) +{ + return _nc_expand_try(SP->_key_ok, code, &count, 0); +} diff --git a/contrib/ncurses/ncurses/base/keyok.c b/contrib/ncurses/ncurses/base/keyok.c new file mode 100644 index 0000000..a138576 --- /dev/null +++ b/contrib/ncurses/ncurses/base/keyok.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: keyok.c,v 1.3 1999/02/19 11:29:48 tom Exp $") + +/* + * Enable (or disable) ncurses' interpretation of a keycode by adding (or + * removing) the corresponding 'tries' entry. + * + * Do this by storing a second tree of tries, which records the disabled keys. + * The simplest way to copy is to make a function that returns the string (with + * nulls set to 0200), then use that to reinsert the string into the + * corresponding tree. + */ + +int keyok(int c, bool flag) +{ + int code = ERR; + int count = 0; + 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; + } + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_addch.c b/contrib/ncurses/ncurses/base/lib_addch.c new file mode 100644 index 0000000..101d75e --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_addch.c @@ -0,0 +1,293 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_addch.c +** +** The routine waddch(). +** +*/ + +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("$Id: lib_addch.c,v 1.42 1999/07/24 20:01:05 tom Exp $") + +/* + * Ugly microtweaking alert. Everything from here to end of module is + * likely to be speed-critical -- profiling data sure says it is! + * Most of the important screen-painting functions are shells around + * waddch(). So we make every effort to reduce function-call overhead + * by inlining stuff, even at the cost of making wrapped copies for + * export. Also we supply some internal versions that don't call the + * window sync hook, for use by string-put functions. + */ + +/* Return bit mask for clearing color pair number if given ch has color */ +#define COLOR_MASK(ch) (~(chtype)((ch)&A_COLOR?A_COLOR:0)) + +static inline chtype render_char(WINDOW *win, chtype ch) +/* compute a rendition of the given char correct for the current context */ +{ + chtype a = win->_attrs; + + if (ch == ' ') + { + /* color in attrs has precedence over bkgd */ + ch = a | (win->_bkgd & COLOR_MASK(a)); + } + else + { + /* color in attrs has precedence over bkgd */ + a |= (win->_bkgd & A_ATTRIBUTES) & COLOR_MASK(a); + /* color in ch has precedence */ + ch |= (a & COLOR_MASK(ch)); + } + + TR(TRACE_VIRTPUT, ("bkg = %lx, attrs = %lx -> ch = %lx", win->_bkgd, + win->_attrs, ch)); + + return(ch); +} + +chtype _nc_background(WINDOW *win) +/* make render_char() visible while still allowing us to inline it below */ +{ + return (win->_bkgd); +} + +chtype _nc_render(WINDOW *win, chtype ch) +/* make render_char() visible while still allowing us to inline it below */ +{ + return render_char(win, ch); +} + +/* check if position is legal; if not, return error */ +#ifndef NDEBUG /* treat this like an assertion */ +#define CHECK_POSITION(win, x, y) \ + if (y > win->_maxy \ + || x > win->_maxx \ + || y < 0 \ + || x < 0) { \ + TR(TRACE_VIRTPUT, ("Alert! Win=%p _curx = %d, _cury = %d " \ + "(_maxx = %d, _maxy = %d)", win, x, y, \ + win->_maxx, win->_maxy)); \ + return(ERR); \ + } +#else +#define CHECK_POSITION(win, x, y) /* nothing */ +#endif + +static inline +int waddch_literal(WINDOW *win, chtype ch) +{ + int x; + struct ldat *line; + + x = win->_curx; + + 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 (win->_flags & _WRAPPED) { + if (x >= win->_maxx) + return (ERR); + win->_flags &= ~_WRAPPED; + } + + ch = render_char(win, ch); + TR(TRACE_VIRTPUT, ("win attr = %s", _traceattr(win->_attrs))); + + line = win->_line+win->_cury; + + CHANGED_CELL(line,x); + + line->text[x++] = ch; + + TR(TRACE_VIRTPUT, ("(%d, %d) = %s", win->_cury, x, _tracechtype(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. + */ + win->_flags |= _WRAPPED; + if (++win->_cury > win->_regbottom) { + win->_cury = win->_regbottom; + win->_curx = win->_maxx; + if (!win->_scroll) + return (ERR); + scroll(win); + } + win->_curx = 0; + return (OK); + } + win->_curx = x; + return OK; +} + +static inline +int waddch_nosync(WINDOW *win, const chtype ch) +/* the workhorse function -- add a character to the given window */ +{ + int x, y; + int t = 0; + const char *s = 0; + + if ((ch & A_ALTCHARSET) + || ((t = TextOf(ch)) > 127) + || ((s = unctrl(t))[1] == 0)) + return waddch_literal(win, ch); + + x = win->_curx; + y = win->_cury; + + switch (t) { + case '\t': + x += (TABSIZE-(x%TABSIZE)); + + /* + * Space-fill the tab on the bottom line so that we'll get the + * "correct" cursor position. + */ + if ((! win->_scroll && (y == win->_regbottom)) + || (x <= win->_maxx)) { + chtype blank = (' ' | AttrOf(ch)); + while (win->_curx < x) { + if (waddch_literal(win, blank) == ERR) + return(ERR); + } + break; + } else { + wclrtoeol(win); + win->_flags |= _WRAPPED; + if (++y > win->_regbottom) { + x = win->_maxx; + y--; + if (win->_scroll) { + scroll(win); + x = 0; + } + } else { + x = 0; + } + } + break; + case '\n': + wclrtoeol(win); + if (++y > win->_regbottom) { + y--; + if (win->_scroll) + scroll(win); + else + return (ERR); + } + /* FALLTHRU */ + case '\r': + x = 0; + win->_flags &= ~_WRAPPED; + break; + case '\b': + if (x == 0) + return (OK); + x--; + win->_flags &= ~_WRAPPED; + break; + default: + while (*s) + if (waddch_literal(win, (*s++)|AttrOf(ch)) == ERR) + return ERR; + return(OK); + } + + win->_curx = x; + win->_cury = y; + + return(OK); +} + +int _nc_waddch_nosync(WINDOW *win, const chtype c) +/* export copy of waddch_nosync() so the string-put functions can use it */ +{ + return(waddch_nosync(win, c)); +} + +/* + * The versions below call _nc_synhook(). We wanted to avoid this in the + * version exported for string puts; they'll call _nc_synchook once at end + * of run. + */ + +/* These are actual entry points */ + +int waddch(WINDOW *win, const chtype ch) +{ + int code = ERR; + + TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_CALLED("waddch(%p, %s)"), win, _tracechtype(ch))); + + if (win && (waddch_nosync(win, ch) != ERR)) + { + _nc_synchook(win); + code = OK; + } + + TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_RETURN("%d"), code)); + return(code); +} + +int wechochar(WINDOW *win, const chtype ch) +{ + int code = ERR; + + TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"), win, _tracechtype(ch))); + + if (win && (waddch_nosync(win, ch) != ERR)) + { + bool save_immed = win->_immed; + win->_immed = TRUE; + _nc_synchook(win); + win->_immed = save_immed; + code = OK; + } + TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_RETURN("%d"), code)); + return(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_addstr.c b/contrib/ncurses/ncurses/base/lib_addstr.c new file mode 100644 index 0000000..9ac55e4 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_addstr.c @@ -0,0 +1,103 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_addstr.c +* +** The routines waddnstr(), waddchnstr(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_addstr.c,v 1.16 1998/06/28 00:38:29 tom Exp $") + +int +waddnstr(WINDOW *win, const char *const astr, int n) +{ +unsigned const char *str = (unsigned const char *)astr; +int code = ERR; + + T((T_CALLED("waddnstr(%p,%s,%d)"), win, _nc_visbuf(astr), n)); + + if (win && (str != 0)) { + T(("... current %s", _traceattr(win->_attrs))); + TR(TRACE_VIRTPUT, ("str is not null")); + code = OK; + if (n < 0) + n = (int)strlen(astr); + + while((n-- > 0) && (*str != '\0')) { + TR(TRACE_VIRTPUT, ("*str = %#x", *str)); + if (_nc_waddch_nosync(win, (chtype)*str++) == ERR) { + code = ERR; + break; + } + } + _nc_synchook(win); + } + TR(TRACE_VIRTPUT, ("waddnstr returns %d", code)); + returnCode(code); +} + +int +waddchnstr(WINDOW *win, const chtype *const astr, int n) +{ +short y = win->_cury; +short x = win->_curx; +int code = OK; +struct ldat *line; + + T((T_CALLED("waddchnstr(%p,%p,%d)"), win, astr, n)); + + if (!win) + returnCode(ERR); + + if (n < 0) { + const chtype *str; + n = 0; + for (str=(const chtype *)astr; *str!=0; str++) + n++; + } + if (n > win->_maxx - x + 1) + n = win->_maxx - x + 1; + if (n == 0) + returnCode(code); + + line = &(win->_line[y]); + memcpy(line->text+x, astr, n*sizeof(*astr)); + CHANGED_RANGE(line, x, x+n-1); + + _nc_synchook(win); + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_beep.c b/contrib/ncurses/ncurses/base/lib_beep.c new file mode 100644 index 0000000..9b89496 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_beep.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * beep.c + * + * The routine beep(). + * + */ + +#include <curses.priv.h> +#include <term.h> /* beep, flash */ + +MODULE_ID("$Id: lib_beep.c,v 1.6 1998/06/29 19:34:16 Alexander.V.Lukyanov Exp $") + +/* + * beep() + * + * Sound the current terminal's audible bell if it has one. If not, + * flash the screen if possible. + * + */ + +int beep(void) +{ + int res = ERR; + + T((T_CALLED("beep()"))); + + /* FIXME: should make sure that we are not in altchar mode */ + if (bell) { + TPUTS_TRACE("bell"); + res = putp(bell); + fflush(SP->_ofp); + } else if (flash_screen) { + TPUTS_TRACE("flash_screen"); + res = putp(flash_screen); + fflush(SP->_ofp); + } + + returnCode(res); +} diff --git a/contrib/ncurses/ncurses/base/lib_bkgd.c b/contrib/ncurses/ncurses/base/lib_bkgd.c new file mode 100644 index 0000000..410ee05 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_bkgd.c @@ -0,0 +1,86 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_bkgd.c,v 1.12 1998/02/11 12:13:54 tom Exp $") + +void wbkgdset(WINDOW *win, chtype ch) +{ + T((T_CALLED("wbkgdset(%p,%s)"), win, _tracechtype(ch))); + + if (win) { + chtype off = AttrOf(win->_bkgd); + chtype on = AttrOf(ch); + + toggle_attr_off(win->_attrs,off); + toggle_attr_on (win->_attrs,on); + + if (TextOf(ch)==0) + ch |= BLANK; + win->_bkgd = ch; + } + returnVoid; +} + +int wbkgd(WINDOW *win, const chtype ch) +{ + int code = ERR; + int x, y; + chtype new_bkgd = ch; + + T((T_CALLED("wbkgd(%p,%s)"), win, _tracechtype(new_bkgd))); + + if (win) { + chtype old_bkgd = getbkgd(win); + + wbkgdset(win, new_bkgd); + wattrset(win, AttrOf(win->_bkgd)); + + for (y = 0; y <= win->_maxy; y++) { + for (x = 0; x <= win->_maxx; x++) { + if (win->_line[y].text[x] == old_bkgd) + win->_line[y].text[x] = win->_bkgd; + else + win->_line[y].text[x] = + _nc_render(win,(A_ALTCHARSET & + AttrOf(win->_line[y].text[x])) + | TextOf(win->_line[y].text[x])); + } + } + touchwin(win); + _nc_synchook(win); + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_box.c b/contrib/ncurses/ncurses/base/lib_box.c new file mode 100644 index 0000000..bcd9641 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_box.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_box.c +** +** The routine wborder(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_box.c,v 1.10 1998/02/11 12:13:56 tom Exp $") + +int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, + chtype bs, chtype tl, chtype tr, chtype bl, chtype br) +{ +short i; +short endx, endy; + + T((T_CALLED("wborder(%p,%s,%s,%s,%s,%s,%s,%s,%s)"), + win, + _tracechtype2(1,ls), + _tracechtype2(2,rs), + _tracechtype2(3,ts), + _tracechtype2(4,bs), + _tracechtype2(5,tl), + _tracechtype2(6,tr), + _tracechtype2(7,bl), + _tracechtype2(8,br))); + + if (!win) + returnCode(ERR); + + if (ls == 0) ls = ACS_VLINE; + if (rs == 0) rs = ACS_VLINE; + if (ts == 0) ts = ACS_HLINE; + if (bs == 0) bs = ACS_HLINE; + if (tl == 0) tl = ACS_ULCORNER; + if (tr == 0) tr = ACS_URCORNER; + if (bl == 0) bl = ACS_LLCORNER; + if (br == 0) br = ACS_LRCORNER; + + ls = _nc_render(win, ls); + rs = _nc_render(win, rs); + ts = _nc_render(win, ts); + bs = _nc_render(win, bs); + tl = _nc_render(win, tl); + tr = _nc_render(win, tr); + bl = _nc_render(win, bl); + br = _nc_render(win, br); + + T(("using %#lx, %#lx, %#lx, %#lx, %#lx, %#lx, %#lx, %#lx", ls, rs, ts, bs, tl, tr, bl, br)); + + endx = win->_maxx; + endy = win->_maxy; + + for (i = 0; i <= endx; i++) { + win->_line[0].text[i] = ts; + win->_line[endy].text[i] = bs; + } + win->_line[endy].firstchar = win->_line[0].firstchar = 0; + win->_line[endy].lastchar = win->_line[0].lastchar = endx; + + for (i = 0; i <= endy; i++) { + win->_line[i].text[0] = ls; + win->_line[i].text[endx] = rs; + win->_line[i].firstchar = 0; + win->_line[i].lastchar = endx; + } + win->_line[0].text[0] = tl; + win->_line[0].text[endx] = tr; + win->_line[endy].text[0] = bl; + win->_line[endy].text[endx] = br; + + _nc_synchook(win); + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_chgat.c b/contrib/ncurses/ncurses/base/lib_chgat.c new file mode 100644 index 0000000..7690ae4 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_chgat.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_chgat.c +** +** The routine wchgat(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_chgat.c,v 1.2 1998/02/11 12:14:00 tom Exp $") + +int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts GCC_UNUSED) +{ + int i; + + T((T_CALLED("wchgat(%p,%d,%s,%d)"), win, n, _traceattr(attr), color)); + + if (win) { + toggle_attr_on(attr,COLOR_PAIR(color)); + + for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++) + win->_line[win->_cury].text[i] + = TextOf(win->_line[win->_cury].text[i]) | attr; + + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_clear.c b/contrib/ncurses/ncurses/base/lib_clear.c new file mode 100644 index 0000000..9c07cf0 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_clear.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_clear.c +** +** The routine wclear(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_clear.c,v 1.5 1998/02/11 12:13:53 tom Exp $") + +int wclear(WINDOW *win) +{ +int code = ERR; + + T((T_CALLED("wclear(%p)"), win)); + + if ((code = werase(win))!=ERR) + win->_clear = TRUE; + + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_clearok.c b/contrib/ncurses/ncurses/base/lib_clearok.c new file mode 100644 index 0000000..cc904b1 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_clearok.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_clearok.c +** +** The routine clearok. +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_clearok.c,v 1.2 1998/02/11 12:14:00 tom Exp $") + +int clearok(WINDOW *win, bool flag) +{ + T((T_CALLED("clearok(%p,%d)"), win, flag)); + + if (win) { + win->_clear = flag; + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_clrbot.c b/contrib/ncurses/ncurses/base/lib_clrbot.c new file mode 100644 index 0000000..cec3416 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_clrbot.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_clrbot.c +** +** The routine wclrtobot(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_clrbot.c,v 1.14 1998/06/28 00:36:26 tom Exp $") + +int wclrtobot(WINDOW *win) +{ +int code = ERR; + + T((T_CALLED("wclrtobot(%p)"), win)); + + if (win) { + short y; + short startx = win->_curx; + chtype blank = _nc_background(win); + + T(("clearing from y = %d to y = %d with maxx = %d", win->_cury, win->_maxy, win->_maxx)); + + for (y = win->_cury; y <= win->_maxy; y++) { + struct ldat *line = &(win->_line[y]); + chtype *ptr = &(line->text[startx]); + chtype *end = &(line->text[win->_maxx]); + + CHANGED_TO_EOL(line, startx, win->_maxx); + + while (ptr <= end) + *ptr++ = blank; + + startx = 0; + } + _nc_synchook(win); + code = OK; + } + returnCode(code); +} + diff --git a/contrib/ncurses/ncurses/base/lib_clreol.c b/contrib/ncurses/ncurses/base/lib_clreol.c new file mode 100644 index 0000000..0c75222 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_clreol.c @@ -0,0 +1,91 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_clreol.c +** +** The routine wclrtoeol(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_clreol.c,v 1.15 1998/06/28 00:32:20 tom Exp $") + +int wclrtoeol(WINDOW *win) +{ +int code = ERR; + + T((T_CALLED("wclrtoeol(%p)"), win)); + + if (win) { + chtype blank; + chtype *ptr, *end; + struct ldat *line; + short y = win->_cury; + short x = win->_curx; + + /* + * If we have just wrapped the cursor, the clear applies to the + * new line, unless we are at the lower right corner. + */ + if (win->_flags & _WRAPPED + && y < win->_maxy) { + win->_flags &= ~_WRAPPED; + } + + /* + * There's no point in clearing if we're not on a legal + * position, either. + */ + if (win->_flags & _WRAPPED + || y > win->_maxy + || x > win->_maxx) + returnCode(ERR); + + blank = _nc_background(win); + line = &win->_line[y]; + CHANGED_TO_EOL(line, x, win->_maxx); + + ptr = &(line->text[x]); + end = &(line->text[win->_maxx]); + + while (ptr <= end) + *ptr++ = blank; + + _nc_synchook(win); + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_color.c b/contrib/ncurses/ncurses/base/lib_color.c new file mode 100644 index 0000000..cdc943a --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_color.c @@ -0,0 +1,429 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* lib_color.c + * + * Handles color emulation of SYS V curses + * + */ + +#include <curses.priv.h> + +#include <term.h> + +MODULE_ID("$Id: lib_color.c,v 1.35 1999/03/15 01:45:14 Alexander.V.Lukyanov Exp $") + +/* + * These should be screen structure members. They need to be globals for + * hystorical reasons. So we assign them in start_color() and also in + * set_term()'s screen-switching logic. + */ +int COLOR_PAIRS; +int 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. + */ +#define RGB_ON 680 +#define RGB_OFF 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 */ +}; +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 */ +}; + +/* + * SVr4 curses is known to interchange color codes (1,4) and (3,6), possibly + * to maintain compatibility with a pre-ANSI scheme. The same scheme is + * also used in the FreeBSD syscons. + */ +static int toggled_colors(int c) +{ + if (c < 16) { + static const int table[] = + { 0, 4, 2, 6, 1, 5, 3, 7, + 8, 12, 10, 14, 9, 13, 11, 15}; + c = table[c]; + } + return c; +} + +static void set_background_color(int bg, int (*outc)(int)) +{ + if (set_a_background) + { + TPUTS_TRACE("set_a_background"); + tputs(tparm(set_a_background, bg), 1, outc); + } + else + { + TPUTS_TRACE("set_background"); + tputs(tparm(set_background, toggled_colors(bg)), 1, outc); + } +} + +static void set_foreground_color(int fg, int (*outc)(int)) +{ + if (set_a_foreground) + { + TPUTS_TRACE("set_a_foreground"); + tputs(tparm(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; + } + return FALSE; +} + +int start_color(void) +{ + T((T_CALLED("start_color()"))); + + if (set_original_colors() != TRUE) + { + set_foreground_color(COLOR_WHITE, _nc_outch); + set_background_color(COLOR_BLACK, _nc_outch); + } + + if (max_pairs != -1) + 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(COLOR_WHITE, COLOR_BLACK); + if (max_colors != -1) + COLORS = SP->_color_count = max_colors; + else + returnCode(ERR); + SP->_coloron = 1; + + if ((SP->_color_table = typeMalloc(color_t, COLORS)) == 0) + returnCode(ERR); + if (hue_lightness_saturation) + memcpy(SP->_color_table, hls_palette, sizeof(color_t) * COLORS); + else + memcpy(SP->_color_table, cga_palette, sizeof(color_t) * COLORS); + + T(("started color: COLORS = %d, COLOR_PAIRS = %d", COLORS, COLOR_PAIRS)); + + returnCode(OK); +} + +/* This function was originally written by Daniel Weaver <danw@znyx.com> */ +static void rgb2hls(short r, short g, short b, short *h, short *l, short *s) +/* convert RGB to HLS system */ +{ + short min, max, t; + + if ((min = g < r ? g : r) > b) min = b; + if ((max = g > r ? g : r) < b) max = b; + + /* calculate lightness */ + *l = (min + max) / 20; + + if (min == max) /* black, white and all shades of gray */ + { + *h = 0; + *s = 0; + return; + } + + /* calculate saturation */ + if (*l < 50) + *s = ((max - min) * 100) / (max + min); + else *s = ((max - min) * 100) / (2000 - max - min); + + /* calculate hue */ + if (r == max) + t = 120 + ((g - b) * 60) / (max - min); + else + if (g == max) + t = 240 + ((b - r) * 60) / (max - min); + else + t = 360 + ((r - g) * 60) / (max - min); + + *h = t % 360; +} + +/* + * Extension (1997/1/18) - Allow negative f/b values to set default color + * values. + */ +int init_pair(short pair, short f, short b) +{ + unsigned result; + + T((T_CALLED("init_pair(%d,%d,%d)"), pair, f, b)); + + if ((pair < 1) || (pair >= COLOR_PAIRS)) + returnCode(ERR); + if (SP->_default_color) + { + if (f < 0) + f = C_MASK; + if (b < 0) + b = C_MASK; + if (f >= COLORS && f != C_MASK) + returnCode(ERR); + if (b >= COLORS && b != C_MASK) + returnCode(ERR); + } + else + if ((f < 0) || (f >= COLORS) + || (b < 0) || (b >= COLORS)) + returnCode(ERR); + + /* + * When a pair's content is changed, replace its colors (if pair was + * initialized before a screen update is performed replacing original + * pair colors with the new ones). + */ + result = PAIR_OF(f,b); + if (SP->_color_pairs[pair] != 0 + && SP->_color_pairs[pair] != result) { + int y, x; + 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 ((ptr->text[x] & A_COLOR) == z) { + /* Set the old cell to zero to ensure it will be + updated on the next doupdate() */ + ptr->text[x] = 0; + CHANGED_CELL(ptr,x); + changed = TRUE; + } + } + if (changed) + _nc_make_oldhash(y); + } + } + SP->_color_pairs[pair] = result; + + if (initialize_pair) + { + const color_t *tp = hue_lightness_saturation ? hls_palette : cga_palette; + + T(("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)", + pair, + tp[f].red, tp[f].green, tp[f].blue, + tp[b].red, tp[b].green, tp[b].blue)); + + 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)); + } + } + + returnCode(OK); +} + +int init_color(short color, short r, short g, short b) +{ + T((T_CALLED("init_color(%d,%d,%d,%d)"), color, r, g, b)); + + 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); + + 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)); + } + returnCode(OK); +} + +bool can_change_color(void) +{ + T((T_CALLED("can_change_color()"))); + returnCode ((can_change != 0) ? TRUE : FALSE); +} + +bool has_colors(void) +{ + T((T_CALLED("has_colors()"))); + returnCode (((max_colors != -1) && (max_pairs != -1) + && (((set_foreground != NULL) + && (set_background != NULL)) + || ((set_a_foreground != NULL) + && (set_a_background != NULL)) + || set_color_pair)) ? TRUE : FALSE); +} + +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); + + 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); +} + +int pair_content(short pair, short *f, short *b) +{ + 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); + + returnCode(OK); +} + +void _nc_do_color(int pair, bool reverse, int (*outc)(int)) +{ + short fg, bg; + + if (pair == 0) + { + if (orig_pair) + { + TPUTS_TRACE("orig_pair"); + tputs(orig_pair, 1, outc); + } + else if (set_color_pair) + { + TPUTS_TRACE("set_color_pair"); + tputs(tparm(set_color_pair, pair), 1, outc); + } + else + { + set_foreground_color(COLOR_WHITE, outc); + set_background_color(COLOR_BLACK, outc); + } + } + else + { + if (set_color_pair) + { + TPUTS_TRACE("set_color_pair"); + tputs(tparm(set_color_pair, pair), 1, outc); + } + else + { + pair_content(pair, &fg, &bg); + if (reverse) { + short xx = fg; + fg = bg; + bg = xx; + } + + T(("setting colors: pair = %d, fg = %d, bg = %d", pair, fg, bg)); + + if (fg == C_MASK || bg == C_MASK) + { + if (set_original_colors() != TRUE) + { + if (fg == C_MASK) + set_foreground_color(COLOR_WHITE, outc); + if (bg == C_MASK) + set_background_color(COLOR_BLACK, outc); + } + } + if (fg != C_MASK) + { + set_foreground_color(fg, outc); + } + if (bg != C_MASK) + { + set_background_color(bg, outc); + } + } + } +} diff --git a/contrib/ncurses/ncurses/base/lib_colorset.c b/contrib/ncurses/ncurses/base/lib_colorset.c new file mode 100644 index 0000000..d9fc5c2 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_colorset.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1998 * + ****************************************************************************/ + +/* +** lib_colorset.c +** +** The routine wcolor_set(). +** +*/ + +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("$Id: lib_colorset.c,v 1.5 1999/05/16 17:13:43 juergen Exp $") + +int wcolor_set(WINDOW *win, short color_pair_number, void *opts) +{ + T((T_CALLED("wcolor_set(%p,%d)"), win, color_pair_number)); + if (win && !opts && (color_pair_number >= 0) && (color_pair_number < COLOR_PAIRS)) { + T(("... current %ld", (long) PAIR_NUMBER(win->_attrs))); + toggle_attr_on(win->_attrs,COLOR_PAIR(color_pair_number)); + returnCode(OK); + } else + returnCode(ERR); +} + + diff --git a/contrib/ncurses/ncurses/base/lib_delch.c b/contrib/ncurses/ncurses/base/lib_delch.c new file mode 100644 index 0000000..0169d31 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_delch.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_delch.c +** +** The routine wdelch(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_delch.c,v 1.8 1998/06/28 00:28:17 tom Exp $") + +int wdelch(WINDOW *win) +{ +int code = ERR; + + T((T_CALLED("wdelch(%p)"), win)); + + if (win) { + chtype blank = _nc_background(win); + struct ldat *line = &(win->_line[win->_cury]); + chtype *end = &(line->text[win->_maxx]); + chtype *temp2 = &(line->text[win->_curx + 1]); + chtype *temp1 = temp2 - 1; + + CHANGED_TO_EOL(line, win->_curx, win->_maxx); + while (temp1 < end) + *temp1++ = *temp2++; + + *temp1 = blank; + + _nc_synchook(win); + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_delwin.c b/contrib/ncurses/ncurses/base/lib_delwin.c new file mode 100644 index 0000000..7bab0c7 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_delwin.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_delwin.c +** +** The routine delwin(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_delwin.c,v 1.9 1998/02/11 12:13:53 tom Exp $") + +static bool have_children(WINDOW *win) +{ + WINDOWLIST *p; + for (p = _nc_windows; p != 0; p = p->next) { + if (p->win->_flags & _SUBWIN + && p->win->_parent == win) + return TRUE; + } + return FALSE; +} + +int delwin(WINDOW *win) +{ + T((T_CALLED("delwin(%p)"), win)); + + if (win == 0 + || have_children(win)) + returnCode(ERR); + + if (win->_flags & _SUBWIN) + touchwin(win->_parent); + else if (curscr != 0) + touchwin(curscr); + + _nc_freewin(win); + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_dft_fgbg.c b/contrib/ncurses/ncurses/base/lib_dft_fgbg.c new file mode 100644 index 0000000..a2dfbd2 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_dft_fgbg.c @@ -0,0 +1,60 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ +#include <curses.priv.h> +#include <term.h> + +MODULE_ID("$Id: lib_dft_fgbg.c,v 1.3 1998/02/11 12:13:54 tom Exp $") + +/* + * Modify the behavior of color-pair 0 so that the library doesn't assume that + * it is black on white. This is an extension to XSI curses. + * + * Invoke this function after 'start_color()'. + */ +int +use_default_colors(void) +{ + T((T_CALLED("use_default_colors()"))); + + if (!SP->_coloron) + returnCode(ERR); + + if (!orig_pair && !orig_colors) + returnCode(ERR); + + if (initialize_pair) /* don't know how to handle this */ + returnCode(ERR); + + SP->_default_color = TRUE; + SP->_color_pairs[0] = PAIR_OF(C_MASK, C_MASK); + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_echo.c b/contrib/ncurses/ncurses/base/lib_echo.c new file mode 100644 index 0000000..4ccf97f --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_echo.c @@ -0,0 +1,60 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * echo.c + * + * Routines: + * echo() + * noecho() + * + */ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_echo.c,v 1.3 1998/10/12 13:15:33 Alexander.V.Lukyanov Exp $") + +int echo(void) +{ + T((T_CALLED("echo()"))); + SP->_echo = TRUE; + returnCode(OK); +} + +int noecho(void) +{ + T((T_CALLED("noecho()"))); + SP->_echo = FALSE; + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_endwin.c b/contrib/ncurses/ncurses/base/lib_endwin.c new file mode 100644 index 0000000..31b6e51 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_endwin.c @@ -0,0 +1,61 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_endwin.c +** +** The routine endwin(). +** +*/ + +#include <curses.priv.h> +#include <term.h> + +MODULE_ID("$Id: lib_endwin.c,v 1.17 1999/06/12 23:01:46 tom Exp $") + +int +endwin(void) +{ + T((T_CALLED("endwin()"))); + + if (SP) { + SP->_endwin = TRUE; + SP->_mouse_wrap(SP); + _nc_screen_wrap(); + _nc_mvcur_wrap(); /* wrap up cursor addressing */ + returnCode(reset_shell_mode()); + } + + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_erase.c b/contrib/ncurses/ncurses/base/lib_erase.c new file mode 100644 index 0000000..1e4237b --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_erase.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_erase.c +** +** The routine werase(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_erase.c,v 1.11 1998/02/11 12:13:54 tom Exp $") + +int werase(WINDOW *win) +{ +int code = ERR; +int y; +chtype blank; +chtype *sp, *end, *start; + + T((T_CALLED("werase(%p)"), win)); + + if (win) { + blank = _nc_background(win); + for (y = 0; y <= win->_maxy; y++) { + start = win->_line[y].text; + end = &start[win->_maxx]; + + for (sp = start; sp <= end; sp++) + *sp = blank; + + win->_line[y].firstchar = 0; + win->_line[y].lastchar = win->_maxx; + } + win->_curx = win->_cury = 0; + win->_flags &= ~_WRAPPED; + _nc_synchook(win); + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_flash.c b/contrib/ncurses/ncurses/base/lib_flash.c new file mode 100644 index 0000000..faf381f --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_flash.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * flash.c + * + * The routine flash(). + * + */ + +#include <curses.priv.h> +#include <term.h> /* beep, flash */ + +MODULE_ID("$Id: lib_flash.c,v 1.3 1998/06/29 19:34:16 Alexander.V.Lukyanov Exp $") + +/* + * flash() + * + * Flash the current terminal's screen if possible. If not, + * sound the audible bell if one exists. + * + */ + +int flash(void) +{ + int res = ERR; + + T((T_CALLED("flash()"))); + + /* FIXME: should make sure that we are not in altchar mode */ + if (flash_screen) { + TPUTS_TRACE("flash_screen"); + res = putp(flash_screen); + fflush(SP->_ofp); + } else if (bell) { + TPUTS_TRACE("bell"); + res = putp(bell); + fflush(SP->_ofp); + } + + returnCode(res); +} diff --git a/contrib/ncurses/ncurses/base/lib_freeall.c b/contrib/ncurses/ncurses/base/lib_freeall.c new file mode 100644 index 0000000..e9a11ac --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_freeall.c @@ -0,0 +1,134 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 * + ****************************************************************************/ + +#include <curses.priv.h> +#include <term_entry.h> + +#if HAVE_NC_FREEALL + +#if HAVE_LIBDBMALLOC +extern int malloc_errfd; /* FIXME */ +#endif + +MODULE_ID("$Id: lib_freeall.c,v 1.14 1999/04/03 23:17:06 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; + } +} + +/* + * Free all ncurses data. This is used for testing only (there's no practical + * use for it as an extension). + */ +void _nc_freeall(void) +{ + WINDOWLIST *p, *q; + +#if NO_LEAKS + _nc_free_tparm(); +#endif + while (_nc_windows != 0) { + /* Delete only windows that're not a parent */ + for (p = _nc_windows; p != 0; p = p->next) { + bool found = FALSE; + + for (q = _nc_windows; q != 0; q = q->next) { + if ((p != q) + && (q->win->_flags & _SUBWIN) + && (p->win == q->win->_parent)) { + found = TRUE; + break; + } + } + + if (!found) { + delwin(p->win); + break; + } + } + } + + if (SP != 0) { + free_tries (SP->_keytry); + free_tries (SP->_key_ok); + free_slk(SP->_slk); + FreeIfNeeded(SP->_color_pairs); + FreeIfNeeded(SP->_color_table); + /* it won't free buffer anyway */ +/* _nc_set_buffer(SP->_ofp, FALSE);*/ +#if !BROKEN_LINKER + FreeAndNull(SP); +#endif + } + + if (cur_term != 0) { + _nc_free_termtype(&(cur_term->type)); + free(cur_term); + } + +#ifdef TRACE + (void) _nc_trace_buf(-1, 0); +#endif +#if HAVE_LIBDBMALLOC + malloc_dump(malloc_errfd); +#elif HAVE_LIBDMALLOC +#elif HAVE_PURIFY + purify_all_inuse(); +#endif +} + +void _nc_free_and_exit(int code) +{ + _nc_freeall(); + exit(code); +} +#else +void _nc_freeall(void) { } +#endif diff --git a/contrib/ncurses/ncurses/base/lib_getch.c b/contrib/ncurses/ncurses/base/lib_getch.c new file mode 100644 index 0000000..b740885 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_getch.c @@ -0,0 +1,414 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_getch.c +** +** The routine getch(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_getch.c,v 1.43 1999/03/08 02:35:10 tom Exp $") + +#include <fifo_defs.h> + +int ESCDELAY = 1000; /* max interval betw. chars in funkeys, in millisecs */ + +#ifdef USE_EMX_MOUSE +# include <sys/select.h> +static int +kbd_mouse_read(unsigned char *p) +{ +fd_set fdset; +int nums = SP->_ifd+1; + + for (;;) { + FD_ZERO(&fdset); + FD_SET(SP->_checkfd, &fdset); + if (SP->_mouse_fd >= 0) { + FD_SET(SP->_mouse_fd, &fdset); + if (SP->_mouse_fd > SP->_checkfd) + nums = SP->_mouse_fd+1; + } + if (select(nums, &fdset, NULL, NULL, NULL) >= 0) { + int n; + + if (FD_ISSET(SP->_mouse_fd, &fdset)) /* Prefer mouse */ + n = read(SP->_mouse_fd, p, 1); + else + n = read(SP->_ifd, p, 1); + return n; + } + if (errno != EINTR) + return -1; + } +} +#endif /* USE_EMX_MOUSE */ + +static inline int fifo_peek(void) +{ + int ch = SP->_fifo[peek]; + T(("peeking at %d", peek)); + + p_inc(); + return ch; +} + + +static inline int fifo_pull(void) +{ +int ch; + ch = SP->_fifo[head]; + T(("pulling %d from %d", ch, head)); + + if (peek == head) + { + h_inc(); + peek = head; + } + else + h_inc(); + +#ifdef TRACE + if (_nc_tracing & TRACE_IEVENT) _nc_fifo_dump(); +#endif + return ch; +} + +static inline int fifo_push(void) +{ +int n; +unsigned int ch; + + if (tail == -1) return ERR; + +#ifdef HIDE_EINTR +again: + errno = 0; +#endif + +#if USE_GPM_SUPPORT + if ((SP->_mouse_fd >= 0) + && (_nc_timed_wait(3, -1, (int *)0) & 2)) + { + SP->_mouse_event(SP); + ch = KEY_MOUSE; + n = 1; + } else +#endif + { + unsigned char c2=0; +#ifdef USE_EMX_MOUSE + n = kbd_mouse_read(&c2); +#else + n = read(SP->_ifd, &c2, 1); +#endif + ch = c2 & 0xff; + } + +#ifdef HIDE_EINTR + /* + * Under System V curses with non-restarting signals, getch() returns + * with value ERR when a handled signal keeps it from completing. + * If signals restart system calls, OTOH, the signal is invisible + * except to its handler. + * + * We don't want this difference to show. This piece of code + * tries to make it look like we always have restarting signals. + */ + if (n <= 0 && errno == EINTR) + goto again; +#endif + + if ((n == -1) || (n == 0)) + { + T(("read(%d,&ch,1)=%d, errno=%d", SP->_ifd, n, errno)); + return ERR; + } + T(("read %d characters", n)); + + SP->_fifo[tail] = ch; + SP->_fifohold = 0; + if (head == -1) + head = peek = tail; + t_inc(); + T(("pushed %#x at %d", ch, tail)); +#ifdef TRACE + if (_nc_tracing & TRACE_IEVENT) _nc_fifo_dump(); +#endif + return ch; +} + +static inline void fifo_clear(void) +{ +int i; + for (i = 0; i < FIFO_SIZE; i++) + SP->_fifo[i] = 0; + head = -1; tail = peek = 0; +} + +static int kgetch(WINDOW *); + +#define wgetch_should_refresh(win) (\ + (is_wintouched(win) || (win->_flags & _HASMOVED)) \ + && !(win->_flags & _ISPAD)) + +int +wgetch(WINDOW *win) +{ +int ch; + + T((T_CALLED("wgetch(%p)"), win)); + + if (!win) + returnCode(ERR); + + if (cooked_key_in_fifo()) + { + if (wgetch_should_refresh(win)) + wrefresh(win); + + ch = fifo_pull(); + T(("wgetch returning (pre-cooked): %#x = %s", ch, _trace_key(ch));) + returnCode(ch); + } + + /* + * 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) + { + char buf[MAXCOLUMNS], *sp; + + T(("filling queue in cooked mode")); + + wgetnstr(win, buf, MAXCOLUMNS); + + /* ungetch in reverse order */ + ungetch('\n'); + for (sp = buf+strlen(buf); sp>buf; sp--) + ungetch(sp[-1]); + + returnCode(fifo_pull()); + } + + if (wgetch_should_refresh(win)) + wrefresh(win); + + if (!win->_notimeout && (win->_delay >= 0 || SP->_cbreak > 1)) + { + int delay; + + T(("timed delay in wgetch()")); + if (SP->_cbreak > 1) + delay = (SP->_cbreak - 1) * 100; + else + delay = win->_delay; + + T(("delay is %d milliseconds", delay)); + + if (head == -1) /* fifo is empty */ + if (!_nc_timed_wait(3, delay, (int *)0)) + returnCode(ERR); + /* else go on to read data available */ + } + + if (win->_use_keypad) + { + /* + * This is tricky. We only want to get special-key + * events one at a time. But we want to accumulate + * mouse events until either (a) the mouse logic tells + * us it's picked up a complete gesture, or (b) + * there's a detectable time lapse after one. + * + * Note: if the mouse code starts failing to compose + * press/release events into clicks, you should probably + * increase the wait with mouseinterval(). + */ + int runcount = 0; + + do { + ch = kgetch(win); + if (ch == KEY_MOUSE) + { + ++runcount; + if (SP->_mouse_inline(SP)) + break; + } + } while + (ch == KEY_MOUSE + && (_nc_timed_wait(3, SP->_maxclick, (int *)0) + || !SP->_mouse_parse(runcount))); + if (runcount > 0 && ch != KEY_MOUSE) + { + /* mouse event sequence ended by keystroke, push it */ + ungetch(ch); + ch = KEY_MOUSE; + } + } else { + if (head == -1) + fifo_push(); + ch = fifo_pull(); + } + + if (ch == ERR) + { +#if USE_SIZECHANGE + if(SP->_sig_winch) + { + _nc_update_screensize(); + /* resizeterm can push KEY_RESIZE */ + if(cooked_key_in_fifo()) + { + ch = fifo_pull(); + T(("wgetch returning (pre-cooked): %#x = %s", ch, _trace_key(ch));) + returnCode(ch); + } + } +#endif + T(("wgetch returning ERR")); + returnCode(ERR); + } + + /* + * Simulate ICRNL mode + */ + if ((ch == '\r') && SP->_nl) + ch = '\n'; + + /* Strip 8th-bit if so desired. We do this only for characters that + * are in the range 128-255, to provide compatibility with terminals + * that display only 7-bit characters. Note that 'ch' may be a + * function key at this point, so we mustn't strip _those_. + */ + if ((ch < KEY_MIN) && (ch & 0x80)) + if (!SP->_use_meta) + ch &= 0x7f; + + if (SP->_echo && ch < KEY_MIN && !(win->_flags & _ISPAD)) + wechochar(win, (chtype)ch); + + T(("wgetch returning : %#x = %s", ch, _trace_key(ch))); + + returnCode(ch); +} + + +/* +** int +** kgetch() +** +** Get an input character, but take care of keypad sequences, returning +** an appropriate code when one matches the input. After each character +** is received, set an alarm call based on ESCDELAY. If no more of the +** sequence is received by the time the alarm goes off, pass through +** the sequence gotten so far. +** +** This function must be called when there is no cooked keys in queue. +** (that is head==-1 || peek==head) +** +*/ + +static int +kgetch(WINDOW *win GCC_UNUSED) +{ +struct tries *ptr; +int ch = 0; +int timeleft = ESCDELAY; + + TR(TRACE_IEVENT, ("kgetch(%p) called", win)); + + ptr = SP->_keytry; + + for(;;) + { + if (!raw_key_in_fifo()) + { + if(fifo_push() == ERR) + { + peek = head; /* the keys stay uninterpreted */ + return ERR; + } + } + ch = fifo_peek(); + if (ch >= KEY_MIN) + { + peek = head; + /* assume the key is the last in fifo */ + t_dec(); /* remove the key */ + return ch; + } + + TR(TRACE_IEVENT, ("ch: %s", _trace_key((unsigned char)ch))); + while ((ptr != NULL) && (ptr->ch != (unsigned char)ch)) + ptr = ptr->sibling; +#ifdef TRACE + if (ptr == NULL) + {TR(TRACE_IEVENT, ("ptr is null"));} + else + TR(TRACE_IEVENT, ("ptr=%p, ch=%d, value=%d", + ptr, ptr->ch, ptr->value)); +#endif /* TRACE */ + + if (ptr == NULL) + break; + + if (ptr->value != 0) { /* sequence terminated */ + TR(TRACE_IEVENT, ("end of sequence")); + if (peek == tail) + fifo_clear(); + else + head = peek; + return(ptr->value); + } + + ptr = ptr->child; + + if (!raw_key_in_fifo()) + { + TR(TRACE_IEVENT, ("waiting for rest of sequence")); + if (!_nc_timed_wait(3, timeleft, &timeleft)) { + TR(TRACE_IEVENT, ("ran out of time")); + break; + } + } + } + ch = fifo_pull(); + peek = head; + return ch; +} diff --git a/contrib/ncurses/ncurses/base/lib_getstr.c b/contrib/ncurses/ncurses/base/lib_getstr.c new file mode 100644 index 0000000..485c6e3 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_getstr.c @@ -0,0 +1,192 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_getstr.c +** +** The routine wgetstr(). +** +*/ + +#include <curses.priv.h> +#include <term.h> + +MODULE_ID("$Id: lib_getstr.c,v 1.20 1998/12/20 00:16:01 tom Exp $") + +/* + * This wipes out the last character, no matter whether it was a tab, control + * or other character, and handles reverse wraparound. + */ +static char *WipeOut(WINDOW *win, int y, int x, char *first, char *last, bool echoed) +{ + if (last > first) { + *--last = '\0'; + if (echoed) { + int y1 = win->_cury; + int x1 = win->_curx; + + wmove(win, y, x); + waddstr(win, first); + getyx(win, y, x); + while (win->_cury < y1 + || (win->_cury == y1 && win->_curx < x1)) + waddch(win, ' '); + + wmove(win, y, x); + } + } + return last; +} + +int wgetnstr(WINDOW *win, char *str, int maxlen) +{ +TTY buf; +bool oldnl, oldecho, oldraw, oldcbreak; +char erasec; +char killc; +char *oldstr; +int ch; +int y, x; + + T((T_CALLED("wgetnstr(%p,%p, %d)"), win, str, maxlen)); + + if (!win) + returnCode(ERR); + + _nc_get_tty_mode(&buf); + + oldnl = SP->_nl; + oldecho = SP->_echo; + oldraw = SP->_raw; + oldcbreak = SP->_cbreak; + nl(); + noecho(); + noraw(); + cbreak(); + + erasec = erasechar(); + killc = killchar(); + + oldstr = str; + getyx(win, y, x); + + if (is_wintouched(win) || (win->_flags & _HASMOVED)) + wrefresh(win); + + while ((ch = wgetch(win)) != ERR) { + /* + * Some terminals (the Wyse-50 is the most common) generate + * a \n from the down-arrow key. With this logic, it's the + * user's choice whether to set kcud=\n for wgetch(); + * terminating *getstr() with \n should work either way. + */ + if (ch == '\n' + || ch == '\r' + || ch == KEY_DOWN + || ch == KEY_ENTER) { + if (oldecho == TRUE + && win->_cury == win->_maxy + && win->_scroll) + wechochar(win, '\n'); + break; + } + if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) { + if (str > oldstr) { + str = WipeOut(win, y, x, oldstr, str, oldecho); + } + } else if (ch == killc) { + while (str > oldstr) { + str = WipeOut(win, y, x, oldstr, str, oldecho); + } + } else if (ch >= KEY_MIN + || (maxlen >= 0 && str - oldstr >= maxlen)) { + beep(); + } else { + *str++ = ch; + if (oldecho == TRUE) { + int oldy = win->_cury; + if (waddch(win, ch) == ERR) { + /* + * We can't really use the lower-right + * corner for input, since it'll mess + * up bookkeeping for erases. + */ + win->_flags &= ~_WRAPPED; + waddch(win, ' '); + str = WipeOut(win, y, x, oldstr, str, oldecho); + continue; + } else if (win->_flags & _WRAPPED) { + /* + * If the last waddch forced a wrap & + * scroll, adjust our reference point + * for erasures. + */ + if (win->_scroll + && oldy == win->_maxy + && win->_cury == win->_maxy) { + if (--y <= 0) { + y = 0; + } + } + win->_flags &= ~_WRAPPED; + } + wrefresh(win); + } + } + } + + win->_curx = 0; + win->_flags &= ~_WRAPPED; + if (win->_cury < win->_maxy) + win->_cury++; + wrefresh(win); + + /* Restore with a single I/O call, to fix minor asymmetry between + * raw/noraw, etc. + */ + SP->_nl = oldnl; + SP->_echo = oldecho; + SP->_raw = oldraw; + SP->_cbreak = oldcbreak; + + _nc_set_tty_mode(&buf); + + *str = '\0'; + if (ch == ERR) + returnCode(ERR); + + T(("wgetnstr returns %s", _nc_visbuf(oldstr))); + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_hline.c b/contrib/ncurses/ncurses/base/lib_hline.c new file mode 100644 index 0000000..3b0a602 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_hline.c @@ -0,0 +1,76 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_hline.c +** +** The routine whline(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_hline.c,v 1.4 1998/06/28 00:11:01 tom Exp $") + +int whline(WINDOW *win, chtype ch, int n) +{ +int code = ERR; +short start; +short end; + + T((T_CALLED("whline(%p,%s,%d)"), win, _tracechtype(ch), n)); + + if (win) { + struct ldat *line = &(win->_line[win->_cury]); + + start = win->_curx; + end = start + n - 1; + if (end > win->_maxx) + end = win->_maxx; + + CHANGED_RANGE(line, start, end); + + if (ch == 0) + ch = ACS_HLINE; + ch = _nc_render(win, ch); + + while ( end >= start) { + line->text[end] = ch; + end--; + } + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_immedok.c b/contrib/ncurses/ncurses/base/lib_immedok.c new file mode 100644 index 0000000..5590ec9 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_immedok.c @@ -0,0 +1,54 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_immedok.c +** +** The routine immedok. +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_immedok.c,v 1.2 1998/02/11 12:14:01 tom Exp $") + +void immedok(WINDOW *win, bool flag) +{ + T((T_CALLED("immedok(%p,%d)"), win, flag)); + + if (win) + win->_immed = flag; + + returnVoid; +} diff --git a/contrib/ncurses/ncurses/base/lib_inchstr.c b/contrib/ncurses/ncurses/base/lib_inchstr.c new file mode 100644 index 0000000..4779ae0 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_inchstr.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_inchstr.c +** +** The routine winchnstr(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_inchstr.c,v 1.7 1998/02/11 12:13:55 tom Exp $") + +int winchnstr(WINDOW *win, chtype *str, int n) +{ + int i = 0; + + T((T_CALLED("winchnstr(%p,%p,%d)"), win, str, n)); + + if (!str) + returnCode(0); + + if (win) { + for (; (n < 0 || (i < n)) && (win->_curx + i <= win->_maxx); i++) + str[i] = win->_line[win->_cury].text[win->_curx + i]; + } + str[i] = (chtype)0; + + returnCode(i); +} diff --git a/contrib/ncurses/ncurses/base/lib_initscr.c b/contrib/ncurses/ncurses/base/lib_initscr.c new file mode 100644 index 0000000..9a89a07 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_initscr.c @@ -0,0 +1,78 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_initscr.c +** +** The routines initscr(), and termname(). +** +*/ + +#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.26 1998/12/19 23:10:09 tom Exp $") + +WINDOW *initscr(void) +{ +static bool initialized = FALSE; +NCURSES_CONST char *name; +int value; + + T((T_CALLED("initscr()"))); + /* Portable applications must not call initscr() more than once */ + if (!initialized) { + initialized = TRUE; + + if ((name = getenv("TERM")) == 0 + || *name == '\0') + name = "unknown"; + 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(); + } + returnWin(stdscr); +} diff --git a/contrib/ncurses/ncurses/base/lib_insch.c b/contrib/ncurses/ncurses/base/lib_insch.c new file mode 100644 index 0000000..ccc5ff5 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_insch.c @@ -0,0 +1,67 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_insch.c +** +** The routine winsch(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_insch.c,v 1.10 1998/06/28 00:26:52 tom Exp $") + +int winsch(WINDOW *win, chtype c) +{ +int code = ERR; + + T((T_CALLED("winsch(%p, %s)"), win, _tracechtype(c))); + + if (win) { + struct ldat *line = &(win->_line[win->_cury]); + chtype *end = &(line->text[win->_curx]); + chtype *temp1 = &(line->text[win->_maxx]); + chtype *temp2 = temp1 - 1; + + CHANGED_TO_EOL(line, win->_curx, win->_maxx); + while (temp1 > end) + *temp1-- = *temp2--; + + *temp1 = _nc_render(win, c); + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_insdel.c b/contrib/ncurses/ncurses/base/lib_insdel.c new file mode 100644 index 0000000..48e108d --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_insdel.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_insdel.c +** +** The routine winsdelln(win, n). +** positive n insert n lines above current line +** negative n delete n lines starting from current line +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_insdel.c,v 1.8 1998/02/11 12:13:55 tom Exp $") + +int +winsdelln(WINDOW *win, int n) +{ +int code = ERR; + + T((T_CALLED("winsdel(%p,%d)"), win, n)); + + if (win) { + if (n != 0) { + _nc_scroll_window(win, -n, win->_cury, win->_maxy, _nc_background(win)); + _nc_synchook(win); + } + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_insstr.c b/contrib/ncurses/ncurses/base/lib_insstr.c new file mode 100644 index 0000000..cba1473 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_insstr.c @@ -0,0 +1,81 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_insstr.c +** +** The routine winsnstr(). +** +*/ + +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("$Id: lib_insstr.c,v 1.13 1999/03/14 00:27:21 tom Exp $") + +int winsnstr(WINDOW *win, const char *s, int n) +{ +int code = ERR; +short oy; +short ox ; +const unsigned char *str = (const unsigned char *)s; +const unsigned char *cp; + + T((T_CALLED("winsnstr(%p,%s,%d)"), win, _nc_visbuf(s), n)); + + if (win && str) { + oy = win->_cury; ox = win->_curx; + for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) { + if (*cp == '\n' || *cp == '\r' || *cp == '\t' || *cp == '\b') + _nc_waddch_nosync(win, (chtype)(*cp)); + else if (is7bits(*cp) && iscntrl(*cp)) { + winsch(win, ' ' + (chtype)(*cp)); + winsch(win, '^'); + win->_curx += 2; + } else { + winsch(win, (chtype)(*cp)); + win->_curx++; + } + if (win->_curx > win->_maxx) + win->_curx = win->_maxx; + } + + 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 new file mode 100644 index 0000000..b3e1d03 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_instr.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_instr.c +** +** The routine winnstr(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_instr.c,v 1.8 1998/02/11 12:13:54 tom Exp $") + +int winnstr(WINDOW *win, char *str, int n) +{ + int i=0, row, col; + + T((T_CALLED("winnstr(%p,%p,%d)"), win, str, n)); + + if (!str) + returnCode(0); + + if (win) { + getyx(win, row, col); + + if (n < 0) + n = win->_maxx - win->_curx + 1; + + for (; i < n;) { + str[i++] = TextOf(win->_line[row].text[col]); + if (++col > win->_maxx) { + col = 0; + if (++row > win->_maxy) + break; + } + } + } + str[i] = '\0'; /* SVr4 does not seem to count the null */ + returnCode(i); +} + diff --git a/contrib/ncurses/ncurses/base/lib_isendwin.c b/contrib/ncurses/ncurses/base/lib_isendwin.c new file mode 100644 index 0000000..60015fc --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_isendwin.c @@ -0,0 +1,51 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_endwin.c +** +** The routine endwin(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_isendwin.c,v 1.4 1998/04/11 22:52:32 tom Exp $") + +bool isendwin(void) +{ + if (SP == NULL) + return FALSE; + return SP->_endwin; +} diff --git a/contrib/ncurses/ncurses/base/lib_leaveok.c b/contrib/ncurses/ncurses/base/lib_leaveok.c new file mode 100644 index 0000000..e83285d --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_leaveok.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_leaveok.c +** +** The routine leaveok. +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_leaveok.c,v 1.3 1998/03/21 22:54:20 jtc Exp $") + +int leaveok(WINDOW *win, bool flag) +{ + T((T_CALLED("leaveok(%p,%d)"), win, flag)); + + if (win) { + win->_leaveok = flag; + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_mouse.c b/contrib/ncurses/ncurses/base/lib_mouse.c new file mode 100644 index 0000000..0aefdf3 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_mouse.c @@ -0,0 +1,964 @@ +/**************************************************************************** + * Copyright (c) 1998,1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * 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. + * + * Notes for implementors of new mouse-interface methods: + * + * The code is logically split into a lower level that accepts event reports + * in a device-dependent format and an upper level that parses mouse gestures + * and filters events. The mediating data structure is a circular queue of + * MEVENT structures. + * + * Functionally, the lower level's job is to pick up primitive events and + * put them on the circular queue. This can happen in one of two ways: + * either (a) _nc_mouse_event() detects a series of incoming mouse reports + * and queues them, or (b) code in lib_getch.c detects the kmous prefix in + * the keyboard input stream and calls _nc_mouse_inline to queue up a series + * of adjacent mouse reports. + * + * In either case, _nc_mouse_parse() should be called after the series is + * accepted to parse the digested mouse reports (low-level MEVENTs) into + * a gesture (a high-level or composite MEVENT). + * + * Don't be too shy about adding new event types or modifiers, if you can find + * room for them in the 32-bit mask. The API is written so that users get + * feedback on which theoretical event types they won't see when they call + * mousemask. There's one bit per button (the RESERVED_EVENT bit) not being + * used yet, and a couple of bits open at the high end. + */ + +#ifdef __EMX__ +# include "io.h" +# include "fcntl.h" +# define INCL_DOS +# define INCL_VIO +# define INCL_KBD +# define INCL_MOU +# define INCL_DOSPROCESS +# include <os2.h> /* Need to include before the others */ +#endif + +#include <curses.priv.h> +#include <term.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 */ +#endif +#endif + +MODULE_ID("$Id: lib_mouse.c,v 1.44 1999/07/24 21:10:48 tom Exp $") + +#define MY_TRACE TRACE_ICALLS|TRACE_IEVENT + +#define INVALID_EVENT -1 + +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) */ + +#if USE_GPM_SUPPORT +#ifndef LINT +static Gpm_Connect gpm_connect; +#endif +#endif + +static mmask_t eventmask; /* current event mask */ + +static bool _nc_mouse_parse(int); +static void _nc_mouse_resume(SCREEN *); +static void _nc_mouse_wrap(SCREEN *); + +/* maintain a circular list of mouse events */ + +/* 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) + +#ifdef TRACE +static void _trace_slot(const char *tag) +{ + MEVENT *ep; + + _tracef(tag); + + for (ep = events; ep < events + EV_MAX; ep++) + _tracef("mouse event queue slot %ld = %s", + (long) (ep - events), + _tracemouse(ep)); +} +#endif + +#ifdef 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 +write_event(int down, int button, int x, int y) +{ + char buf[6]; + unsigned long ignore; + + strcpy(buf, key_mouse); + 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); +} + +static void +mouse_server(unsigned long ignored GCC_UNUSED) +{ + unsigned short fWait = MOU_WAIT; + /* NOPTRRECT mourt = { 0,0,24,79 }; */ + MOUEVENTINFO mouev; + HMOU hmou; + unsigned short mask = MOUSE_BN1_DOWN | MOUSE_BN2_DOWN | MOUSE_BN3_DOWN; + int oldstate = 0; + char errmess[] = "Unexpected termination of mouse thread\r\n"; + unsigned long ignore; + + /* open the handle for the mouse */ + if (MouOpen(NULL,&hmou) == 0) { + + if (MouSetEventMask(&mask,hmou) == 0 + && MouDrawPtr(hmou) == 0) { + + for (;;) { + /* sit and wait on the event queue */ + if (MouReadEventQue(&mouev,&fWait,hmou)) + break; + if (!mouse_activated) + goto finish; + + /* + * OS/2 numbers a 3-button mouse inconsistently from other + * platforms: + * 1 = left + * 2 = right + * 3 = middle. + */ + if ((mouev.fs ^ oldstate) & MOUSE_BN1_DOWN) + write_event(mouev.fs & MOUSE_BN1_DOWN, + mouse_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); + if ((mouev.fs ^ oldstate) & MOUSE_BN3_DOWN) + write_event(mouev.fs & MOUSE_BN3_DOWN, + mouse_buttons[2], mouev.col, mouev.row); + + finish: + oldstate = mouev.fs; + } + } + + DosWrite(2, errmess, strlen(errmess), &ignore); + MouClose(hmou); + } + DosExit(EXIT_THREAD, 0L ); +} +static void +server_state(const int state) +{ /* It would be nice to implement pointer-off and stop looping... */ + mouse_activated = state; +} + +#endif + +static int initialized; + +static void _nc_mouse_init(void) +/* initialize the mouse */ +{ + int i; + + if (initialized) { + return; + } + initialized = TRUE; + + TR(MY_TRACE, ("_nc_mouse_init() called")); + + for (i = 0; i < EV_MAX; i++) + events[i].id = INVALID_EVENT; + + /* we know how to recognize mouse events under xterm */ + if (key_mouse != 0 + && getenv("DISPLAY") != 0) + mousetype = M_XTERM; + +#if USE_GPM_SUPPORT + else if (!strncmp(cur_term->type.term_names, "linux", 5)) + { + /* 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; + } + } +#endif + + /* OS/2 VIO */ +#ifdef USE_EMX_MOUSE + if (!mouse_thread && mousetype != M_XTERM && key_mouse) { + int handles[2]; + if (pipe(handles) < 0) { + perror("mouse pipe error"); + } else { + int rc; + + if (!mouse_buttons[0]) { + char *s = getenv("MOUSE_BUTTONS_123"); + + mouse_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'; + } + } + mouse_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, mouse_server, 0, 0, 8192); + if (rc) + printf("mouse thread error %d=%#x", rc, rc); + else + mousetype = M_XTERM; + } + } +#endif + + T(("_nc_mouse_init() set mousetype to %d", mousetype)); +} + +static bool _nc_mouse_event(SCREEN *sp GCC_UNUSED) +/* query to see if there is a pending mouse event */ +{ +#if USE_GPM_SUPPORT + /* GPM: query server for event, return TRUE if we find one */ + Gpm_Event ev; + + if (gpm_fd >= 0 + && _nc_timed_wait(2, 0, (int *)0) + && Gpm_GetEvent(&ev) == 1) + { + eventp->id = 0; /* there's only one mouse... */ + + eventp->bstate = 0; + switch (ev.type & 0x0f) + { + case(GPM_DOWN): + if (ev.buttons & GPM_B_LEFT) eventp->bstate |= BUTTON1_PRESSED; + if (ev.buttons & GPM_B_MIDDLE) eventp->bstate |= BUTTON2_PRESSED; + if (ev.buttons & GPM_B_RIGHT) eventp->bstate |= BUTTON3_PRESSED; + break; + case(GPM_UP): + if (ev.buttons & GPM_B_LEFT) eventp->bstate |= BUTTON1_RELEASED; + if (ev.buttons & GPM_B_MIDDLE) eventp->bstate |= BUTTON2_RELEASED; + if (ev.buttons & GPM_B_RIGHT) eventp->bstate |= BUTTON3_RELEASED; + break; + default: + break; + } + + eventp->x = ev.x - 1; + eventp->y = ev.y - 1; + eventp->z = 0; + + /* bump the next-free pointer into the circular list */ + eventp = NEXT(eventp); + return (TRUE); + } +#endif + + /* xterm: never have to query, mouse events are in the keyboard stream */ + return(FALSE); /* no event waiting */ +} + +static bool _nc_mouse_inline(SCREEN *sp) +/* mouse report received in the keyboard stream -- parse its info */ +{ + TR(MY_TRACE, ("_nc_mouse_inline() called")); + + if (mousetype == M_XTERM) + { + unsigned char kbuf[4]; + MEVENT *prev; + size_t grabbed; + int res; + + /* This code requires that your xterm entry contain the kmous + * capability and that it be set to the \E[M documented in the + * Xterm Control Sequences reference. This is how we + * arrange for mouse events to be reported via a KEY_MOUSE + * return value from wgetch(). After this value is received, + * _nc_mouse_inline() gets called and is immediately + * responsible for parsing the mouse status information + * following the prefix. + * + * The following quotes from the ctrlseqs.ms document in the + * X distribution, describing the X mouse tracking feature: + * + * Parameters for all mouse tracking escape sequences + * generated by xterm encode numeric parameters in a single + * character as value+040. For example, ! is 1. + * + * On button press or release, xterm sends ESC [ M CbCxCy. + * The low two bits of Cb encode button information: 0=MB1 + * pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release. The + * upper bits encode what modifiers were down when the + * button was pressed and are added together. 4=Shift, + * 8=Meta, 16=Control. Cx and Cy are the x and y coordinates + * of the mouse event. The upper left corner is (1,1). + * + * (End quote) By the time we get here, we've eaten the + * key prefix. FYI, the loop below is necessary because + * mouse click info isn't guaranteed to present as a + * single clist item. It always does under Linux but often + * fails to under Solaris. + */ + for (grabbed = 0; grabbed < 3; grabbed += res) + { + + /* For VIO mouse we add extra bit 64 to disambiguate button-up. */ +#ifdef USE_EMX_MOUSE + res = read( M_FD(sp) >= 0 ? M_FD(sp) : sp->_ifd, &kbuf, 3); +#else + res = read(sp->_ifd, kbuf + grabbed, 3-grabbed); +#endif + if (res == -1) + break; + } + kbuf[3] = '\0'; + + TR(TRACE_IEVENT, ("_nc_mouse_inline sees the following xterm data: '%s'", kbuf)); + + eventp->id = 0; /* there's only one mouse... */ + + /* processing code goes here */ + eventp->bstate = 0; + switch (kbuf[0] & 0x3) + { + case 0x0: + eventp->bstate = BUTTON1_PRESSED; +#ifdef USE_EMX_MOUSE + if (kbuf[0] & 0x40) + eventp->bstate = BUTTON1_RELEASED; +#endif + break; + + case 0x1: + eventp->bstate = BUTTON2_PRESSED; +#ifdef USE_EMX_MOUSE + if (kbuf[0] & 0x40) + eventp->bstate = BUTTON2_RELEASED; +#endif + break; + + case 0x2: + eventp->bstate = BUTTON3_PRESSED; +#ifdef USE_EMX_MOUSE + if (kbuf[0] & 0x40) + eventp->bstate = BUTTON3_RELEASED; +#endif + break; + + case 0x3: + /* + * Release events aren't reported for individual buttons, + * just for the button set as a whole... + */ + 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; + break; + } + + if (kbuf[0] & 4) { + eventp->bstate |= BUTTON_SHIFT; + } + if (kbuf[0] & 8) { + eventp->bstate |= BUTTON_ALT; + } + if (kbuf[0] & 16) { + eventp->bstate |= BUTTON_CTRL; + } + + eventp->x = (kbuf[1] - ' ') - 1; + eventp->y = (kbuf[2] - ' ') - 1; + TR(MY_TRACE, ("_nc_mouse_inline: primitive mouse-event %s has slot %ld", + _tracemouse(eventp), + (long) (eventp - events))); + + /* bump the next-free pointer into the circular list */ + eventp = NEXT(eventp); +#if 0 /* this return would be needed for QNX's mods to lib_getch.c */ + return(TRUE); +#endif + } + + return(FALSE); +} + +static void mouse_activate(bool on) +{ + if (!on && !initialized) + return; + + _nc_mouse_init(); + + if (on) { + + switch (mousetype) { + case M_XTERM: +#ifdef 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 + break; +#if USE_GPM_SUPPORT + case M_GPM: + SP->_mouse_fd = gpm_fd; + break; +#endif + } + /* Make runtime binding to cut down on object size of applications that + * do not use the mouse (e.g., 'clear'). + */ + SP->_mouse_event = _nc_mouse_event; + SP->_mouse_inline = _nc_mouse_inline; + SP->_mouse_parse = _nc_mouse_parse; + SP->_mouse_resume = _nc_mouse_resume; + SP->_mouse_wrap = _nc_mouse_wrap; + + } else { + + switch (mousetype) { + case M_XTERM: + TPUTS_TRACE("xterm mouse deinitialization"); +#ifdef USE_EMX_MOUSE + server_state(0); +#else + putp("\033[?1000l"); +#endif + break; +#if USE_GPM_SUPPORT + case M_GPM: + break; +#endif + } + } + (void) fflush(SP->_ofp); +} + +/************************************************************************** + * + * Device-independent code + * + **************************************************************************/ + +static bool _nc_mouse_parse(int runcount) +/* parse a run of atomic mouse events into a gesture */ +{ + MEVENT *ep, *runp, *next, *prev = PREV(eventp); + int n; + bool merge; + + TR(MY_TRACE, ("_nc_mouse_parse(%d) called", runcount)); + + /* + * When we enter this routine, the event list next-free pointer + * points just past a run of mouse events that we know were separated + * in time by less than the critical click interval. The job of this + * routine is to collaps this run into a single higher-level event + * or gesture. + * + * We accomplish this in two passes. The first pass merges press/release + * pairs into click events. The second merges runs of click events into + * double or triple-click events. + * + * It's possible that the run may not resolve to a single event (for + * example, if the user quadruple-clicks). If so, leading events + * in the run are ignored. + * + * Note that this routine is independent of the format of the specific + * format of the pointing-device's reports. We can use it to parse + * gestures on anything that reports press/release events on a per- + * button basis, as long as the device-dependent mouse code puts stuff + * on the queue in MEVENT format. + */ + if (runcount == 1) + { + TR(MY_TRACE, ("_nc_mouse_parse: returning simple mouse event %s at slot %ld", + _tracemouse(prev), + (long) (prev - events))); + return (prev->id >= 0) + ? ((prev->bstate & eventmask) ? TRUE : FALSE) + : FALSE; + } + + /* find the start of the run */ + runp = eventp; + for (n = runcount; n > 0; n--) { + runp = PREV(runp); + } + +#ifdef TRACE + 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, + runcount); + } +#endif /* TRACE */ + + /* first pass; merge press/release pairs */ + do { + merge = FALSE; + for (ep = runp; next = NEXT(ep), next != eventp; ep = next) + { + 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)) + ) + { + 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; + } + if (merge) + next->id = INVALID_EVENT; + } + } + } while + (merge); + +#ifdef TRACE + 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, + runcount); + } +#endif /* TRACE */ + + /* + * Second pass; merge click runs. At this point, click events are + * each followed by one invalid event. We merge click events + * forward in the queue. + * + * NOTE: There is a problem with this design! If the application + * allows enough click events to pile up in the circular queue so + * they wrap around, it will cheerfully merge the newest forward + * into the oldest, creating a bogus doubleclick and confusing + * the queue-traversal logic rather badly. Generally this won't + * happen, because calling getmouse() marks old events invalid and + * ineligible for merges. The true solution to this problem would + * be to timestamp each MEVENT and perform the obvious sanity check, + * but the timer element would have to have sub-second resolution, + * which would get us into portability trouble. + */ + do { + MEVENT *follower; + + merge = FALSE; + for (ep = runp; next = NEXT(ep), next != eventp; ep = next) + if (ep->id != INVALID_EVENT) + { + if (next->id != INVALID_EVENT) + continue; + follower = NEXT(next); + if (follower->id == INVALID_EVENT) + continue; + + /* merge click events forward */ + if ((ep->bstate & + (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 (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 (merge) + ep->id = INVALID_EVENT; + } + } + } while + (merge); + +#ifdef TRACE + 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, + runcount); + } +#endif /* TRACE */ + + /* + * Now try to throw away trailing events flagged invalid, or that + * don't match the current event mask. + */ + for (; runcount; prev = PREV(eventp), runcount--) + if (prev->id == INVALID_EVENT || !(prev->bstate & eventmask)) { + 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, + runcount); + } + for (ep = runp; ep != eventp; ep = NEXT(ep)) + if (ep->id != INVALID_EVENT) + TR(MY_TRACE, ("_nc_mouse_parse: returning composite mouse event %s at slot %ld", + _tracemouse(ep), + (long) (ep - events))); +#endif /* TRACE */ + + /* after all this, do we have a valid event? */ + return(PREV(eventp)->id != INVALID_EVENT); +} + +static void _nc_mouse_wrap(SCREEN *sp GCC_UNUSED) +/* release mouse -- called by endwin() before shellout/exit */ +{ + TR(MY_TRACE, ("_nc_mouse_wrap() called")); + + switch (mousetype) { + case M_XTERM: + if (eventmask) + mouse_activate(FALSE); + break; +#if USE_GPM_SUPPORT + /* GPM: pass all mouse events to next client */ + case M_GPM: + break; +#endif + } +} + +static void _nc_mouse_resume(SCREEN *sp GCC_UNUSED) +/* re-connect to mouse -- called by doupdate() after shellout */ +{ + TR(MY_TRACE, ("_nc_mouse_resume() called")); + + /* xterm: re-enable reporting */ + if (mousetype == M_XTERM && eventmask) + mouse_activate(TRUE); + + /* GPM: reclaim our event set */ +} + +/************************************************************************** + * + * Mouse interface entry points for the API + * + **************************************************************************/ + +int getmouse(MEVENT *aevent) +/* grab a copy of the current mouse event */ +{ + T((T_CALLED("getmouse(%p)"), aevent)); + + if (aevent && (mousetype != M_NONE)) + { + /* compute the current-event pointer */ + MEVENT *prev = PREV(eventp); + + /* copy the event we find there */ + *aevent = *prev; + + TR(TRACE_IEVENT, ("getmouse: returning event %s from slot %ld", + _tracemouse(prev), + (long) (prev - events))); + + prev->id = INVALID_EVENT; /* so the queue slot becomes free */ + returnCode(OK); + } + returnCode(ERR); +} + +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; + + /* bump the next-free pointer into the circular list */ + eventp = NEXT(eventp); + + /* push back the notification event on the keyboard queue */ + return ungetch(KEY_MOUSE); +} + +mmask_t mousemask(mmask_t newmask, mmask_t *oldmask) +/* set the mouse event mask */ +{ + mmask_t result = 0; + + T((T_CALLED("mousemask(%#lx,%p)"), 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; + } + + returnCode(result); +} + +bool wenclose(const WINDOW *win, int y, int x) +/* check to see if given window encloses given screen location */ +{ + if (win) + { + y -= win->_yoffset; + return ((win->_begy <= y && + win->_begx <= x && + (win->_begx + win->_maxx) >= x && + (win->_begy + win->_maxy) >= y) ? TRUE : FALSE); + } + return FALSE; +} + +int mouseinterval(int maxclick) +/* set the maximum mouse interval within which to recognize a click */ +{ + int oldval; + + if (SP != 0) { + oldval = SP->_maxclick; + if (maxclick >= 0) + SP->_maxclick = maxclick; + } else { + oldval = DEFAULT_MAXCLICK; + } + + return(oldval); +} + +/* This may be used by other routines to ask for the existence of mouse + support */ +int _nc_has_mouse(void) { + return (mousetype==M_NONE ? 0:1); +} + +bool wmouse_trafo(const WINDOW* win, int* pY, int* pX, bool to_screen) +{ + bool result = FALSE; + + if (win && pY && pX) + { + int y = *pY; int x = *pX; + + if (to_screen) + { + y += win->_begy + win->_yoffset; + x += win->_begx; + if (wenclose(win,y,x)) + result = TRUE; + } + else + { + if (wenclose(win,y,x)) + { + y -= (win->_begy + win->_yoffset); + x -= win->_begx; + result = TRUE; + } + } + if (result) + { + *pX = x; + *pY = y; + } + } + return(result); +} + +/* lib_mouse.c ends here */ diff --git a/contrib/ncurses/ncurses/base/lib_move.c b/contrib/ncurses/ncurses/base/lib_move.c new file mode 100644 index 0000000..6f5bddf --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_move.c @@ -0,0 +1,63 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_move.c +** +** The routine wmove(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_move.c,v 1.8 1998/02/11 12:13:53 tom Exp $") + +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) + { + win->_curx = (short)x; + win->_cury = (short)y; + + win->_flags &= ~_WRAPPED; + win->_flags |= _HASMOVED; + returnCode(OK); + } else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_mvwin.c b/contrib/ncurses/ncurses/base/lib_mvwin.c new file mode 100644 index 0000000..9774d9f --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_mvwin.c @@ -0,0 +1,109 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_mvwin.c +** +** The routine mvwin(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_mvwin.c,v 1.7 1998/02/11 12:13:55 tom Exp $") + +int mvwin(WINDOW *win, int by, int bx) +{ + T((T_CALLED("mvwin(%p,%d,%d)"), win, by, bx)); + + if (!win || (win->_flags & _ISPAD)) + returnCode(ERR); + + /* Copying subwindows is allowed, but it is expensive... */ + if (win->_flags & _SUBWIN) { + int err = ERR; + WINDOW *parent = win->_parent; + if (parent) + { /* Now comes the complicated and costly part, you should really + * try to avoid to move subwindows. Because a subwindow shares + * the text buffers with its parent, one can't do a simple + * memmove of the text buffers. One has to create a copy, then + * to relocate the subwindow and then to do a copy. + */ + if ((by - parent->_begy == win->_pary) && + (bx - parent->_begx == win->_parx)) + err=OK; /* we don't actually move */ + else { + WINDOW* clone = dupwin(win); + if (clone) { + /* now we have the clone, so relocate win */ + + werase(win); /* Erase the original place */ + wbkgd(win,parent->_bkgd);/* fill with parents background */ + wsyncup(win); /* Tell the parent(s) */ + + err = mvderwin(win, + by - parent->_begy, + bx - parent->_begx); + if (err!=ERR) { + err = copywin(clone,win, + 0, 0, 0, 0, win->_maxy, win->_maxx, 0); + if (ERR!=err) + wsyncup(win); + } + if (ERR==delwin(clone)) + err=ERR; + } + } + } + returnCode(err); + } + + if (by + win->_maxy > screen_lines - 1 + || bx + win->_maxx > screen_columns - 1 + || by < 0 + || bx < 0) + returnCode(ERR); + + /* + * Whether or not the window is moved, touch the window's contents so + * that a following call to 'wrefresh()' will paint the window at the + * new location. This ensures that if the caller has refreshed another + * window at the same location, that this one will be displayed. + */ + win->_begy = by; + win->_begx = bx; + returnCode(touchwin(win)); +} diff --git a/contrib/ncurses/ncurses/base/lib_newterm.c b/contrib/ncurses/ncurses/base/lib_newterm.c new file mode 100644 index 0000000..9a4919b --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_newterm.c @@ -0,0 +1,206 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_newterm.c +** +** The newterm() function. +** +*/ + +#include <curses.priv.h> + +#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE) +#define _POSIX_SOURCE +#endif + +#include <term.h> /* clear_screen, cup & friends, cur_term */ + +MODULE_ID("$Id: lib_newterm.c,v 1.41 1999/07/24 20:07:48 tom Exp $") + +#ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */ +#define ONLCR 0 +#endif + +/* + * SVr4/XSI Curses specify that hardware echo is turned off in initscr, and not + * restored during the curses session. The library simulates echo in software. + * (The behavior is unspecified if the application enables hardware echo). + * + * The newterm function also initializes terminal settings, and since initscr + * is supposed to behave as if it calls newterm, we do it here. + */ +static inline int _nc_initscr(void) +{ + /* for extended XPG4 conformance requires cbreak() at this point */ + /* (SVr4 curses does this anyway) */ + cbreak(); + +#ifdef TERMIOS + cur_term->Nttyb.c_lflag &= ~(ECHO|ECHONL); + cur_term->Nttyb.c_iflag &= ~(ICRNL|INLCR|IGNCR); + cur_term->Nttyb.c_oflag &= ~(ONLCR); +#else + cur_term->Nttyb.sg_flags &= ~(ECHO|CRMOD); +#endif + return _nc_set_tty_mode(&cur_term->Nttyb); +} + +/* + * filter() has to be called before either initscr() or newterm(), so there is + * apparently no way to make this flag apply to some terminals and not others, + * aside from possibly delaying a filter() call until some terminals have been + * initialized. + */ +static int filter_mode = FALSE; + +void filter(void) +{ + filter_mode = TRUE; +} + +SCREEN * newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp) +{ +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 + + 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) + return 0; + + /* implement filter mode */ + if (filter_mode) { + LINES = 1; + + if (init_tabs != -1) + 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; + } + + /* 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)) + return 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); + return 0; + } + + /* 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)); +#ifdef TERMIOS + SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 && + !(cur_term->Ottyb.c_iflag & ISTRIP)); +#else + SP->_use_meta = FALSE; +#endif + SP->_endwin = FALSE; + + /* Check whether we can optimize scrolling under dumb terminals in case + * we do not have any of these capabilities, scrolling optimization + * will be useless. + */ + SP->_scrolling = ((scroll_forward && scroll_reverse) || + ((parm_rindex || parm_insert_line || insert_line) && + (parm_index || parm_delete_line || delete_line))); + + baudrate(); /* sets a field in the SP structure */ + + SP->_keytry = 0; + + /* + * Check for mismatched graphic-rendition capabilities. Most SVr4 + * terminfo trees contain entries that have rmul or rmso equated to + * sgr0 (Solaris curses copes with those entries). We do this only for + * curses, since many termcap applications assume that smso/rmso and + * smul/rmul are paired, and will not function properly if we remove + * rmso or rmul. Curses applications shouldn't be looking at this + * detail. + */ +#define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode)) + SP->_use_rmso = SGR0_TEST(exit_standout_mode); + SP->_use_rmul = SGR0_TEST(exit_underline_mode); + + /* compute movement costs so we can do better move optimization */ + _nc_mvcur_init(); + + /* initialize terminal to a sane state */ + _nc_screen_init(); + + /* Initialize the terminal line settings. */ + _nc_initscr(); + + _nc_signal_handler(TRUE); + + T((T_RETURN("%p"), SP)); + return(SP); +} diff --git a/contrib/ncurses/ncurses/base/lib_newwin.c b/contrib/ncurses/ncurses/base/lib_newwin.c new file mode 100644 index 0000000..61c0eb3 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_newwin.c @@ -0,0 +1,271 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_newwin.c +** +** The routines newwin(), subwin() and their dependent +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_newwin.c,v 1.20 1998/05/23 23:21:32 Alexander.V.Lukyanov Exp $") + +void _nc_freewin(WINDOW *win) +{ +WINDOWLIST *p, *q; +int i; + + if (win != 0) { + for (p = _nc_windows, q = 0; p != 0; q = p, p = p->next) { + if (p->win == win) { + if (q == 0) + _nc_windows = p->next; + else + q->next = p->next; + free(p); + + if (! (win->_flags & _SUBWIN)) { + for (i = 0; i <= win->_maxy && win->_line[i].text; i++) + free(win->_line[i].text); + } + free(win->_line); + free(win); + + if (win == curscr) curscr = 0; + if (win == stdscr) stdscr = 0; + if (win == newscr) newscr = 0; + + T(("...deleted win=%p", win)); + break; + } + } + } +} + +WINDOW * newwin(int num_lines, int num_columns, int begy, int begx) +{ +WINDOW *win; +chtype *ptr; +int i; + + T((T_CALLED("newwin(%d,%d,%d,%d)"), num_lines, num_columns, begy, begx)); + + if (begy < 0 || begx < 0 || num_lines < 0 || num_columns < 0) + returnWin(0); + + if (num_lines == 0) + num_lines = SP->_lines_avail - begy; + if (num_columns == 0) + num_columns = screen_columns - begx; + + if (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); + + for (i = 0; i < num_lines; i++) { + if ((win->_line[i].text = typeCalloc(chtype, (unsigned)num_columns)) == 0) { + _nc_freewin(win); + returnWin(0); + } + for (ptr = win->_line[i].text; ptr < win->_line[i].text + num_columns; ) + *ptr++ = ' '; + } + + T(("newwin: returned window is %p", win)); + + returnWin(win); +} + +WINDOW * derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx) +{ +WINDOW *win; +int i; +int flags = _SUBWIN; + + T((T_CALLED("derwin(%p,%d,%d,%d,%d)"), orig, num_lines, num_columns, begy, begx)); + + /* + ** make sure window fits inside the original one + */ + if ( begy < 0 || begx < 0 || orig == 0 || num_lines < 0 || num_columns < 0) + returnWin(0); + if ( begy + num_lines > orig->_maxy + 1 + || begx + num_columns > orig->_maxx + 1) + returnWin(0); + + if (num_lines == 0) + num_lines = orig->_maxy + 1 - begy; + + if (num_columns == 0) + num_columns = orig->_maxx + 1 - begx; + + if (orig->_flags & _ISPAD) + flags |= _ISPAD; + + if ((win = _nc_makenew(num_lines, num_columns, orig->_begy + begy, orig->_begx + begx, flags)) == 0) + returnWin(0); + + win->_pary = begy; + win->_parx = begx; + win->_attrs = orig->_attrs; + win->_bkgd = orig->_bkgd; + + for (i = 0; i < num_lines; i++) + win->_line[i].text = &orig->_line[begy++].text[begx]; + + win->_parent = orig; + + T(("derwin: returned window is %p", win)); + + returnWin(win); +} + + +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)); + + returnWin(derwin(w, l, c, y - w->_begy, x - w->_begx)); +} + +WINDOW * +_nc_makenew(int num_lines, int num_columns, int begy, int begx, int flags) +{ +int i; +WINDOWLIST *wp; +WINDOW *win; +bool is_pad = (flags & _ISPAD); + + T(("_nc_makenew(%d,%d,%d,%d)", num_lines, num_columns, begy, begx)); + + if (num_lines <= 0 || num_columns <= 0) + return 0; + + if ((wp = typeCalloc(WINDOWLIST, 1)) == 0) + return 0; + + if ((win = typeCalloc(WINDOW, 1)) == 0) + return 0; + + if ((win->_line = typeCalloc(struct ldat, ((unsigned)num_lines))) == 0) { + free(win); + return 0; + } + + win->_curx = 0; + win->_cury = 0; + win->_maxy = num_lines - 1; + win->_maxx = num_columns - 1; + win->_begy = begy; + win->_begx = begx; + win->_yoffset = SP->_topstolen; + + win->_flags = flags; + win->_attrs = A_NORMAL; + win->_bkgd = BLANK; + + win->_clear = is_pad ? FALSE : (num_lines == screen_lines && num_columns == screen_columns); + win->_idlok = FALSE; + win->_idcok = TRUE; + win->_scroll = FALSE; + win->_leaveok = FALSE; + win->_use_keypad = FALSE; + win->_delay = -1; + win->_immed = FALSE; + win->_sync = 0; + win->_parx = -1; + win->_pary = -1; + win->_parent = 0; + + win->_regtop = 0; + win->_regbottom = num_lines - 1; + + win->_pad._pad_y = -1; + win->_pad._pad_x = -1; + win->_pad._pad_top = -1; + win->_pad._pad_bottom = -1; + win->_pad._pad_left = -1; + win->_pad._pad_right = -1; + + for (i = 0; i < num_lines; i++) + { + /* + * This used to do + * + * win->_line[i].firstchar = win->_line[i].lastchar = _NOCHANGE; + * + * which marks the whole window unchanged. That's how + * SVr1 curses did it, but SVr4 curses marks the whole new + * window changed. + * + * With the old SVr1-like code, say you have stdscr full of + * characters, then create a new window with newwin(), + * then do a printw(win, "foo ");, the trailing spaces are + * completely ignored by the following refreshes. So, you + * get "foojunkjunk" on the screen instead of "foo " as + * you actually intended. + * + * SVr4 doesn't do this. Instead the spaces are actually written. + * So that's how we want ncurses to behave. + */ + win->_line[i].firstchar = 0; + win->_line[i].lastchar = num_columns-1; + + if_USE_SCROLL_HINTS(win->_line[i].oldindex = i); + } + + if (!is_pad && (begx + num_columns == screen_columns)) { + win->_flags |= _ENDLINE; + + if (begx == 0 && num_lines == screen_lines && begy == 0) + win->_flags |= _FULLWIN; + + if (begy + num_lines == screen_lines) + win->_flags |= _SCROLLWIN; + } + + wp->next = _nc_windows; + wp->win = win; + _nc_windows = wp; + + T((T_CREATE("window %p"), win)); + + return(win); +} diff --git a/contrib/ncurses/ncurses/base/lib_nl.c b/contrib/ncurses/ncurses/base/lib_nl.c new file mode 100644 index 0000000..d5c4266 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_nl.c @@ -0,0 +1,79 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * nl.c + * + * Routines: + * nl() + * nonl() + * + */ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_nl.c,v 1.3 1998/10/14 15:14:08 Alexander.V.Lukyanov Exp $") + +#ifdef __EMX__ +#include <io.h> +#include <fcntl.h> +#endif + +int nl(void) +{ + T((T_CALLED("nl()"))); + + SP->_nl = TRUE; + +#ifdef __EMX__ + fflush(SP->_ofp); + _fsetmode(SP->_ofp, "t"); +#endif + + returnCode(OK); +} + +int nonl(void) +{ + T((T_CALLED("nonl()"))); + + SP->_nl = FALSE; + +#ifdef __EMX__ + fflush(SP->_ofp); + _fsetmode(SP->_ofp, "b"); +#endif + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_overlay.c b/contrib/ncurses/ncurses/base/lib_overlay.c new file mode 100644 index 0000000..db2dce1 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_overlay.c @@ -0,0 +1,161 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_overlay.c +** +** The routines overlay(), copywin(), and overwrite(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_overlay.c,v 1.12 1998/02/11 12:13:59 tom Exp $") + +static int overlap(const WINDOW *const s, WINDOW *const d, int const flag) +{ +int sminrow, smincol, dminrow, dmincol, 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)); + + if (!s || !d) + 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)); +} + +/* +** +** overlay(win1, win2) +** +** +** overlay() writes the overlapping area of win1 behind win2 +** on win2 non-destructively. +** +**/ + +int overlay(const WINDOW *win1, WINDOW *win2) +{ + T((T_CALLED("overlay(%p,%p)"), win1, win2)); + returnCode(overlap(win1, win2, TRUE)); +} + +/* +** +** overwrite(win1, win2) +** +** +** overwrite() writes the overlapping area of win1 behind win2 +** on win2 destructively. +** +**/ + +int overwrite(const WINDOW *win1, WINDOW *win2) +{ + T((T_CALLED("overwrite(%p,%p)"), win1, win2)); + returnCode(overlap(win1, win2, FALSE)); +} + +int 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; +chtype bk = AttrOf(dst->_bkgd); +chtype mask = ~(chtype)((bk&A_COLOR) ? A_COLOR : 0); + + T((T_CALLED("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)"), + src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over)); + + if (!src || !dst) + returnCode(ERR); + + /* make sure rectangle exists in source */ + if ((sminrow + dmaxrow - dminrow) > (src->_maxy + 1) || + (smincol + dmaxcol - dmincol) > (src->_maxx + 1)) { + returnCode(ERR); + } + + T(("rectangle exists in source")); + + /* make sure rectangle fits in destination */ + if (dmaxrow > dst->_maxy || dmaxcol > dst->_maxx) { + returnCode(ERR); + } + + T(("rectangle fits in destination")); + + for (dy = dminrow, sy = sminrow; dy <= dmaxrow; sy++, dy++) { + touched = FALSE; + for(dx=dmincol, sx=smincol; dx <= dmaxcol; sx++, dx++) + { + if (over) + { + if ((TextOf(src->_line[sy].text[sx]) != ' ') && + (dst->_line[dy].text[dx]!=src->_line[sy].text[sx])) + { + dst->_line[dy].text[dx] = + (src->_line[sy].text[sx] & mask) | bk; + touched = TRUE; + } + } + else { + if (dst->_line[dy].text[dx] != src->_line[sy].text[sx]) + { + dst->_line[dy].text[dx] = src->_line[sy].text[sx]; + touched = TRUE; + } + } + } + if (touched) + { + touchline(dst,0,getmaxy(dst)); + } + } + T(("finished copywin")); + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_pad.c b/contrib/ncurses/ncurses/base/lib_pad.c new file mode 100644 index 0000000..d4e341c --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_pad.c @@ -0,0 +1,280 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * lib_pad.c + * newpad -- create a new pad + * pnoutrefresh -- refresh a pad, no update + * pechochar -- add a char to a pad and refresh + */ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_pad.c,v 1.27 1998/06/28 00:10:16 tom Exp $") + +WINDOW *newpad(int l, int c) +{ +WINDOW *win; +chtype *ptr; +int i; + + T((T_CALLED("newpad(%d, %d)"), l, c)); + + if (l <= 0 || c <= 0) + returnWin(0); + + if ((win = _nc_makenew(l,c,0,0,_ISPAD)) == NULL) + returnWin(0); + + for (i = 0; i < l; i++) { + if_USE_SCROLL_HINTS(win->_line[i].oldindex = _NEWINDEX); + if ((win->_line[i].text = typeCalloc(chtype, ((size_t)c))) == 0) { + _nc_freewin(win); + returnWin(0); + } + for (ptr = win->_line[i].text; ptr < win->_line[i].text + c; ) + *ptr++ = ' '; + } + + returnWin(win); +} + +WINDOW *subpad(WINDOW *orig, int l, int c, int begy, int begx) +{ +WINDOW *win = (WINDOW *)0; + + T((T_CALLED("subpad(%d, %d)"), l, c)); + + if (orig) { + if (!(orig->_flags & _ISPAD) || ((win = derwin(orig, l, c, begy, begx)) == NULL)) + returnWin(0); + } + returnWin(win); +} + +int prefresh(WINDOW *win, int pminrow, int pmincol, + int sminrow, int smincol, int smaxrow, int smaxcol) +{ + T((T_CALLED("prefresh()"))); + if (pnoutrefresh(win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol) != ERR + && doupdate() != ERR) { + returnCode(OK); + } + returnCode(ERR); +} + +int pnoutrefresh(WINDOW *win, int pminrow, int pmincol, + int sminrow, int smincol, int smaxrow, int smaxcol) +{ +const int my_len = 2; /* parameterize the threshold for hardscroll */ +short i, j; +short m, n; +short pmaxrow; +short pmaxcol; +short displaced; +bool wide; + + T((T_CALLED("pnoutrefresh(%p, %d, %d, %d, %d, %d, %d)"), + win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)); + + if (win == 0) + returnCode(ERR); + + if (!(win->_flags & _ISPAD)) + returnCode(ERR); + + /* negative values are interpreted as zero */ + if (pminrow < 0) pminrow = 0; + if (pmincol < 0) pmincol = 0; + if (sminrow < 0) sminrow = 0; + if (smincol < 0) smincol = 0; + + pmaxrow = pminrow + smaxrow - sminrow; + pmaxcol = pmincol + smaxcol - smincol; + + T((" pminrow + smaxrow - sminrow %d, win->_maxy %d", pmaxrow, win->_maxy)); + T((" pmincol + smaxcol - smincol %d, win->_maxx %d", pmaxcol, win->_maxx)); + + /* + * Trim the caller's screen size back to the actual limits. + */ + if (pmaxrow > win->_maxy) { + smaxrow -= (pmaxrow - win->_maxy); + pmaxrow = pminrow + smaxrow - sminrow; + } + if (pmaxcol > win->_maxx) { + smaxcol -= (pmaxcol - win->_maxx); + pmaxcol = pmincol + smaxcol - smincol; + } + + if (smaxrow > screen_lines + || smaxcol > screen_columns + || sminrow > smaxrow + || smincol > smaxcol) + returnCode(ERR); + + T(("pad being refreshed")); + + if (win->_pad._pad_y >= 0) { + displaced = pminrow - win->_pad._pad_y + -(sminrow - win->_pad._pad_top); + T(("pad being shifted by %d line(s)", displaced)); + } else + displaced = 0; + + /* + * For pure efficiency, we'd want to transfer scrolling information + * from the pad to newscr whenever the window is wide enough that + * its update will dominate the cost of the update for the horizontal + * band of newscr that it occupies. Unfortunately, this threshold + * tends to be complex to estimate, and in any case scrolling the + * whole band and rewriting the parts outside win's image would look + * really ugly. So. What we do is consider the pad "wide" if it + * either (a) occupies the whole width of newscr, or (b) occupies + * all but at most one column on either vertical edge of the screen + * (this caters to fussy people who put boxes around full-screen + * windows). Note that changing this formula will not break any code, + * merely change the costs of various update cases. + */ + wide = (smincol < my_len && smaxcol > (newscr->_maxx - my_len)); + + for (i = pminrow, m = sminrow + win->_yoffset; + i <= pmaxrow && m <= newscr->_maxy; + i++, m++) { + register struct ldat *nline = &newscr->_line[m]; + register struct ldat *oline = &win->_line[i]; + + for (j = pmincol, n = smincol; j <= pmaxcol; j++, n++) { + if (oline->text[j] != nline->text[n]) { + nline->text[n] = oline->text[j]; + CHANGED_CELL(nline,n); + } + } + +#if USE_SCROLL_HINTS + if (wide) { + int nind = m + displaced; + if (oline->oldindex < 0 + || nind < sminrow + || nind > smaxrow) { + nind = _NEWINDEX; + } else if (displaced) { + register struct ldat *pline = &curscr->_line[nind]; + for (j = 0; j <= my_len; j++) { + int k = newscr->_maxx - j; + if (pline->text[j] != nline->text[j] + || pline->text[k] != nline->text[k]) { + nind = _NEWINDEX; + break; + } + } + } + + nline->oldindex = nind; + } +#endif /* USE_SCROLL_HINTS */ + oline->firstchar = oline->lastchar = _NOCHANGE; + if_USE_SCROLL_HINTS(oline->oldindex = i); + } + + /* + * Clean up debris from scrolling or resizing the pad, so we do not + * accidentally pick up the index value during the next call to this + * procedure. The only rows that should have an index value are those + * that are displayed during this cycle. + */ +#if USE_SCROLL_HINTS + for (i = pminrow-1; (i >= 0) && (win->_line[i].oldindex >= 0); i--) + win->_line[i].oldindex = _NEWINDEX; + for (i = pmaxrow+1; (i <= win->_maxy) && (win->_line[i].oldindex >= 0); i++) + win->_line[i].oldindex = _NEWINDEX; +#endif + + win->_begx = smincol; + win->_begy = sminrow; + + if (win->_clear) { + win->_clear = FALSE; + newscr->_clear = TRUE; + } + + /* + * Use the pad's current position, if it will be visible. + * If not, don't do anything; it's not an error. + */ + if (win->_leaveok == FALSE + && win->_cury >= pminrow + && win->_curx >= pmincol + && win->_cury <= pmaxrow + && win->_curx <= pmaxcol) { + newscr->_cury = win->_cury - pminrow + win->_begy + win->_yoffset; + newscr->_curx = win->_curx - pmincol + win->_begx; + } + win->_flags &= ~_HASMOVED; + + /* + * Update our cache of the line-numbers that we displayed from the pad. + * We will use this on subsequent calls to this function to derive + * values to stuff into 'oldindex[]' -- for scrolling optimization. + */ + win->_pad._pad_y = pminrow; + win->_pad._pad_x = pmincol; + win->_pad._pad_top = sminrow; + win->_pad._pad_left = smincol; + win->_pad._pad_bottom = smaxrow; + win->_pad._pad_right = smaxcol; + + returnCode(OK); +} + +int pechochar(WINDOW *pad, const chtype ch) +{ + T((T_CALLED("pechochar(%p, %s)"), pad, _tracechtype(ch))); + + if (pad == 0) + returnCode(ERR); + + if (!(pad->_flags & _ISPAD)) + returnCode(wechochar(pad,ch)); + + waddch(pad, ch); + prefresh(pad, pad->_pad._pad_y, + pad->_pad._pad_x, + pad->_pad._pad_top, + pad->_pad._pad_left, + pad->_pad._pad_bottom, + pad->_pad._pad_right); + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_printw.c b/contrib/ncurses/ncurses/base/lib_printw.c new file mode 100644 index 0000000..8d28f28 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_printw.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ + +/* +** lib_printw.c +** +** The routines printw(), wprintw() and friends. +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_printw.c,v 1.7 1998/04/11 22:53:44 tom Exp $") + +int printw(NCURSES_CONST char *fmt, ...) +{ + va_list argp; + int code; + + T(("printw(%s,...) called", _nc_visbuf(fmt))); + + va_start(argp, fmt); + code = vwprintw(stdscr, fmt, argp); + va_end(argp); + + return code; +} + +int wprintw(WINDOW *win, NCURSES_CONST char *fmt, ...) +{ + va_list argp; + int code; + + T(("wprintw(%p,%s,...) called", win, _nc_visbuf(fmt))); + + va_start(argp, fmt); + code = vwprintw(win, fmt, argp); + va_end(argp); + + return code; +} + +int mvprintw(int y, int x, NCURSES_CONST char *fmt, ...) +{ + va_list argp; + int code = move(y, x); + + if (code != ERR) { + va_start(argp, fmt); + code = vwprintw(stdscr, fmt, argp); + va_end(argp); + } + return code; +} + +int mvwprintw(WINDOW *win, int y, int x, NCURSES_CONST char *fmt, ...) +{ + va_list argp; + int code = wmove(win, y, x); + + if (code != ERR) { + va_start(argp, fmt); + code = vwprintw(win, fmt, argp); + va_end(argp); + } + return code; +} + +int vwprintw(WINDOW *win, NCURSES_CONST char *fmt, va_list argp) +{ + char *buf = _nc_printf_string(fmt, argp); + int code = ERR; + + if (buf != 0) { + code = waddstr(win, buf); +#if USE_SAFE_SPRINTF + free(buf); +#endif + } + return code; +} diff --git a/contrib/ncurses/ncurses/base/lib_redrawln.c b/contrib/ncurses/ncurses/base/lib_redrawln.c new file mode 100644 index 0000000..10fda91 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_redrawln.c @@ -0,0 +1,69 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ + +/* + * lib_redrawln.c + * + * The routine wredrawln(). + * + */ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_redrawln.c,v 1.7 1998/09/19 20:09:50 Alexander.V.Lukyanov Exp $") + +int wredrawln(WINDOW *win, int beg, int num) +{ + int i; + int end; + size_t len = (win->_maxx + 1) * sizeof(chtype); + + T((T_CALLED("wredrawln(%p,%d,%d)"), win, beg, num)); + + if (beg < 0) + beg = 0; + + if (touchline (win, beg, num) == ERR) + returnCode(ERR); + + end = beg + num; + if (end > win->_maxy + 1) + end = win->_maxy + 1; + + for (i = beg; i < end; i++) + { + memset (curscr->_line[i+win->_begy].text+win->_begx, 0, len); + _nc_make_oldhash(i+win->_begy); + } + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_refresh.c b/contrib/ncurses/ncurses/base/lib_refresh.c new file mode 100644 index 0000000..88e3b75 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_refresh.c @@ -0,0 +1,183 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* + * lib_refresh.c + * + * The routines wrefresh() and wnoutrefresh(). + * + */ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_refresh.c,v 1.24 1999/07/31 11:36:37 juergen Exp $") + +int wrefresh(WINDOW *win) +{ +int code; + + T((T_CALLED("wrefresh(%p)"), win)); + + if (win == curscr) { + curscr->_clear = TRUE; + code = doupdate(); + } else if ((code = wnoutrefresh(win)) == OK) { + if (win->_clear) + newscr->_clear = TRUE; + code = doupdate(); + /* + * Reset the clearok() flag in case it was set for the special + * case in hardscroll.c (if we don't reset it here, we'll get 2 + * refreshes because the flag is copied from stdscr to newscr). + * Resetting the flag shouldn't do any harm, anyway. + */ + win->_clear = FALSE; + } + returnCode(code); +} + +int wnoutrefresh(WINDOW *win) +{ +short limit_x; +short i, j; +short begx; +short begy; +short m, n; +bool wide; + + T((T_CALLED("wnoutrefresh(%p)"), win)); +#ifdef TRACE + if (_nc_tracing & TRACE_UPDATE) + _tracedump("...win", win); +#endif /* TRACE */ + + /* + * This function will break badly if we try to refresh a pad. + */ + if ((win == 0) + || (win->_flags & _ISPAD)) + returnCode(ERR); + + /* put them here so "win == 0" won't break our code */ + begx = win->_begx; + begy = win->_begy; + + newscr->_bkgd = win->_bkgd; + newscr->_attrs = win->_attrs; + + /* merge in change information from all subwindows of this window */ + wsyncdown(win); + + /* + * For pure efficiency, we'd want to transfer scrolling information + * from the window to newscr whenever the window is wide enough that + * its update will dominate the cost of the update for the horizontal + * band of newscr that it occupies. Unfortunately, this threshold + * tends to be complex to estimate, and in any case scrolling the + * whole band and rewriting the parts outside win's image would look + * really ugly. So. What we do is consider the window "wide" if it + * either (a) occupies the whole width of newscr, or (b) occupies + * all but at most one column on either vertical edge of the screen + * (this caters to fussy people who put boxes around full-screen + * windows). Note that changing this formula will not break any code, + * merely change the costs of various update cases. + */ + wide = (begx <= 1 && win->_maxx >= (newscr->_maxx - 1)); + + win->_flags &= ~_HASMOVED; + + /* + * Microtweaking alert! This double loop is one of the genuine + * hot spots in the code. Even gcc doesn't seem to do enough + * common-subexpression chunking to make it really tense, + * so we'll force the issue. + */ + + /* limit(n) */ + limit_x = win->_maxx; + /* limit(j) */ + if (limit_x > win->_maxx) + limit_x = win->_maxx; + + for (i = 0, m = begy + win->_yoffset; + i <= win->_maxy && m <= newscr->_maxy; + i++, m++) { + register struct ldat *nline = &newscr->_line[m]; + register struct ldat *oline = &win->_line[i]; + + if (oline->firstchar != _NOCHANGE) { + int last = oline->lastchar; + + if (last > limit_x) + last = limit_x; + + for (j = oline->firstchar, n = j + begx; j <= last; j++, n++) { + if (oline->text[j] != nline->text[n]) { + nline->text[n] = oline->text[j]; + CHANGED_CELL(nline, n); + } + } + + } + +#if USE_SCROLL_HINTS + if (wide) { + int oind = oline->oldindex; + + nline->oldindex = (oind == _NEWINDEX) ? _NEWINDEX : begy + oind + win->_yoffset; + } +#endif /* USE_SCROLL_HINTS */ + + oline->firstchar = oline->lastchar = _NOCHANGE; + if_USE_SCROLL_HINTS(oline->oldindex = i); + } + + if (win->_clear) { + win->_clear = FALSE; + newscr->_clear = TRUE; + } + + if (! win->_leaveok) { + newscr->_cury = win->_cury + win->_begy + win->_yoffset; + newscr->_curx = win->_curx + win->_begx; + } + newscr->_leaveok = win->_leaveok; + +#ifdef TRACE + if (_nc_tracing & TRACE_UPDATE) + _tracedump("newscr", newscr); +#endif /* TRACE */ + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_restart.c b/contrib/ncurses/ncurses/base/lib_restart.c new file mode 100644 index 0000000..de0182f --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_restart.c @@ -0,0 +1,90 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * Terminfo-only terminal setup routines: + * + * int restartterm(const char *, int, int *) + * TERMINAL *set_curterm(TERMINAL *) + * int del_curterm(TERMINAL *) + */ + +#include <curses.priv.h> + +#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE) +#define _POSIX_SOURCE +#endif + +#include <term.h> /* lines, columns, cur_term */ + +MODULE_ID("$Id: lib_restart.c,v 1.2 1999/07/24 20:10:04 tom Exp $") + +int 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; + + T((T_CALLED("restartterm(%s,%d,%p)"), termp, filenum, errret)); + + setupterm(termp, filenum, errret); + + if (saveecho) + echo(); + else + noecho(); + + if (savecbreak) { + cbreak(); + noraw(); + } else if (saveraw) { + nocbreak(); + raw(); + } else { + nocbreak(); + noraw(); + } + if (savenl) + nl(); + else + nonl(); + + reset_prog_mode(); + +#if USE_SIZECHANGE + _nc_update_screensize(); +#endif + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_scanw.c b/contrib/ncurses/ncurses/base/lib_scanw.c new file mode 100644 index 0000000..cc66613 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_scanw.c @@ -0,0 +1,111 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_scanw.c +** +** The routines scanw(), wscanw() and friends. +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_scanw.c,v 1.8 1998/04/11 22:54:18 tom Exp $") + +#if !HAVE_VSSCANF +#if defined(__QNX__) +extern int vsscanf(const char *str, const char *format, __va_list __arg); +#else +extern int vsscanf(const char *str, const char *format, ...); +#endif +#endif + +int vwscanw(WINDOW *win, NCURSES_CONST char *fmt, va_list argp) +{ +char buf[BUFSIZ]; + + if (wgetnstr(win, buf, sizeof(buf)-1) == ERR) + return(ERR); + + return(vsscanf(buf, fmt, argp)); +} + +int scanw(NCURSES_CONST char *fmt, ...) +{ +int code; +va_list ap; + + T(("scanw(\"%s\",...) called", fmt)); + + va_start(ap, fmt); + code = vwscanw(stdscr, fmt, ap); + va_end(ap); + return (code); +} + +int wscanw(WINDOW *win, NCURSES_CONST char *fmt, ...) +{ +int code; +va_list ap; + + T(("wscanw(%p,\"%s\",...) called", win, fmt)); + + va_start(ap, fmt); + code = vwscanw(win, fmt, ap); + va_end(ap); + return (code); +} + +int mvscanw(int y, int x, NCURSES_CONST char *fmt, ...) +{ +int code; +va_list ap; + + va_start(ap, fmt); + code = (move(y, x) == OK) ? vwscanw(stdscr, fmt, ap) : ERR; + va_end(ap); + return (code); +} + +int mvwscanw(WINDOW *win, int y, int x, NCURSES_CONST char *fmt, ...) +{ +int code; +va_list ap; + + va_start(ap, fmt); + code = (wmove(win, y, x) == OK) ? vwscanw(win, fmt, ap) : ERR; + va_end(ap); + return (code); +} diff --git a/contrib/ncurses/ncurses/base/lib_screen.c b/contrib/ncurses/ncurses/base/lib_screen.c new file mode 100644 index 0000000..3038393 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_screen.c @@ -0,0 +1,198 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +#include <curses.priv.h> + +#include <sys/stat.h> +#include <time.h> +#include <term.h> /* exit_ca_mode, non_rev_rmcup */ + +MODULE_ID("$Id: lib_screen.c,v 1.15 1999/07/24 20:05:29 tom Exp $") + +static time_t dumptime; + +WINDOW *getwin(FILE *filep) +{ + WINDOW tmp, *nwin; + int n; + + T((T_CALLED("getwin(%p)"), 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); + + /* + * 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->_bkgd = tmp._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); + } + } + touchwin(nwin); + + returnWin(nwin); +} + +int 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); + + 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)) + returnCode(code); + } + code = OK; + } + returnCode(code); +} + +int scr_restore(const char *file) +{ + FILE *fp = 0; + + T((T_CALLED("scr_restore(%s)"), _nc_visbuf(file))); + + if (_nc_access(file, R_OK) < 0 + || (fp = fopen(file, "rb")) == 0) + returnCode(ERR); + else + { + delwin(newscr); + newscr = getwin(fp); + (void) fclose(fp); + returnCode(OK); + } +} + +int scr_dump(const char *file) +{ + FILE *fp = 0; + + T((T_CALLED("scr_dump(%s)"), _nc_visbuf(file))); + + if (_nc_access(file, W_OK) < 0 + || (fp = fopen(file, "wb")) == 0) + returnCode(ERR); + else + { + (void) putwin(newscr, fp); + (void) fclose(fp); + dumptime = time((time_t *)0); + returnCode(OK); + } +} + +int scr_init(const char *file) +{ + FILE *fp = 0; + struct stat stb; + + T((T_CALLED("scr_init(%s)"), _nc_visbuf(file))); + + if (exit_ca_mode && non_rev_rmcup) + returnCode(ERR); + + if (_nc_access(file, R_OK) < 0 + || (fp = fopen(file, "rb")) == 0) + returnCode(ERR); + else if (fstat(STDOUT_FILENO, &stb) || stb.st_mtime > dumptime) + returnCode(ERR); + else + { + delwin(curscr); + curscr = getwin(fp); + (void) fclose(fp); + returnCode(OK); + } +} + +int scr_set(const char *file) +{ + T((T_CALLED("scr_set(%s)"), _nc_visbuf(file))); + + if (scr_init(file) == ERR) + returnCode(ERR); + else + { + delwin(newscr); + newscr = dupwin(curscr); + returnCode(OK); + } +} diff --git a/contrib/ncurses/ncurses/base/lib_scroll.c b/contrib/ncurses/ncurses/base/lib_scroll.c new file mode 100644 index 0000000..197bb22 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_scroll.c @@ -0,0 +1,118 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_scroll.c +** +** The routine wscrl(win, n). +** positive n scroll the window up (ie. move lines down) +** negative n scroll the window down (ie. move lines up) +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_scroll.c,v 1.16 1998/02/11 12:13:55 tom Exp $") + +void _nc_scroll_window(WINDOW *win, int const n, short const top, short const bottom, chtype blank) +{ +int line, j; +size_t to_copy = (size_t)(sizeof(chtype) * (win->_maxx + 1)); + + TR(TRACE_MOVE, ("_nc_scroll_window(%p, %d, %d, %d)", win, n, top,bottom)); + + /* + * This used to do a line-text pointer-shuffle instead of text copies. + * That (a) doesn't work when the window is derived and doesn't have + * its own storage, (b) doesn't save you a lot on modern machines + * anyway. Your typical memcpy implementations are coded in + * assembler using a tight BLT loop; for the size of copies we're + * talking here, the total execution time is dominated by the one-time + * setup cost. So there is no point in trying to be excessively + * clever -- esr. + */ + + /* shift n lines downwards */ + if (n < 0) { + for (line = bottom; line >= top-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 < top-n; line++) { + for (j = 0; j <= win->_maxx; j ++) + win->_line[line].text[j] = blank; + if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX); + } + } + + /* shift n lines upwards */ + if (n > 0) { + for (line = top; line <= bottom-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 = bottom; line > bottom-n; 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); +} + +int +wscrl(WINDOW *win, int n) +{ + T((T_CALLED("wscrl(%p,%d)"), win, n)); + + if (!win || !win->_scroll) + returnCode(ERR); + + if (n == 0) + returnCode(OK); + + if ((n > (win->_regbottom - win->_regtop)) || + (-n > (win->_regbottom - win->_regtop))) + returnCode(ERR); + + _nc_scroll_window(win, n, win->_regtop, win->_regbottom, _nc_background(win)); + + _nc_synchook(win); + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_scrollok.c b/contrib/ncurses/ncurses/base/lib_scrollok.c new file mode 100644 index 0000000..f24eb8e --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_scrollok.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_scrollok.c +** +** The routine scrollok. +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_scrollok.c,v 1.2 1998/02/11 12:14:01 tom Exp $") + +int scrollok(WINDOW *win, bool flag) +{ + T((T_CALLED("scrollok(%p,%d)"), win, flag)); + + if (win) { + win->_scroll = flag; + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_scrreg.c b/contrib/ncurses/ncurses/base/lib_scrreg.c new file mode 100644 index 0000000..ddeab24 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_scrreg.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_scrreg.c +** +** The routine wsetscrreg(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_scrreg.c,v 1.7 1998/02/11 12:13:53 tom Exp $") + +int wsetscrreg(WINDOW *win, int top, int bottom) +{ + T((T_CALLED("wsetscrreg(%p,%d,%d)"), win, top, bottom)); + + if (win && + top >= 0 && top <= win->_maxy && + bottom >= 0 && bottom <= win->_maxy && + bottom > top) + { + win->_regtop = (short)top; + win->_regbottom = (short)bottom; + + returnCode(OK); + } else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_set_term.c b/contrib/ncurses/ncurses/base/lib_set_term.c new file mode 100644 index 0000000..443236c --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_set_term.c @@ -0,0 +1,315 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_set_term.c +** +** The routine set_term(). +** +*/ + +#include <curses.priv.h> + +#include <term.h> /* cur_term */ + +MODULE_ID("$Id: lib_set_term.c,v 1.46 1999/07/24 20:05:49 tom Exp $") + +SCREEN * set_term(SCREEN *screenp) +{ +SCREEN *oldSP; + + T((T_CALLED("set_term(%p)"), screenp)); + + oldSP = SP; + _nc_set_screen(screenp); + + set_curterm(SP->_term); + curscr = SP->_curscr; + newscr = SP->_newscr; + 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); +} + +static void _nc_free_keytry(struct tries *kt) +{ + if (kt != 0) { + _nc_free_keytry(kt->child); + _nc_free_keytry(kt->sibling); + free(kt); + } +} + +/* + * Free the storage associated with the given SCREEN sp. + */ +void delscreen(SCREEN *sp) +{ + SCREEN **scan = &_nc_screen_chain; + + T((T_CALLED("delscreen(%p)"), sp)); + + while(*scan) + { + if (*scan == sp) + { + *scan = sp->_next_screen; + break; + } + scan = &(*scan)->_next_screen; + } + + _nc_freewin(sp->_curscr); + _nc_freewin(sp->_newscr); + _nc_freewin(sp->_stdscr); + _nc_free_keytry(sp->_keytry); + _nc_free_keytry(sp->_key_ok); + + FreeIfNeeded(sp->_color_table); + FreeIfNeeded(sp->_color_pairs); + + FreeIfNeeded(sp->oldhash); + FreeIfNeeded(sp->newhash); + + del_curterm(sp->_term); + + free(sp); + + /* + * If this was the current screen, reset everything that the + * application might try to use (except cur_term, which may have + * multiple references in different screens). + */ + if (sp == SP) { + curscr = 0; + newscr = 0; + stdscr = 0; + COLORS = 0; + COLOR_PAIRS = 0; + _nc_set_screen(0); + } + returnVoid; +} + +static ripoff_t rippedoff[5]; +static ripoff_t *rsp = rippedoff; +#define N_RIPS SIZEOF(rippedoff) + +static bool no_mouse_event (SCREEN *sp GCC_UNUSED) { return FALSE; } +static bool no_mouse_inline(SCREEN *sp GCC_UNUSED) { return FALSE; } +static bool no_mouse_parse (int code GCC_UNUSED) { return TRUE; } +static void no_mouse_resume(SCREEN *sp GCC_UNUSED) { } +static void no_mouse_wrap (SCREEN *sp GCC_UNUSED) { } + +int _nc_setupscreen(short slines, short const scolumns, FILE *output) +/* OS-independent screen initializations */ +{ +int bottom_stolen = 0; +size_t i; + + assert(SP==0); /* has been reset in newterm() ! */ + if (!_nc_alloc_screen()) + return ERR; + + SP->_next_screen = _nc_screen_chain; + _nc_screen_chain = SP; + + _nc_set_buffer(output, TRUE); + SP->_term = cur_term; + SP->_lines = slines; + SP->_lines_avail = slines; + SP->_columns = scolumns; + SP->_cursrow = -1; + SP->_curscol = -1; + SP->_nl = TRUE; + SP->_raw = FALSE; + SP->_cbreak = 0; + SP->_echo = TRUE; + SP->_fifohead = -1; + SP->_endwin = TRUE; + SP->_ofp = output; + SP->_cursor = -1; /* cannot know real cursor shape */ +#ifdef NCURSES_NO_PADDING + SP->_no_padding = getenv("NCURSES_NO_PADDING") != 0; +#endif + + SP->_maxclick = DEFAULT_MAXCLICK; + SP->_mouse_event = no_mouse_event; + SP->_mouse_inline = no_mouse_inline; + SP->_mouse_parse = no_mouse_parse; + SP->_mouse_resume = no_mouse_resume; + SP->_mouse_wrap = no_mouse_wrap; + SP->_mouse_fd = -1; + + /* initialize the panel hooks */ + SP->_panelHook.top_panel = (struct panel*)0; + SP->_panelHook.bottom_panel = (struct panel*)0; + SP->_panelHook.stdscr_pseudo_panel = (struct panel*)0; + + /* + * If we've no magic cookie support, we suppress attributes that xmc + * would affect, i.e., the attributes that affect the rendition of a + * space. Note that this impacts the alternate character set mapping + * as well. + */ + if (magic_cookie_glitch > 0) { + + SP->_xmc_triggers = termattrs() & ( + A_ALTCHARSET | + A_BLINK | + A_BOLD | + A_REVERSE | + A_STANDOUT | + A_UNDERLINE + ); + SP->_xmc_suppress = SP->_xmc_triggers & (chtype)~(A_BOLD); + + T(("magic cookie attributes %s", _traceattr(SP->_xmc_suppress))); +#if USE_XMC_SUPPORT + /* + * To keep this 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 = -1; + acs_chars = 0; +#endif + } + _nc_init_acs(); + memcpy(SP->_acs_map, acs_map, sizeof(chtype)*ACS_LEN); + + _nc_idcok = TRUE; + _nc_idlok = FALSE; + + _nc_windows = 0; /* no windows yet */ + + SP->oldhash = 0; + SP->newhash = 0; + + T(("creating newscr")); + if ((newscr = newwin(slines, scolumns, 0, 0)) == 0) + return ERR; + + T(("creating curscr")); + if ((curscr = newwin(slines, scolumns, 0, 0)) == 0) + return ERR; + + SP->_newscr = newscr; + SP->_curscr = curscr; +#if USE_SIZECHANGE + SP->_resize = resizeterm; +#endif + + newscr->_clear = TRUE; + curscr->_clear = FALSE; + + for (i=0, rsp = rippedoff; rsp->line && (i < N_RIPS); rsp++, 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->_lines_avail -= count; + } + rsp->line = 0; + } + /* 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; + SP->_stdscr = stdscr; + + def_shell_mode(); + def_prog_mode(); + + return OK; +} + +/* The internal implementation interprets line as the number of + lines to rip off from the top or bottom. + */ +int +_nc_ripoffline(int line, int (*init)(WINDOW *,int)) +{ + if (line == 0) + return(OK); + + if (rsp >= rippedoff + N_RIPS) + return(ERR); + + rsp->line = line; + rsp->hook = init; + rsp->w = 0; + rsp++; + + return(OK); +} + +int +ripoffline(int line, int (*init)(WINDOW *, int)) +{ + T((T_CALLED("ripoffline(%d,%p)"), line, init)); + + if (line == 0) + returnCode(OK); + + returnCode(_nc_ripoffline ((line<0) ? -1 : 1, init)); +} diff --git a/contrib/ncurses/ncurses/base/lib_slk.c b/contrib/ncurses/ncurses/base/lib_slk.c new file mode 100644 index 0000000..9b9b09a --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slk.c @@ -0,0 +1,214 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slk.c + * Soft key routines. + */ + +#include <curses.priv.h> + +#include <ctype.h> +#include <term.h> /* num_labels, label_*, plab_norm */ + +MODULE_ID("$Id: lib_slk.c,v 1.16 1999/03/03 23:44:22 juergen Exp $") + +/* + * We'd like to move these into the screen context structure, but cannot, + * because slk_init() is called before initscr()/newterm(). + */ +int _nc_slk_format; /* one more than format specified in slk_init() */ + +/* + * Paint the info line for the PC style SLK emulation. + * + */ +static void +slk_paint_info(WINDOW *win) +{ + if (win && SP->slk_format==4) + { + int i; + + mvwhline (win,0,0,0,getmaxx(win)); + wmove (win,0,0); + + for (i = 0; i < SP->_slk->maxlab; i++) { + if (win && SP->slk_format==4) + { + mvwaddch(win,0,SP->_slk->ent[i].x,'F'); + if (i<9) + waddch(win,'1'+i); + else + { + waddch(win,'1'); + waddch(win,'0' + (i-9)); + } + } + } + } +} + +/* + * Initialize soft labels. + * Called from newterm() + */ +int +_nc_slk_initialize(WINDOW *stwin, int cols) +{ +int i, x; +int res = OK; +char *p; + + T(("slk_initialize()")); + + if (SP->_slk) + { /* we did this already, so simply return */ + return(OK); + } + else + if ((SP->_slk = typeCalloc(SLK, 1)) == 0) + return(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; + + SP->_slk->ent = typeCalloc(slk_ent, SP->_slk->labcnt); + if (SP->_slk->ent == NULL) + goto exception; + + p = SP->_slk->buffer = (char*) calloc(2*SP->_slk->labcnt,(1+SP->_slk->maxlen)); + if (SP->_slk->buffer == NULL) + goto exception; + + 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)); + 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; + + if (gap < 1) + gap = 1; + + for (i = x = 0; i < SP->_slk->maxlab; i++) { + SP->_slk->ent[i].x = x; + x += SP->_slk->maxlen; + x += (i==3 || i==7) ? gap : 1; + } + if (_nc_slk_format == 4) + slk_paint_info (stwin); + } + else { + if (_nc_slk_format == 2) { /* 4-4 */ + int gap = cols - (SP->_slk->maxlab * SP->_slk->maxlen) - 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; + 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) / 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; + x += (i == 2 || i == 4) ? gap : 1; + } + } + else + goto exception; + } + } + 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); + } + } + + /* We now reset the format so that the next newterm has again + * per default no SLK keys and may call slk_init again to + * define a new layout. (juergen 03-Mar-1999) + */ + SP->slk_format = _nc_slk_format; + _nc_slk_format = 0; + return(res); +} + + +/* + * Restore the soft labels on the screen. + */ +int +slk_restore(void) +{ + T((T_CALLED("slk_restore()"))); + + if (SP->_slk == NULL) + return(ERR); + SP->_slk->hidden = FALSE; + SP->_slk->dirty = TRUE; + /* we have to repaint info line eventually */ + slk_paint_info(SP->_slk->win); + + returnCode(slk_refresh()); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkatr_set.c b/contrib/ncurses/ncurses/base/lib_slkatr_set.c new file mode 100644 index 0000000..0695d18 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkatr_set.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1998 * + ****************************************************************************/ + +/* + * lib_slkatr_set.c + * Soft key routines. + * Set the labels attributes + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slkatr_set.c,v 1.3 1999/05/16 17:13:59 juergen Exp $") + +int +slk_attr_set(const attr_t attr, short color_pair_number, void* opts) +{ + T((T_CALLED("slk_attr_set(%s,%d)"), _traceattr(attr), color_pair_number)); + + if (SP!=0 && SP->_slk!=0 && !opts && + color_pair_number>=0 && color_pair_number<COLOR_PAIRS) + { + SP->_slk->attr = attr; + toggle_attr_on(SP->_slk->attr,COLOR_PAIR(color_pair_number)); + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkatrof.c b/contrib/ncurses/ncurses/base/lib_slkatrof.c new file mode 100644 index 0000000..5e4f5f5 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkatrof.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slkatrof.c + * Soft key routines. + * Switch off labels attributes + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slkatrof.c,v 1.4 1998/03/11 19:26:07 juergen Exp $") + +int +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); + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkatron.c b/contrib/ncurses/ncurses/base/lib_slkatron.c new file mode 100644 index 0000000..a248865 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkatron.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slkatron.c + * Soft key routines. + * Switch on labels attributes + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slkatron.c,v 1.4 1998/03/11 19:26:07 juergen Exp $") + +int +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); + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkatrset.c b/contrib/ncurses/ncurses/base/lib_slkatrset.c new file mode 100644 index 0000000..391c7ff --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkatrset.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slkatrset.c + * Soft key routines. + * Set the labels attributes + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slkatrset.c,v 1.4 1998/03/11 19:26:01 juergen Exp $") + +int +slk_attrset(const chtype attr) +{ + T((T_CALLED("slk_attrset(%s)"), _traceattr(attr))); + + if (SP!=0 && SP->_slk!=0) + { + 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 new file mode 100644 index 0000000..a132403 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkattr.c @@ -0,0 +1,54 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slkattr.c + * Soft key routines. + * Fetch the labels attributes + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slkattr.c,v 1.3 1998/02/11 12:13:56 tom Exp $") + +attr_t +slk_attr(void) +{ + T((T_CALLED("slk_attr()"))); + + if (SP!=0 && SP->_slk!=0) + { + returnAttr(SP->_slk->attr); + } + else + returnAttr(0); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkclear.c b/contrib/ncurses/ncurses/base/lib_slkclear.c new file mode 100644 index 0000000..ac6e414 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkclear.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slkclear.c + * Soft key routines. + * Remove soft labels from the screen. + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slkclear.c,v 1.4 1999/03/03 23:44:22 juergen Exp $") + +int +slk_clear(void) +{ + T((T_CALLED("slk_clear()"))); + + if (SP == NULL || SP->_slk == NULL) + returnCode(ERR); + SP->_slk->hidden = TRUE; + /* For simulated SLK's it's looks much more natural to + inherit those attributes from the standard screen */ + SP->_slk->win->_bkgd = stdscr->_bkgd; + SP->_slk->win->_attrs = stdscr->_attrs; + if (SP->_slk->win == stdscr) { + returnCode(OK); + } + else { + werase(SP->_slk->win); + returnCode(wrefresh(SP->_slk->win)); + } +} diff --git a/contrib/ncurses/ncurses/base/lib_slkcolor.c b/contrib/ncurses/ncurses/base/lib_slkcolor.c new file mode 100644 index 0000000..3728808 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkcolor.c @@ -0,0 +1,54 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1998 * + ****************************************************************************/ + +/* + * lib_slkcolor.c + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slkcolor.c,v 1.5 1999/05/16 17:14:13 juergen Exp $") + +int +slk_color(short color_pair_number) +{ + T((T_CALLED("slk_color(%d)"), color_pair_number)); + + if (SP!=0 && SP->_slk!=0 && + color_pair_number>=0 && color_pair_number<COLOR_PAIRS) + { + T(("... current %ld", (long) PAIR_NUMBER(SP->_slk->attr))); + toggle_attr_on(SP->_slk->attr,COLOR_PAIR(color_pair_number)); + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkinit.c b/contrib/ncurses/ncurses/base/lib_slkinit.c new file mode 100644 index 0000000..7084426 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkinit.c @@ -0,0 +1,51 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slkinit.c + * Soft key routines. + * Initialize soft labels. Called by the user before initscr(). + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slkinit.c,v 1.3 1998/02/11 12:13:56 tom Exp $") + +int +slk_init(int format) +{ + T((T_CALLED("slk_init(%d)"), format)); + if (format < 0 || format > 3) + returnCode(ERR); + _nc_slk_format = 1 + format; + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_slklab.c b/contrib/ncurses/ncurses/base/lib_slklab.c new file mode 100644 index 0000000..03039ad --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slklab.c @@ -0,0 +1,51 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slklab.c + * Soft key routines. + * Fetch the label text. + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slklab.c,v 1.4 1998/02/11 12:13:54 tom Exp $") + +char* +slk_label(int n) +{ + T((T_CALLED("slk_label(%d)"), n)); + + if (SP == NULL || SP->_slk == NULL || n < 1 || n > SP->_slk->labcnt) + returnPtr(0); + returnPtr(SP->_slk->ent[n-1].text); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkrefr.c b/contrib/ncurses/ncurses/base/lib_slkrefr.c new file mode 100644 index 0000000..ee3c91d --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkrefr.c @@ -0,0 +1,126 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slkrefr.c + * Write SLK window to the (virtual) screen. + */ +#include <curses.priv.h> +#include <term.h> /* num_labels, label_*, plab_norm */ + +MODULE_ID("$Id: lib_slkrefr.c,v 1.8 1999/03/14 00:10:27 Alexander.V.Lukyanov Exp $") + +/* + * Write the soft labels to the soft-key window. + */ +static void +slk_intern_refresh(SLK *slk) +{ +int i; +int fmt = SP->slk_format; + + for (i = 0; i < slk->labcnt; i++) { + if (slk->dirty || slk->ent[i].dirty) { + if (slk->ent[i].visible) { + if (num_labels > 0 && SLK_STDFMT(fmt)) + { + if (i < num_labels) { + TPUTS_TRACE("plab_norm"); + putp(tparm(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)); + /* 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); + } + } + slk->ent[i].dirty = FALSE; + } + } + slk->dirty = FALSE; + + if (num_labels > 0) { + if (slk->hidden) + { + TPUTS_TRACE("label_off"); + putp(label_off); + } + else + { + TPUTS_TRACE("label_on"); + putp(label_on); + } + } +} + +/* + * Refresh the soft labels. + */ +int +slk_noutrefresh(void) +{ + T((T_CALLED("slk_noutrefresh()"))); + + if (SP == NULL || SP->_slk == NULL) + returnCode(ERR); + if (SP->_slk->hidden) + returnCode(OK); + slk_intern_refresh(SP->_slk); + + returnCode(wnoutrefresh(SP->_slk->win)); +} + +/* + * Refresh the soft labels. + */ +int +slk_refresh(void) +{ + T((T_CALLED("slk_refresh()"))); + + if (SP == NULL || SP->_slk == NULL) + returnCode(ERR); + if (SP->_slk->hidden) + returnCode(OK); + slk_intern_refresh(SP->_slk); + + returnCode(wrefresh(SP->_slk->win)); +} diff --git a/contrib/ncurses/ncurses/base/lib_slkset.c b/contrib/ncurses/ncurses/base/lib_slkset.c new file mode 100644 index 0000000..27471ad --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slkset.c @@ -0,0 +1,95 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slkset.c + * Set soft label text. + */ +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("$Id: lib_slkset.c,v 1.3 1998/02/11 12:13:56 tom Exp $") + +int +slk_set(int i, const char *astr, int format) +{ +SLK *slk = SP->_slk; +size_t len; +const char *str = astr; +const char *p; + + T((T_CALLED("slk_set(%d, \"%s\", %d)"), i, str, format)); + + if (slk == NULL || i < 1 || i > slk->labcnt || format < 0 || format > 2) + returnCode(ERR); + if (str == NULL) + str = ""; + + while (isspace(*str)) str++; /* skip over leading spaces */ + p = str; + while (isprint(*p)) p++; /* The first non-print stops */ + + --i; /* Adjust numbering of labels */ + + 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); */ + + switch(format) { + case 0: /* left-justified */ + memcpy(slk->ent[i].form_text, + slk->ent[i].text, + len); + break; + case 1: /* centered */ + memcpy(slk->ent[i].form_text+(slk->maxlen - len)/2, + slk->ent[i].text, + len); + break; + case 2: /* right-justified */ + memcpy(slk->ent[i].form_text+ slk->maxlen - len, + slk->ent[i].text, + len); + break; + } + slk->ent[i].form_text[slk->maxlen] = 0; + slk->ent[i].dirty = TRUE; + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_slktouch.c b/contrib/ncurses/ncurses/base/lib_slktouch.c new file mode 100644 index 0000000..c2829ae --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_slktouch.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_slktouch.c + * Soft key routines. + * Force the code to believe that the soft keys have been changed. + */ +#include <curses.priv.h> + +MODULE_ID("$Id: lib_slktouch.c,v 1.3 1998/02/11 12:13:56 tom Exp $") + +int +slk_touch(void) +{ + T((T_CALLED("slk_touch()"))); + + if (SP == NULL || SP->_slk == NULL) + returnCode(ERR); + SP->_slk->dirty = TRUE; + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_touch.c b/contrib/ncurses/ncurses/base/lib_touch.c new file mode 100644 index 0000000..7ce863d --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_touch.c @@ -0,0 +1,87 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_touch.c +** +** The routines untouchwin(), +** wtouchln(), +** is_linetouched() +** is_wintouched(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_touch.c,v 1.6 1998/04/11 22:55:02 tom Exp $") + +bool is_linetouched(WINDOW *win, int line) +{ + T((T_CALLED("is_linetouched(%p,%d)"), win, line)); + + /* XSI doesn't define any error */ + if (!win || (line > win->_maxy) || (line < 0)) + returnCode(ERR); + + returnCode(win->_line[line].firstchar != _NOCHANGE ? TRUE : FALSE); +} + +bool is_wintouched(WINDOW *win) +{ +int i; + + T((T_CALLED("is_wintouched(%p)"), win)); + + if (win) + for (i = 0; i <= win->_maxy; i++) + if (win->_line[i].firstchar != _NOCHANGE) + returnCode(TRUE); + returnCode(FALSE); +} + +int wtouchln(WINDOW *win, int y, int n, int changed) +{ +int i; + + T((T_CALLED("wtouchln(%p,%d,%d,%d)"), win, y, n, changed)); + + if (!win || (n<0) || (y<0) || (y>win->_maxy)) + returnCode(ERR); + + for (i = y; i < y+n; i++) { + if (i>win->_maxy) break; + win->_line[i].firstchar = changed ? 0 : _NOCHANGE; + win->_line[i].lastchar = changed ? win->_maxx : _NOCHANGE; + } + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/lib_ungetch.c b/contrib/ncurses/ncurses/base/lib_ungetch.c new file mode 100644 index 0000000..5fdfb47 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_ungetch.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_ungetch.c +** +** The routine ungetch(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_ungetch.c,v 1.2 1998/02/11 12:13:56 tom Exp $") + +#include <fifo_defs.h> + +#ifdef TRACE +void _nc_fifo_dump(void) +{ +int i; + T(("head = %d, tail = %d, peek = %d", head, tail, peek)); + for (i = 0; i < 10; i++) + T(("char %d = %s", i, _trace_key(SP->_fifo[i]))); +} +#endif /* TRACE */ + +int ungetch(int ch) +{ + if (tail == -1) + return ERR; + if (head == -1) { + head = 0; + t_inc() + peek = tail; /* no raw keys */ + } else + h_dec(); + + SP->_fifo[head] = ch; + T(("ungetch %#x ok", ch)); +#ifdef TRACE + if (_nc_tracing & TRACE_IEVENT) _nc_fifo_dump(); +#endif + return OK; +} diff --git a/contrib/ncurses/ncurses/base/lib_vline.c b/contrib/ncurses/ncurses/base/lib_vline.c new file mode 100644 index 0000000..007ef55 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_vline.c @@ -0,0 +1,77 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** lib_vline.c +** +** The routine wvline(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_vline.c,v 1.4 1998/06/28 00:10:12 tom Exp $") + +int wvline(WINDOW *win, chtype ch, int n) +{ +int code = ERR; +short row, col; +short end; + + T((T_CALLED("wvline(%p,%s,%d)"), win, _tracechtype(ch), n)); + + if (win) { + row = win->_cury; + col = win->_curx; + end = row + n - 1; + if (end > win->_maxy) + end = win->_maxy; + + if (ch == 0) + ch = ACS_VLINE; + ch = _nc_render(win, ch); + + while(end >= row) { + struct ldat *line = &(win->_line[end]); + line->text[col] = ch; + CHANGED_CELL(line, col); + end--; + } + + _nc_synchook(win); + code = OK; + } + returnCode(code); +} diff --git a/contrib/ncurses/ncurses/base/lib_wattroff.c b/contrib/ncurses/ncurses/base/lib_wattroff.c new file mode 100644 index 0000000..a6c9f0f1 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_wattroff.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_wattroff.c +** +** The routine wattr_off(). +** +*/ + +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("$Id: lib_wattroff.c,v 1.4 1998/05/10 12:02:11 tom Exp $") + +int wattr_off(WINDOW *win, NCURSES_CONST 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); + returnCode(OK); + } else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_wattron.c b/contrib/ncurses/ncurses/base/lib_wattron.c new file mode 100644 index 0000000..a951c57 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_wattron.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_wattron.c +** +** The routines wattr_on(). +** +*/ + +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("$Id: lib_wattron.c,v 1.4 1998/05/10 12:02:28 tom Exp $") + +int wattr_on(WINDOW *win, NCURSES_CONST 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); + returnCode(OK); + } else + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/base/lib_winch.c b/contrib/ncurses/ncurses/base/lib_winch.c new file mode 100644 index 0000000..119c731 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_winch.c @@ -0,0 +1,52 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1998 * + ****************************************************************************/ + +/* +** lib_winch.c +** +** The routine winch(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_winch.c,v 1.1 1998/11/14 22:06:09 tom Exp $") + +chtype winch(WINDOW *win) +{ + T((T_CALLED("winch(%p)"), win)); + if (win != 0) { + returnCode(win->_line[win->_cury].text[win->_curx]); + } else { + returnCode(0); + } +} diff --git a/contrib/ncurses/ncurses/base/lib_window.c b/contrib/ncurses/ncurses/base/lib_window.c new file mode 100644 index 0000000..5eae9b1 --- /dev/null +++ b/contrib/ncurses/ncurses/base/lib_window.c @@ -0,0 +1,221 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_window.c +** +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_window.c,v 1.13 1998/06/28 00:10:59 tom Exp $") + +void _nc_synchook(WINDOW *win) +/* hook to be called after each window change */ +{ + if (win->_immed) wrefresh(win); + if (win->_sync) wsyncup(win); +} + +int mvderwin(WINDOW *win, int y, int x) +/* move a derived window */ +{ + WINDOW *orig; + int i; + + T((T_CALLED("mvderwin(%p,%d,%d)"), win, y, x)); + + if (win && (orig = win->_parent)) + { + if (win->_parx==x && win->_pary==y) + returnCode(OK); + if (x<0 || y<0) + returnCode(ERR); + if ( (x+getmaxx(win) > getmaxx(orig)) || + (y+getmaxy(win) > getmaxy(orig)) ) + returnCode(ERR); + } + else + returnCode(ERR); + wsyncup(win); + win->_parx = x; + win->_pary = y; + for(i=0;i<getmaxy(win);i++) + win->_line[i].text = &(orig->_line[y++].text[x]); + returnCode(OK); +} + +int syncok(WINDOW *win, bool bf) +/* enable/disable automatic wsyncup() on each change to window */ +{ + T((T_CALLED("syncok(%p,%d)"), win, bf)); + + if (win) { + win->_sync = bf; + returnCode(OK); + } else + returnCode(ERR); +} + +void wsyncup(WINDOW *win) +/* mark changed every cell in win's ancestors that is changed in win */ +/* Rewritten by J. Pfeifer, 1-Apr-96 (don't even think that...) */ +{ + WINDOW *wp; + + if (win && win->_parent) + for (wp = win; wp->_parent; wp = wp->_parent) + { + int y; + WINDOW *pp = wp->_parent; + + assert((wp->_pary <= pp->_maxy) && + ((wp->_pary+wp->_maxy) <= pp->_maxy)); + + for (y = 0; y <= wp->_maxy; y++) + { + int left = wp->_line[y].firstchar; + if (left >= 0) /* line is touched */ + { + struct ldat *line = &(pp->_line[wp->_pary + y]); + /* left & right character in parent window coordinates */ + int right = wp->_line[y].lastchar + wp->_parx; + left += wp->_parx; + + CHANGED_RANGE(line, left, right); + } + } + } +} + +void wsyncdown(WINDOW *win) +/* mark changed every cell in win that is changed in any of its ancestors */ +/* Rewritten by J. Pfeifer, 1-Apr-96 (don't even think that...) */ +{ + if (win && win->_parent) + { + WINDOW *pp = win->_parent; + int y; + + /* This recursion guarantees, that the changes are propagated down- + wards from the root to our direct parent. */ + wsyncdown(pp); + + /* and now we only have to propagate the changes from our direct + parent, if there are any. */ + assert((win->_pary <= pp->_maxy) && + ((win->_pary + win->_maxy) <= pp->_maxy)); + + for (y = 0; y <= win->_maxy; y++) + { + if (pp->_line[win->_pary + y].firstchar >= 0) /* parent changed */ + { + struct ldat *line = &(win->_line[y]); + /* left and right character in child coordinates */ + int left = pp->_line[win->_pary + y].firstchar - win->_parx; + int right = pp->_line[win->_pary + y].lastchar - win->_parx; + /* The change maybe outside the childs range */ + if (left<0) + left = 0; + if (right > win->_maxx) + right = win->_maxx; + CHANGED_RANGE(line, left, right); + } + } + } +} + +void wcursyncup(WINDOW *win) +/* sync the cursor in all derived windows to its value in the base window */ +{ + WINDOW *wp; + for( wp = win; wp && wp->_parent; wp = wp->_parent ) { + wmove( wp->_parent, wp->_pary + wp->_cury, wp->_parx + wp->_curx ); + } +} + +WINDOW *dupwin(WINDOW *win) +/* make an exact duplicate of the given window */ +{ +WINDOW *nwin; +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->_bkgd = win->_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; + } + + returnWin(nwin); +} diff --git a/contrib/ncurses/ncurses/base/memmove.c b/contrib/ncurses/ncurses/base/memmove.c new file mode 100644 index 0000000..55a4106 --- /dev/null +++ b/contrib/ncurses/ncurses/base/memmove.c @@ -0,0 +1,63 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: memmove.c,v 1.2 1999/02/27 19:55:57 tom Exp $") + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1998 * + ****************************************************************************/ + +#if USE_MY_MEMMOVE +#define DST ((char *)s1) +#define SRC ((const char *)s2) +void * _nc_memmove(void * s1, const void * s2, size_t n) +{ + if (n != 0) { + if ((DST+n > SRC) && (SRC+n > DST)) { + static char *bfr; + static size_t length; + register size_t j; + if (length < n) { + length = (n * 3) / 2; + bfr = typeRealloc(char,length,bfr); + } + for (j = 0; j < n; j++) + bfr[j] = SRC[j]; + SRC = bfr; + } + while (n-- != 0) + DST[n] = SRC[n]; + } + return s1; +} +#else +extern void _nc_memmove(void); /* quiet's gcc warning */ +void _nc_memmove(void) { } /* nonempty for strict ANSI compilers */ +#endif /* USE_MY_MEMMOVE */ diff --git a/contrib/ncurses/ncurses/base/nc_panel.c b/contrib/ncurses/ncurses/base/nc_panel.c new file mode 100644 index 0000000..536aab3 --- /dev/null +++ b/contrib/ncurses/ncurses/base/nc_panel.c @@ -0,0 +1,41 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: nc_panel.c,v 1.2 1998/02/11 12:13:56 tom Exp $") + +struct panelhook* +_nc_panelhook(void) +{ + return (SP ? &(SP->_panelHook) : NULL); +} diff --git a/contrib/ncurses/ncurses/base/resizeterm.c b/contrib/ncurses/ncurses/base/resizeterm.c new file mode 100644 index 0000000..8603550 --- /dev/null +++ b/contrib/ncurses/ncurses/base/resizeterm.c @@ -0,0 +1,121 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 * + ****************************************************************************/ + +/* + * This is an extension to the curses library. It provides callers with a hook + * into the NCURSES data to resize windows, primarily for use by programs + * running in an X Window terminal (e.g., xterm). I abstracted this module + * from my application library for NCURSES because it must be compiled with + * the private data structures -- T.Dickey 1995/7/4. + */ + +#include <curses.priv.h> +#include <term.h> + +MODULE_ID("$Id: resizeterm.c,v 1.7 1998/09/19 19:27:43 Alexander.V.Lukyanov Exp $") + +/* + * This function reallocates NCURSES window structures. It is invoked in + * response to a SIGWINCH interrupt. Other user-defined windows may also need + * to be reallocated. + * + * Because this performs memory allocation, it should not (in general) be + * invoked directly from the signal handler. + */ +int +resizeterm(int ToLines, int ToCols) +{ + int stolen = screen_lines - SP->_lines_avail; + int bottom = screen_lines + SP->_topstolen - stolen; + + T((T_CALLED("resizeterm(%d,%d) old(%d,%d)"), + ToLines, ToCols, + screen_lines, screen_columns)); + + SP->_sig_winch = FALSE; + + if (ToLines != screen_lines + || ToCols != screen_columns) { + WINDOWLIST *wp; + +#if USE_SIGWINCH + ungetch(KEY_RESIZE); /* so application can know this */ + clearok(curscr, TRUE); /* screen contents are unknown */ +#endif + + 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; + } + + if (myCols == screen_columns + && ToCols != screen_columns) + myCols = ToCols; + + if (wresize(win, myLines, myCols) != OK) + returnCode(ERR); + } + + screen_lines = lines = ToLines; + screen_columns = columns = ToCols; + + SP->_lines_avail = lines - stolen; + + if (SP->oldhash) { FreeAndNull(SP->oldhash); } + if (SP->newhash) { FreeAndNull(SP->newhash); } + } + + /* + * 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; + COLS = ToCols; + + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/base/safe_sprintf.c b/contrib/ncurses/ncurses/base/safe_sprintf.c new file mode 100644 index 0000000..0809225c --- /dev/null +++ b/contrib/ncurses/ncurses/base/safe_sprintf.c @@ -0,0 +1,243 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ + +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("$Id: safe_sprintf.c,v 1.10 1999/02/27 19:56:37 tom Exp $") + +#if USE_SAFE_SPRINTF + +typedef enum { Flags, Width, Prec, Type, Format } PRINTF; + +#define VA_INTGR(type) ival = va_arg(ap, type) +#define VA_FLOAT(type) fval = va_arg(ap, type) +#define VA_POINT(type) pval = (void *)va_arg(ap, type) + +/* + * Scan a variable-argument list for printf to determine the number of + * characters that would be emitted. + */ +static int +_nc_printf_length(const char *fmt, va_list ap) +{ + size_t length = BUFSIZ; + char *buffer; + char *format; + int len = 0; + + if (fmt == 0 || *fmt == '\0') + return -1; + if ((format = typeMalloc(char, strlen(fmt)+1)) == 0) + return -1; + if ((buffer = typeMalloc(char, length)) == 0) { + free(format); + return -1; + } + + while (*fmt != '\0') { + if (*fmt == '%') { + static char dummy[] = ""; + PRINTF state = Flags; + char *pval = dummy; /* avoid const-cast */ + double fval = 0.0; + int done = FALSE; + int ival = 0; + int prec = -1; + int type = 0; + int used = 0; + int width = -1; + size_t f = 0; + + format[f++] = *fmt; + while (*++fmt != '\0' && len >= 0 && !done) { + format[f++] = *fmt; + + if (isdigit(*fmt)) { + int num = *fmt - '0'; + if (state == Flags && num != 0) + state = Width; + if (state == Width) { + if (width < 0) + width = 0; + width = (width * 10) + num; + } else if (state == Prec) { + if (prec < 0) + prec = 0; + prec = (prec * 10) + num; + } + } else if (*fmt == '*') { + VA_INTGR(int); + if (state == Flags) + state = Width; + if (state == Width) { + width = ival; + } else if (state == Prec) { + prec = ival; + } + sprintf(&format[--f], "%d", ival); + f = strlen(format); + } else if (isalpha(*fmt)) { + done = TRUE; + switch (*fmt) { + case 'Z': /* FALLTHRU */ + case 'h': /* FALLTHRU */ + case 'l': /* FALLTHRU */ + case 'L': /* FALLTHRU */ + done = FALSE; + type = *fmt; + break; + case 'i': /* FALLTHRU */ + case 'd': /* FALLTHRU */ + case 'u': /* FALLTHRU */ + case 'x': /* FALLTHRU */ + case 'X': /* FALLTHRU */ + if (type == 'l') + VA_INTGR(long); + else if (type == 'Z') + VA_INTGR(size_t); + else + VA_INTGR(int); + used = 'i'; + break; + case 'f': /* FALLTHRU */ + case 'e': /* FALLTHRU */ + case 'E': /* FALLTHRU */ + case 'g': /* FALLTHRU */ + case 'G': /* FALLTHRU */ + if (type == 'L') + VA_FLOAT(long double); + else + VA_FLOAT(double); + used = 'f'; + break; + case 'c': + VA_INTGR(int); + used = 'i'; + break; + case 's': + VA_POINT(char *); + if (prec < 0) + prec = strlen(pval); + if (prec > (int)length) { + length = length + prec; + buffer = typeRealloc(char, length, buffer); + if (buffer == 0) { + free(format); + return -1; + } + } + used = 'p'; + break; + case 'p': + VA_POINT(void *); + used = 'p'; + break; + case 'n': + VA_POINT(int *); + used = 0; + break; + default: + break; + } + } else if (*fmt == '.') { + state = Prec; + } else if (*fmt == '%') { + done = TRUE; + used = 'p'; + } + } + format[f] = '\0'; + switch (used) { + case 'i': + sprintf(buffer, format, ival); + break; + case 'f': + sprintf(buffer, format, fval); + break; + default: + sprintf(buffer, format, pval); + break; + } + len += (int)strlen(buffer); + } else { + fmt++; + len++; + } + } + + free(buffer); + free(format); + return len; +} +#endif + +/* + * Wrapper for vsprintf that allocates a buffer big enough to hold the result. + */ +char * +_nc_printf_string(const char *fmt, va_list ap) +{ +#if USE_SAFE_SPRINTF + char *buf = 0; + int len = _nc_printf_length(fmt, ap); + + if (len > 0) { + if ((buf = typeMalloc(char, len+1)) == 0) + return(0); + vsprintf(buf, fmt, ap); + } +#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); + } + } + + if (buf != 0) { +# if HAVE_VSNPRINTF + vsnprintf(buf, len, fmt, ap); /* GNU extension */ +# else + vsprintf(buf, fmt, ap); /* ANSI */ +# endif + } +#endif + return buf; +} diff --git a/contrib/ncurses/ncurses/base/sigaction.c b/contrib/ncurses/ncurses/base/sigaction.c new file mode 100644 index 0000000..ab1e569 --- /dev/null +++ b/contrib/ncurses/ncurses/base/sigaction.c @@ -0,0 +1,106 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +#include <curses.priv.h> + +#include <signal.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.9 1999/06/19 23:05:16 tom Exp $") + +int +sigaction (int sig, sigaction_t * sigact, sigaction_t * osigact) +{ + return sigvec(sig, sigact, osigact); +} + +int +sigemptyset (sigset_t * mask) +{ + *mask = 0; + return 0; +} + +int +sigprocmask (int mode, sigset_t * mask, sigset_t * omask) +{ + sigset_t current = sigsetmask(0); + + if (omask) *omask = current; + + if (mode==SIG_BLOCK) + current |= *mask; + else if (mode==SIG_UNBLOCK) + current &= ~*mask; + else if (mode==SIG_SETMASK) + current = *mask; + + sigsetmask(current); + return 0; +} + +int +sigsuspend (sigset_t * mask) +{ + return sigpause (*mask); +} + +int +sigdelset (sigset_t * mask, int sig) +{ + *mask &= ~sigmask (sig); + return 0; +} + +int +sigaddset (sigset_t * mask, int sig) +{ + *mask |= sigmask (sig); + return 0; +} + +int +sigismember (sigset_t * mask, int sig) +{ + return (*mask & sigmask (sig)) != 0; +} + +#else +extern void _nc_sigaction(void); /* quiet's gcc warning */ +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 new file mode 100644 index 0000000..3c39652 --- /dev/null +++ b/contrib/ncurses/ncurses/base/tries.c @@ -0,0 +1,138 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ + +/* +** tries.c +** +** Functions to manage the tree of partial-completions for keycodes. +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: tries.c,v 1.12 1999/03/01 23:23:59 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. + */ +char *_nc_expand_try(struct tries *tree, unsigned short code, int *count, size_t len) +{ + struct tries *ptr = tree; + char *result = 0; + + if (code != 0) { + while (ptr != 0) { + if ((result = _nc_expand_try(ptr->child, code, count, len + 1)) != 0) { + break; + } + if (ptr->value == code) { + *count -= 1; + if (*count == -1) { + result = typeCalloc(char, len+2); + break; + } + } + ptr = ptr->sibling; + } + } + if (result != 0) { + if ((result[len] = ptr->ch) == 0) + *((unsigned char *)(result+len)) = 128; +#ifdef TRACE + if (len == 0) + _tracef("expand_key %s %s", _trace_key(code), _nc_visbuf(result)); +#endif + } + return result; +} + +/* + * Remove a code from the specified tree, freeing the unused nodes. Returns + * true if the code was found/removed. + */ +int _nc_remove_key(struct tries **tree, unsigned short code) +{ + T((T_CALLED("_nc_remove_key(%p,%d)"), tree, code)); + + if (code == 0) + returnCode(FALSE); + + while (*tree != 0) { + if (_nc_remove_key(&(*tree)->child, code)) { + returnCode(TRUE); + } + if ((*tree)->value == code) { + if((*tree)->child) { + /* don't cut the whole sub-tree */ + (*tree)->value = 0; + } else { + struct tries *to_free = *tree; + *tree = (*tree)->sibling; + free(to_free); + } + returnCode(TRUE); + } + tree = &(*tree)->sibling; + } + returnCode(FALSE); +} + +/* + * Remove a string from the specified tree, freeing the unused nodes. Returns + * true if the string was found/removed. + */ +int _nc_remove_string(struct tries **tree, char *string) +{ + T((T_CALLED("_nc_remove_string(%p,%s)"), tree, _nc_visbuf(string))); + + if (string == 0 || *string == 0) + returnCode(FALSE); + + while (*tree != 0) { + if ((unsigned char)(*tree)->ch == (unsigned char)*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 { + struct tries *to_free = *tree; + *tree = (*tree)->sibling; + free(to_free); + } + returnCode(TRUE); + } + tree = &(*tree)->sibling; + } + returnCode(FALSE); +} diff --git a/contrib/ncurses/ncurses/base/vsscanf.c b/contrib/ncurses/ncurses/base/vsscanf.c new file mode 100644 index 0000000..ac2bf9f --- /dev/null +++ b/contrib/ncurses/ncurses/base/vsscanf.c @@ -0,0 +1,47 @@ +/* + * This function is needed to support vwscanw + */ + +#include <curses.priv.h> + +#if !HAVE_VSSCANF + +MODULE_ID("$Id: vsscanf.c,v 1.10 1996/12/21 14:24:06 tom Exp $") + +#if defined(_IOREAD) && defined(_NFILE) +/*VARARGS2*/ +int vsscanf(const char *str, const char *format, va_list ap) +{ + /* + * This code should work on anything descended from AT&T SVr1. + */ + FILE strbuf; + + strbuf._flag = _IOREAD; + strbuf._ptr = strbuf._base = (unsigned char*)str; + strbuf._cnt = strlen(str); + strbuf._file = _NFILE; + +#if HAVE_VFSCANF + return(vfscanf(&strbuf, format, ap)); +#else + return(_doscan(&strbuf, format, ap)); +#endif +} +#else +/*VARARGS2*/ +int vsscanf(const char *str, const char *format, va_list ap) +{ + /* + * You don't have a native vsscanf(3), and you don't have System-V + * compatible stdio internals. You're probably using a BSD + * older than 4.4 or a really old Linux. You lose. Upgrade + * to a current C library to win. + */ + return -1; /* not implemented */ +} +#endif +#else +extern void _nc_vsscanf(void); /* quiet's gcc warning */ +void _nc_vsscanf(void) { } /* nonempty for strict ANSI compilers */ +#endif /* !HAVE_VSSCANF */ diff --git a/contrib/ncurses/ncurses/base/wresize.c b/contrib/ncurses/ncurses/base/wresize.c new file mode 100644 index 0000000..1b91476 --- /dev/null +++ b/contrib/ncurses/ncurses/base/wresize.c @@ -0,0 +1,166 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: wresize.c,v 1.12 1999/02/27 18:57:31 tom Exp $") + +/* + * 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,chtype,n) + +int +wresize(WINDOW *win, int ToLines, int ToCols) +{ + register int row; + int size_x, size_y; + struct ldat *pline; + chtype blank; + +#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)); + if (_nc_tracing & TRACE_UPDATE) + _tracedump("...before", win); + } +#endif + + if (!win || --ToLines < 0 || --ToCols < 0) + returnCode(ERR); + + size_x = win->_maxx; + size_y = win->_maxy; + + if (ToLines == size_y + && ToCols == size_x) + returnCode(OK); + + pline = (win->_flags & _SUBWIN) ? win->_parent->_line : 0; + + /* + * If the number of lines has changed, adjust the size of the overall + * vector: + */ + 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->_begy + row].text[win->_begx]; + } + } + } + + /* + * Adjust the width of the columns: + */ + blank = _nc_background(win); + for (row = 0; row <= ToLines; row++) { + chtype *s = win->_line[row].text; + int begin = (s == 0) ? 0 : size_x + 1; + int end = ToCols; + + 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); + } else if (s == 0) { + win->_line[row].text = s = + &pline[win->_begy + row].text[win->_begx]; + } + + if (end >= begin) { /* growing */ + if (win->_line[row].firstchar < begin) + win->_line[row].firstchar = begin; + win->_line[row].lastchar = ToCols; + do { + s[end] = blank; + } while (--end >= begin); + } else { /* shrinking */ + win->_line[row].firstchar = 0; + win->_line[row].lastchar = ToCols; + } + } + } + + /* + * Finally, adjust the parameters showing screen size and cursor + * position: + */ + win->_maxx = ToCols; + win->_maxy = ToLines; + + if (win->_regtop > win->_maxy) + win->_regtop = win->_maxy; + if (win->_regbottom > win->_maxy + || win->_regbottom == size_y) + win->_regbottom = win->_maxy; + + if (win->_curx > win->_maxx) + win->_curx = win->_maxx; + if (win->_cury > win->_maxy) + win->_cury = win->_maxy; + +#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)); + if (_nc_tracing & TRACE_UPDATE) + _tracedump("...after:", win); +#endif + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/curses.priv.h b/contrib/ncurses/ncurses/curses.priv.h new file mode 100644 index 0000000..02b81a4 --- /dev/null +++ b/contrib/ncurses/ncurses/curses.priv.h @@ -0,0 +1,791 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * $Id: curses.priv.h,v 1.142 1999/07/04 01:21:35 tom Exp $ + * + * curses.priv.h + * + * Header file for curses library objects which are private to + * the library. + * + */ + +#ifndef CURSES_PRIV_H +#define CURSES_PRIV_H 1 + +#ifdef __cplusplus +extern "C" { +#endif + +#include <ncurses_cfg.h> + +#if USE_RCS_IDS +#define MODULE_ID(id) static const char Ident[] = id; +#else +#define MODULE_ID(id) /*nothing*/ +#endif + +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> + +#if HAVE_UNISTD_H +#include <unistd.h> +#endif + +#if HAVE_SYS_BSDTYPES_H +#include <sys/bsdtypes.h> /* needed for ISC */ +#endif + +#if HAVE_LIMITS_H +# include <limits.h> +#elif HAVE_SYS_PARAM_H +# include <sys/param.h> +#endif + +#ifndef PATH_MAX +# if defined(_POSIX_PATH_MAX) +# define PATH_MAX _POSIX_PATH_MAX +# elif defined(MAXPATHLEN) +# define PATH_MAX MAXPATHLEN +# else +# define PATH_MAX 255 /* the Posix minimum path-size */ +# endif +#endif + +#include <assert.h> +#include <stdio.h> + +#include <errno.h> + +#if DECL_ERRNO +extern int errno; +#endif + +#include <nc_panel.h> + +/* Some systems have a broken 'select()', but workable 'poll()'. Use that */ +#if HAVE_POLL && HAVE_SYS_STROPTS_H && HAVE_POLL_H +#define USE_FUNC_POLL 1 +#else +#define USE_FUNC_POLL 0 +#endif + +/* Alessandro Rubini's GPM (general-purpose mouse) */ +#if HAVE_LIBGPM && HAVE_GPM_H +#define USE_GPM_SUPPORT 1 +#else +#define USE_GPM_SUPPORT 0 +#endif + +/* QNX mouse support */ +#if defined(__QNX__) && !defined(__QNXNTO__) +#define USE_QNX_MOUSE 1 +#else +#define USE_QNX_MOUSE 0 +#endif + +/* EMX mouse support */ +#ifdef __EMX__ +#define USE_EMX_MOUSE +#endif + +#define DEFAULT_MAXCLICK 166 +#define EV_MAX 8 /* size of mouse circular event queue */ + +/* + * If we don't have signals to support it, don't add a sigwinch handler. + * In any case, resizing is an extended feature. Use it if we've got it. + */ +#ifndef NCURSES_EXT_FUNCS +#undef HAVE_SIZECHANGE +#endif + +#if HAVE_SIZECHANGE +#define USE_SIZECHANGE 1 +#else +#undef USE_SIGWINCH +#endif + +/* + * Not all platforms have memmove; some have an equivalent bcopy. (Some may + * have neither). + */ +#if USE_OK_BCOPY +#define memmove(d,s,n) bcopy(s,d,n) +#elif USE_MY_MEMMOVE +#define memmove(d,s,n) _nc_memmove(d,s,n) +extern void * _nc_memmove(void *, const void *, size_t); +#endif + +/* + * Scroll hints are useless when hashmap is used + */ +#if !USE_SCROLL_HINTS +#if !USE_HASHMAP +#define USE_SCROLL_HINTS 1 +#else +#define USE_SCROLL_HINTS 0 +#endif +#endif + +#if USE_SCROLL_HINTS +#define if_USE_SCROLL_HINTS(stmt) stmt +#else +#define if_USE_SCROLL_HINTS(stmt) /*nothing*/ +#endif + +/* + * Note: ht/cbt expansion flakes out randomly under Linux 1.1.47, but only + * when we're throwing control codes at the screen at high volume. To see + * this, re-enable USE_HARD_TABS and run worm for a while. Other systems + * probably don't want to define this either due to uncertainties about tab + * delays and expansion in raw mode. + */ + +struct tries { + struct tries *child; /* ptr to child. NULL if none */ + struct tries *sibling; /* ptr to sibling. NULL if none */ + unsigned char ch; /* character at this node */ + unsigned short value; /* code of string so far. 0 if none. */ +}; + +/* + * 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 '{' +#define R_BRACE '}' +#define S_QUOTE '\'' + +/* + * Structure for palette tables + */ + +typedef struct +{ + short red, green, blue; +} +color_t; + +#define MAXCOLUMNS 135 +#define MAXLINES 66 +#define FIFO_SIZE MAXCOLUMNS+2 /* for nocbreak mode input */ + +#define ACS_LEN 128 + +#define WINDOWLIST struct _win_list + +#include <curses.h> /* we'll use -Ipath directive to get the right one! */ + +/* + * Structure for soft labels. + */ + +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 */ +} slk_ent; + +typedef struct { + char dirty; /* all labels have changed */ + char hidden; /* soft labels are hidden */ + struct _win_st *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 */ +} SLK; + +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) */ + int _tried; /* keypad mode was initialized */ + + 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? */ + unsigned long _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 */ + /* cursor movement costs; units are 10ths of milliseconds */ +#ifdef NCURSES_NO_PADDING + 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) */ +#if USE_HARD_TABS + int _ht_cost; /* cost of (tab) */ + int _cbt_cost; /* cost of (backtab) */ +#endif /* USE_HARD_TABS */ + int _cub1_cost; /* cost of (cursor_left) */ + int _cuf1_cost; /* cost of (cursor_right) */ + int _cud1_cost; /* cost of (cursor_down) */ + int _cuu1_cost; /* cost of (cursor_up) */ + int _cub_cost; /* cost of (parm_cursor_left) */ + int _cuf_cost; /* cost of (parm_cursor_right) */ + int _cud_cost; /* cost of (parm_cursor_down) */ + int _cuu_cost; /* cost of (parm_cursor_up) */ + int _hpa_cost; /* cost of (column_address) */ + int _vpa_cost; /* cost of (row_address) */ + /* used in lib_doupdate.c, must be chars */ + int _ed_cost; /* cost of (clr_eos) */ + int _el_cost; /* cost of (clr_eol) */ + int _el1_cost; /* cost of (clr_bol) */ + int _dch1_cost; /* cost of (delete_character) */ + int _ich1_cost; /* cost of (insert_character) */ + int _dch_cost; /* cost of (parm_dch) */ + int _ich_cost; /* cost of (parm_ich) */ + int _ech_cost; /* cost of (erase_chars) */ + int _rep_cost; /* cost of (repeat_char) */ + int _hpa_ch_cost; /* cost of (column_address) */ + int _cup_ch_cost; /* cost of (cursor_address) */ + int _smir_cost; /* cost of (enter_insert_mode) */ + int _rmir_cost; /* cost of (exit_insert_mode) */ + int _ip_cost; /* cost of (insert_padding) */ + /* used in lib_mvcur.c */ + char * _address_cursor; + int _carriage_return_length; + int _cursor_home_length; + int _cursor_to_ll_length; + 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 */ + int _default_color; /* use default colors */ + chtype _xmc_suppress; /* attributes to suppress if xmc */ + chtype _xmc_triggers; /* attributes to process if xmc */ + chtype _acs_map[ACS_LEN]; + + /* used in lib_vidattr.c */ + bool _use_rmso; /* true if we may use 'rmso' */ + bool _use_rmul; /* true if we may use 'rmul' */ + + /* + * These data correspond to the state of the idcok() and idlok() + * functions. A caveat is in order here: the XSI and SVr4 + * documentation specify that these functions apply to the window which + * is given as an argument. However, ncurses implements this logic + * only for the newscr/curscr update process, _not_ per-window. + */ + bool _nc_sp_idlok; + bool _nc_sp_idcok; +#define _nc_idlok SP->_nc_sp_idlok +#define _nc_idcok SP->_nc_sp_idcok + + /* + * These are the data that support the mouse interface. + */ + 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 */ + + /* + * This supports automatic resizing + */ +#if USE_SIZECHANGE + int (*_resize)(int,int); +#endif + + /* + * These are data that support the proper handling of the panel stack on an + * per screen basis. + */ + struct panelhook _panelHook; + /* + * Linked-list of all windows, to support '_nc_resizeall()' and + * '_nc_freeall()' + */ + WINDOWLIST *_nc_sp_windows; +#define _nc_windows SP->_nc_sp_windows + + bool _sig_winch; + SCREEN *_next_screen; + + /* hashes for old and new lines */ + unsigned long *oldhash, *newhash; +}; + +extern SCREEN *_nc_screen_chain; + +#ifdef NCURSES_NOMACROS +#include <nomacros.h> +#endif + + WINDOWLIST { + WINDOWLIST *next; + 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; + +/* The terminfo source is assumed to be 7-bit ASCII */ +#define is7bits(c) ((unsigned)(c) < 128) + +#ifndef min +#define min(a,b) ((a) > (b) ? (b) : (a)) +#endif + +#ifndef max +#define max(a,b) ((a) < (b) ? (b) : (a)) +#endif + +/* usually in <unistd.h> */ +#ifndef STDIN_FILENO +#define STDIN_FILENO 0 +#endif + +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 +#endif + +#ifndef STDERR_FILENO +#define STDERR_FILENO 2 +#endif + +#ifndef EXIT_SUCCESS +#define EXIT_SUCCESS 0 +#endif + +#ifndef EXIT_FAILURE +#define EXIT_FAILURE 1 +#endif + +#ifndef R_OK +#define R_OK 4 /* Test for read permission. */ +#endif +#ifndef W_OK +#define W_OK 2 /* Test for write permission. */ +#endif +#ifndef X_OK +#define X_OK 1 /* Test for execute permission. */ +#endif +#ifndef F_OK +#define F_OK 0 /* Test for existence. */ +#endif + +#define TextOf(c) ((c) & (chtype)A_CHARTEXT) +#define AttrOf(c) ((c) & (chtype)A_ATTRIBUTES) + +#define BLANK (' '|A_NORMAL) + +#define CHANGED -1 + +#define CHANGED_CELL(line,col) \ + if (line->firstchar == _NOCHANGE) \ + line->firstchar = line->lastchar = col; \ + else if ((col) < line->firstchar) \ + line->firstchar = col; \ + else if ((col) > line->lastchar) \ + line->lastchar = col + +#define CHANGED_RANGE(line,start,end) \ + if (line->firstchar == _NOCHANGE \ + || line->firstchar > (start)) \ + line->firstchar = start; \ + if (line->lastchar == _NOCHANGE \ + || line->lastchar < (end)) \ + line->lastchar = end + +#define CHANGED_TO_EOL(line,start,end) \ + if (line->firstchar == _NOCHANGE \ + || line->firstchar > (start)) \ + line->firstchar = start; \ + line->lastchar = end + +#define SIZEOF(v) (sizeof(v)/sizeof(v[0])) +#define typeMalloc(type,elts) (type *)malloc((elts)*sizeof(type)) +#define typeCalloc(type,elts) (type *)calloc((elts),sizeof(type)) +#define typeRealloc(type,elts,ptr) (type *)_nc_doalloc(ptr, (elts)*sizeof(type)) +#define FreeIfNeeded(p) if(p != 0) free(p) +#define FreeAndNull(p) free(p); p = 0 + +#include <nc_alloc.h> + +/* + * Prefixes for call/return points of library function traces. We use these to + * instrument the public functions so that the traces can be easily transformed + * into regression scripts. + */ +#define T_CALLED(fmt) "called " fmt +#define T_CREATE(fmt) "create " fmt +#define T_RETURN(fmt) "return " fmt + +#ifdef TRACE +#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 returnCode(code) TRACE_RETURN(code,int) +#define returnPtr(code) TRACE_RETURN(code,ptr) +#define returnVoid T((T_RETURN(""))); return +#define returnWin(code) TRACE_RETURN(code,win) +extern WINDOW * _nc_retrace_win(WINDOW *); +extern attr_t _nc_retrace_attr_t(attr_t); +extern char *_nc_retrace_ptr(char *); +extern const char *_nc_tputs_trace; +extern int _nc_retrace_int(int); +extern long _nc_outchars; +extern void _nc_fifo_dump(void); +#else +#define T(a) +#define TR(n, a) +#define TPUTS_TRACE(s) +#define returnAttr(code) return code +#define returnCode(code) return code +#define returnPtr(code) return code +#define returnVoid return +#define returnWin(code) return code +#endif + +extern unsigned _nc_tracing; +extern const char *_nc_visbuf2(int, const char *); + +#define _trace_key(ch) ((ch > KEY_MIN) ? keyname(ch) : _tracechar((unsigned char)ch)) + +#define ALL_BUT_COLOR ((chtype)~(A_COLOR)) +#define IGNORE_COLOR_OFF FALSE +#define NONBLANK_ATTR (A_BOLD|A_DIM|A_BLINK) +#define XMC_CHANGES(c) ((c) & SP->_xmc_suppress) + + +#define toggle_attr_on(S,at) \ + if (PAIR_NUMBER(at) > 0)\ + (S) = ((S) & ALL_BUT_COLOR) | (at);\ + else\ + (S) |= (at);\ + T(("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);\ + } else {\ + if (PAIR_NUMBER(at) > 0x00) /* turn off color */\ + (S) &= ~(at|A_COLOR);\ + else /* leave color alone */\ + (S) &= ~(at);\ + }\ + T(("new attribute is %s", _traceattr((S)))); + +#define DelCharCost(count) \ + ((parm_dch != 0) \ + ? SP->_dch_cost \ + : ((delete_character != 0) \ + ? (SP->_dch1_cost * count) \ + : INFINITY)) + +#define InsCharCost(count) \ + ((parm_ich != 0) \ + ? SP->_ich_cost \ + : ((enter_insert_mode && exit_insert_mode) \ + ? SP->_smir_cost + SP->_rmir_cost + (SP->_ip_cost * count) \ + : ((insert_character != 0) \ + ? (SP->_ich1_cost * count) \ + : INFINITY))) + +#if USE_XMC_SUPPORT +#define UpdateAttrs(c) if (SP->_current_attr != AttrOf(c)) { \ + attr_t chg = SP->_current_attr; \ + vidattr(AttrOf(c)); \ + if (magic_cookie_glitch > 0 \ + && XMC_CHANGES((chg ^ SP->_current_attr))) { \ + T(("%s @%d before glitch %d,%d", \ + __FILE__, __LINE__, \ + SP->_cursrow, \ + SP->_curscol)); \ + _nc_do_xmc_glitch(chg); \ + } \ + } +#else +#define UpdateAttrs(c) if (SP->_current_attr != AttrOf(c)) \ + vidattr(AttrOf(c)); +#endif + +/* + * Check whether the given character can be output by clearing commands. This + * includes test for being a space and not including any 'bad' attributes, such + * as A_REVERSE. All attribute flags which don't affect appearance of a space + * or can be output by clearing (A_COLOR in case of bce-terminal) are excluded. + */ +#define can_clear_with(ch) \ + ((ch & ~(NONBLANK_ATTR|(back_color_erase ? A_COLOR:0))) == BLANK) + +#ifdef NCURSES_EXPANDED + +#undef toggle_attr_on +#define toggle_attr_on(S,at) _nc_toggle_attr_on(&(S), at) +extern void _nc_toggle_attr_on(attr_t *, attr_t); + +#undef toggle_attr_off +#define toggle_attr_off(S,at) _nc_toggle_attr_off(&(S), at) +extern void _nc_toggle_attr_off(attr_t *, attr_t); + +#undef can_clear_with +#define can_clear_with(ch) _nc_can_clear_with(ch) +extern int _nc_can_clear_with(chtype); + +#undef DelCharCost +#define DelCharCost(count) _nc_DelCharCost(count) +extern int _nc_DelCharCost(int); + +#undef InsCharCost +#define InsCharCost(count) _nc_InsCharCost(count) +extern int _nc_InsCharCost(int); + +#undef UpdateAttrs +#define UpdateAttrs(c) _nc_UpdateAttrs(c) +extern void _nc_UpdateAttrs(chtype); + +#else + +extern void _nc_expanded(void); + +#endif + +#if !HAVE_GETCWD +#define getcwd(buf,len) getwd(buf) +#endif + +/* doalloc.c */ +extern void *_nc_doalloc(void *, size_t); +#if !HAVE_STRDUP +#define strdup _nc_strdup +extern char *_nc_strdup(const char *); +#endif + +/* doupdate.c */ +#if USE_XMC_SUPPORT +extern void _nc_do_xmc_glitch(attr_t); +#endif + +/* hardscroll.c */ +#if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG) +extern void _nc_linedump(void); +#endif + +/* lib_acs.c */ +extern void _nc_init_acs(void); /* corresponds to traditional 'init_acs()' */ +extern int _nc_msec_cost(const char *const, int); /* used by 'tack' program */ + +/* lib_mvcur.c */ +#define INFINITY 1000000 /* cost: too high to use */ + +extern void _nc_mvcur_init(void); +extern void _nc_mvcur_resume(void); +extern void _nc_mvcur_wrap(void); + +extern int _nc_scrolln(int, int, int, int); + +extern void _nc_screen_init(void); +extern void _nc_screen_resume(void); +extern void _nc_screen_wrap(void); + +#if !HAVE_STRSTR +#define strstr _nc_strstr +extern char *_nc_strstr(const char *, const char *); +#endif + +/* lib_mouse.c */ +extern int _nc_has_mouse(void); + +/* safe_sprintf.c */ +extern char * _nc_printf_string(const char *fmt, va_list ap); + +/* tries.c */ +extern void _nc_add_to_try(struct tries **tree, char *str, unsigned short code); +extern char *_nc_expand_try(struct tries *tree, unsigned short code, int *count, size_t len); +extern int _nc_remove_key(struct tries **tree, unsigned short code); +extern int _nc_remove_string(struct tries **tree, char *string); + +/* elsewhere ... */ +extern WINDOW *_nc_makenew(int, int, int, int, int); +extern char *_nc_home_terminfo(void); +extern char *_nc_trace_buf(int, size_t); +extern chtype _nc_background(WINDOW *); +extern chtype _nc_render(WINDOW *, chtype); +extern int _nc_access(const char *, int); +extern int _nc_baudrate(int); +extern int _nc_getenv_num(const char *); +extern int _nc_keypad(bool); +extern int _nc_ospeed(int); +extern int _nc_outch(int); +extern int _nc_setupscreen(short, short const, FILE *); +extern int _nc_timed_wait(int, int, int *); +extern int _nc_waddch_nosync(WINDOW *, const chtype); +extern void _nc_do_color(int, bool, int (*)(int)); +extern void _nc_freeall(void); +extern void _nc_freewin(WINDOW *win); +extern void _nc_hash_map(void); +extern void _nc_init_keytry(void); +extern void _nc_keep_tic_dir(const char *); +extern void _nc_make_oldhash(int i); +extern void _nc_outstr(const char *str); +extern void _nc_scroll_oldhash(int n, int top, int bot); +extern void _nc_scroll_optimize(void); +extern void _nc_scroll_window(WINDOW *, int const, short const, short const, chtype); +extern void _nc_set_buffer(FILE *ofp, bool buffered); +extern void _nc_signal_handler(bool); +extern void _nc_synchook(WINDOW *win); +extern void _nc_trace_tries(struct tries *tree); + +#if USE_SIZECHANGE +extern void _nc_update_screensize(void); +#endif + +/* scroll indices */ +extern int *_nc_oldnums; + +#define USE_SETBUF_0 0 + +#define NC_BUFFERED(flag) \ + if ((SP->_buffered != 0) != flag) \ + _nc_set_buffer(SP->_ofp, flag) + +/* + * On systems with a broken linker, define 'SP' as a function to force the + * linker to pull in the data-only module with 'SP'. + */ +#ifndef BROKEN_LINKER +#define BROKEN_LINKER 0 +#endif + +#if BROKEN_LINKER +#define SP _nc_screen() +extern SCREEN *_nc_screen(void); +extern int _nc_alloc_screen(void); +extern void _nc_set_screen(SCREEN *); +#else +/* current screen is private data; avoid possible linking conflicts too */ +extern SCREEN *SP; +#define _nc_alloc_screen() ((SP = typeCalloc(SCREEN, 1)) != 0) +#define _nc_set_screen(sp) SP = sp +#endif + +/* + * We don't want to use the lines or columns capabilities internally, + * because if the application is running multiple screens under + * X windows, it's quite possible they could all have type xterm + * but have different sizes! So... + */ +#define screen_lines SP->_lines +#define screen_columns SP->_columns + +extern int _nc_slk_format; /* != 0 if slk_init() called */ +extern int _nc_slk_initialize(WINDOW *, int); + +/* + * Some constants related to SLK's + */ +#define MAX_SKEY_OLD 8 /* count of soft keys */ +#define MAX_SKEY_LEN_OLD 8 /* max length of soft key text */ +#define MAX_SKEY_PC 12 /* This is what most PC's have */ +#define MAX_SKEY_LEN_PC 5 + +/* Macro to check whether or not we use a standard format */ +#define SLK_STDFMT(fmt) (fmt < 3) +/* Macro to determine height of label window */ +#define SLK_LINES(fmt) (SLK_STDFMT(fmt) ? 1 : ((fmt) - 2)) + +#define MAX_SKEY(fmt) (SLK_STDFMT(fmt)? MAX_SKEY_OLD : MAX_SKEY_PC) +#define MAX_SKEY_LEN(fmt) (SLK_STDFMT(fmt)? MAX_SKEY_LEN_OLD : MAX_SKEY_LEN_PC) + +extern int _nc_ripoffline(int line, int (*init)(WINDOW *,int)); + +#ifdef __cplusplus +} +#endif + +#endif /* CURSES_PRIV_H */ diff --git a/contrib/ncurses/ncurses/fifo_defs.h b/contrib/ncurses/ncurses/fifo_defs.h new file mode 100644 index 0000000..f4dd7be --- /dev/null +++ b/contrib/ncurses/ncurses/fifo_defs.h @@ -0,0 +1,59 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * Common macros for lib_getch.c, lib_ungetch.c + * + * $Id: fifo_defs.h,v 1.2 1998/02/11 12:13:56 tom Exp $ + */ + +#ifndef FIFO_DEFS_H +#define FIFO_DEFS_H 1 + +#define head SP->_fifohead +#define tail SP->_fifotail +/* peek points to next uninterpreted character */ +#define peek SP->_fifopeek + +#define h_inc() { head == FIFO_SIZE-1 ? head = 0 : head++; if (head == tail) head = -1, tail = 0;} +#define h_dec() { head == 0 ? head = FIFO_SIZE-1 : head--; if (head == tail) tail = -1;} +#define t_inc() { tail == FIFO_SIZE-1 ? tail = 0 : tail++; if (tail == head) tail = -1;} +#define t_dec() { tail == 0 ? tail = FIFO_SIZE-1 : tail--; if (head == tail) fifo_clear();} +#define p_inc() { peek == FIFO_SIZE-1 ? peek = 0 : peek++;} + +#define cooked_key_in_fifo() (head!=-1 && peek!=head) +#define raw_key_in_fifo() (head!=-1 && peek!=tail) + +#undef HIDE_EINTR + +#endif /* FIFO_DEFS_H */ diff --git a/contrib/ncurses/ncurses/llib-lncurses b/contrib/ncurses/ncurses/llib-lncurses new file mode 100644 index 0000000..c30c6eb --- /dev/null +++ b/contrib/ncurses/ncurses/llib-lncurses @@ -0,0 +1,2868 @@ +/**************************************************************************** + * Copyright (c) 1998,1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997,1998,1999 * + ****************************************************************************/ +/* LINTLIBRARY */ + +/* ./tty/hardscroll.c */ + +#include <curses.priv.h> + +#undef _nc_oldnums +int *_nc_oldnums; + +#undef _nc_scroll_optimize +void _nc_scroll_optimize(void) + { /* void */ } + +/* ./tty/hashmap.c */ + +#include <term.h> + +typedef struct +{ + unsigned long hashval; + int oldcount, newcount; + int oldindex, newindex; +} + sym; + +#undef _nc_hash_map +void _nc_hash_map(void) + { /* void */ } + +#undef _nc_make_oldhash +void _nc_make_oldhash( + int i) + { /* void */ } + +#undef _nc_scroll_oldhash +void _nc_scroll_oldhash( + int n, + int top, + int bot) + { /* void */ } + +/* ./base/lib_addch.c */ + +#include <ctype.h> + +#undef _nc_background +chtype _nc_background( + WINDOW *win) + { return(*(chtype *)0); } + +#undef _nc_render +chtype _nc_render( + WINDOW *win, + chtype ch) + { return(*(chtype *)0); } + +#undef _nc_waddch_nosync +int _nc_waddch_nosync( + WINDOW *win, + const chtype c) + { return(*(int *)0); } + +#undef waddch +int waddch( + WINDOW *win, + const chtype ch) + { return(*(int *)0); } + +#undef wechochar +int wechochar( + WINDOW *win, + const chtype ch) + { return(*(int *)0); } + +/* ./base/lib_addstr.c */ + +#undef waddnstr +int waddnstr( + WINDOW *win, + const char *const astr, + int n) + { return(*(int *)0); } + +#undef waddchnstr +int waddchnstr( + WINDOW *win, + const chtype *const astr, + int n) + { return(*(int *)0); } + +/* ./base/lib_beep.c */ + +#undef beep +int beep(void) + { return(*(int *)0); } + +/* ./base/lib_bkgd.c */ + +#undef wbkgdset +void wbkgdset( + WINDOW *win, + chtype ch) + { /* void */ } + +#undef wbkgd +int wbkgd( + WINDOW *win, + const chtype ch) + { return(*(int *)0); } + +/* ./base/lib_box.c */ + +#undef wborder +int wborder( + WINDOW *win, + chtype ls, + chtype rs, + chtype ts, + chtype bs, + chtype tl, + chtype tr, + chtype bl, + chtype br) + { return(*(int *)0); } + +/* ./base/lib_chgat.c */ + +#undef wchgat +int wchgat( + WINDOW *win, + int n, + attr_t attr, + short color, + const void *opts) + { return(*(int *)0); } + +/* ./base/lib_clear.c */ + +#undef wclear +int wclear( + WINDOW *win) + { return(*(int *)0); } + +/* ./base/lib_clearok.c */ + +#undef clearok +int clearok( + WINDOW *win, + bool flag) + { return(*(int *)0); } + +/* ./base/lib_clrbot.c */ + +#undef wclrtobot +int wclrtobot( + WINDOW *win) + { return(*(int *)0); } + +/* ./base/lib_clreol.c */ + +#undef wclrtoeol +int wclrtoeol( + WINDOW *win) + { return(*(int *)0); } + +/* ./base/lib_color.c */ + +#undef COLOR_PAIRS +int COLOR_PAIRS; +#undef COLORS +int COLORS; + +#undef start_color +int start_color(void) + { return(*(int *)0); } + +#undef init_pair +int init_pair( + short pair, + short f, + short b) + { return(*(int *)0); } + +#undef init_color +int init_color( + short color, + short r, + short g, + short b) + { return(*(int *)0); } + +#undef can_change_color +bool can_change_color(void) + { return(*(bool *)0); } + +#undef has_colors +bool has_colors(void) + { return(*(bool *)0); } + +#undef color_content +int color_content( + short color, + short *r, + short *g, + short *b) + { return(*(int *)0); } + +#undef pair_content +int pair_content( + short pair, + short *f, + short *b) + { return(*(int *)0); } + +#undef _nc_do_color +void _nc_do_color( + int pair, + bool reverse, + int (*outc)( + int p1)) + { /* void */ } + +/* ./base/lib_colorset.c */ + +#undef wcolor_set +int wcolor_set( + WINDOW *win, + short color_pair_number, + void *opts) + { return(*(int *)0); } + +/* ./base/lib_delch.c */ + +#undef wdelch +int wdelch( + WINDOW *win) + { return(*(int *)0); } + +/* ./base/lib_delwin.c */ + +#undef delwin +int delwin( + WINDOW *win) + { return(*(int *)0); } + +/* ./base/lib_echo.c */ + +#undef echo +int echo(void) + { return(*(int *)0); } + +#undef noecho +int noecho(void) + { return(*(int *)0); } + +/* ./base/lib_endwin.c */ + +#undef endwin +int endwin(void) + { return(*(int *)0); } + +/* ./base/lib_erase.c */ + +#undef werase +int werase( + WINDOW *win) + { return(*(int *)0); } + +/* ./base/lib_flash.c */ + +#undef flash +int flash(void) + { return(*(int *)0); } + +/* ./lib_gen.c */ + +#undef addch +int addch( + const chtype z) + { return(*(int *)0); } + +#undef addchnstr +int addchnstr( + const chtype *a1, + int z) + { return(*(int *)0); } + +#undef addchstr +int addchstr( + const chtype *z) + { return(*(int *)0); } + +#undef addnstr +int addnstr( + const char *a1, + int z) + { return(*(int *)0); } + +#undef addstr +int addstr( + const char *z) + { return(*(int *)0); } + +#undef attroff +int attroff( + NCURSES_ATTR_T z) + { return(*(int *)0); } + +#undef attron +int attron( + NCURSES_ATTR_T z) + { return(*(int *)0); } + +#undef attrset +int attrset( + NCURSES_ATTR_T z) + { return(*(int *)0); } + +#undef attr_get +int attr_get( + attr_t *a1, + short *a2, + void *z) + { return(*(int *)0); } + +#undef attr_off +int attr_off( + attr_t a1, + void *z) + { return(*(int *)0); } + +#undef attr_on +int attr_on( + attr_t a1, + void *z) + { return(*(int *)0); } + +#undef attr_set +int attr_set( + attr_t a1, + short a2, + void *z) + { return(*(int *)0); } + +#undef bkgd +int bkgd( + chtype z) + { return(*(int *)0); } + +#undef bkgdset +void bkgdset( + chtype z) + { /* void */ } + +#undef border +int border( + chtype a1, + chtype a2, + chtype a3, + chtype a4, + chtype a5, + chtype a6, + chtype a7, + chtype z) + { return(*(int *)0); } + +#undef box +int box( + WINDOW *a1, + chtype a2, + chtype z) + { return(*(int *)0); } + +#undef chgat +int chgat( + int a1, + attr_t a2, + short a3, + const void *z) + { return(*(int *)0); } + +#undef clear +int clear(void) + { return(*(int *)0); } + +#undef clrtobot +int clrtobot(void) + { return(*(int *)0); } + +#undef clrtoeol +int clrtoeol(void) + { return(*(int *)0); } + +#undef color_set +int color_set( + short a1, + void *z) + { return(*(int *)0); } + +#undef COLOR_PAIR +int COLOR_PAIR( + int z) + { return(*(int *)0); } + +#undef delch +int delch(void) + { return(*(int *)0); } + +#undef deleteln +int deleteln(void) + { return(*(int *)0); } + +#undef echochar +int echochar( + const chtype z) + { return(*(int *)0); } + +#undef getbkgd +chtype getbkgd( + WINDOW *z) + { return(*(chtype *)0); } + +#undef getch +int getch(void) + { return(*(int *)0); } + +#undef getnstr +int getnstr( + char *a1, + int z) + { return(*(int *)0); } + +#undef getstr +int getstr( + char *z) + { return(*(int *)0); } + +#undef hline +int hline( + chtype a1, + int z) + { return(*(int *)0); } + +#undef inch +chtype inch(void) + { return(*(chtype *)0); } + +#undef inchnstr +int inchnstr( + chtype *a1, + int z) + { return(*(int *)0); } + +#undef inchstr +int inchstr( + chtype *z) + { return(*(int *)0); } + +#undef innstr +int innstr( + char *a1, + int z) + { return(*(int *)0); } + +#undef insch +int insch( + chtype z) + { return(*(int *)0); } + +#undef insdelln +int insdelln( + int z) + { return(*(int *)0); } + +#undef insertln +int insertln(void) + { return(*(int *)0); } + +#undef insnstr +int insnstr( + const char *a1, + int z) + { return(*(int *)0); } + +#undef insstr +int insstr( + const char *z) + { return(*(int *)0); } + +#undef instr +int instr( + char *z) + { return(*(int *)0); } + +#undef move +int move( + int a1, + int z) + { return(*(int *)0); } + +#undef mvaddch +int mvaddch( + int a1, + int a2, + const chtype z) + { return(*(int *)0); } + +#undef mvaddchnstr +int mvaddchnstr( + int a1, + int a2, + const chtype *a3, + int z) + { return(*(int *)0); } + +#undef mvaddchstr +int mvaddchstr( + int a1, + int a2, + const chtype *z) + { return(*(int *)0); } + +#undef mvaddnstr +int mvaddnstr( + int a1, + int a2, + const char *a3, + int z) + { return(*(int *)0); } + +#undef mvaddstr +int mvaddstr( + int a1, + int a2, + const char *z) + { return(*(int *)0); } + +#undef mvchgat +int mvchgat( + int a1, + int a2, + int a3, + attr_t a4, + short a5, + const void *z) + { return(*(int *)0); } + +#undef mvdelch +int mvdelch( + int a1, + int z) + { return(*(int *)0); } + +#undef mvgetch +int mvgetch( + int a1, + int z) + { return(*(int *)0); } + +#undef mvgetnstr +int mvgetnstr( + int a1, + int a2, + char *a3, + int z) + { return(*(int *)0); } + +#undef mvgetstr +int mvgetstr( + int a1, + int a2, + char *z) + { return(*(int *)0); } + +#undef mvhline +int mvhline( + int a1, + int a2, + chtype a3, + int z) + { return(*(int *)0); } + +#undef mvinch +chtype mvinch( + int a1, + int z) + { return(*(chtype *)0); } + +#undef mvinchnstr +int mvinchnstr( + int a1, + int a2, + chtype *a3, + int z) + { return(*(int *)0); } + +#undef mvinchstr +int mvinchstr( + int a1, + int a2, + chtype *z) + { return(*(int *)0); } + +#undef mvinnstr +int mvinnstr( + int a1, + int a2, + char *a3, + int z) + { return(*(int *)0); } + +#undef mvinsch +int mvinsch( + int a1, + int a2, + chtype z) + { return(*(int *)0); } + +#undef mvinsnstr +int mvinsnstr( + int a1, + int a2, + const char *a3, + int z) + { return(*(int *)0); } + +#undef mvinsstr +int mvinsstr( + int a1, + int a2, + const char *z) + { return(*(int *)0); } + +#undef mvinstr +int mvinstr( + int a1, + int a2, + char *z) + { return(*(int *)0); } + +#undef mvvline +int mvvline( + int a1, + int a2, + chtype a3, + int z) + { return(*(int *)0); } + +#undef mvwaddch +int mvwaddch( + WINDOW *a1, + int a2, + int a3, + const chtype z) + { return(*(int *)0); } + +#undef mvwaddchnstr +int mvwaddchnstr( + WINDOW *a1, + int a2, + int a3, + const chtype *a4, + int z) + { return(*(int *)0); } + +#undef mvwaddchstr +int mvwaddchstr( + WINDOW *a1, + int a2, + int a3, + const chtype *z) + { return(*(int *)0); } + +#undef mvwaddnstr +int mvwaddnstr( + WINDOW *a1, + int a2, + int a3, + const char *a4, + int z) + { return(*(int *)0); } + +#undef mvwaddstr +int mvwaddstr( + WINDOW *a1, + int a2, + int a3, + const char *z) + { return(*(int *)0); } + +#undef mvwchgat +int mvwchgat( + WINDOW *a1, + int a2, + int a3, + int a4, + attr_t a5, + short a6, + const void *z) + { return(*(int *)0); } + +#undef mvwdelch +int mvwdelch( + WINDOW *a1, + int a2, + int z) + { return(*(int *)0); } + +#undef mvwgetch +int mvwgetch( + WINDOW *a1, + int a2, + int z) + { return(*(int *)0); } + +#undef mvwgetnstr +int mvwgetnstr( + WINDOW *a1, + int a2, + int a3, + char *a4, + int z) + { return(*(int *)0); } + +#undef mvwgetstr +int mvwgetstr( + WINDOW *a1, + int a2, + int a3, + char *z) + { return(*(int *)0); } + +#undef mvwhline +int mvwhline( + WINDOW *a1, + int a2, + int a3, + chtype a4, + int z) + { return(*(int *)0); } + +#undef mvwinch +chtype mvwinch( + WINDOW *a1, + int a2, + int z) + { return(*(chtype *)0); } + +#undef mvwinchnstr +int mvwinchnstr( + WINDOW *a1, + int a2, + int a3, + chtype *a4, + int z) + { return(*(int *)0); } + +#undef mvwinchstr +int mvwinchstr( + WINDOW *a1, + int a2, + int a3, + chtype *z) + { return(*(int *)0); } + +#undef mvwinnstr +int mvwinnstr( + WINDOW *a1, + int a2, + int a3, + char *a4, + int z) + { return(*(int *)0); } + +#undef mvwinsch +int mvwinsch( + WINDOW *a1, + int a2, + int a3, + chtype z) + { return(*(int *)0); } + +#undef mvwinsnstr +int mvwinsnstr( + WINDOW *a1, + int a2, + int a3, + const char *a4, + int z) + { return(*(int *)0); } + +#undef mvwinsstr +int mvwinsstr( + WINDOW *a1, + int a2, + int a3, + const char *z) + { return(*(int *)0); } + +#undef mvwinstr +int mvwinstr( + WINDOW *a1, + int a2, + int a3, + char *z) + { return(*(int *)0); } + +#undef mvwvline +int mvwvline( + WINDOW *a1, + int a2, + int a3, + chtype a4, + int z) + { return(*(int *)0); } + +#undef PAIR_NUMBER +int PAIR_NUMBER( + int z) + { return(*(int *)0); } + +#undef redrawwin +int redrawwin( + WINDOW *z) + { return(*(int *)0); } + +#undef refresh +int refresh(void) + { return(*(int *)0); } + +#undef scrl +int scrl( + int z) + { return(*(int *)0); } + +#undef scroll +int scroll( + WINDOW *z) + { return(*(int *)0); } + +#undef setscrreg +int setscrreg( + int a1, + int z) + { return(*(int *)0); } + +#undef standout +int standout(void) + { return(*(int *)0); } + +#undef standend +int standend(void) + { return(*(int *)0); } + +#undef timeout +void timeout( + int z) + { /* void */ } + +#undef untouchwin +int untouchwin( + WINDOW *z) + { return(*(int *)0); } + +#undef vline +int vline( + chtype a1, + int z) + { return(*(int *)0); } + +#undef vw_printw +int vw_printw( + WINDOW *a1, + char *a2, + va_list z) + { return(*(int *)0); } + +#undef vw_scanw +int vw_scanw( + WINDOW *a1, + char *a2, + va_list z) + { return(*(int *)0); } + +#undef waddchstr +int waddchstr( + WINDOW *a1, + const chtype *z) + { return(*(int *)0); } + +#undef waddstr +int waddstr( + WINDOW *a1, + const char *z) + { return(*(int *)0); } + +#undef wattron +int wattron( + WINDOW *a1, + int z) + { return(*(int *)0); } + +#undef wattroff +int wattroff( + WINDOW *a1, + int z) + { return(*(int *)0); } + +#undef wattrset +int wattrset( + WINDOW *a1, + int z) + { return(*(int *)0); } + +#undef wattr_get +int wattr_get( + WINDOW *a1, + attr_t *a2, + short *a3, + void *z) + { return(*(int *)0); } + +#undef wattr_set +int wattr_set( + WINDOW *a1, + attr_t a2, + short a3, + void *z) + { return(*(int *)0); } + +#undef wdeleteln +int wdeleteln( + WINDOW *z) + { return(*(int *)0); } + +#undef wgetstr +int wgetstr( + WINDOW *a1, + char *z) + { return(*(int *)0); } + +#undef winchstr +int winchstr( + WINDOW *a1, + chtype *z) + { return(*(int *)0); } + +#undef winsertln +int winsertln( + WINDOW *z) + { return(*(int *)0); } + +#undef winsstr +int winsstr( + WINDOW *a1, + const char *z) + { return(*(int *)0); } + +#undef winstr +int winstr( + WINDOW *a1, + char *z) + { return(*(int *)0); } + +#undef wstandout +int wstandout( + WINDOW *z) + { return(*(int *)0); } + +#undef wstandend +int wstandend( + WINDOW *z) + { return(*(int *)0); } + +#undef mouse_trafo +bool mouse_trafo( + int *a1, + int *a2, + bool z) + { return(*(bool *)0); } + +/* ./base/lib_getch.c */ + +#include <fifo_defs.h> + +#undef ESCDELAY +int ESCDELAY; + +#undef wgetch +int wgetch( + WINDOW *win) + { return(*(int *)0); } + +/* ./base/lib_getstr.c */ + +#undef wgetnstr +int wgetnstr( + WINDOW *win, + char *str, + int maxlen) + { return(*(int *)0); } + +/* ./base/lib_hline.c */ + +#undef whline +int whline( + WINDOW *win, + chtype ch, + int n) + { return(*(int *)0); } + +/* ./base/lib_immedok.c */ + +#undef immedok +void immedok( + WINDOW *win, + bool flag) + { /* void */ } + +/* ./base/lib_inchstr.c */ + +#undef winchnstr +int winchnstr( + WINDOW *win, + chtype *str, + int n) + { return(*(int *)0); } + +/* ./base/lib_initscr.c */ + +#include <tic.h> + +#undef initscr +WINDOW *initscr(void) + { return(*(WINDOW **)0); } + +/* ./base/lib_insch.c */ + +#undef winsch +int winsch( + WINDOW *win, + chtype c) + { return(*(int *)0); } + +/* ./base/lib_insdel.c */ + +#undef winsdelln +int winsdelln( + WINDOW *win, + int n) + { return(*(int *)0); } + +/* ./base/lib_insstr.c */ + +#undef winsnstr +int winsnstr( + WINDOW *win, + const char *s, + int n) + { return(*(int *)0); } + +/* ./base/lib_instr.c */ + +#undef winnstr +int winnstr( + WINDOW *win, + char *str, + int n) + { return(*(int *)0); } + +/* ./base/lib_isendwin.c */ + +#undef isendwin +bool isendwin(void) + { return(*(bool *)0); } + +/* ./base/lib_leaveok.c */ + +#undef leaveok +int leaveok( + WINDOW *win, + bool flag) + { return(*(int *)0); } + +/* ./base/lib_mouse.c */ + +#undef getmouse +int getmouse( + MEVENT *aevent) + { return(*(int *)0); } + +#undef ungetmouse +int ungetmouse( + MEVENT *aevent) + { return(*(int *)0); } + +#undef mousemask +mmask_t mousemask( + mmask_t newmask, + mmask_t *oldmask) + { return(*(mmask_t *)0); } + +#undef wenclose +bool wenclose( + const WINDOW *win, + int y, + int x) + { return(*(bool *)0); } + +#undef mouseinterval +int mouseinterval( + int maxclick) + { return(*(int *)0); } + +#undef _nc_has_mouse +int _nc_has_mouse(void) + { return(*(int *)0); } + +#undef wmouse_trafo +bool wmouse_trafo( + const WINDOW *win, + int *pY, + int *pX, + bool to_screen) + { return(*(bool *)0); } + +/* ./base/lib_move.c */ + +#undef wmove +int wmove( + WINDOW *win, + int y, + int x) + { return(*(int *)0); } + +/* ./tty/lib_mvcur.c */ + +#undef _nc_msec_cost +int _nc_msec_cost( + const char *const cap, + int affcnt) + { return(*(int *)0); } + +#undef _nc_mvcur_resume +void _nc_mvcur_resume(void) + { /* void */ } + +#undef _nc_mvcur_init +void _nc_mvcur_init(void) + { /* void */ } + +#undef _nc_mvcur_wrap +void _nc_mvcur_wrap(void) + { /* void */ } + +#undef mvcur +int mvcur( + int yold, + int xold, + int ynew, + int xnew) + { return(*(int *)0); } + +/* ./base/lib_mvwin.c */ + +#undef mvwin +int mvwin( + WINDOW *win, + int by, + int bx) + { return(*(int *)0); } + +/* ./base/lib_newterm.c */ + +#undef filter +void filter(void) + { /* void */ } + +#undef newterm +SCREEN *newterm( + char *term, + FILE *ofp, + FILE *ifp) + { return(*(SCREEN **)0); } + +/* ./base/lib_newwin.c */ + +#undef _nc_freewin +void _nc_freewin( + WINDOW *win) + { /* void */ } + +#undef newwin +WINDOW *newwin( + int num_lines, + int num_columns, + int begy, + int begx) + { return(*(WINDOW **)0); } + +#undef derwin +WINDOW *derwin( + WINDOW *orig, + int num_lines, + int num_columns, + int begy, + int begx) + { return(*(WINDOW **)0); } + +#undef subwin +WINDOW *subwin( + WINDOW *w, + int l, + int c, + int y, + int x) + { return(*(WINDOW **)0); } + +#undef _nc_makenew +WINDOW *_nc_makenew( + int num_lines, + int num_columns, + int begy, + int begx, + int flags) + { return(*(WINDOW **)0); } + +/* ./base/lib_nl.c */ + +#undef nl +int nl(void) + { return(*(int *)0); } + +#undef nonl +int nonl(void) + { return(*(int *)0); } + +/* ./base/lib_overlay.c */ + +#undef overlay +int overlay( + const WINDOW *win1, + WINDOW *win2) + { return(*(int *)0); } + +#undef overwrite +int overwrite( + const WINDOW *win1, + WINDOW *win2) + { return(*(int *)0); } + +#undef copywin +int copywin( + const WINDOW *src, + WINDOW *dst, + int sminrow, + int smincol, + int dminrow, + int dmincol, + int dmaxrow, + int dmaxcol, + int over) + { return(*(int *)0); } + +/* ./base/lib_pad.c */ + +#undef newpad +WINDOW *newpad( + int l, + int c) + { return(*(WINDOW **)0); } + +#undef subpad +WINDOW *subpad( + WINDOW *orig, + int l, + int c, + int begy, + int begx) + { return(*(WINDOW **)0); } + +#undef prefresh +int prefresh( + WINDOW *win, + int pminrow, + int pmincol, + int sminrow, + int smincol, + int smaxrow, + int smaxcol) + { return(*(int *)0); } + +#undef pnoutrefresh +int pnoutrefresh( + WINDOW *win, + int pminrow, + int pmincol, + int sminrow, + int smincol, + int smaxrow, + int smaxcol) + { return(*(int *)0); } + +#undef pechochar +int pechochar( + WINDOW *pad, + const chtype ch) + { return(*(int *)0); } + +/* ./base/lib_printw.c */ + +#undef printw +int printw( + char *fmt, + ...) + { return(*(int *)0); } + +#undef wprintw +int wprintw( + WINDOW *win, + char *fmt, + ...) + { return(*(int *)0); } + +#undef mvprintw +int mvprintw( + int y, + int x, + char *fmt, + ...) + { return(*(int *)0); } + +#undef mvwprintw +int mvwprintw( + WINDOW *win, + int y, + int x, + char *fmt, + ...) + { return(*(int *)0); } + +#undef vwprintw +int vwprintw( + WINDOW *win, + char *fmt, + va_list argp) + { return(*(int *)0); } + +/* ./base/lib_redrawln.c */ + +#undef wredrawln +int wredrawln( + WINDOW *win, + int beg, + int num) + { return(*(int *)0); } + +/* ./base/lib_refresh.c */ + +#undef wrefresh +int wrefresh( + WINDOW *win) + { return(*(int *)0); } + +#undef wnoutrefresh +int wnoutrefresh( + WINDOW *win) + { return(*(int *)0); } + +/* ./base/lib_restart.c */ + +#undef restartterm +int restartterm( + char *term, + int filenum, + int *errret) + { return(*(int *)0); } + +/* ./base/lib_scanw.c */ + +#undef vwscanw +int vwscanw( + WINDOW *win, + char *fmt, + va_list argp) + { return(*(int *)0); } + +#undef scanw +int scanw( + char *fmt, + ...) + { return(*(int *)0); } + +#undef wscanw +int wscanw( + WINDOW *win, + char *fmt, + ...) + { return(*(int *)0); } + +#undef mvscanw +int mvscanw( + int y, + int x, + char *fmt, + ...) + { return(*(int *)0); } + +#undef mvwscanw +int mvwscanw( + WINDOW *win, + int y, + int x, + char *fmt, + ...) + { return(*(int *)0); } + +/* ./base/lib_screen.c */ + +#include <sys/stat.h> +#include <time.h> + +#undef getwin +WINDOW *getwin( + FILE *filep) + { return(*(WINDOW **)0); } + +#undef putwin +int putwin( + WINDOW *win, + FILE *filep) + { return(*(int *)0); } + +#undef scr_restore +int scr_restore( + const char *file) + { return(*(int *)0); } + +#undef scr_dump +int scr_dump( + const char *file) + { return(*(int *)0); } + +#undef scr_init +int scr_init( + const char *file) + { return(*(int *)0); } + +#undef scr_set +int scr_set( + const char *file) + { return(*(int *)0); } + +/* ./base/lib_scroll.c */ + +#undef _nc_scroll_window +void _nc_scroll_window( + WINDOW *win, + int const n, + short const top, + short const bottom, + chtype blank) + { /* void */ } + +#undef wscrl +int wscrl( + WINDOW *win, + int n) + { return(*(int *)0); } + +/* ./base/lib_scrollok.c */ + +#undef scrollok +int scrollok( + WINDOW *win, + bool flag) + { return(*(int *)0); } + +/* ./base/lib_scrreg.c */ + +#undef wsetscrreg +int wsetscrreg( + WINDOW *win, + int top, + int bottom) + { return(*(int *)0); } + +/* ./base/lib_set_term.c */ + +#undef set_term +SCREEN *set_term( + SCREEN *screen) + { return(*(SCREEN **)0); } + +#undef delscreen +void delscreen( + SCREEN *sp) + { /* void */ } + +#undef _nc_setupscreen +int _nc_setupscreen( + short slines, + short const scolumns, + FILE *output) + { return(*(int *)0); } + +#undef _nc_ripoffline +int _nc_ripoffline( + int line, + int (*init)( + WINDOW *p1, + int p2)) + { return(*(int *)0); } + +#undef ripoffline +int ripoffline( + int line, + int (*init)( + WINDOW *p1, + int p2)) + { return(*(int *)0); } + +/* ./base/lib_slk.c */ + +#undef _nc_slk_format +int _nc_slk_format; + +#undef _nc_slk_initialize +int _nc_slk_initialize( + WINDOW *stwin, + int cols) + { return(*(int *)0); } + +#undef slk_restore +int slk_restore(void) + { return(*(int *)0); } + +/* ./base/lib_slkatr_set.c */ + +#undef slk_attr_set +int slk_attr_set( + const attr_t attr, + short color_pair_number, + void *opts) + { return(*(int *)0); } + +/* ./base/lib_slkatrof.c */ + +#undef slk_attroff +int slk_attroff( + const chtype attr) + { return(*(int *)0); } + +/* ./base/lib_slkatron.c */ + +#undef slk_attron +int slk_attron( + const chtype attr) + { return(*(int *)0); } + +/* ./base/lib_slkatrset.c */ + +#undef slk_attrset +int slk_attrset( + const chtype attr) + { return(*(int *)0); } + +/* ./base/lib_slkattr.c */ + +#undef slk_attr +attr_t slk_attr(void) + { return(*(attr_t *)0); } + +/* ./base/lib_slkclear.c */ + +#undef slk_clear +int slk_clear(void) + { return(*(int *)0); } + +/* ./base/lib_slkcolor.c */ + +#undef slk_color +int slk_color( + short color_pair_number) + { return(*(int *)0); } + +/* ./base/lib_slkinit.c */ + +#undef slk_init +int slk_init( + int format) + { return(*(int *)0); } + +/* ./base/lib_slklab.c */ + +#undef slk_label +char *slk_label( + int n) + { return(*(char **)0); } + +/* ./base/lib_slkrefr.c */ + +#undef slk_noutrefresh +int slk_noutrefresh(void) + { return(*(int *)0); } + +#undef slk_refresh +int slk_refresh(void) + { return(*(int *)0); } + +/* ./base/lib_slkset.c */ + +#undef slk_set +int slk_set( + int i, + const char *astr, + int format) + { return(*(int *)0); } + +/* ./base/lib_slktouch.c */ + +#undef slk_touch +int slk_touch(void) + { return(*(int *)0); } + +/* ./base/lib_touch.c */ + +#undef is_linetouched +bool is_linetouched( + WINDOW *win, + int line) + { return(*(bool *)0); } + +#undef is_wintouched +bool is_wintouched( + WINDOW *win) + { return(*(bool *)0); } + +#undef wtouchln +int wtouchln( + WINDOW *win, + int y, + int n, + int changed) + { return(*(int *)0); } + +/* ./trace/lib_traceatr.c */ + +#undef _nc_lib_traceatr +void _nc_lib_traceatr(void) + { /* void */ } + +/* ./trace/lib_tracedmp.c */ + +#undef _nc_lib_tracedmp +void _nc_lib_tracedmp(void) + { /* void */ } + +/* ./trace/lib_tracemse.c */ + +#undef _nc_lib_tracemouse +void _nc_lib_tracemouse(void) + { /* void */ } + +/* ./tty/lib_tstp.c */ + +#include <signal.h> +#include <SigAction.h> + +#undef _nc_signal_handler +void _nc_signal_handler( + bool enable) + { /* void */ } + +/* ./base/lib_ungetch.c */ + +#undef ungetch +int ungetch( + int ch) + { return(*(int *)0); } + +/* ./tty/lib_vidattr.c */ + +#undef vidputs +int vidputs( + attr_t newmode, + int (*outc)( + int p1)) + { return(*(int *)0); } + +#undef vidattr +int vidattr( + attr_t newmode) + { return(*(int *)0); } + +#undef termattrs +chtype termattrs(void) + { return(*(chtype *)0); } + +/* ./base/lib_vline.c */ + +#undef wvline +int wvline( + WINDOW *win, + chtype ch, + int n) + { return(*(int *)0); } + +/* ./base/lib_wattroff.c */ + +#undef wattr_off +int wattr_off( + WINDOW *win, + attr_t at, + void *opts) + { return(*(int *)0); } + +/* ./base/lib_wattron.c */ + +#undef wattr_on +int wattr_on( + WINDOW *win, + attr_t at, + void *opts) + { return(*(int *)0); } + +/* ./base/lib_winch.c */ + +#undef winch +chtype winch( + WINDOW *win) + { return(*(chtype *)0); } + +/* ./base/lib_window.c */ + +#undef _nc_synchook +void _nc_synchook( + WINDOW *win) + { /* void */ } + +#undef mvderwin +int mvderwin( + WINDOW *win, + int y, + int x) + { return(*(int *)0); } + +#undef syncok +int syncok( + WINDOW *win, + bool bf) + { return(*(int *)0); } + +#undef wsyncup +void wsyncup( + WINDOW *win) + { /* void */ } + +#undef wsyncdown +void wsyncdown( + WINDOW *win) + { /* void */ } + +#undef wcursyncup +void wcursyncup( + WINDOW *win) + { /* void */ } + +#undef dupwin +WINDOW *dupwin( + WINDOW *win) + { return(*(WINDOW **)0); } + +/* ./base/nc_panel.c */ + +#undef _nc_panelhook +struct panelhook *_nc_panelhook(void) + { return(*(struct panelhook **)0); } + +/* ./base/safe_sprintf.c */ + +#undef _nc_printf_string +char *_nc_printf_string( + const char *fmt, + va_list ap) + { return(*(char **)0); } + +/* ./tty/tty_update.c */ + +#include <sys/time.h> + +#undef doupdate +int doupdate(void) + { return(*(int *)0); } + +#undef _nc_outstr +void _nc_outstr( + const char *str) + { /* void */ } + +#undef _nc_scrolln +int _nc_scrolln( + int n, + int top, + int bot, + int maxy) + { return(*(int *)0); } + +#undef _nc_screen_resume +void _nc_screen_resume(void) + { /* void */ } + +#undef _nc_screen_init +void _nc_screen_init(void) + { /* void */ } + +#undef _nc_screen_wrap +void _nc_screen_wrap(void) + { /* void */ } + +#undef _nc_do_xmc_glitch +void _nc_do_xmc_glitch( + attr_t previous) + { /* void */ } + +/* ./base/memmove.c */ + +#undef _nc_memmove +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 */ + +#undef define_key +int define_key( + char *str, + int keycode) + { return(*(int *)0); } + +/* ./expanded.c */ + +#undef _nc_toggle_attr_on +void _nc_toggle_attr_on( + attr_t *S, + attr_t at) + { /* void */ } + +#undef _nc_toggle_attr_off +void _nc_toggle_attr_off( + attr_t *S, + attr_t at) + { /* void */ } + +#undef _nc_can_clear_with +int _nc_can_clear_with( + chtype ch) + { return(*(int *)0); } + +#undef _nc_DelCharCost +int _nc_DelCharCost( + int count) + { return(*(int *)0); } + +#undef _nc_InsCharCost +int _nc_InsCharCost( + int count) + { return(*(int *)0); } + +#undef _nc_UpdateAttrs +void _nc_UpdateAttrs( + chtype c) + { /* void */ } + +/* ./base/keybound.c */ + +#undef keybound +char *keybound( + int code, + int count) + { return(*(char **)0); } + +/* ./base/keyok.c */ + +#undef keyok +int keyok( + int c, + bool flag) + { return(*(int *)0); } + +/* ./base/lib_dft_fgbg.c */ + +#undef use_default_colors +int use_default_colors(void) + { return(*(int *)0); } + +/* ./base/lib_freeall.c */ + +#undef _nc_freeall +void _nc_freeall(void) + { /* void */ } + +/* ./tinfo/lib_print.c */ + +#undef mcprint +int mcprint( + char *data, + int len) + { return(*(int *)0); } + +/* ./base/resizeterm.c */ + +#undef resizeterm +int resizeterm( + int ToLines, + int ToCols) + { return(*(int *)0); } + +/* ./trace/trace_tries.c */ + +#undef _nc_trace_tries +void _nc_trace_tries( + struct tries *tree) + { /* void */ } + +/* ./trace/trace_xnames.c */ + +#include <term_entry.h> + +#undef _nc_trace_xnames +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/wresize.c */ + +#undef wresize +int wresize( + WINDOW *win, + int ToLines, + int ToCols) + { return(*(int *)0); } + +/* ./tinfo/access.c */ + +#undef _nc_access +int _nc_access( + const char *path, + int mode) + { return(*(int *)0); } + +/* ./tinfo/alloc_entry.c */ + +#undef _nc_init_entry +void _nc_init_entry( + TERMTYPE *const tp) + { /* void */ } + +#undef _nc_copy_entry +ENTRY *_nc_copy_entry( + ENTRY *oldp) + { return(*(ENTRY **)0); } + +#undef _nc_save_str +char *_nc_save_str( + const char *const string) + { return(*(char **)0); } + +#undef _nc_wrap_entry +void _nc_wrap_entry( + ENTRY *const ep) + { /* void */ } + +#undef _nc_merge_entry +void _nc_merge_entry( + TERMTYPE *const to, + TERMTYPE *const from) + { /* void */ } + +/* ./tinfo/alloc_ttype.c */ + +#undef _nc_align_termtype +void _nc_align_termtype( + TERMTYPE *to, + TERMTYPE *from) + { /* void */ } + +#undef _nc_copy_termtype +void _nc_copy_termtype( + TERMTYPE *dst, + TERMTYPE *src) + { /* void */ } + +/* ./tinfo/captoinfo.c */ + +#undef _nc_captoinfo +char *_nc_captoinfo( + const char *cap, + const char *s, + int const parametrized) + { return(*(char **)0); } + +#undef _nc_infotocap +char *_nc_infotocap( + const char *cap, + const char *str, + int const parametrized) + { return(*(char **)0); } + +/* ./codes.c */ + +#undef boolcodes +char *const boolcodes[] = {0}; +#undef numcodes +char *const numcodes[] = {0}; +#undef strcodes +char *const strcodes[] = {0}; + +/* ./comp_captab.c */ + +#include <ncurses_cfg.h> + +#undef _nc_info_hash_table +const struct name_table_entry *const _nc_info_hash_table[995] = {0}; +#undef _nc_cap_hash_table +const struct name_table_entry *const _nc_cap_hash_table[995] = {0}; +#undef _nc_capalias_table +const struct alias _nc_capalias_table[] = {0}; +#undef _nc_infoalias_table +const struct alias _nc_infoalias_table[] = {0}; + +#undef _nc_get_table +const struct name_table_entry *_nc_get_table( + bool termcap) + { return(*(const struct name_table_entry **)0); } + +#undef _nc_get_hash_table +const struct name_table_entry *const *_nc_get_hash_table( + bool termcap) + { return(*(const struct name_table_entry **)0); } + +/* ./tinfo/comp_error.c */ + +#undef _nc_suppress_warnings +bool _nc_suppress_warnings; +#undef _nc_curr_line +int _nc_curr_line; +#undef _nc_curr_col +int _nc_curr_col; + +#undef _nc_set_source +void _nc_set_source( + const char *const name) + { /* void */ } + +#undef _nc_set_type +void _nc_set_type( + const char *const name) + { /* void */ } + +#undef _nc_get_type +void _nc_get_type( + char *name) + { /* void */ } + +#undef _nc_warning +void _nc_warning( + const char *const fmt, + ...) + { /* void */ } + +#undef _nc_err_abort +void _nc_err_abort( + const char *const fmt, + ...) + { /* void */ } + +#undef _nc_syserr_abort +void _nc_syserr_abort( + const char *const fmt, + ...) + { /* void */ } + +/* ./tinfo/comp_expand.c */ + +#undef _nc_tic_expand +char *_nc_tic_expand( + const char *srcp, + bool tic_format, + bool numbers) + { return(*(char **)0); } + +/* ./tinfo/comp_hash.c */ + +#include <hashsize.h> + +#undef _nc_find_entry +struct name_table_entry const *_nc_find_entry( + const char *string, + const struct name_table_entry *const *hash_table) + { return(*(struct name_table_entry const **)0); } + +#undef _nc_find_type_entry +struct name_table_entry const *_nc_find_type_entry( + const char *string, + int type, + const struct name_table_entry *table) + { return(*(struct name_table_entry const **)0); } + +/* ./tinfo/comp_parse.c */ + +#undef _nc_check_termtype +void (*_nc_check_termtype)( + TERMTYPE *p1); +#undef _nc_head +ENTRY *_nc_head; +#undef _nc_tail +ENTRY *_nc_tail; + +#undef _nc_free_entries +void _nc_free_entries( + ENTRY *head) + { /* void */ } + +#undef _nc_entry_match +bool _nc_entry_match( + char *n1, + char *n2) + { return(*(bool *)0); } + +#undef _nc_read_entry_source +void _nc_read_entry_source( + FILE *fp, + char *buf, + int literal, + bool silent, + bool (*hook)( + ENTRY *p1)) + { /* void */ } + +#undef _nc_resolve_uses +int _nc_resolve_uses(void) + { return(*(int *)0); } + +/* ./tinfo/comp_scan.c */ + +#undef _nc_syntax +int _nc_syntax; +#undef _nc_curr_file_pos +long _nc_curr_file_pos; +#undef _nc_comment_start +long _nc_comment_start; +#undef _nc_comment_end +long _nc_comment_end; +#undef _nc_start_line +long _nc_start_line; + +#undef _nc_get_token +int _nc_get_token(void) + { return(*(int *)0); } + +#undef _nc_trans_string +char _nc_trans_string( + char *ptr) + { return(*(char *)0); } + +#undef _nc_push_token +void _nc_push_token( + int tokclass) + { /* void */ } + +#undef _nc_panic_mode +void _nc_panic_mode( + char ch) + { /* void */ } + +#undef _nc_reset_input +void _nc_reset_input( + FILE *fp, + char *buf) + { /* void */ } + +/* ./tinfo/doalloc.c */ + +#undef _nc_doalloc +void *_nc_doalloc( + void *oldp, + size_t amount) + { return(*(void **)0); } + +/* ./fallback.c */ + +#undef _nc_fallback +const TERMTYPE *_nc_fallback( + const char *name) + { return(*(const TERMTYPE **)0); } + +/* ./tinfo/free_ttype.c */ + +#undef _nc_free_termtype +void _nc_free_termtype( + TERMTYPE *ptr) + { /* void */ } + +#undef _nc_user_definable +bool _nc_user_definable; + +#undef use_extended_names +int use_extended_names( + bool flag) + { return(*(int *)0); } + +/* ./tinfo/getenv_num.c */ + +#undef _nc_getenv_num +int _nc_getenv_num( + const char *name) + { return(*(int *)0); } + +/* ./tinfo/home_terminfo.c */ + +#undef _nc_home_terminfo +char *_nc_home_terminfo(void) + { return(*(char **)0); } + +/* ./tinfo/init_keytry.c */ + +#if 0 + +#include <init_keytry.h> + +#undef _nc_tinfo_fkeys +struct tinfo_fkeys _nc_tinfo_fkeys[]; + +#endif + +#undef _nc_init_keytry +void _nc_init_keytry(void) + { /* void */ } + +/* ./tinfo/lib_acs.c */ + +#undef acs_map +chtype acs_map[128 ]; + +#undef _nc_init_acs +void _nc_init_acs(void) + { /* void */ } + +/* ./tinfo/lib_baudrate.c */ + +#include <termcap.h> + +struct speed { + speed_t s; + int sp; +}; + +#undef _nc_baudrate +int _nc_baudrate( + int OSpeed) + { return(*(int *)0); } + +#undef _nc_ospeed +int _nc_ospeed( + int BaudRate) + { return(*(int *)0); } + +#undef baudrate +int baudrate(void) + { return(*(int *)0); } + +/* ./tinfo/lib_cur_term.c */ + +#undef cur_term +TERMINAL *cur_term; + +#undef set_curterm +TERMINAL *set_curterm( + TERMINAL *term) + { return(*(TERMINAL **)0); } + +#undef del_curterm +int del_curterm( + TERMINAL *term) + { return(*(int *)0); } + +/* ./tinfo/lib_data.c */ + +#undef stdscr +WINDOW *stdscr; +#undef curscr +WINDOW *curscr; +#undef newscr +WINDOW *newscr; +#undef _nc_screen_chain +SCREEN *_nc_screen_chain; +#undef SP +SCREEN *SP; + +/* ./tinfo/lib_has_cap.c */ + +#undef has_ic +bool has_ic(void) + { return(*(bool *)0); } + +#undef has_il +bool has_il(void) + { return(*(bool *)0); } + +/* ./tinfo/lib_kernel.c */ + +#undef erasechar +char erasechar(void) + { return(*(char *)0); } + +#undef killchar +char killchar(void) + { return(*(char *)0); } + +#undef flushinp +int flushinp(void) + { return(*(int *)0); } + +/* ./lib_keyname.c */ + +#include <stdlib.h> +#include <string.h> +#include <curses.h> + +#undef _nc_key_names +const struct kn _nc_key_names[] = {0}; + +#undef keyname +char *keyname( + int c) + { return(*(char **)0); } + +/* ./tinfo/lib_longname.c */ + +#undef longname +char *longname(void) + { return(*(char **)0); } + +/* ./tinfo/lib_napms.c */ + +#undef napms +int napms( + int ms) + { return(*(int *)0); } + +/* ./tinfo/lib_options.c */ + +#undef idlok +int idlok( + WINDOW *win, + bool flag) + { return(*(int *)0); } + +#undef idcok +void idcok( + WINDOW *win, + bool flag) + { /* void */ } + +#undef halfdelay +int halfdelay( + int t) + { return(*(int *)0); } + +#undef nodelay +int nodelay( + WINDOW *win, + bool flag) + { return(*(int *)0); } + +#undef notimeout +int notimeout( + WINDOW *win, + bool f) + { return(*(int *)0); } + +#undef wtimeout +void wtimeout( + WINDOW *win, + int delay) + { /* void */ } + +#undef keypad +int keypad( + WINDOW *win, + bool flag) + { return(*(int *)0); } + +#undef meta +int meta( + WINDOW *win, + bool flag) + { return(*(int *)0); } + +#undef curs_set +int curs_set( + int vis) + { return(*(int *)0); } + +#undef typeahead +int typeahead( + int fd) + { return(*(int *)0); } + +#undef has_key +int has_key( + int keycode) + { return(*(int *)0); } + +#undef _nc_keypad +int _nc_keypad( + bool flag) + { return(*(int *)0); } + +/* ./tinfo/lib_raw.c */ + +#undef raw +int raw(void) + { return(*(int *)0); } + +#undef cbreak +int cbreak(void) + { return(*(int *)0); } + +#undef qiflush +void qiflush(void) + { /* void */ } + +#undef noraw +int noraw(void) + { return(*(int *)0); } + +#undef nocbreak +int nocbreak(void) + { return(*(int *)0); } + +#undef noqiflush +void noqiflush(void) + { /* void */ } + +#undef intrflush +int intrflush( + WINDOW *win, + bool flag) + { return(*(int *)0); } + +/* ./tinfo/lib_setup.c */ + +#include <sys/ioctl.h> + +#undef use_env +void use_env( + bool f) + { /* void */ } + +#undef LINES +int LINES; +#undef COLS +int COLS; +#undef TABSIZE +int TABSIZE; + +#undef _nc_update_screensize +void _nc_update_screensize(void) + { /* void */ } + +#undef ttytype +char ttytype[256 ]; + +#undef setupterm +int setupterm( + char *tname, + int Filedes, + int *errret) + { return(*(int *)0); } + +/* ./tinfo/lib_termcap.c */ + +#undef UP +char *UP; +#undef BC +char *BC; + +#undef tgetent +int tgetent( + char *bufp, + const char *name) + { return(*(int *)0); } + +#if 0 + +#include <capdefaults.c> + +#endif + +#undef tgetflag +int tgetflag( + char *id) + { return(*(int *)0); } + +#undef tgetnum +int tgetnum( + char *id) + { return(*(int *)0); } + +#undef tgetstr +char *tgetstr( + char *id, + char **area) + { return(*(char **)0); } + +#undef tgoto +char *tgoto( + const char *string, + int x, + int y) + { return(*(char **)0); } + +/* ./tinfo/lib_termname.c */ + +#undef termname +char *termname(void) + { return(*(char **)0); } + +/* ./tinfo/lib_ti.c */ + +#undef tigetflag +int tigetflag( + char *str) + { return(*(int *)0); } + +#undef tigetnum +int tigetnum( + char *str) + { return(*(int *)0); } + +#undef tigetstr +char *tigetstr( + char *str) + { return(*(char **)0); } + +/* ./tinfo/lib_tparm.c */ + +typedef union { + unsigned int num; + char *str; +} stack_frame; + +#undef tparm +char *tparm( + char *string, + ...) + { return(*(char **)0); } + +/* ./tinfo/lib_tputs.c */ + +#undef PC +char PC; +#undef ospeed +speed_t ospeed; +#undef _nc_nulls_sent +int _nc_nulls_sent; + +#undef delay_output +int delay_output( + int ms) + { return(*(int *)0); } + +#undef _nc_outch +int _nc_outch( + int ch) + { return(*(int *)0); } + +#undef putp +int putp( + const char *string) + { return(*(int *)0); } + +#undef tputs +int tputs( + const char *string, + int affcnt, + int (*outc)( + int p1)) + { return(*(int *)0); } + +/* ./trace/lib_trace.c */ + +#include <fcntl.h> + +#undef _nc_tracing +unsigned _nc_tracing; + +#undef trace +void trace( + const unsigned int tracelevel) + { /* void */ } + +#undef _nc_visbuf2 +const char *_nc_visbuf2( + int bufnum, + const char *buf) + { return(*(const char **)0); } + +#undef _nc_visbuf +const char *_nc_visbuf( + const char *buf) + { return(*(const char **)0); } + +/* ./trace/lib_tracebits.c */ + +#undef _nc_tracebits +char *_nc_tracebits(void) + { return(*(char **)0); } + +/* ./trace/lib_tracechr.c */ + +#undef _tracechar +char *_tracechar( + const unsigned char ch) + { return(*(char **)0); } + +/* ./tinfo/lib_ttyflags.c */ + +#undef _nc_get_tty_mode +int _nc_get_tty_mode( + struct termios *buf) + { return(*(int *)0); } + +#undef _nc_set_tty_mode +int _nc_set_tty_mode( + struct termios *buf) + { return(*(int *)0); } + +#undef def_shell_mode +int def_shell_mode(void) + { return(*(int *)0); } + +#undef def_prog_mode +int def_prog_mode(void) + { return(*(int *)0); } + +#undef reset_prog_mode +int reset_prog_mode(void) + { return(*(int *)0); } + +#undef reset_shell_mode +int reset_shell_mode(void) + { return(*(int *)0); } + +#undef savetty +int savetty(void) + { return(*(int *)0); } + +#undef resetty +int resetty(void) + { return(*(int *)0); } + +/* ./tty/lib_twait.c */ + +#undef _nc_timed_wait +int _nc_timed_wait( + int mode, + int milliseconds, + int *timeleft) + { return(*(int *)0); } + +/* ./tinfo/name_match.c */ + +#undef _nc_first_name +char *_nc_first_name( + const char *const sp) + { return(*(char **)0); } + +#undef _nc_name_match +int _nc_name_match( + const char *const namelst, + const char *const name, + const char *const delim) + { return(*(int *)0); } + +/* ./names.c */ + +#undef boolnames +char *const boolnames[] = {0}; +#undef boolfnames +char *const boolfnames[] = {0}; +#undef numnames +char *const numnames[] = {0}; +#undef numfnames +char *const numfnames[] = {0}; +#undef strnames +char *const strnames[] = {0}; +#undef strfnames +char *const strfnames[] = {0}; + +/* ./tinfo/parse_entry.c */ +#undef _nc_curr_token +struct token _nc_curr_token; + +#undef _nc_parse_entry +int _nc_parse_entry( + struct entry *entryp, + int literal, + bool silent) + { return(*(int *)0); } + +#undef _nc_capcmp +int _nc_capcmp( + const char *s, + const char *t) + { return(*(int *)0); } + +typedef struct {const char *from; const char *to;} assoc; + +/* ./tinfo/read_entry.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_read_file_entry +int _nc_read_file_entry( + const char *const filename, + TERMTYPE *ptr) + { return(*(int *)0); } + +#undef _nc_read_entry +int _nc_read_entry( + const char *const tn, + char *const filename, + TERMTYPE *const tp) + { return(*(int *)0); } + +/* ./tinfo/read_termcap.c */ + +#undef _nc_read_termcap +void _nc_read_termcap(void) + { /* void */ } + +/* ./tinfo/setbuf.c */ + +#undef _nc_set_buffer +void _nc_set_buffer( + FILE *ofp, + bool buffered) + { /* void */ } + +/* ./trace/trace_buf.c */ + +typedef struct { + char *text; + size_t size; +} LIST; + +#undef _nc_trace_buf +char *_nc_trace_buf( + int bufnum, + size_t want) + { return(*(char **)0); } + +/* ./tinfo/add_tries.c */ + +#undef _nc_add_to_try +void _nc_add_to_try( + struct tries **tree, + char *str, + unsigned short code) + { /* void */ } + +/* ./unctrl.c */ + +#undef unctrl +char *unctrl( + chtype ch) + { return(*(char **)0); } + +/* ./tinfo/write_entry.c */ + +#undef _nc_set_writedir +void _nc_set_writedir( + char *dir) + { /* void */ } + +#undef _nc_write_entry +void _nc_write_entry( + TERMTYPE *const tp) + { /* void */ } + +#undef _nc_tic_written +int _nc_tic_written(void) + { return(*(int *)0); } diff --git a/contrib/ncurses/ncurses/modules b/contrib/ncurses/ncurses/modules new file mode 100644 index 0000000..5bb8227 --- /dev/null +++ b/contrib/ncurses/ncurses/modules @@ -0,0 +1,186 @@ +# $Id: modules,v 1.69 1999/07/18 02:38:37 tom Exp $ +############################################################################## +# Copyright (c) 1998,1999 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +# +# Author: Thomas E. Dickey <dickey@clark.net> 1996,1997,1998 +# + +@ base +# Library objects +hardscroll lib $(serial) +hashmap lib $(serial) ../include/term.h +lib_addch lib $(base) +lib_addstr lib $(base) +lib_beep lib $(base) ../include/term.h +lib_bkgd lib $(base) +lib_box lib $(base) +lib_chgat lib $(base) +lib_clear lib $(base) +lib_clearok lib $(base) +lib_clrbot lib $(base) +lib_clreol lib $(base) +lib_color lib $(base) ../include/term.h +lib_colorset lib $(base) +lib_delch lib $(base) +lib_delwin lib $(base) +lib_echo lib $(base) +lib_endwin lib $(base) ../include/term.h +lib_erase lib $(base) +lib_flash lib $(base) ../include/term.h +lib_gen lib . ../include/curses.h +lib_getch lib $(base) +lib_getstr lib $(base) ../include/term.h +lib_hline lib $(base) +lib_immedok lib $(base) +lib_inchstr lib $(base) +lib_initscr lib $(base) $(INCDIR)/tic.h +lib_insch lib $(base) +lib_insdel lib $(base) +lib_insstr lib $(base) +lib_instr lib $(base) +lib_isendwin lib $(base) +lib_leaveok lib $(base) +lib_mouse lib $(base) ../include/term.h +lib_move lib $(base) +lib_mvcur lib $(serial) ../include/term.h $(INCDIR)/tic.h +lib_mvwin lib $(base) +lib_newterm lib $(base) ../include/term.h +lib_newwin lib $(base) +lib_nl lib $(base) +lib_overlay lib $(base) +lib_pad lib $(base) +lib_printw lib $(base) +lib_redrawln lib $(base) +lib_refresh lib $(base) +lib_restart lib $(base) ../include/term.h +lib_scanw lib $(base) +lib_screen lib $(base) ../include/term.h +lib_scroll lib $(base) +lib_scrollok lib $(base) +lib_scrreg lib $(base) +lib_set_term lib $(base) ../include/term.h +lib_slk lib $(base) ../include/term.h +lib_slkatr_set lib $(base) +lib_slkatrof lib $(base) +lib_slkatron lib $(base) +lib_slkatrset lib $(base) +lib_slkattr lib $(base) +lib_slkclear lib $(base) +lib_slkcolor lib $(base) +lib_slkinit lib $(base) +lib_slklab lib $(base) +lib_slkrefr lib $(base) ../include/term.h +lib_slkset lib $(base) +lib_slktouch lib $(base) +lib_touch lib $(base) +lib_traceatr lib $(trace) ../include/term.h +lib_tracedmp lib $(trace) +lib_tracemse lib $(trace) +lib_tstp lib $(serial) +lib_ungetch lib $(base) +lib_vidattr lib $(serial) ../include/term.h +lib_vline lib $(base) +lib_wattroff lib $(base) +lib_wattron lib $(base) +lib_winch lib $(base) +lib_window lib $(base) +nc_panel lib $(base) +safe_sprintf lib $(base) +tty_update lib $(serial) ../include/term.h + +# Modules for porting +memmove lib $(base) +sigaction lib $(base) +vsscanf lib $(base) + +# Extensions to the base library +@ ext_funcs +define_key lib $(base) +expanded lib . +keybound lib $(base) +keyok lib $(base) +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) +wresize lib $(base) ../include/term.h + +# Support for termcap (and tic, etc.), which can be a separate library +@ termlib +access lib $(tinfo) +add_tries lib $(tinfo) +alloc_entry lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h +alloc_ttype lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h +captoinfo lib $(tinfo) $(INCDIR)/tic.h +codes lib . +comp_captab lib . $(INCDIR)/tic.h ../include/term.h ../include/hashsize.h +comp_error lib $(tinfo) $(INCDIR)/tic.h +comp_expand lib $(tinfo) $(INCDIR)/tic.h +comp_hash lib $(tinfo) ../include/term.h $(INCDIR)/tic.h ../include/hashsize.h +comp_parse lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h +comp_scan lib $(tinfo) $(INCDIR)/tic.h +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 +getenv_num lib $(tinfo) +home_terminfo lib $(tinfo) +init_keytry lib $(tinfo) ../include/term.h $(INCDIR)/tic.h init_keytry.h +lib_acs lib $(tinfo) ../include/term.h +lib_baudrate lib $(tinfo) ../include/term.h +lib_cur_term lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h +lib_data lib $(tinfo) +lib_has_cap lib $(tinfo) ../include/term.h +lib_kernel lib $(tinfo) ../include/term.h +lib_keyname lib . ../include/term.h +lib_longname lib $(tinfo) +lib_napms lib $(tinfo) +lib_options lib $(tinfo) ../include/term.h +lib_raw lib $(tinfo) ../include/term.h +lib_setup lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h +lib_termcap lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h +lib_termname lib $(tinfo) $(INCDIR)/tic.h +lib_ti lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h +lib_tparm lib $(tinfo) ../include/term.h $(INCDIR)/tic.h +lib_tputs lib $(tinfo) ../include/term.h $(INCDIR)/tic.h +lib_trace lib $(trace) $(INCDIR)/tic.h +lib_tracebits lib $(trace) ../include/term.h +lib_tracechr lib $(trace) +lib_ttyflags lib $(tinfo) ../include/term.h +lib_twait lib $(serial) +name_match lib $(tinfo) ../include/term.h $(INCDIR)/tic.h +names lib . +parse_entry lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h ../include/parametrized.h +read_entry lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h +read_termcap lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h +setbuf lib $(tinfo) +trace_buf lib $(trace) +trace_tries lib $(trace) +unctrl lib . +write_entry lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h diff --git a/contrib/ncurses/ncurses/tinfo/MKcaptab.awk b/contrib/ncurses/ncurses/tinfo/MKcaptab.awk new file mode 100644 index 0000000..910af94 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/MKcaptab.awk @@ -0,0 +1,70 @@ +#!/bin/sh +# $Id: MKcaptab.awk,v 1.11 1999/01/24 02:46:42 Jeffrey.C.Honig Exp $ +AWK=${1-awk} +DATA=${2-../include/Caps} + +cat <<'EOF' +/* + * comp_captab.c -- The names of the capabilities indexed via a hash + * table for the compiler. + * + */ + +#include <ncurses_cfg.h> +#include <tic.h> +#include <term.h> + +EOF + +./make_hash 1 info <$DATA +./make_hash 3 cap <$DATA + +cat <<'EOF' +const struct alias _nc_capalias_table[] = +{ +EOF + +$AWK <$DATA ' +$1 == "capalias" { + if ($3 == "IGNORE") + to = "(char *)NULL"; + else + to = "\"" $3 "\""; + printf "\t{\"%s\", %s, \"%s\"},\t /* %s */\n", + $2, to, $4, $5 + } +' + +cat <<'EOF' + {(char *)NULL, (char *)NULL, (char *)NULL} +}; + +const struct alias _nc_infoalias_table[] = +{ +EOF + +$AWK <$DATA ' +$1 == "infoalias" { + if ($3 == "IGNORE") + to = "(char *)NULL"; + else + to = "\"" $3 "\""; + printf "\t{\"%s\", %s, \"%s\"},\t /* %s */\n", + $2, to, $4, $5 + } +' + +cat <<'EOF' + {(char *)NULL, (char *)NULL, (char *)NULL} +}; + +const struct name_table_entry *_nc_get_table(bool termcap) +{ + return termcap ? _nc_cap_table: _nc_info_table ; +} + +const struct name_table_entry * const * _nc_get_hash_table(bool termcap) +{ + return termcap ? _nc_cap_hash_table: _nc_info_hash_table ; +} +EOF diff --git a/contrib/ncurses/ncurses/tinfo/MKfallback.sh b/contrib/ncurses/ncurses/tinfo/MKfallback.sh new file mode 100755 index 0000000..2a76f62 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/MKfallback.sh @@ -0,0 +1,75 @@ +#!/bin/sh +# $Id: MKfallback.sh,v 1.9 1999/06/15 22:57:45 tom Exp $ +# +# MKfallback.sh -- create fallback table for entry reads +# +# This script generates source code for a custom version of read_entry.c +# that (instead of reading capabilities for an argument terminal type +# from an on-disk terminfo tree) tries to match the type with one of a +# specified list of types generated in. +# +cat <<EOF +/* + * DO NOT EDIT THIS FILE BY HAND! It is generated by MKfallback.sh. + */ + +#include <curses.priv.h> +#include <term.h> + +EOF + +if [ "$*" ] +then + cat <<EOF +#include <tic.h> + +/* fallback entries for: $* */ +EOF + for x in $* + do + echo "/* $x */" + infocmp -E $x + done + + cat <<EOF +static const TERMTYPE fallbacks[$#] = +{ +EOF + comma="" + for x in $* + do + echo "$comma /* $x */" + infocmp -e $x + comma="," + done + + cat <<EOF +}; + +EOF +fi + +cat <<EOF +const TERMTYPE *_nc_fallback(const char *name GCC_UNUSED) +{ +EOF + +if [ "$*" ] +then + cat <<EOF + const TERMTYPE *tp; + + for (tp = fallbacks; + tp < fallbacks + sizeof(fallbacks)/sizeof(TERMTYPE); + tp++) + if (_nc_name_match(tp->term_names, name, "|")) + return(tp); +EOF +else + echo " /* the fallback list is empty */"; +fi + +cat <<EOF + return((TERMTYPE *)0); +} +EOF diff --git a/contrib/ncurses/ncurses/tinfo/MKnames.awk b/contrib/ncurses/ncurses/tinfo/MKnames.awk new file mode 100644 index 0000000..b97eccc --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/MKnames.awk @@ -0,0 +1,98 @@ +# $Id: MKnames.awk,v 1.10 1999/01/16 23:36:34 tom Exp $ +BEGIN { + print "/* This file was generated by MKnames.awk */" > "namehdr" + print "" > "namehdr" + print "#include <curses.priv.h>" > "namehdr" + print "" > "namehdr" + print "#define IT NCURSES_CONST char * const" > "namehdr" + print "" > "namehdr" + print "#if BROKEN_LINKER" > "namehdr" + print "#include <term.h>" > "namehdr" + print "#define DCL(it) static IT data##it[]" > "namehdr" + print "#else" > "namehdr" + print "#define DCL(it) IT it[]" > "namehdr" + print "#endif" > "namehdr" + print "" > "namehdr" + print "/*" > "boolnames" + print " * names.c - Arrays of capability names and codes" > "boolnames" + print " *" > "boolnames" + print " */" > "boolnames" + print "" > "boolnames" + print "DCL(boolnames) = {" > "boolnames" + print "DCL(boolfnames) = {" > "boolfnames" + print "DCL(boolcodes) = {" > "boolcodes" + print "DCL(numnames) = {" > "numnames" + print "DCL(numfnames) = {" > "numfnames" + print "DCL(numcodes) = {" > "numcodes" + print "DCL(strnames) = {" > "strnames" + print "DCL(strfnames) = {" > "strfnames" + print "DCL(strcodes) = {" > "strcodes" + } + +$1 ~ /^#/ {next;} + +$1 == "SKIPWARN" {next;} + +$3 == "bool" { + printf "\t\t\"%s\",\n", $2 > "boolnames" + printf "\t\t\"%s\",\n", $1 > "boolfnames" + printf "\t\t\"%s\",\n", $4 > "boolcodes" + } + +$3 == "num" { + printf "\t\t\"%s\",\n", $2 > "numnames" + printf "\t\t\"%s\",\n", $1 > "numfnames" + printf "\t\t\"%s\",\n", $4 > "numcodes" + } + +$3 == "str" { + printf "\t\t\"%s\",\n", $2 > "strnames" + printf "\t\t\"%s\",\n", $1 > "strfnames" + printf "\t\t\"%s\",\n", $4 > "strcodes" + } + +END { + print "\t\t(NCURSES_CONST char *)0," > "boolnames" + print "};" > "boolnames" + print "" > "boolnames" + print "\t\t(NCURSES_CONST char *)0," > "boolfnames" + print "};" > "boolfnames" + print "" > "boolfnames" + print "\t\t(NCURSES_CONST char *)0," > "boolcodes" + print "};" > "boolcodes" + print "" > "boolcodes" + print "\t\t(NCURSES_CONST char *)0," > "numnames" + print "};" > "numnames" + print "" > "numnames" + print "\t\t(NCURSES_CONST char *)0," > "numfnames" + print "};" > "numfnames" + print "" > "numfnames" + print "\t\t(NCURSES_CONST char *)0," > "numcodes" + print "};" > "numcodes" + print "" > "numcodes" + print "\t\t(NCURSES_CONST char *)0," > "strnames" + print "};" > "strnames" + print "" > "strnames" + print "\t\t(NCURSES_CONST char *)0," > "strfnames" + print "};" > "strfnames" + print "" > "strfnames" + print "\t\t(NCURSES_CONST char *)0," > "strcodes" + print "};" > "strcodes" + print "" > "strcodes" + print "#if BROKEN_LINKER" > "nameftr" + print "#define FIX(it) IT *_nc_##it(void) { return data##it; }" > "nameftr" + print "FIX(boolnames)" > "nameftr" + print "FIX(boolfnames)" > "nameftr" + print "FIX(numnames)" > "nameftr" + print "FIX(numfnames)" > "nameftr" + print "FIX(strnames)" > "nameftr" + print "FIX(strfnames)" > "nameftr" + print "#endif /* BROKEN_LINKER */" > "nameftr" + print "" > "codeftr" + print "#if BROKEN_LINKER" > "codeftr" + print "#define FIX(it) IT *_nc_##it(void) { return data##it; }" > "codeftr" + print "FIX(boolcodes)" > "codeftr" + print "FIX(numcodes)" > "codeftr" + print "FIX(strcodes)" > "codeftr" + print "#endif /* BROKEN_LINKER */" > "codeftr" + } diff --git a/contrib/ncurses/ncurses/tinfo/README b/contrib/ncurses/ncurses/tinfo/README new file mode 100644 index 0000000..8b092c1 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/README @@ -0,0 +1,8 @@ +-- $Id: README,v 1.1 1998/11/07 22:59:07 tom Exp $ + +The files in this directory (tinfo) are those that support the terminfo +database and interfaces for ncurses. The terminfo library can be built +separately, as a lower-level library for ncurses, but usually is bundled. + +In addition to the standard documented interfaces, ncurses uses internal +functions which reside in tinfo to satisfy linkage requirements. diff --git a/contrib/ncurses/ncurses/tinfo/access.c b/contrib/ncurses/ncurses/tinfo/access.c new file mode 100644 index 0000000..54e5494 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/access.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1998 * + ****************************************************************************/ + + +#include <curses.priv.h> + +MODULE_ID("$Id: access.c,v 1.1 1998/07/25 20:17:09 tom Exp $") + +int _nc_access(const char *path, int mode) +{ + if (access(path, mode) < 0) { + if ((mode & W_OK) != 0 + && errno == ENOENT) { + char head[PATH_MAX]; + char *leaf = strrchr(strcpy(head, path), '/'); + if (leaf == 0) + leaf = head; + *leaf = '\0'; + if (head == leaf) + (void)strcpy(head, "."); + return access(head, R_OK|W_OK|X_OK); + } + return -1; + } + return 0; +} diff --git a/contrib/ncurses/ncurses/tinfo/add_tries.c b/contrib/ncurses/ncurses/tinfo/add_tries.c new file mode 100644 index 0000000..95a9e96 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/add_tries.c @@ -0,0 +1,124 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1998 * + ****************************************************************************/ + +/* +** add_tries.c +** +** Add keycode/string to tries-tree. +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: add_tries.c,v 1.1 1998/11/08 00:04:18 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)) + +void _nc_add_to_try(struct tries **tree, char *str, unsigned short code) +{ + static bool out_of_memory = FALSE; + struct tries *ptr, *savedptr; + unsigned char *txt = (unsigned char *)str; + + if (txt == 0 || *txt == '\0' || out_of_memory || code == 0) + return; + + if ((*tree) != 0) { + ptr = savedptr = (*tree); + + for (;;) { + unsigned char cmp = *txt; + + while (!CMP_TRY(ptr->ch, cmp) + && ptr->sibling != 0) + ptr = ptr->sibling; + + if (CMP_TRY(ptr->ch, cmp)) { + if (*(++txt) == '\0') { + ptr->value = code; + return; + } + if (ptr->child != 0) + ptr = ptr->child; + else + break; + } else { + if ((ptr->sibling = typeCalloc(struct tries,1)) == 0) { + out_of_memory = TRUE; + return; + } + + savedptr = ptr = ptr->sibling; + SET_TRY(ptr,txt); + ptr->value = 0; + + break; + } + } /* end for (;;) */ + } else { /* (*tree) == 0 :: First sequence to be added */ + savedptr = ptr = (*tree) = typeCalloc(struct tries,1); + + if (ptr == 0) { + out_of_memory = TRUE; + return; + } + + SET_TRY(ptr,txt); + ptr->value = 0; + } + + /* at this point, we are adding to the try. ptr->child == 0 */ + + while (*txt) { + ptr->child = typeCalloc(struct tries,1); + + ptr = ptr->child; + + if (ptr == 0) { + out_of_memory = TRUE; + + while ((ptr = savedptr) != 0) { + savedptr = ptr->child; + free(ptr); + } + + return; + } + + SET_TRY(ptr,txt); + ptr->value = 0; + } + + ptr->value = code; + return; +} diff --git a/contrib/ncurses/ncurses/tinfo/alloc_entry.c b/contrib/ncurses/ncurses/tinfo/alloc_entry.c new file mode 100644 index 0000000..570b48a --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/alloc_entry.c @@ -0,0 +1,225 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * alloc_entry.c -- allocation functions for terminfo entries + * + * _nc_copy_entry() + * _nc_init_entry() + * _nc_merge_entry() + * _nc_save_str() + * _nc_wrap_entry() + * + */ + +#include <curses.priv.h> + +#include <tic.h> +#include <term_entry.h> + +MODULE_ID("$Id: alloc_entry.c,v 1.30 1999/03/01 02:03:45 tom Exp $") + +#define ABSENT_OFFSET -1 +#define CANCELLED_OFFSET -2 + +#define MAX_STRTAB 4096 /* documented maximum entry size */ + +static char stringbuf[MAX_STRTAB]; /* buffer for string capabilities */ +static size_t next_free; /* next free character in stringbuf */ + +void _nc_init_entry(TERMTYPE *const tp) +/* initialize a terminal type data block */ +{ +int i; + +#if NCURSES_XNAMES + tp->num_Booleans = BOOLCOUNT; + tp->num_Numbers = NUMCOUNT; + tp->num_Strings = STRCOUNT; + tp->ext_Booleans = 0; + tp->ext_Numbers = 0; + tp->ext_Strings = 0; +#endif + if (tp->Booleans == 0) + tp->Booleans = typeMalloc(char,BOOLCOUNT); + if (tp->Numbers == 0) + tp->Numbers = typeMalloc(short,NUMCOUNT); + if (tp->Strings == 0) + tp->Strings = typeMalloc(char *,STRCOUNT); + + for_each_boolean(i,tp) + tp->Booleans[i] = FALSE; + + for_each_number(i,tp) + tp->Numbers[i] = ABSENT_NUMERIC; + + for_each_string(i,tp) + tp->Strings[i] = ABSENT_STRING; + + next_free = 0; +} + +ENTRY *_nc_copy_entry(ENTRY *oldp) +{ + ENTRY *newp = typeCalloc(ENTRY,1); + + if (newp != 0) { + *newp = *oldp; + _nc_copy_termtype(&(newp->tterm), &(oldp->tterm)); + } + return newp; +} + +char *_nc_save_str(const char *const string) +/* save a copy of string in the string buffer */ +{ +size_t old_next_free = next_free; +size_t len = strlen(string) + 1; + + 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; + } + return(stringbuf + old_next_free); +} + +void _nc_wrap_entry(ENTRY *const ep) +/* copy the string parts to allocated storage, preserving pointers to it */ +{ +int offsets[MAX_ENTRY_SIZE/2], useoffsets[MAX_USES]; +int i, n; +TERMTYPE *tp = &(ep->tterm); + + n = tp->term_names - stringbuf; + for_each_string(i, &(ep->tterm)) { + if (tp->Strings[i] == ABSENT_STRING) + offsets[i] = ABSENT_OFFSET; + else if (tp->Strings[i] == CANCELLED_STRING) + offsets[i] = CANCELLED_OFFSET; + else + offsets[i] = tp->Strings[i] - stringbuf; + } + + for (i=0; i < ep->nuses; i++) { + if (ep->uses[i].parent == (void *)0) + useoffsets[i] = ABSENT_OFFSET; + else + useoffsets[i] = (char *)(ep->uses[i].parent) - stringbuf; + } + + if ((tp->str_table = typeMalloc(char, next_free)) == (char *)0) + _nc_err_abort("Out of memory"); + (void) memcpy(tp->str_table, stringbuf, next_free); + + tp->term_names = tp->str_table + n; + for_each_string(i, &(ep->tterm)) { + if (offsets[i] == ABSENT_OFFSET) + tp->Strings[i] = ABSENT_STRING; + else if (offsets[i] == CANCELLED_OFFSET) + tp->Strings[i] = CANCELLED_STRING; + else + tp->Strings[i] = tp->str_table + offsets[i]; + } + +#if NCURSES_XNAMES + if ((n = NUM_EXT_NAMES(tp)) != 0) { + unsigned length = 0; + for (i = 0; i < n; i++) { + length += strlen(tp->ext_Names[i]) + 1; + offsets[i] = tp->ext_Names[i] - stringbuf; + } + if ((tp->ext_str_table = typeMalloc(char, length)) == 0) + _nc_err_abort("Out of memory"); + for (i = 0, length = 0; i < n; i++) { + tp->ext_Names[i] = tp->ext_str_table + length; + strcpy(tp->ext_Names[i], stringbuf + offsets[i]); + length += strlen(tp->ext_Names[i]) + 1; + } + } +#endif + + for (i=0; i < ep->nuses; i++) { + if (useoffsets[i] == ABSENT_OFFSET) + ep->uses[i].parent = (void *)0; + else + ep->uses[i].parent = (char *)(tp->str_table + useoffsets[i]); + } +} + +void _nc_merge_entry(TERMTYPE *const to, TERMTYPE *const from) +/* merge capabilities from `from' entry into `to' entry */ +{ + int i; + +#if NCURSES_XNAMES + _nc_align_termtype(to, from); +#endif + for_each_boolean(i, from) + { + int mergebool = from->Booleans[i]; + + 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 (mergenum == CANCELLED_NUMERIC) + to->Numbers[i] = ABSENT_NUMERIC; + else if (mergenum != ABSENT_NUMERIC) + to->Numbers[i] = mergenum; + } + + /* + * Note: the copies of strings this makes don't have their own + * storage. This is OK right now, but will be a problem if we + * we ever want to deallocate entries. + */ + for_each_string(i, from) + { + char *mergestring = from->Strings[i]; + + if (mergestring == CANCELLED_STRING) + to->Strings[i] = ABSENT_STRING; + else if (mergestring != ABSENT_STRING) + to->Strings[i] = mergestring; + } +} diff --git a/contrib/ncurses/ncurses/tinfo/alloc_ttype.c b/contrib/ncurses/ncurses/tinfo/alloc_ttype.c new file mode 100644 index 0000000..a1bf9b0 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/alloc_ttype.c @@ -0,0 +1,461 @@ +/**************************************************************************** + * Copyright (c) 1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + ****************************************************************************/ + + +/* + * align_ttype.c -- functions for TERMTYPE + * + * _nc_align_termtype() + * _nc_copy_termtype() + * + */ + +#include <curses.priv.h> + +#include <tic.h> +#include <term_entry.h> + +MODULE_ID("$Id: alloc_ttype.c,v 1.6 1999/03/01 22:10:44 tom Exp $") + +#if NCURSES_XNAMES +/* + * Merge the a/b lists into dst. Both a/b are sorted (see _nc_extend_names()), + * so we do not have to worry about order dependencies. + */ +static int merge_names(char **dst, char **a, int na, char **b, int nb) +{ + int n = 0; + while (na && nb) { + int cmp = strcmp(*a, *b); + if (cmp < 0) { + dst[n++] = *a++; + na--; + } else if (cmp > 0) { + dst[n++] = *b++; + nb--; + } else if (cmp == 0) { + dst[n++] = *a; + a++, b++; + na--, nb--; + } + } + while (na-- > 0) { + dst[n++] = *a++; + } + while (nb-- > 0) { + dst[n++] = *b++; + } + DEBUG(4, ("merge_names -> %d", n)); + return n; +} + +static bool find_name(char **table, int length, char *name) +{ + while (length-- > 0) { + if (!strcmp(*table++, name)) { + DEBUG(4, ("found name '%s'", name)); + return TRUE; + } + } + DEBUG(4, ("did not find name '%s'", name)); + return FALSE; +} + +static void realign_data(TERMTYPE *to, char **ext_Names, int ext_Booleans, int ext_Numbers, int ext_Strings) +{ + int n, m, base; + int limit = (to->ext_Booleans + to->ext_Numbers + to->ext_Strings); + + if (to->ext_Booleans != ext_Booleans) { + to->num_Booleans += (ext_Booleans - to->ext_Booleans); + to->Booleans = typeRealloc(char, to->num_Booleans, to->Booleans); + for (n = to->ext_Booleans-1, + m = ext_Booleans-1, + base = to->num_Booleans - (m+1); m >= 0; m--) { + if (find_name(to->ext_Names, limit, ext_Names[m])) { + to->Booleans[base + m] = to->Booleans[base + n--]; + } else { + to->Booleans[base + m] = FALSE; + } + } + to->ext_Booleans = ext_Booleans; + } + if (to->ext_Numbers != ext_Numbers) { + to->num_Numbers += (ext_Numbers - to->ext_Numbers); + to->Numbers = typeRealloc(short, to->num_Numbers, to->Numbers); + for (n = to->ext_Numbers-1, + m = ext_Numbers-1, + base = to->num_Numbers - (m+1); m >= 0; m--) { + if (find_name(to->ext_Names, limit, ext_Names[m+ext_Booleans])) { + to->Numbers[base + m] = to->Numbers[base + n--]; + } else { + to->Numbers[base + m] = ABSENT_NUMERIC; + } + } + to->ext_Numbers = ext_Numbers; + } + if (to->ext_Strings != ext_Strings) { + to->num_Strings += (ext_Strings - to->ext_Strings); + to->Strings = typeRealloc(char*, to->num_Strings, to->Strings); + for (n = to->ext_Strings-1, + m = ext_Strings-1, + base = to->num_Strings - (m+1); m >= 0; m--) { + if (find_name(to->ext_Names, limit, ext_Names[m+ext_Booleans+ext_Numbers])) { + to->Strings[base + m] = to->Strings[base + n--]; + } else { + to->Strings[base + m] = ABSENT_STRING; + } + } + to->ext_Strings = ext_Strings; + } +} + +/* + * Returns the first index in ext_Names[] for the given token-type + */ +static int _nc_first_ext_name(TERMTYPE *tp, int token_type) +{ + int first; + + switch (token_type) { + case BOOLEAN: + first = 0; + break; + case NUMBER: + first = tp->ext_Booleans; + break; + case STRING: + first = tp->ext_Booleans + tp->ext_Numbers; + break; + default: + first = 0; + break; + } + return first; +} + +/* + * Returns the last index in ext_Names[] for the given token-type + */ +static int _nc_last_ext_name(TERMTYPE *tp, int token_type) +{ + int last; + + switch (token_type) { + case BOOLEAN: + last = tp->ext_Booleans; + break; + case NUMBER: + last = tp->ext_Booleans + tp->ext_Numbers; + break; + default: + case STRING: + last = NUM_EXT_NAMES(tp); + break; + } + return last; +} + +/* + * Lookup an entry from extended-names, returning -1 if not found + */ +static int _nc_find_ext_name(TERMTYPE *tp, char *name, int token_type) +{ + unsigned j; + unsigned first = _nc_first_ext_name(tp, token_type); + unsigned last = _nc_last_ext_name(tp, token_type); + + for (j = first; j < last; j++) { + if (!strcmp(name, tp->ext_Names[j])) { + return j; + } + } + return -1; +} + +/* + * Translate an index into ext_Names[] into the corresponding index into data + * (e.g., Booleans[]). + */ +static int _nc_ext_data_index(TERMTYPE *tp, int n, int token_type) +{ + switch (token_type) { + case BOOLEAN: + n += (tp->num_Booleans - tp->ext_Booleans); + break; + case NUMBER: + n += (tp->num_Numbers - tp->ext_Numbers) + - (tp->ext_Booleans); + break; + default: + case STRING: + n += (tp->num_Strings - tp->ext_Strings) + - (tp->ext_Booleans + tp->ext_Numbers); + } + return n; +} + +/* + * Adjust tables to remove (not free) an extended name and its corresponding + * data. + */ +static void _nc_del_ext_name(TERMTYPE *tp, char *name, int token_type) +{ + int j; + int first, last; + + if ((first = _nc_find_ext_name(tp, name, token_type)) >= 0) { + last = NUM_EXT_NAMES(tp) - 1; + for (j = first; j < last; j++) { + tp->ext_Names[j] = tp->ext_Names[j+1]; + } + first = _nc_ext_data_index(tp, first, token_type); + switch (token_type) { + case BOOLEAN: + last = tp->num_Booleans - 1; + for (j = first; j < last; j++) + tp->Booleans[j] = tp->Booleans[j+1]; + tp->ext_Booleans -= 1; + tp->num_Booleans -= 1; + break; + case NUMBER: + last = tp->num_Numbers - 1; + for (j = first; j < last; j++) + tp->Numbers[j] = tp->Numbers[j+1]; + tp->ext_Numbers -= 1; + tp->num_Numbers -= 1; + break; + case STRING: + last = tp->num_Strings - 1; + for (j = first; j < last; j++) + tp->Strings[j] = tp->Strings[j+1]; + tp->ext_Strings -= 1; + tp->num_Strings -= 1; + break; + } + } +} + +/* + * Adjust tables to insert an extended name, making room for new data. The + * index into the corresponding data array is returned. + */ +static int _nc_ins_ext_name(TERMTYPE *tp, char *name, int token_type) +{ + unsigned first = _nc_first_ext_name(tp, token_type); + unsigned last = _nc_last_ext_name(tp, token_type); + unsigned total = NUM_EXT_NAMES(tp) + 1; + unsigned j, k; + + for (j = first; j < last; j++) { + int cmp = strcmp(name, tp->ext_Names[j]); + if (cmp == 0) + /* already present */ + return _nc_ext_data_index(tp, j, token_type); + if (cmp < 0) { + break; + } + } + + tp->ext_Names = typeRealloc(char *, total, tp->ext_Names); + for (k = total-1; k > j; k--) + tp->ext_Names[k] = tp->ext_Names[k-1]; + tp->ext_Names[j] = name; + j = _nc_ext_data_index(tp, 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); + for (k = tp->num_Booleans-1; k > j; k--) + tp->Booleans[k] = tp->Booleans[k-1]; + break; + case NUMBER: + tp->ext_Numbers += 1; + tp->num_Numbers += 1; + tp->Numbers = typeRealloc(short, tp->num_Numbers, tp->Numbers); + for (k = tp->num_Numbers-1; k > j; k--) + tp->Numbers[k] = tp->Numbers[k-1]; + break; + case STRING: + tp->ext_Strings += 1; + tp->num_Strings += 1; + tp->Strings = typeRealloc(char *, tp->num_Strings, tp->Strings); + for (k = tp->num_Strings-1; k > j; k--) + tp->Strings[k] = tp->Strings[k-1]; + break; + } + return j; +} + +/* + * Look for strings that are marked cancelled, which happen to be the same name + * as a boolean or number. We'll get this as a special case when we get a + * cancellation of a name that is inherited from another entry. + */ +static void adjust_cancels(TERMTYPE *to, TERMTYPE *from) +{ + int first = to->ext_Booleans + to->ext_Numbers; + int last = first + to->ext_Strings; + int j, k; + + for (j = first; j < last; ) { + char *name = to->ext_Names[j]; + unsigned j_str = to->num_Strings - first - to->ext_Strings; + + if (to->Strings[j + j_str] == CANCELLED_STRING) { + if ((k = _nc_find_ext_name(from, to->ext_Names[j], BOOLEAN)) >= 0) { + _nc_del_ext_name(to, name, STRING); + k = _nc_ins_ext_name(to, name, BOOLEAN); + to->Booleans[k] = FALSE; + } else if ((k = _nc_find_ext_name(from, to->ext_Names[j], NUMBER)) >= 0) { + _nc_del_ext_name(to, name, STRING); + k = _nc_ins_ext_name(to, name, NUMBER); + to->Numbers[k] = CANCELLED_NUMERIC; + } + } else { + j++; + } + } +} + +void _nc_align_termtype(TERMTYPE *to, TERMTYPE *from) +{ + int na = NUM_EXT_NAMES(to); + int nb = NUM_EXT_NAMES(from); + int n; + bool same; + char **ext_Names; + int ext_Booleans, ext_Numbers, ext_Strings; + + DEBUG(2, ("align_termtype to(%d:%s), from(%d:%s)", na, to->term_names, nb, from->term_names)); + + if (na != 0 || nb != 0) { + if ((na == nb) /* check if the arrays are equivalent */ + && (to->ext_Booleans == from->ext_Booleans) + && (to->ext_Numbers == from->ext_Numbers) + && (to->ext_Strings == from->ext_Strings)) { + for (n = 0, same = TRUE; n < na; n++) { + if (strcmp(to->ext_Names[n], from->ext_Names[n])) { + same = FALSE; + break; + } + } + if (same) + return; + } + /* + * This is where we pay for having a simple extension representation. + * Allocate a new ext_Names array and merge the two ext_Names arrays + * into it, updating to's counts for booleans, etc. Fortunately we do + * this only for the terminfo compiler (tic) and comparer (infocmp). + */ + ext_Names = typeMalloc(char *, na+nb); + + if (to->ext_Strings && (from->ext_Booleans + from->ext_Numbers)) + adjust_cancels(to, from); + + if (from->ext_Strings && (to->ext_Booleans + to->ext_Numbers)) + adjust_cancels(from, to); + + ext_Booleans = merge_names(ext_Names, + to->ext_Names, + to->ext_Booleans, + from->ext_Names, + from->ext_Booleans); + ext_Numbers = merge_names(ext_Names + ext_Booleans, + to->ext_Names + + to->ext_Booleans, + to->ext_Numbers, + from->ext_Names + + from->ext_Booleans, + from->ext_Numbers); + ext_Strings = merge_names(ext_Names + ext_Numbers + ext_Booleans, + to->ext_Names + + to->ext_Booleans + + to->ext_Numbers, + to->ext_Strings, + from->ext_Names + + from->ext_Booleans + + from->ext_Numbers, + from->ext_Strings); + /* + * Now we must reallocate the Booleans, etc., to allow the data to be + * overlaid. + */ + if (na != (ext_Booleans + ext_Numbers + ext_Strings)) { + realign_data(to, ext_Names, ext_Booleans, ext_Numbers, ext_Strings); + free(to->ext_Names); + to->ext_Names = ext_Names; + DEBUG(2, ("realigned %d extended names for '%s' (to)", NUM_EXT_NAMES(to), to->term_names)); + } + if (nb != (ext_Booleans + ext_Numbers + ext_Strings)) { + nb = (ext_Booleans + ext_Numbers + ext_Strings); + realign_data(from, ext_Names, ext_Booleans, ext_Numbers, ext_Strings); + from->ext_Names = typeRealloc(char *, nb, from->ext_Names); + memcpy(from->ext_Names, ext_Names, sizeof(char *) * nb); + DEBUG(2, ("realigned %d extended names for '%s' (from)", NUM_EXT_NAMES(from), from->term_names)); + } + } +} +#endif + +void _nc_copy_termtype(TERMTYPE *dst, TERMTYPE *src) +{ + int i; + + *dst = *src; /* ...to copy the sizes and string-tables */ + dst->Booleans = typeMalloc(char, NUM_BOOLEANS(dst)); + dst->Numbers = typeMalloc(short, NUM_NUMBERS(dst)); + dst->Strings = typeMalloc(char *, NUM_STRINGS(dst)); + + /* FIXME: use memcpy for these and similar loops */ + for_each_boolean(i,dst) + dst->Booleans[i] = src->Booleans[i]; + for_each_number(i,dst) + dst->Numbers[i] = src->Numbers[i]; + for_each_string(i,dst) + dst->Strings[i] = src->Strings[i]; + + /* FIXME: we probably should also copy str_table and ext_str_table, + * but tic and infocmp are not written to exploit that (yet). + */ + +#if NCURSES_XNAMES + if ((i = NUM_EXT_NAMES(src)) != 0) { + dst->ext_Names = typeMalloc(char *, i); + memcpy(dst->ext_Names, src->ext_Names, i * sizeof(char *)); + } +#endif + +} diff --git a/contrib/ncurses/ncurses/tinfo/captoinfo.c b/contrib/ncurses/ncurses/tinfo/captoinfo.c new file mode 100644 index 0000000..d0881ec --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/captoinfo.c @@ -0,0 +1,807 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* + * captoinfo.c --- conversion between termcap and terminfo formats + * + * The captoinfo() code was swiped from Ross Ridge's mytinfo package, + * adapted to fit ncurses by Eric S. Raymond <esr@snark.thyrsus.com>. + * + * There is just one entry point: + * + * char *captoinfo(n, s, parametrized) + * + * Convert value s for termcap string capability named n into terminfo + * format. + * + * This code recognizes all the standard 4.4BSD %-escapes: + * + * %% output `%' + * %d output value as in printf %d + * %2 output value as in printf %2d + * %3 output value as in printf %3d + * %. output value as in printf %c + * %+x add x to value, then do %. + * %>xy if value > x then add y, no output + * %r reverse order of two parameters, no output + * %i increment by one, no output + * %n exclusive-or all parameters with 0140 (Datamedia 2500) + * %B BCD (16*(value/10)) + (value%10), no output + * %D Reverse coding (value - 2*(value%16)), no output (Delta Data). + * + * Also, %02 and %03 are accepted as synonyms for %2 and %3. + * + * Besides all the standard termcap escapes, this translator understands + * the following extended escapes: + * + * used by GNU Emacs termcap libraries + * %a[+*-/=][cp]x GNU arithmetic. + * %m xor the first two parameters by 0177 + * %b backup to previous parameter + * %f skip this parameter + * + * used by the University of Waterloo (MFCF) termcap libraries + * %-x subtract parameter FROM char x and output it as a char + * %ax add the character x to parameter + * + * If #define WATERLOO is on, also enable these translations: + * + * %sx subtract parameter FROM the character x + * + * By default, this Waterloo translations are not compiled in, because + * the Waterloo %s conflicts with the way terminfo uses %s in strings for + * function programming. + * + * Note the two definitions of %a: the GNU definition is translated if the + * characters after the 'a' are valid for it, otherwise the UW definition + * is translated. + */ + +#include <curses.priv.h> + +#include <ctype.h> +#include <tic.h> + +MODULE_ID("$Id: captoinfo.c,v 1.24 1999/07/24 20:06:13 tom Exp $") + +#define MAX_PUSHED 16 /* max # args we can push onto the stack */ +#define MAX_ENTRY 2048 /* maximum chars in a translated capability */ + +static int stack[MAX_PUSHED]; /* the stack */ +static int stackptr; /* the next empty place on the stack */ +static int onstack; /* the top of stack */ +static int seenm; /* seen a %m */ +static int seenn; /* seen a %n */ +static int seenr; /* seen a %r */ +static int param; /* current parameter */ +static char *dp; /* pointer to end of the converted string */ + +static char *my_string; +static size_t my_length; + +static char *init_string(void) +/* initialize 'my_string', 'my_length' */ +{ + if (my_string == 0) + my_string = typeMalloc(char, my_length = 256); + if (my_string == 0) + _nc_err_abort("Out of memory"); + + *my_string = '\0'; + return my_string; +} + +static char *save_string(char *d, const char *const s) +{ + size_t have = (d - my_string); + size_t need = have + strlen(s) + 2; + if (need > my_length) { + my_string = (char *)realloc(my_string, my_length = (need + need)); + if (my_string == 0) + _nc_err_abort("Out of memory"); + d = my_string + have; + } + (void) strcpy(d, s); + return d + strlen(d); +} + +static inline char *save_char(char *s, char c) +{ + static char temp[2]; + temp[0] = c; + return save_string(s, temp); +} + +static void push(void) +/* push onstack on to the stack */ +{ + if (stackptr > MAX_PUSHED) + _nc_warning("string too complex to convert"); + else + stack[stackptr++] = onstack; +} + +static void pop(void) +/* pop the top of the stack into onstack */ +{ + if (stackptr == 0) { + if (onstack == 0) + _nc_warning("I'm confused"); + else + onstack = 0; + } + else + onstack = stack[--stackptr]; + param++; +} + +static int cvtchar(register const char *sp) +/* convert a character to a terminfo push */ +{ + unsigned char c = 0; + int len; + + switch(*sp) { + case '\\': + switch(*++sp) { + case '\'': + case '$': + case '\\': + case '%': + c = *sp; + len = 2; + break; + case '\0': + c = '\\'; + len = 1; + break; + case '0': + case '1': + case '2': + case '3': + len = 1; + while (isdigit(*sp)) + { + c = 8 * c + (*sp++ - '0'); + len++; + } + break; + default: + c = *sp; + len = 2; + break; + } + break; + case '^': + c = (*++sp & 0x1f); + len = 2; + break; + default: + c = *sp; + len = 1; + } + if (isgraph(c) && c != ',' && c != '\'' && c != '\\' && c != ':') { + *dp++ = '%'; *dp++ = '\''; *dp++ = c; *dp++ = '\''; + } else { + *dp++ = '%'; *dp++ = '{'; + if (c > 99) + *dp++ = c / 100 + '0'; + if (c > 9) + *dp++ = ((int)(c / 10)) % 10 + '0'; + *dp++ = c % 10 + '0'; + *dp++ = '}'; + } + return len; +} + +static void getparm(int parm, int n) +/* push n copies of param on the terminfo stack if not already there */ +{ + if (seenr) { + if (parm == 1) + parm = 2; + else if (parm == 2) + parm = 1; + } + if (onstack == parm) { + if (n > 1) { + _nc_warning("string may not be optimal"); + *dp++ = '%'; *dp++ = 'P'; *dp++ = 'a'; + while(n--) { + *dp++ = '%'; *dp++ = 'g'; *dp++ = 'a'; + } + } + return; + } + if (onstack != 0) + push(); + + onstack = parm; + + while(n--) { /* %p0 */ + *dp++ = '%'; *dp++ = 'p'; *dp++ = '0' + parm; + } + + if (seenn && parm < 3) { /* %{96}%^ */ + *dp++ = '%'; *dp++ = '{'; *dp++ = '9'; *dp++ = '6'; *dp++ = '}'; + *dp++ = '%'; *dp++ = '^'; + } + + if (seenm && parm < 3) { /* %{127}%^ */ + *dp++ = '%'; *dp++ = '{'; *dp++ = '1'; *dp++ = '2'; *dp++ = '7'; + *dp++ = '}'; *dp++ = '%'; *dp++ = '^'; + } +} + +char *_nc_captoinfo( +/* convert a termcap string to terminfo format */ +register const char *cap, /* relevant terminfo capability index */ +register const char *s, /* string value of the capability */ +int const parametrized) /* do % translations if 1, pad translations if >=0 */ +{ + static char line[MAX_ENTRY]; + const char *capstart; + + stackptr = 0; + onstack = 0; + seenm = 0; + seenn = 0; + seenr = 0; + param = 1; + + dp = line; + + /* skip the initial padding (if we haven't been told not to) */ + capstart = 0; + if (s == 0) + s = ""; + if (parametrized >= 0 && isdigit(*s)) + for (capstart = s; ; s++) + if (!(isdigit(*s) || *s == '*' || *s == '.')) + break; + + while(*s != '\0') { + switch(*s) { + case '%': + s++; + if (parametrized < 1) { + *dp++ = '%'; + break; + } + switch(*s++) { + case '%': *dp++ = '%'; break; + case 'r': + if (seenr++ == 1) { + _nc_warning("saw %%r twice in %s", cap); + } + break; + case 'm': + if (seenm++ == 1) { + _nc_warning("saw %%m twice in %s", cap); + } + break; + case 'n': + if (seenn++ == 1) { + _nc_warning("saw %%n twice in %s", cap); + } + break; + case 'i': *dp++ = '%'; *dp++ = 'i'; break; + case '6': + case 'B': + getparm(param, 2); + /* %{6}%*%+ */ + *dp++ = '%'; *dp++ = '{'; *dp++ = '6'; + *dp++ = '}'; *dp++ = '%'; *dp++ = '*'; + *dp++ = '%'; *dp++ = '+'; + break; + case '8': + case 'D': + getparm(param, 2); + /* %{2}%*%- */ + *dp++ = '%'; *dp++ = '{'; *dp++ = '2'; + *dp++ = '}'; *dp++ = '%'; *dp++ = '*'; + *dp++ = '%'; *dp++ = '-'; + break; + case '>': + getparm(param, 2); + /* %?%{x}%>%t%{y}%+%; */ + *dp++ = '%'; *dp++ = '?'; + s += cvtchar(s); + *dp++ = '%'; *dp++ = '>'; + *dp++ = '%'; *dp++ = 't'; + s += cvtchar(s); + *dp++ = '%'; *dp++ = '+'; + *dp++ = '%'; *dp++ = ';'; + break; + case 'a': + if ((*s == '=' || *s == '+' || *s == '-' + || *s == '*' || *s == '/') + && (s[1] == 'p' || s[1] == 'c') + && s[2] != '\0') { + int l; + l = 2; + if (*s != '=') + getparm(param, 1); + if (s[1] == 'p') { + getparm(param + s[2] - '@', 1); + if (param != onstack) { + pop(); + param--; + } + l++; + } else + l += cvtchar(s + 2); + switch(*s) { + case '+': + *dp++ = '%'; *dp++ = '+'; + break; + case '-': + *dp++ = '%'; *dp++ = '-'; + break; + case '*': + *dp++ = '%'; *dp++ = '*'; + break; + case '/': + *dp++ = '%'; *dp++ = '/'; + break; + case '=': + if (seenr) { + if (param == 1) + onstack = 2; + else if (param == 2) + onstack = 1; + else + onstack = param; + } + else + onstack = param; + break; + } + s += l; + break; + } + getparm(param, 1); + s += cvtchar(s); + *dp++ = '%'; *dp++ = '+'; + break; + case '+': + getparm(param, 1); + s += cvtchar(s); + *dp++ = '%'; *dp++ = '+'; + *dp++ = '%'; *dp++ = 'c'; + pop(); + break; + case 's': +#ifdef WATERLOO + s += cvtchar(s); + getparm(param, 1); + *dp++ = '%'; *dp++ = '-'; +#else + getparm(param, 1); + *dp++ = '%'; *dp++ = 's'; + pop(); +#endif /* WATERLOO */ + break; + case '-': + s += cvtchar(s); + getparm(param, 1); + *dp++ = '%'; *dp++ = '-'; + *dp++ = '%'; *dp++ = 'c'; + pop(); + break; + case '.': + getparm(param, 1); + *dp++ = '%'; *dp++ = 'c'; + pop(); + break; + case '0': /* not clear any of the historical termcaps did this */ + if (*s == '3') + goto see03; + else if (*s != '2') + goto invalid; + /* FALLTHRU */ + case '2': + getparm(param, 1); + *dp++ = '%'; /* *dp++ = '0'; */ + *dp++ = '2'; *dp++ = 'd'; + pop(); + break; + case '3': see03: + getparm(param, 1); + *dp++ = '%'; /* *dp++ = '0'; */ + *dp++ = '3'; *dp++ = 'd'; + pop(); + break; + case 'd': + getparm(param, 1); + *dp++ = '%'; *dp++ = 'd'; + pop(); + break; + case 'f': + param++; + break; + case 'b': + param--; + break; + case '\\': + *dp++ = '%'; + *dp++ = '\\'; + break; + default: invalid: + *dp++ = '%'; + s--; + _nc_warning("unknown %% code %s in %s", + _tracechar(*s), cap); + break; + } + break; +#ifdef REVISIBILIZE + case '\\': + *dp++ = *s++; *dp++ = *s++; break; + case '\n': + *dp++ = '\\'; *dp++ = 'n'; s++; break; + case '\t': + *dp++ = '\\'; *dp++ = 't'; s++; break; + case '\r': + *dp++ = '\\'; *dp++ = 'r'; s++; break; + case '\200': + *dp++ = '\\'; *dp++ = '0'; s++; break; + case '\f': + *dp++ = '\\'; *dp++ = 'f'; s++; break; + case '\b': + *dp++ = '\\'; *dp++ = 'b'; s++; break; + case ' ': + *dp++ = '\\'; *dp++ = 's'; s++; break; + case '^': + *dp++ = '\\'; *dp++ = '^'; s++; break; + case ':': + *dp++ = '\\'; *dp++ = ':'; s++; break; + case ',': + *dp++ = '\\'; *dp++ = ','; s++; break; + default: + if (*s == '\033') { + *dp++ = '\\'; + *dp++ = 'E'; + s++; + } else if (*s > 0 && *s < 32) { + *dp++ = '^'; + *dp++ = *s + '@'; + s++; + } else if (*s <= 0 || *s >= 127) { + *dp++ = '\\'; + *dp++ = ((*s & 0300) >> 6) + '0'; + *dp++ = ((*s & 0070) >> 3) + '0'; + *dp++ = (*s & 0007) + '0'; + s++; + } else + *dp++ = *s++; + break; +#else + default: + *dp++ = *s++; + break; +#endif + } + } + + /* + * Now, if we stripped off some leading padding, add it at the end + * of the string as mandatory padding. + */ + if (capstart) + { + *dp++ = '$'; + *dp++ = '<'; + for (s = capstart; ; s++) + if (isdigit(*s) || *s == '*' || *s == '.') + *dp++ = *s; + else + break; + *dp++ = '/'; + *dp++ = '>'; + } + + *dp = '\0'; + return(line); +} + +/* + * Here are the capabilities infotocap assumes it can translate to: + * + * %% output `%' + * %d output value as in printf %d + * %2 output value as in printf %2d + * %3 output value as in printf %3d + * %. output value as in printf %c + * %+c add character c to value, then do %. + * %>xy if value > x then add y, no output + * %r reverse order of two parameters, no output + * %i increment by one, no output + * %n exclusive-or all parameters with 0140 (Datamedia 2500) + * %B BCD (16*(value/10)) + (value%10), no output + * %D Reverse coding (value - 2*(value%16)), no output (Delta Data). + * %m exclusive-or all parameters with 0177 (not in 4.4BSD) + */ + +char *_nc_infotocap( +/* convert a terminfo string to termcap format */ +register const char *cap GCC_UNUSED, /* relevant termcap capability index */ +register const char *str, /* string value of the capability */ +int const parametrized) /* do % translations if 1, pad translations if >=0 */ +{ + int seenone = 0, seentwo = 0, saw_m = 0, saw_n = 0; + const char *padding; + const char *trimmed = 0; + char ch1 = 0, ch2 = 0; + char *bufptr = init_string(); + char temp[256]; + + /* we may have to move some trailing mandatory padding up front */ + padding = str + strlen(str) - 1; + if (*padding == '>' && *--padding == '/') + { + --padding; + while (isdigit(*padding) || *padding == '.' || *padding == '*') + padding--; + if (*padding == '<' && *--padding == '$') + trimmed = padding; + padding += 2; + + while (isdigit(*padding) || *padding == '.' || *padding == '*') + bufptr = save_char(bufptr, *padding++); + } + + for (; *str && str != trimmed; str++) + { + int c1, c2; + char *cp = 0; + + if (str[0] == '\\' && (str[1] == '^' || str[1] == ',')) + { + bufptr = save_char(bufptr, *++str); + } + else if (str[0] == '$' && str[1] == '<') /* discard padding */ + { + str += 2; + while (isdigit(*str) || *str == '.' || *str == '*' || *str == '/' || *str == '>') + str++; + --str; + } + else if (*str != '%' || (parametrized < 1)) + bufptr = save_char(bufptr, *str); + else if (sscanf(str, "%%?%%{%d}%%>%%t%%{%d}%%+%%;", &c1,&c2) == 2) + { + str = strchr(str, ';'); + (void) sprintf(temp, "%%>%s%s", unctrl(c1), unctrl(c2)); + bufptr = save_string(bufptr, temp); + } + else if (sscanf(str, "%%?%%{%d}%%>%%t%%'%c'%%+%%;", &c1,&ch2) == 2) + { + str = strchr(str, ';'); + (void) sprintf(temp, "%%>%s%c", unctrl(c1), ch2); + bufptr = save_string(bufptr, temp); + } + else if (sscanf(str, "%%?%%'%c'%%>%%t%%{%d}%%+%%;", &ch1,&c2) == 2) + { + str = strchr(str, ';'); + (void) sprintf(temp, "%%>%c%c", ch1, c2); + bufptr = save_string(bufptr, temp); + } + else if (sscanf(str, "%%?%%'%c'%%>%%t%%'%c'%%+%%;", &ch1, &ch2) == 2) + { + str = strchr(str, ';'); + (void) sprintf(temp, "%%>%c%c", ch1, ch2); + bufptr = save_string(bufptr, temp); + } + else if (strncmp(str, "%{6}%*%+", 8) == 0) + { + str += 7; + (void) sprintf(temp, "%%B"); + bufptr = save_string(bufptr, temp); + } + else if ((sscanf(str, "%%{%d}%%+%%c", &c1) == 1 + || sscanf(str, "%%'%c'%%+%%c", &ch1) == 1) + && (cp = strchr(str, '+'))) + { + str = cp + 2; + bufptr = save_char(bufptr, '%'); + bufptr = save_char(bufptr, '+'); + + if (ch1) + c1 = ch1; + if (is7bits(c1) && isprint(c1)) + bufptr = save_char(bufptr, (char)c1); + else + { + if (c1 == (c1 & 0x1f)) /* iscntrl() returns T on 255 */ + (void) strcpy(temp, unctrl(c1)); + else + (void) sprintf(temp, "\\%03o", c1); + bufptr = save_string(bufptr, temp); + } + } + else if (strncmp(str, "%{2}%*%-", 8) == 0) + { + str += 7; + (void) sprintf(temp, "%%D"); + bufptr = save_string(bufptr, temp); + } + else if (strncmp(str, "%{96}%^", 7) == 0) + { + str += 6; + if (saw_m++ == 0) + { + (void) sprintf(temp, "%%n"); + bufptr = save_string(bufptr, temp); + } + } + else if (strncmp(str, "%{127}%^", 8) == 0) + { + str += 7; + if (saw_n++ == 0) + { + (void) sprintf(temp, "%%m"); + bufptr = save_string(bufptr, temp); + } + } + else + { + str++; + switch (*str) { + case '%': + bufptr = save_char(bufptr, '%'); + break; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + bufptr = save_char(bufptr, '%'); + while (isdigit(*str)) + bufptr = save_char(bufptr, *str++); + if (*str == 'd') + str++; + else + _nc_warning("numeric prefix is missing trailing d in %s", + cap); + --str; + break; + + case 'd': + bufptr = save_char(bufptr, '%'); + bufptr = save_char(bufptr, 'd'); + break; + + case 'c': + bufptr = save_char(bufptr, '%'); + bufptr = save_char(bufptr, '.'); + break; + + /* + * %s isn't in termcap, but it's convenient to pass it through + * so we can represent things like terminfo pfkey strings in + * termcap notation. + */ + case 's': + bufptr = save_char(bufptr, '%'); + bufptr = save_char(bufptr, 's'); + break; + + case 'p': + str++; + if (*str == '1') + seenone = 1; + else if (*str == '2') + { + if (!seenone && !seentwo) + { + bufptr = save_char(bufptr, '%'); + bufptr = save_char(bufptr, 'r'); + seentwo++; + } + } + else if (*str >= '3') + return(0); + break; + + case 'i': + bufptr = save_char(bufptr, '%'); + bufptr = save_char(bufptr, 'i'); + break; + + default: + return(0); + + } /* endswitch (*str) */ + } /* endelse (*str == '%') */ + + if (*str == '\0') + break; + + } /* endwhile (*str) */ + + return(my_string); +} + +#ifdef MAIN + +int curr_line; + +int main(int argc, char *argv[]) +{ + int c, tc = FALSE; + + while ((c = getopt(argc, argv, "c")) != EOF) + switch (c) + { + case 'c': + tc = TRUE; + break; + } + + curr_line = 0; + for (;;) + { + char buf[BUFSIZ]; + + ++curr_line; + if (fgets(buf, sizeof(buf), stdin) == 0) + break; + buf[strlen(buf) - 1] = '\0'; + _nc_set_source(buf); + + if (tc) + { + char *cp = _nc_infotocap("to termcap", buf, 1); + + if (cp) + (void) fputs(cp, stdout); + } + else + (void) fputs(_nc_captoinfo("to terminfo", buf, 1), stdout); + (void) putchar('\n'); + } + return(0); +} +#endif /* MAIN */ + +/* captoinfo.c ends here */ + diff --git a/contrib/ncurses/ncurses/tinfo/comp_error.c b/contrib/ncurses/ncurses/tinfo/comp_error.c new file mode 100644 index 0000000..2b2d503 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/comp_error.c @@ -0,0 +1,132 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * comp_error.c -- Error message routines + * + */ + +#include <curses.priv.h> + +#include <tic.h> + +MODULE_ID("$Id: comp_error.c,v 1.16 1998/08/01 23:39:51 tom Exp $") + +bool _nc_suppress_warnings; +int _nc_curr_line; /* current line # in input */ +int _nc_curr_col; /* current column # in input */ + +static const char *sourcename; +static char termtype[MAX_NAME_SIZE+1]; + +void _nc_set_source(const char *const name) +{ + sourcename = name; +} + +void _nc_set_type(const char *const name) +{ + if (name) + strncpy( termtype, name, MAX_NAME_SIZE ); + else + termtype[0] = '\0'; +} + +void _nc_get_type(char *name) +{ + strcpy( name, termtype ); +} + +static inline void where_is_problem(void) +{ + fprintf (stderr, "\"%s\"", sourcename); + if (_nc_curr_line >= 0) + fprintf (stderr, ", line %d", _nc_curr_line); + if (_nc_curr_col >= 0) + fprintf (stderr, ", col %d", _nc_curr_col); + if (termtype[0]) + fprintf (stderr, ", terminal '%s'", termtype); + fputc(':', stderr); + fputc(' ', stderr); +} + +void _nc_warning(const char *const fmt, ...) +{ +va_list argp; + + if (_nc_suppress_warnings) + return; + + where_is_problem(); + va_start(argp,fmt); + vfprintf (stderr, fmt, argp); + fprintf (stderr, "\n"); + va_end(argp); +} + + +void _nc_err_abort(const char *const fmt, ...) +{ +va_list argp; + + where_is_problem(); + va_start(argp,fmt); + vfprintf (stderr, fmt, argp); + fprintf (stderr, "\n"); + va_end(argp); + exit(EXIT_FAILURE); +} + + +void _nc_syserr_abort(const char *const fmt, ...) +{ +va_list argp; + + where_is_problem(); + va_start(argp,fmt); + vfprintf (stderr, fmt, argp); + fprintf (stderr, "\n"); + va_end(argp); + + /* If we're debugging, try to show where the problem occurred - this + * will dump core. + */ +#if defined(TRACE) || !defined(NDEBUG) + abort(); +#else + /* Dumping core in production code is not a good idea. + */ + exit(EXIT_FAILURE); +#endif +} diff --git a/contrib/ncurses/ncurses/tinfo/comp_expand.c b/contrib/ncurses/ncurses/tinfo/comp_expand.c new file mode 100644 index 0000000..eb552fa --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/comp_expand.c @@ -0,0 +1,189 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1998 * + ****************************************************************************/ + +#include <curses.priv.h> + +#include <ctype.h> +#include <tic.h> + +MODULE_ID("$Id: comp_expand.c,v 1.11 1999/03/07 00:51:07 tom Exp $") + +static int trailing_spaces(const char *src) +{ + while (*src == ' ') + src++; + return *src == 0; +} + +/* this deals with differences over whether 0x7f and 0x80..0x9f are controls */ +#define CHAR_OF(s) (*(unsigned const char *)(s)) +#define REALCTL(s) (CHAR_OF(s) < 127 && iscntrl(CHAR_OF(s))) +#define REALPRINT(s) (CHAR_OF(s) < 127 && isprint(CHAR_OF(s))) + +char *_nc_tic_expand(const char *srcp, bool tic_format, int numbers) +{ +static char * buffer; +static size_t length; + +int bufp; +const char *ptr, *str = VALID_STRING(srcp) ? srcp : ""; +bool islong = (strlen(str) > 3); +size_t need = (2 + strlen(str)) * 4; +int ch; + + if (buffer == 0 || need > length) { + if ((buffer = typeRealloc(char, length = need, buffer)) == 0) + return 0; + } + + bufp = 0; + ptr = str; + while ((ch = (*str & 0xff)) != 0) { + if (ch == '%' && REALPRINT(str+1)) { + buffer[bufp++] = *str++; + /* + * Though the character literals are more compact, most + * terminal descriptions use numbers and are not easy + * to read in character-literal form. + */ + switch (numbers) { + case -1: + if (str[0] == S_QUOTE + && str[1] != '\\' + && REALPRINT(str+1) + && str[2] == S_QUOTE) { + sprintf(buffer+bufp, "{%d}", str[1]); + bufp += strlen(buffer+bufp); + str += 2; + } else { + buffer[bufp++] = *str; + } + break; + /* + * If we have a "%{number}", try to translate it into + * a "%'char'" form, since that will run a little faster + * when we're interpreting it. Also, having one form + * for the constant makes it simpler to compare terminal + * descriptions. + */ + case 1: + if (str[0] == L_BRACE + && isdigit(str[1])) { + char *dst = 0; + long value = strtol(str+1, &dst, 0); + if (dst != 0 + && *dst == R_BRACE + && value < 127 + && value != '\\' /* FIXME */ + && isprint((int)value)) { + ch = (int)value; + buffer[bufp++] = S_QUOTE; + if (ch == '\\' + || ch == S_QUOTE) + buffer[bufp++] = '\\'; + buffer[bufp++] = ch; + buffer[bufp++] = S_QUOTE; + str = dst; + } else { + buffer[bufp++] = *str; + } + } else { + buffer[bufp++] = *str; + } + break; + default: + buffer[bufp++] = *str; + break; + } + } + else if (ch == 128) { + buffer[bufp++] = '\\'; + buffer[bufp++] = '0'; + } + else if (ch == '\033') { + buffer[bufp++] = '\\'; + buffer[bufp++] = 'E'; + } + else if (ch == '\\' && tic_format && (str == srcp || str[-1] != '^')) { + buffer[bufp++] = '\\'; + buffer[bufp++] = '\\'; + } + else if (ch == ' ' && tic_format && (str == srcp || trailing_spaces(str))) { + buffer[bufp++] = '\\'; + buffer[bufp++] = 's'; + } + else if ((ch == ',' || ch == ':' || ch == '^') && tic_format) { + buffer[bufp++] = '\\'; + buffer[bufp++] = ch; + } + else if (REALPRINT(str) && (ch != ',' && ch != ':' && !(ch == '!' && !tic_format) && ch != '^')) + buffer[bufp++] = ch; +#if 0 /* FIXME: this would be more readable (in fact the whole 'islong' logic should be removed) */ + else if (ch == '\b') { + buffer[bufp++] = '\\'; + buffer[bufp++] = 'b'; + } + else if (ch == '\f') { + buffer[bufp++] = '\\'; + buffer[bufp++] = 'f'; + } + else if (ch == '\t' && islong) { + buffer[bufp++] = '\\'; + buffer[bufp++] = 't'; + } +#endif + else if (ch == '\r' && (islong || (strlen(srcp) > 2 && str[1] == '\0'))) { + buffer[bufp++] = '\\'; + buffer[bufp++] = 'r'; + } + else if (ch == '\n' && islong) { + buffer[bufp++] = '\\'; + buffer[bufp++] = 'n'; + } +#define UnCtl(c) ((c) + '@') + else if (REALCTL(str) && ch != '\\' && (!islong || isdigit(str[1]))) + { + (void) sprintf(&buffer[bufp], "^%c", UnCtl(ch)); + bufp += 2; + } + else + { + (void) sprintf(&buffer[bufp], "\\%03o", ch); + bufp += 4; + } + + str++; + } + + buffer[bufp] = '\0'; + return(buffer); +} diff --git a/contrib/ncurses/ncurses/tinfo/comp_hash.c b/contrib/ncurses/ncurses/tinfo/comp_hash.c new file mode 100644 index 0000000..7e0bdd0 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/comp_hash.c @@ -0,0 +1,325 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * comp_hash.c --- Routines to deal with the hashtable of capability + * names. + * + */ + +#include <curses.priv.h> + +#include <tic.h> +#include <hashsize.h> + +#ifdef MAIN_PROGRAM +#include <ctype.h> +#undef DEBUG +#define DEBUG(level, params) /*nothing*/ +#endif + +MODULE_ID("$Id: comp_hash.c,v 1.21 1999/06/26 21:25:11 tom Exp $") + +static int hash_function(const char *); + +/* + * _nc_make_hash_table() + * + * Takes the entries in table[] and hashes them into hash_table[] + * by name. There are CAPTABSIZE entries in table[] and HASHTABSIZE + * slots in hash_table[]. + * + */ + +#ifdef MAIN_PROGRAM + +#undef MODULE_ID +#define MODULE_ID(id) /*nothing*/ +#include <tinfo/doalloc.c> + +static void _nc_make_hash_table(struct name_table_entry *table, + struct name_table_entry **hash_table) +{ +int i; +int hashvalue; +int collisions = 0; + + for (i = 0; i < CAPTABSIZE; i++) { + hashvalue = hash_function(table[i].nte_name); + + if (hash_table[hashvalue] != (struct name_table_entry *) 0) + collisions++; + + if (hash_table[hashvalue] != 0) + table[i].nte_link = (short)(hash_table[hashvalue] - table); + hash_table[hashvalue] = &table[i]; + } + + DEBUG(4, ("Hash table complete: %d collisions out of %d entries", collisions, CAPTABSIZE)); +} +#endif + + +/* + * int hash_function(string) + * + * Computes the hashing function on the given string. + * + * The current hash function is the sum of each consectutive pair + * of characters, taken as two-byte integers, mod Hashtabsize. + * + */ + +static +int +hash_function(const char *string) +{ +long sum = 0; + + DEBUG(9, ("hashing %s", string)); + while (*string) { + sum += (long)(*string + (*(string + 1) << 8)); + string++; + } + + DEBUG(9, ("sum is %ld", sum)); + return (int)(sum % HASHTABSIZE); +} + + +/* + * struct name_table_entry * + * find_entry(string) + * + * Finds the entry for the given string in the hash table if present. + * Returns a pointer to the entry in the table or 0 if not found. + * + */ + +#ifndef MAIN_PROGRAM +struct name_table_entry const * +_nc_find_entry(const char *string, const struct name_table_entry *const *hash_table) +{ +int hashvalue; +struct name_table_entry const *ptr; + + hashvalue = hash_function(string); + + if ((ptr = hash_table[hashvalue]) != 0) { + while (strcmp(ptr->nte_name, string) != 0) { + if (ptr->nte_link < 0) + return 0; + ptr = ptr->nte_link + hash_table[HASHTABSIZE]; + } + } + + return (ptr); +} + +/* + * struct name_table_entry * + * find_type_entry(string, type, table) + * + * Finds the first entry for the given name with the given type in the + * given table if present (as distinct from find_entry, which finds the + * the last entry regardless of type). You can use this if you detect + * a name clash. It's slower, though. Returns a pointer to the entry + * in the table or 0 if not found. + */ + +struct name_table_entry const * +_nc_find_type_entry(const char *string, + int type, + const struct name_table_entry *table) +{ +struct name_table_entry const *ptr; + + for (ptr = table; ptr < table + CAPTABSIZE; ptr++) { + if (ptr->nte_type == type && strcmp(string, ptr->nte_name) == 0) + return(ptr); + } + + return ((struct name_table_entry *)NULL); +} +#endif + +#ifdef MAIN_PROGRAM +/* + * This filter reads from standard input a list of tab-delimited columns, + * (e.g., from Caps.filtered) computes the hash-value of a specified column and + * writes the hashed tables to standard output. + * + * By compiling the hash table at build time, we're able to make the entire + * set of terminfo and termcap tables readonly (and also provide some runtime + * performance enhancement). + */ + +#define MAX_COLUMNS BUFSIZ /* this _has_ to be worst-case */ + +static char **parse_columns(char *buffer) +{ + static char **list; + + int col = 0; + + if (list == 0 && (list = typeCalloc(char *, MAX_COLUMNS)) == 0) + return(0); + + if (*buffer != '#') { + while (*buffer != '\0') { + char *s; + for (s = buffer; (*s != '\0') && !isspace(*s); s++) + /*EMPTY*/; + if (s != buffer) { + char mark = *s; + *s = '\0'; + if ((s - buffer) > 1 + && (*buffer == '"') + && (s[-1] == '"')) { /* strip the quotes */ + buffer++; + s[-1] = '\0'; + } + list[col] = buffer; + col++; + if (mark == '\0') + break; + while (*++s && isspace(*s)) + /*EMPTY*/; + buffer = s; + } else + break; + } + } + return col ? list : 0; +} + +int main(int argc, char **argv) +{ + struct name_table_entry *name_table = typeCalloc(struct name_table_entry, CAPTABSIZE); + struct name_table_entry **hash_table = typeCalloc(struct name_table_entry *, HASHTABSIZE); + const char *root_name = ""; + int column = 0; + int n; + char buffer[BUFSIZ]; + + static const char * typenames[] = { "BOOLEAN", "NUMBER", "STRING" }; + + short BoolCount = 0; + short NumCount = 0; + short StrCount = 0; + + /* The first argument is the column-number (starting with 0). + * The second is the root name of the tables to generate. + */ + if (argc <= 2 + || (column = atoi(argv[1])) <= 0 + || (column >= MAX_COLUMNS) + || *(root_name = argv[2]) == 0) { + fprintf(stderr, "usage: make_hash column root_name\n"); + exit(EXIT_FAILURE); + } + + /* + * Read the table into our arrays. + */ + for (n = 0; (n < CAPTABSIZE) && fgets(buffer, BUFSIZ, stdin); ) { + char **list, *nlp = strchr(buffer, '\n'); + if (nlp) + *nlp = '\0'; + list = parse_columns(buffer); + if (list == 0) /* blank or comment */ + continue; + name_table[n].nte_link = -1; /* end-of-hash */ + name_table[n].nte_name = strdup(list[column]); + if (!strcmp(list[2], "bool")) { + name_table[n].nte_type = BOOLEAN; + name_table[n].nte_index = BoolCount++; + } else if (!strcmp(list[2], "num")) { + name_table[n].nte_type = NUMBER; + name_table[n].nte_index = NumCount++; + } else if (!strcmp(list[2], "str")) { + name_table[n].nte_type = STRING; + name_table[n].nte_index = StrCount++; + } else { + fprintf(stderr, "Unknown type: %s\n", list[2]); + exit(EXIT_FAILURE); + } + n++; + } + _nc_make_hash_table(name_table, hash_table); + + /* + * Write the compiled tables to standard output + */ + printf("static struct name_table_entry const _nc_%s_table[] =\n", + root_name); + printf("{\n"); + for (n = 0; n < CAPTABSIZE; n++) { + sprintf(buffer, "\"%s\"", + name_table[n].nte_name); + printf("\t{ %15s,\t%10s,\t%3d, %3d }%c\n", + buffer, + typenames[name_table[n].nte_type], + name_table[n].nte_index, + name_table[n].nte_link, + n < CAPTABSIZE - 1 ? ',' : ' '); + } + printf("};\n\n"); + + printf("const struct name_table_entry * const _nc_%s_hash_table[%d] =\n", + root_name, + HASHTABSIZE+1); + printf("{\n"); + for (n = 0; n < HASHTABSIZE; n++) { + if (hash_table[n] != 0) { + sprintf(buffer, "_nc_%s_table + %3ld", + root_name, + (long) (hash_table[n] - name_table)); + } else { + strcpy(buffer, "0"); + } + printf("\t%s,\n", buffer); + } + printf("\t_nc_%s_table\t/* base-of-table */\n", root_name); + printf("};\n\n"); + + printf("#if (BOOLCOUNT!=%d)||(NUMCOUNT!=%d)||(STRCOUNT!=%d)\n", + BoolCount, NumCount, StrCount); + printf("#error\t--> term.h and comp_captab.c disagree about the <--\n"); + printf("#error\t--> numbers of booleans, numbers and/or strings <--\n"); + printf("#endif\n\n"); + + return EXIT_SUCCESS; +} +#endif diff --git a/contrib/ncurses/ncurses/tinfo/comp_parse.c b/contrib/ncurses/ncurses/tinfo/comp_parse.c new file mode 100644 index 0000000..be419ca --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/comp_parse.c @@ -0,0 +1,490 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* + * comp_parse.c -- parser driver loop and use handling. + * + * _nc_read_entry_source(FILE *, literal, bool, bool (*hook)()) + * _nc_resolve_uses(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 + * storage, do _nc_free_entries(). + * + */ + +#include <curses.priv.h> + +#include <ctype.h> + +#include <tic.h> +#include <term_entry.h> + +MODULE_ID("$Id: comp_parse.c,v 1.34 1999/02/27 22:13:02 tom Exp $") + +static void sanity_check(TERMTYPE *); +void (*_nc_check_termtype)(TERMTYPE *) = sanity_check; + +/**************************************************************************** + * + * Entry queue handling + * + ****************************************************************************/ +/* + * The entry list is a doubly linked list with NULLs terminating the lists: + * + * --------- --------- --------- + * | | | | | | offset + * |-------| |-------| |-------| + * | ----+-->| ----+-->| NULL | next + * |-------| |-------| |-------| + * | NULL |<--+---- |<--+---- | last + * --------- --------- --------- + * ^ ^ + * | | + * | | + * _nc_head _nc_tail + */ + +ENTRY *_nc_head, *_nc_tail; + +static void enqueue(ENTRY *ep) +/* add an entry to the in-core list */ +{ + ENTRY *newp = _nc_copy_entry(ep); + + if (newp == NULL) + _nc_err_abort("Out of memory"); + + newp->last = _nc_tail; + _nc_tail = newp; + + newp->next = (ENTRY *)NULL; + if (newp->last) + newp->last->next = newp; +} + +void _nc_free_entries(ENTRY *head) +/* free the allocated storage consumed by list entries */ +{ + ENTRY *ep, *next; + + for (ep = head; 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); + + next = ep->next; + + free(ep); + if (ep == _nc_head) _nc_head = 0; + if (ep == _nc_tail) _nc_tail = 0; + } +} + +bool _nc_entry_match(char *n1, char *n2) +/* do any of the aliases in a pair of terminal names match? */ +{ + char *pstart, *qstart, *pend, *qend; + char nc1[MAX_NAME_SIZE+1], nc2[MAX_NAME_SIZE+1]; + + if (strchr(n1, '|') == NULL) + { + (void) strncpy(nc1, n1, sizeof(nc1) - 2); + nc1[sizeof(nc1) - 2] = '\0'; + (void) strcat(nc1, "|"); + n1 = nc1; + } + + if (strchr(n2, '|') == NULL) + { + (void) strncpy(nc2, n2, sizeof(nc2) - 2); + nc2[sizeof(nc2) - 2] = '\0'; + (void) strcat(nc2, "|"); + n2 = nc2; + } + + for (pstart = n1; (pend = strchr(pstart, '|')); pstart = pend + 1) + for (qstart = n2; (qend = strchr(qstart, '|')); qstart = qend + 1) + if ((pend-pstart == qend-qstart) + && memcmp(pstart, qstart, (size_t)(pend-pstart)) == 0) + return(TRUE); + + return(FALSE); +} + +/**************************************************************************** + * + * Entry compiler and resolution logic + * + ****************************************************************************/ + +void _nc_read_entry_source(FILE *fp, char *buf, + int literal, bool silent, + bool (*hook)(ENTRY *)) +/* slurp all entries in the given file into core */ +{ + ENTRY thisentry; + bool oldsuppress = _nc_suppress_warnings; + int immediate = 0; + + if (silent) + _nc_suppress_warnings = TRUE; /* shut the lexer up, too */ + + memset(&thisentry, 0, sizeof(thisentry)); + for (_nc_reset_input(fp, buf); _nc_parse_entry(&thisentry, literal, silent) != ERR; ) + { + if (!isalnum(thisentry.tterm.term_names[0])) + _nc_err_abort("terminal names must start with letter or digit"); + + /* + * This can be used for immediate compilation of entries with no + * use references to disk, so as to avoid chewing up a lot of + * core when the resolution code could fetch entries off disk. + */ + if (hook != NULLHOOK && (*hook)(&thisentry)) + immediate++; + else + enqueue(&thisentry); + } + + if (_nc_tail) + { + /* set up the head pointer */ + for (_nc_head = _nc_tail; _nc_head->last; _nc_head = _nc_head->last) + continue; + + DEBUG(1, ("head = %s", _nc_head->tterm.term_names)); + DEBUG(1, ("tail = %s", _nc_tail->tterm.term_names)); + } +#ifdef TRACE + else if (!immediate) + DEBUG(1, ("no entries parsed")); +#endif + + _nc_suppress_warnings = oldsuppress; +} + +int _nc_resolve_uses(void) +/* try to resolve all use capabilities */ +{ + ENTRY *qp, *rp, *lastread = NULL; + bool keepgoing; + int i, j, unresolved, total_unresolved, multiples; + + DEBUG(2, ("RESOLUTION BEGINNING")); + + /* + * Check for multiple occurrences of the same name. + */ + multiples = 0; + for_entry_list(qp) + { + int matchcount = 0; + + for_entry_list(rp) + if (qp > rp + && _nc_entry_match(qp->tterm.term_names, rp->tterm.term_names)) + { + matchcount++; + if (matchcount == 1) + { + (void) fprintf(stderr, "Name collision between %s", + _nc_first_name(qp->tterm.term_names)); + multiples++; + } + if (matchcount >= 1) + (void) fprintf(stderr, " %s", _nc_first_name(rp->tterm.term_names)); + } + if (matchcount >= 1) + (void) putc('\n', stderr); + } + if (multiples > 0) + return(FALSE); + + DEBUG(2, ("NO MULTIPLE NAME OCCURRENCES")); + + /* + * First resolution stage: replace names in use arrays with entry + * pointers. By doing this, we avoid having to do the same name + * match once for each time a use entry is itself unresolved. + */ + total_unresolved = 0; + _nc_curr_col = -1; + for_entry_list(qp) + { + unresolved = 0; + for (i = 0; i < qp->nuses; i++) + { + bool foundit; + char *child = _nc_first_name(qp->tterm.term_names); + char *lookfor = (char *)(qp->uses[i].parent); + long lookline = qp->uses[i].line; + + foundit = FALSE; + + _nc_set_type(child); + + /* first, try to resolve from in-core records */ + for_entry_list(rp) + if (rp != qp + && _nc_name_match(rp->tterm.term_names, lookfor, "|")) + { + DEBUG(2, ("%s: resolving use=%s (in core)", + child, lookfor)); + + qp->uses[i].parent = rp; + foundit = TRUE; + } + + /* if that didn't work, try to merge in a compiled entry */ + if (!foundit) + { + TERMTYPE thisterm; + char filename[PATH_MAX]; + + memset(&thisterm, 0, sizeof(thisterm)); + if (_nc_read_entry(lookfor, filename, &thisterm) == 1) + { + DEBUG(2, ("%s: resolving use=%s (compiled)", + child, lookfor)); + + rp = typeMalloc(ENTRY,1); + if (rp == NULL) + _nc_err_abort("Out of memory"); + rp->tterm = thisterm; + rp->nuses = 0; + rp->next = lastread; + lastread = rp; + + qp->uses[i].parent = rp; + foundit = TRUE; + } + } + + /* no good, mark this one unresolvable and complain */ + if (!foundit) + { + unresolved++; + total_unresolved++; + + _nc_curr_line = lookline; + _nc_warning("resolution of use=%s failed", lookfor); + qp->uses[i].parent = (ENTRY *)NULL; + } + } + } + if (total_unresolved) + { + /* free entries read in off disk */ + _nc_free_entries(lastread); + return(FALSE); + } + + DEBUG(2, ("NAME RESOLUTION COMPLETED OK")); + + /* + * OK, at this point all (char *) references have been successfully + * replaced by (ENTRY *) pointers. Time to do the actual merges. + */ + do { + TERMTYPE merged; + + keepgoing = FALSE; + + for_entry_list(qp) + { + if (qp->nuses > 0) + { + DEBUG(2, ("%s: attempting merge", _nc_first_name(qp->tterm.term_names))); + /* + * If any of the use entries we're looking for is + * incomplete, punt. We'll catch this entry on a + * subsequent pass. + */ + for (i = 0; i < qp->nuses; i++) + if (((ENTRY *)qp->uses[i].parent)->nuses) + { + DEBUG(2, ("%s: use entry %d unresolved", + _nc_first_name(qp->tterm.term_names), i)); + goto incomplete; + } + + /* + * 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. + */ + _nc_copy_termtype(&merged, &(qp->tterm)); + + /* + * Now merge in each use entry in the proper + * (reverse) order. + */ + for (; qp->nuses; qp->nuses--) + _nc_merge_entry(&merged, + &((ENTRY *)qp->uses[qp->nuses-1].parent)->tterm); + + /* + * Now merge in the original entry. + */ + _nc_merge_entry(&merged, &qp->tterm); + + /* + * Replace the original entry with the merged one. + */ + FreeIfNeeded(qp->tterm.Booleans); + FreeIfNeeded(qp->tterm.Numbers); + FreeIfNeeded(qp->tterm.Strings); + qp->tterm = merged; + + /* + * We know every entry is resolvable because name resolution + * didn't bomb. So go back for another pass. + */ + /* FALLTHRU */ + incomplete: + keepgoing = TRUE; + } + } + } while + (keepgoing); + + DEBUG(2, ("MERGES COMPLETED OK")); + + /* + * 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 (qp->tterm.Booleans[j] == CANCELLED_BOOLEAN) + qp->tterm.Booleans[j] = FALSE; + 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; + } + + /* + * We'd like to free entries read in off disk at this point, but can't. + * The merge_entry() code doesn't copy the strings in the use entries, + * it just aliases them. If this ever changes, do a + * free_entries(lastread) here. + */ + + DEBUG(2, ("RESOLUTION FINISHED")); + + if (_nc_check_termtype != 0) + { + _nc_curr_col = -1; + for_entry_list(qp) + { + _nc_curr_line = qp->startline; + _nc_set_type(_nc_first_name(qp->tterm.term_names)); + _nc_check_termtype(&qp->tterm); + } + DEBUG(2, ("SANITY CHECK FINISHED")); + } + + return(TRUE); +} + +/* + * This bit of legerdemain turns all the terminfo variable names into + * references to locations in the arrays Booleans, Numbers, and Strings --- + * precisely what's needed. + */ + +#undef CUR +#define CUR tp-> + +static void sanity_check(TERMTYPE *tp) +{ + if (!PRESENT(exit_attribute_mode)) + { +#ifdef __UNUSED__ /* this casts too wide a net */ + bool terminal_entry = !strchr(tp->term_names, '+'); + if (terminal_entry && + (PRESENT(set_attributes) + || PRESENT(enter_standout_mode) + || PRESENT(enter_underline_mode) + || PRESENT(enter_blink_mode) + || PRESENT(enter_bold_mode) + || PRESENT(enter_dim_mode) + || PRESENT(enter_secure_mode) + || PRESENT(enter_protected_mode) + || PRESENT(enter_reverse_mode))) + _nc_warning("no exit_attribute_mode"); +#endif /* __UNUSED__ */ + PAIRED(enter_standout_mode, exit_standout_mode) + PAIRED(enter_underline_mode, exit_underline_mode) + } + + /* 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) + PAIRED(enter_delete_mode, exit_delete_mode) + ANDMISSING(enter_dim_mode, exit_attribute_mode) + PAIRED(enter_insert_mode, exit_insert_mode) + ANDMISSING(enter_secure_mode, exit_attribute_mode) + ANDMISSING(enter_protected_mode, exit_attribute_mode) + ANDMISSING(enter_reverse_mode, exit_attribute_mode) + PAIRED(from_status_line, to_status_line) + PAIRED(meta_off, meta_on) + + PAIRED(prtr_on, prtr_off) + PAIRED(save_cursor, restore_cursor) + PAIRED(enter_xon_mode, exit_xon_mode) + PAIRED(enter_am_mode, exit_am_mode) + ANDMISSING(label_off, label_on) + PAIRED(display_clock, remove_clock) + ANDMISSING(set_color_pair, initialize_pair) +} diff --git a/contrib/ncurses/ncurses/tinfo/comp_scan.c b/contrib/ncurses/ncurses/tinfo/comp_scan.c new file mode 100644 index 0000000..1529308 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/comp_scan.c @@ -0,0 +1,756 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * comp_scan.c --- Lexical scanner for terminfo compiler. + * + * _nc_reset_input() + * _nc_get_token() + * _nc_panic_mode() + * int _nc_syntax; + * int _nc_curr_line; + * long _nc_curr_file_pos; + * long _nc_comment_start; + * long _nc_comment_end; + */ + +#include <curses.priv.h> + +#include <ctype.h> +#include <tic.h> + +MODULE_ID("$Id: comp_scan.c,v 1.34 1998/11/01 00:56:39 tom Exp $") + +/* + * Maximum length of string capability we'll accept before raising an error. + * Yes, there is a real capability in /etc/termcap this long, an "is". + */ +#define MAXCAPLEN 600 + +#define iswhite(ch) (ch == ' ' || ch == '\t') + +int _nc_syntax; /* termcap or terminfo? */ +long _nc_curr_file_pos; /* file offset of current line */ +long _nc_comment_start; /* start of comment range before name */ +long _nc_comment_end; /* end of comment range before name */ +long _nc_start_line; /* start line of current entry */ + +/***************************************************************************** + * + * Token-grabbing machinery + * + *****************************************************************************/ + +static bool first_column; /* See 'next_char()' below */ +static char separator; /* capability separator */ +static int pushtype; /* type of pushback token */ +static char pushname[MAX_NAME_SIZE+1]; + +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); + +/* Assume we may be looking at a termcap-style continuation */ +static inline int eat_escaped_newline(int ch) +{ + if (ch == '\\') + while ((ch = next_char()) == '\n' || iswhite(ch)) + continue; + return ch; +} + +/* + * int + * get_token() + * + * Scans the input for the next token, storing the specifics in the + * global structure 'curr_token' and returning one of the following: + * + * NAMES A line beginning in column 1. 'name' + * will be set to point to everything up to but + * not including the first separator on the line. + * BOOLEAN An entry consisting of a name followed by + * a separator. 'name' will be set to point to + * the name of the capability. + * NUMBER An entry of the form + * name#digits, + * 'name' will be set to point to the capability + * name and 'valnumber' to the number given. + * STRING An entry of the form + * name=characters, + * 'name' is set to the capability name and + * 'valstring' to the string of characters, with + * input translations done. + * CANCEL An entry of the form + * name@, + * 'name' is set to the capability name and + * 'valnumber' to -1. + * EOF The end of the file has been reached. + * + * A `separator' is either a comma or a semicolon, depending on whether + * we are in termcap or terminfo mode. + * + */ + +int _nc_get_token(void) +{ +static const char terminfo_punct[] = "@%&*!#"; +long number; +int type; +int ch; +char * numchk; +char numbuf[80]; +unsigned found; +static char buffer[MAX_ENTRY_SIZE]; +char *ptr; +int dot_flag = FALSE; +long token_start; + + if (pushtype != NO_PUSHBACK) + { + int retval = pushtype; + + _nc_set_type(pushname); + DEBUG(3, ("pushed-back token: `%s', class %d", + _nc_curr_token.tk_name, pushtype)); + + pushtype = NO_PUSHBACK; + pushname[0] = '\0'; + + /* currtok wasn't altered by _nc_push_token() */ + return(retval); + } + + if (end_of_stream()) + return(EOF); + +start_token: + token_start = stream_pos(); + while ((ch = next_char()) == '\n' || iswhite(ch)) + continue; + + ch = eat_escaped_newline(ch); + + if (ch == EOF) + type = EOF; + else { + /* if this is a termcap entry, skip a leading separator */ + if (separator == ':' && ch == ':') + ch = next_char(); + + if (ch == '.') { + dot_flag = TRUE; + DEBUG(8, ("dot-flag set")); + + while ((ch = next_char())=='.' || iswhite(ch)) + continue; + } + + if (ch == EOF) { + type = EOF; + goto end_of_token; + } + + /* have to make some punctuation chars legal for terminfo */ + if (!isalnum(ch) && !strchr(terminfo_punct, (char)ch)) { + _nc_warning("Illegal character (expected alphanumeric or %s) - %s", + terminfo_punct, _tracechar((chtype)ch)); + _nc_panic_mode(separator); + goto start_token; + } + + 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; + while ((ch = next_char()) != '\n') + { + if (ch == EOF) + _nc_err_abort("premature EOF"); + else if (ch == ':' && last_char() != ',') + { + _nc_syntax = SYN_TERMCAP; + separator = ':'; + break; + } + else if (ch == ',') + { + _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 allows commas to + * be embedded in description fields of + * either syntax. + */ + /* FALLTHRU */ + } + else + ch = eat_escaped_newline(ch); + + *ptr++ = ch; + } + ptr[0] = '\0'; + if (_nc_syntax == ERR) + { + /* + * Grrr...what we ought to do here is barf, + * complaining that the entry is malformed. + * But because a couple of name fields in the + * 8.2 termcap file end with |\, we just have + * to assume it's termcap syntax. + */ + _nc_syntax = SYN_TERMCAP; + separator = ':'; + } + else if (_nc_syntax == SYN_TERMINFO) + { + /* throw away trailing /, *$/ */ + for (--ptr; iswhite(*ptr) || *ptr == ','; ptr--) + continue; + ptr[1] = '\0'; + } + + /* + * This is the soonest we have the terminal name + * fetched. Set up for following warning messages. + */ + ptr = strchr(buffer, '|'); + if (ptr == (char *)NULL) + ptr = buffer + strlen(buffer); + ch = *ptr; + *ptr = '\0'; + _nc_set_type(buffer); + *ptr = ch; + + /* + * Compute the boundary between the aliases and the + * description field for syntax-checking purposes. + */ + desc = strrchr(buffer, '|'); + if (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 (!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(*ptr)) + { + _nc_warning("whitespace in name or alias field"); + break; + } + else if (*ptr == '/') + { + _nc_warning("slashes aren't allowed in names or aliases"); + break; + } + else if (strchr("$[]!*?", *ptr)) + { + _nc_warning("dubious character `%c' in name or alias field", *ptr); + break; + } + } + + ptr = buffer; + + _nc_curr_token.tk_name = buffer; + type = NAMES; + } else { + while ((ch = next_char()) != EOF) { + if (!isalnum(ch)) { + if (_nc_syntax == SYN_TERMINFO) { + if (ch != '_') + break; + } else { /* allow ';' for "k;" */ + if (ch != ';') + break; + } + } + *(ptr++) = ch; + } + + *ptr++ = '\0'; + switch (ch) { + case ',': + case ':': + if (ch != separator) + _nc_err_abort("Separator inconsistent with syntax"); + _nc_curr_token.tk_name = buffer; + type = BOOLEAN; + break; + case '@': + if ((ch = next_char()) != separator) + _nc_warning("Missing separator after `%s', have %s", + buffer, _tracechar((chtype)ch)); + _nc_curr_token.tk_name = buffer; + type = CANCEL; + break; + + case '#': + found = 0; + while (isalnum(ch = next_char())) { + numbuf[found++] = ch; + if (found >= sizeof(numbuf)-1) + break; + } + numbuf[found] = '\0'; + number = strtol(numbuf, &numchk, 0); + if (numchk == numbuf) + _nc_warning("no value given for `%s'", buffer); + if ((*numchk != '\0') || (ch != separator)) + _nc_warning("Missing separator"); + _nc_curr_token.tk_name = buffer; + _nc_curr_token.tk_valnumber = number; + type = NUMBER; + break; + + case '=': + ch = _nc_trans_string(ptr); + if (ch != separator) + _nc_warning("Missing separator"); + _nc_curr_token.tk_name = buffer; + _nc_curr_token.tk_valstring = ptr; + type = STRING; + break; + + case EOF: + type = EOF; + break; + default: + /* just to get rid of the compiler warning */ + type = UNDEF; + _nc_warning("Illegal character - %s", + _tracechar((chtype)ch)); + } + } /* end else (first_column == FALSE) */ + } /* end else (ch != EOF) */ + +end_of_token: + +#ifdef TRACE + if (dot_flag == TRUE) + DEBUG(8, ("Commented out ")); + + if (_nc_tracing & TRACE_IEVENT) + { + fprintf(stderr, "Token: "); + switch (type) + { + case BOOLEAN: + fprintf(stderr, "Boolean; name='%s'\n", + _nc_curr_token.tk_name); + break; + + case NUMBER: + fprintf(stderr, "Number; name='%s', value=%d\n", + _nc_curr_token.tk_name, + _nc_curr_token.tk_valnumber); + break; + + case STRING: + fprintf(stderr, "String; name='%s', value=%s\n", + _nc_curr_token.tk_name, + _nc_visbuf(_nc_curr_token.tk_valstring)); + break; + + case CANCEL: + fprintf(stderr, "Cancel; name='%s'\n", + _nc_curr_token.tk_name); + break; + + case NAMES: + + fprintf(stderr, "Names; value='%s'\n", + _nc_curr_token.tk_name); + break; + + case EOF: + fprintf(stderr, "End of file\n"); + break; + + default: + _nc_warning("Bad token type"); + } + } +#endif + + if (dot_flag == TRUE) /* if commented out, use the next one */ + type = _nc_get_token(); + + DEBUG(3, ("token: `%s', class %d", _nc_curr_token.tk_name, type)); + + return(type); +} + +/* + * char + * trans_string(ptr) + * + * Reads characters using next_char() until encountering a separator, nl, + * or end-of-file. The returned value is the character which caused + * reading to stop. The following translations are done on the input: + * + * ^X goes to ctrl-X (i.e. X & 037) + * {\E,\n,\r,\b,\t,\f} go to + * {ESCAPE,newline,carriage-return,backspace,tab,formfeed} + * {\^,\\} go to {carat,backslash} + * \ddd (for ddd = up to three octal digits) goes to the character ddd + * + * \e == \E + * \0 == \200 + * + */ + +char +_nc_trans_string(char *ptr) +{ +int count = 0; +int number; +int i, c; +chtype ch, last_ch = '\0'; +bool ignored = FALSE; + + while ((ch = c = next_char()) != (chtype)separator && c != EOF) { + if ((_nc_syntax == SYN_TERMCAP) && c == '\n') + break; + if (ch == '^' && last_ch != '%') { + ch = c = next_char(); + if (c == EOF) + _nc_err_abort("Premature EOF"); + + if (! (is7bits(ch) && isprint(ch))) { + _nc_warning("Illegal ^ character - %s", + _tracechar((unsigned char)ch)); + } + if (ch == '?') { + *(ptr++) = '\177'; + } else { + if ((ch &= 037) == 0) + ch = 128; + *(ptr++) = (char)(ch); + } + } + else if (ch == '\\') { + ch = c = next_char(); + if (c == EOF) + _nc_err_abort("Premature EOF"); + + 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"); + + if (c < '0' || c > '7') { + if (isdigit(c)) { + _nc_warning("Non-octal digit `%c' in \\ sequence", c); + /* allow the digit; it'll do less harm */ + } else { + push_back((char)c); + break; + } + } + + number = number * 8 + c - '0'; + } + + if (number == 0) + number = 0200; + *(ptr++) = (char) number; + } else { + switch (c) { + case 'E': + case 'e': *(ptr++) = '\033'; break; + + case 'a': *(ptr++) = '\007'; break; + + case 'l': + case 'n': *(ptr++) = '\n'; break; + + case 'r': *(ptr++) = '\r'; break; + + case 'b': *(ptr++) = '\010'; break; + + case 's': *(ptr++) = ' '; break; + + case 'f': *(ptr++) = '\014'; break; + + case 't': *(ptr++) = '\t'; break; + + case '\\': *(ptr++) = '\\'; break; + + case '^': *(ptr++) = '^'; break; + + case ',': *(ptr++) = ','; break; + + case ':': *(ptr++) = ':'; break; + + case '\n': + continue; + + default: + _nc_warning("Illegal character %s in \\ sequence", + _tracechar((unsigned char)ch)); + *(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 */ + ignored = TRUE; + } else { + *(ptr++) = (char)ch; + } + + if (!ignored) { + last_ch = ch; + count ++; + } + ignored = FALSE; + + if (count > MAXCAPLEN) + _nc_warning("Very long string found. Missing separator?"); + } /* end while */ + + *ptr = '\0'; + + return(ch); +} + +/* + * _nc_push_token() + * + * Push a token of given type so that it will be reread by the next + * get_token() call. + */ + +void _nc_push_token(int tokclass) +{ + /* + * This implementation is kind of bogus, it will fail if we ever do + * more than one pushback at a time between get_token() calls. It + * relies on the fact that curr_tok is static storage that nothing + * but get_token() touches. + */ + pushtype = tokclass; + _nc_get_type(pushname); + + DEBUG(3, ("pushing token: `%s', class %d", + _nc_curr_token.tk_name, pushtype)); +} + +/* + * Panic mode error recovery - skip everything until a "ch" is found. + */ +void _nc_panic_mode(char ch) +{ + int c; + + for (;;) { + c = next_char(); + if (c == ch) + return; + if (c == EOF) + return; + } +} + +/***************************************************************************** + * + * 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. + */ + +void _nc_reset_input(FILE *fp, char *buf) +{ + pushtype = NO_PUSHBACK; + 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(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) + { + 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 line[LEXBUFSIZ]; + size_t len; + + do { + _nc_curr_file_pos = ftell(yyin); + + if ((bufstart = fgets(line, LEXBUFSIZ, yyin)) != NULL) { + _nc_curr_line++; + _nc_curr_col = 0; + } + bufptr = bufstart; + } while + (bufstart != NULL && line[0] == '#'); + + if (bufstart == NULL) + return (EOF); + + 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') { + bufptr[len-2] = '\n'; + bufptr[len-1] = '\0'; + } + } + } + + 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); +} + +/* comp_scan.c ends here */ diff --git a/contrib/ncurses/ncurses/tinfo/doalloc.c b/contrib/ncurses/ncurses/tinfo/doalloc.c new file mode 100644 index 0000000..84471fb --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/doalloc.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1998 * + ****************************************************************************/ + + +/* + * Wrapper for malloc/realloc. Standard implementations allow realloc with + * a null pointer, but older libraries may not (e.g., SunOS). + * + * Also if realloc fails, we discard the old memory to avoid leaks. + */ + +#include <curses.priv.h> + +MODULE_ID("$Id: doalloc.c,v 1.5 1999/03/14 12:25:27 tom Exp $") + +void *_nc_doalloc(void *oldp, size_t amount) +{ + void *newp; + + if (oldp != 0) { + if ((newp = realloc(oldp, amount)) == 0) { + free(oldp); + errno = ENOMEM; /* just in case 'free' reset */ + } + } else { + newp = typeMalloc(char, amount); + } + return newp; +} + +#if !HAVE_STRDUP +char *_nc_strdup(const char *src) +{ + char *dst; + if (src != 0) { + dst = typeMalloc(char, strlen(src) + 1); + if (dst != 0) { + (void)strcpy(dst, src); + } + } else { + dst = 0; + } + return dst; +} +#endif diff --git a/contrib/ncurses/ncurses/tinfo/free_ttype.c b/contrib/ncurses/ncurses/tinfo/free_ttype.c new file mode 100644 index 0000000..203ec89 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/free_ttype.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * Copyright (c) 1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + ****************************************************************************/ + + +/* + * free_ttype.c -- allocation functions for TERMTYPE + * + * _nc_free_termtype() + * use_extended_names() + * + */ + +#include <curses.priv.h> + +#include <tic.h> +#include <term_entry.h> + +MODULE_ID("$Id: free_ttype.c,v 1.2 1999/03/01 00:30:35 tom Exp $") + +void _nc_free_termtype(TERMTYPE *ptr) +{ + FreeIfNeeded(ptr->str_table); + FreeIfNeeded(ptr->term_names); +#if NCURSES_XNAMES + FreeIfNeeded(ptr->ext_str_table); + FreeIfNeeded(ptr->Booleans); + FreeIfNeeded(ptr->Numbers); + FreeIfNeeded(ptr->Strings); + FreeIfNeeded(ptr->ext_Names); +#endif + memset(ptr, 0, sizeof(TERMTYPE)); +} + +#if NCURSES_XNAMES +bool _nc_user_definable = TRUE; + +int use_extended_names(bool flag) +{ + int oldflag = _nc_user_definable; + _nc_user_definable = flag; + return oldflag; +} +#endif diff --git a/contrib/ncurses/ncurses/tinfo/getenv_num.c b/contrib/ncurses/ncurses/tinfo/getenv_num.c new file mode 100644 index 0000000..6294404 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/getenv_num.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1998 * + ****************************************************************************/ + +/* + * getenv_num.c -- obtain a number from the environment + */ + +#include <curses.priv.h> + +MODULE_ID("$Id: getenv_num.c,v 1.1 1998/09/19 21:30:23 tom Exp $") + +int +_nc_getenv_num(const char *name) +{ + char *dst = 0; + char *src = getenv(name); + long value; + + if ((src == 0) + || (value = strtol(src, &dst, 0)) < 0 + || (dst == src) + || (*dst != '\0') + || (int)value < value) + value = -1; + + return (int) value; +} diff --git a/contrib/ncurses/ncurses/tinfo/home_terminfo.c b/contrib/ncurses/ncurses/tinfo/home_terminfo.c new file mode 100644 index 0000000..7aa4ca1 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/home_terminfo.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1998 * + ****************************************************************************/ + +/* + * home_terminfo.c -- return the $HOME/.terminfo string, expanded + */ + +#include <curses.priv.h> +#include <tic.h> + +MODULE_ID("$Id: home_terminfo.c,v 1.2 1999/02/27 19:58:46 tom Exp $") + +#define my_length (strlen(home) + sizeof(PRIVATE_INFO)) + +/* ncurses extension...fall back on user's private directory */ + +char * +_nc_home_terminfo(void) +{ + char *home; + static char *temp = 0; + + if (temp == 0) { + if ((home = getenv("HOME")) != 0 + && my_length <= PATH_MAX) { + temp = typeMalloc(char, my_length); + if (temp == 0) + _nc_err_abort("Out of memory"); + (void) sprintf(temp, PRIVATE_INFO, home); + } + } + return temp; +} diff --git a/contrib/ncurses/ncurses/tinfo/init_keytry.c b/contrib/ncurses/ncurses/tinfo/init_keytry.c new file mode 100644 index 0000000..77102e5 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/init_keytry.c @@ -0,0 +1,67 @@ +/**************************************************************************** + * Copyright (c) 1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +#include <curses.priv.h> + +#include <term.h> /* keypad_xmit, keypad_local, meta_on, meta_off */ + /* cursor_visible,cursor_normal,cursor_invisible */ +#include <tic.h> /* struct tinfo_fkeys */ + +MODULE_ID("$Id: init_keytry.c,v 1.1 1999/02/18 22:39:11 tom Exp $") + +/* +** _nc_init_keytry() +** +** Construct the try for the current terminal's keypad keys. +** +*/ + +/* LINT_PREPRO +#if 0*/ +#include <init_keytry.h> +/* LINT_PREPRO +#endif*/ + +void _nc_init_keytry(void) +{ + size_t n; + + /* The SP->_keytry value is initialized in newterm(), where the SP + * structure is created, because we can not tell where keypad() or + * mouse_activate() (which will call keyok()) are first called. + */ + + 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); +#ifdef TRACE + _nc_trace_tries(SP->_keytry); +#endif +} diff --git a/contrib/ncurses/ncurses/tinfo/keys.list b/contrib/ncurses/ncurses/tinfo/keys.list new file mode 100644 index 0000000..c11300b --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/keys.list @@ -0,0 +1,158 @@ +# $Id: keys.list,v 1.5 1997/10/25 21:05:24 tom Exp $ +# The first column is the #define symbol that is in curses.h +# The second column is the term.h symbol, for terminfo +# Not all keycodes have corresponding terminfo capabilities. +KEY_A1 key_a1 +KEY_A3 key_a3 +KEY_B2 key_b2 +KEY_BACKSPACE key_backspace +KEY_BEG key_beg +KEY_BREAK +KEY_BTAB key_btab +KEY_C1 key_c1 +KEY_C3 key_c3 +KEY_CANCEL key_cancel +KEY_CATAB key_catab +KEY_CLEAR key_clear +KEY_CLOSE key_close +KEY_COMMAND key_command +KEY_COPY key_copy +KEY_CREATE key_create +KEY_CTAB key_ctab +KEY_DC key_dc +KEY_DL key_dl +KEY_DOWN key_down +KEY_EIC key_eic +KEY_END key_end +KEY_ENTER key_enter +KEY_EOL key_eol +KEY_EOS key_eos +KEY_EXIT key_exit +KEY_F(0) key_f0 +KEY_F(1) key_f1 +KEY_F(10) key_f10 +KEY_F(11) key_f11 +KEY_F(12) key_f12 +KEY_F(13) key_f13 +KEY_F(14) key_f14 +KEY_F(15) key_f15 +KEY_F(16) key_f16 +KEY_F(17) key_f17 +KEY_F(18) key_f18 +KEY_F(19) key_f19 +KEY_F(2) key_f2 +KEY_F(20) key_f20 +KEY_F(21) key_f21 +KEY_F(22) key_f22 +KEY_F(23) key_f23 +KEY_F(24) key_f24 +KEY_F(25) key_f25 +KEY_F(26) key_f26 +KEY_F(27) key_f27 +KEY_F(28) key_f28 +KEY_F(29) key_f29 +KEY_F(3) key_f3 +KEY_F(30) key_f30 +KEY_F(31) key_f31 +KEY_F(32) key_f32 +KEY_F(33) key_f33 +KEY_F(34) key_f34 +KEY_F(35) key_f35 +KEY_F(36) key_f36 +KEY_F(37) key_f37 +KEY_F(38) key_f38 +KEY_F(39) key_f39 +KEY_F(4) key_f4 +KEY_F(40) key_f40 +KEY_F(41) key_f41 +KEY_F(42) key_f42 +KEY_F(43) key_f43 +KEY_F(44) key_f44 +KEY_F(45) key_f45 +KEY_F(46) key_f46 +KEY_F(47) key_f47 +KEY_F(48) key_f48 +KEY_F(49) key_f49 +KEY_F(5) key_f5 +KEY_F(50) key_f50 +KEY_F(51) key_f51 +KEY_F(52) key_f52 +KEY_F(53) key_f53 +KEY_F(54) key_f54 +KEY_F(55) key_f55 +KEY_F(56) key_f56 +KEY_F(57) key_f57 +KEY_F(58) key_f58 +KEY_F(59) key_f59 +KEY_F(6) key_f6 +KEY_F(60) key_f60 +KEY_F(61) key_f61 +KEY_F(62) key_f62 +KEY_F(63) key_f63 +KEY_F(7) key_f7 +KEY_F(8) key_f8 +KEY_F(9) key_f9 +KEY_FIND key_find +KEY_HELP key_help +KEY_HOME key_home +KEY_IC key_ic +KEY_IL key_il +KEY_LEFT key_left +KEY_LL key_ll +KEY_MARK key_mark +KEY_MESSAGE key_message +KEY_MOUSE key_mouse +KEY_MOVE key_move +KEY_NEXT key_next +KEY_NPAGE key_npage +KEY_OPEN key_open +KEY_OPTIONS key_options +KEY_PPAGE key_ppage +KEY_PREVIOUS key_previous +KEY_PRINT key_print +KEY_REDO key_redo +KEY_REFERENCE key_reference +KEY_REFRESH key_refresh +KEY_REPLACE key_replace +KEY_RESET +KEY_RESIZE +KEY_RESTART key_restart +KEY_RESUME key_resume +KEY_RIGHT key_right +KEY_SAVE key_save +KEY_SBEG key_sbeg +KEY_SCANCEL key_scancel +KEY_SCOMMAND key_scommand +KEY_SCOPY key_scopy +KEY_SCREATE key_screate +KEY_SDC key_sdc +KEY_SDL key_sdl +KEY_SELECT key_select +KEY_SEND key_send +KEY_SEOL key_seol +KEY_SEXIT key_sexit +KEY_SF key_sf +KEY_SFIND key_sfind +KEY_SHELP key_shelp +KEY_SHOME key_shome +KEY_SIC key_sic +KEY_SLEFT key_sleft +KEY_SMESSAGE key_smessage +KEY_SMOVE key_smove +KEY_SNEXT key_snext +KEY_SOPTIONS key_soptions +KEY_SPREVIOUS key_sprevious +KEY_SPRINT key_sprint +KEY_SR key_sr +KEY_SREDO key_sredo +KEY_SREPLACE key_sreplace +KEY_SRESET +KEY_SRIGHT key_sright +KEY_SRSUME key_srsume +KEY_SSAVE key_ssave +KEY_SSUSPEND key_ssuspend +KEY_STAB key_stab +KEY_SUNDO key_sundo +KEY_SUSPEND key_suspend +KEY_UNDO key_undo +KEY_UP key_up diff --git a/contrib/ncurses/ncurses/tinfo/lib_acs.c b/contrib/ncurses/ncurses/tinfo/lib_acs.c new file mode 100644 index 0000000..d3c782e --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_acs.c @@ -0,0 +1,139 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +#include <curses.priv.h> +#include <term.h> /* ena_acs, acs_chars */ + +MODULE_ID("$Id: lib_acs.c,v 1.15 1999/02/18 11:31:43 tom Exp $") + +chtype acs_map[ACS_LEN]; + +void _nc_init_acs(void) +{ + T(("initializing ACS map")); + + /* + * 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 */ + /* 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 */ + + if (ena_acs != NULL) + { + TPUTS_TRACE("ena_acs"); + putp(ena_acs); + } + +#define ALTCHAR(c) ((chtype)(((unsigned char)(c)) | A_ALTCHARSET)) + + 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; + } + } +#ifdef TRACE + /* Show the equivalent mapping, noting if it does not match the + * given attribute, whether by re-ordering or duplication. + */ + if (_nc_tracing & TRACE_CALLS) { + size_t n, m; + char show[SIZEOF(acs_map) + 1]; + for (n = 1, m = 0; n < SIZEOF(acs_map); n++) { + if (acs_map[n] != 0) { + show[m++] = (char)n; + show[m++] = TextOf(acs_map[n]); + } + } + show[m] = 0; + _tracef("%s acs_chars %s", + (acs_chars == NULL) + ? "NULL" + : (strcmp(acs_chars, show) + ? "DIFF" + : "SAME"), + _nc_visbuf(show)); + } +#endif /* TRACE */ +} diff --git a/contrib/ncurses/ncurses/tinfo/lib_baudrate.c b/contrib/ncurses/ncurses/tinfo/lib_baudrate.c new file mode 100644 index 0000000..4077ba3 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_baudrate.c @@ -0,0 +1,178 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * lib_baudrate.c + * + */ + +#include <curses.priv.h> +#include <term.h> /* cur_term, pad_char */ +#include <termcap.h> /* ospeed */ + +MODULE_ID("$Id: lib_baudrate.c,v 1.15 1999/01/31 03:05:25 tom Exp $") + +/* + * int + * baudrate() + * + * Returns the current terminal's baud rate. + * + */ + +struct speed { + speed_t s; + int sp; +}; + +static struct speed const speeds[] = { + {B0, 0}, + {B50, 50}, + {B75, 75}, + {B110, 110}, + {B134, 134}, + {B150, 150}, + {B200, 200}, + {B300, 300}, + {B600, 600}, + {B1200, 1200}, + {B1800, 1800}, + {B2400, 2400}, + {B4800, 4800}, + {B9600, 9600}, +#ifdef B19200 + {B19200, 19200}, +#else +#ifdef EXTA + {EXTA, 19200}, +#endif +#endif +#ifdef B38400 + {B38400, 38400}, +#else +#ifdef EXTB + {EXTB, 38400}, +#endif +#endif +#ifdef B57600 + {B57600, 57600}, +#endif +#ifdef B115200 + {B115200, 115200}, +#endif +#ifdef B230400 + {B230400, 230400}, +#endif +#ifdef B460800 + {B460800, 460800}, +#endif +}; + +int _nc_baudrate(int OSpeed) +{ + static int last_OSpeed; + static int last_baudrate; + + int result; + unsigned i; + + if (OSpeed == last_OSpeed) { + result = last_baudrate; + } else { + result = ERR; + if (OSpeed >= 0) { + for (i = 0; i < SIZEOF(speeds); i++) { + if (speeds[i].s == (speed_t)OSpeed) { + result = speeds[i].sp; + break; + } + } + } + last_baudrate = result; + } + return (result); +} + + +int _nc_ospeed(int BaudRate) +{ + speed_t result = 1; + unsigned i; + + if (BaudRate >= 0) { + for (i = 0; i < SIZEOF(speeds); i++) { + if (speeds[i].sp == BaudRate) { + result = speeds[i].s; + break; + } + } + } + return (result); +} + +int +baudrate(void) +{ +int result; + + T((T_CALLED("baudrate()"))); + + /* + * In debugging, allow the environment symbol to override when we're + * redirecting to a file, so we can construct repeatable test-cases + * that take into account costs that depend on baudrate. + */ +#ifdef TRACE + if (SP && !isatty(fileno(SP->_ofp)) + && getenv("BAUDRATE") != 0) { + int ret; + if ((ret = _nc_getenv_num("BAUDRATE")) <= 0) + ret = 9600; + ospeed = _nc_ospeed(ret); + returnCode(ret); + } + else +#endif + +#ifdef TERMIOS + ospeed = cfgetospeed(&cur_term->Nttyb); +#else + ospeed = cur_term->Nttyb.sg_ospeed; +#endif + result = _nc_baudrate(ospeed); + if (cur_term != 0) + cur_term->_baudrate = result; + + returnCode(result); +} diff --git a/contrib/ncurses/ncurses/tinfo/lib_cur_term.c b/contrib/ncurses/ncurses/tinfo/lib_cur_term.c new file mode 100644 index 0000000..3250147 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_cur_term.c @@ -0,0 +1,70 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ +/* + * Module that "owns" the 'cur_term' variable: + * + * TERMINAL *set_curterm(TERMINAL *) + * int del_curterm(TERMINAL *) + */ + +#include <curses.priv.h> +#include <term_entry.h> /* TTY, cur_term */ +#include <termcap.h> /* ospeed */ + +MODULE_ID("$Id: lib_cur_term.c,v 1.8 1999/07/24 20:08:19 tom Exp $") + +TERMINAL *cur_term; + +TERMINAL *set_curterm(TERMINAL *termp) +{ + TERMINAL *oldterm = cur_term; + + if ((cur_term = termp) != 0) { + ospeed = _nc_ospeed(cur_term->_baudrate); + PC = (pad_char != NULL) ? pad_char[0] : 0; + } + return oldterm; +} + +int del_curterm(TERMINAL *termp) +{ + T((T_CALLED("del_curterm(%p)"), termp)); + + if (termp != 0) { + _nc_free_termtype(&(termp->type)); + free(termp); + if (termp == cur_term) + cur_term = 0; + returnCode(OK); + } + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/tinfo/lib_data.c b/contrib/ncurses/ncurses/tinfo/lib_data.c new file mode 100644 index 0000000..d2d0d3f --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_data.c @@ -0,0 +1,84 @@ +/**************************************************************************** + * Copyright (c) 1998,1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_data.c +** +** Common data that may/may not be allocated, but is referenced globally +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_data.c,v 1.14 1999/01/31 01:34:33 Ilya.Zakharevich Exp $") + +/* + * OS/2's native linker complains if we don't initialize public data when + * constructing a dll (reported by J.J.G.Ripoll). + */ +WINDOW *stdscr = 0; +WINDOW *curscr = 0; +WINDOW *newscr = 0; + +SCREEN *_nc_screen_chain = 0; + +/* + * The variable 'SP' will be defined as a function on systems that cannot link + * data-only modules, since it is used in a lot of places within ncurses and we + * cannot guarantee that any application will use any particular function. We + * put the WINDOW variables in this module, because it appears that any + * application that uses them will also use 'SP'. + * + * This module intentionally does not reference other ncurses modules, to avoid + * module coupling that increases the size of the executable. + */ +#if BROKEN_LINKER +static SCREEN *my_screen; + +SCREEN *_nc_screen(void) +{ + return my_screen; +} + +int _nc_alloc_screen(void) +{ + return ((my_screen = typeCalloc(SCREEN, 1)) != 0); +} + +void _nc_set_screen(SCREEN *sp) +{ + my_screen = sp; +} +#else +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 new file mode 100644 index 0000000..7121fc7 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_has_cap.c @@ -0,0 +1,63 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_has_cap.c +** +** The routines to query terminal capabilities +** +*/ + +#include <curses.priv.h> + +#include <term.h> + +MODULE_ID("$Id: lib_has_cap.c,v 1.1 1998/10/23 15:32:21 tom Exp $") + +bool has_ic(void) +{ + T((T_CALLED("has_ic()"))); + returnCode(cur_term && + (insert_character || parm_ich + || (enter_insert_mode && exit_insert_mode)) + && (delete_character || parm_dch)); +} + +bool has_il(void) +{ + T((T_CALLED("has_il()"))); + returnCode(cur_term + && (insert_line || parm_insert_line) + && (delete_line || parm_delete_line)); +} diff --git a/contrib/ncurses/ncurses/tinfo/lib_kernel.c b/contrib/ncurses/ncurses/tinfo/lib_kernel.c new file mode 100644 index 0000000..3c8c88e --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_kernel.c @@ -0,0 +1,130 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * lib_kernel.c + * + * Misc. low-level routines: + * erasechar() + * killchar() + * flushinp() + * + * The baudrate() and delay_output() functions could logically live here, + * but are in other modules to reduce the static-link size of programs + * that use only these facilities. + */ + +#include <curses.priv.h> +#include <term.h> /* cur_term */ + +MODULE_ID("$Id: lib_kernel.c,v 1.19 1998/12/20 00:18:45 tom Exp $") + +/* + * erasechar() + * + * Return erase character as given in cur_term->Ottyb. + * + */ + +char +erasechar(void) +{ + T((T_CALLED("erasechar()"))); + + if (cur_term != 0) { +#ifdef TERMIOS + returnCode(cur_term->Ottyb.c_cc[VERASE]); +#else + returnCode(cur_term->Ottyb.sg_erase); +#endif + } + returnCode(ERR); +} + + + +/* + * killchar() + * + * Return kill character as given in cur_term->Ottyb. + * + */ + +char +killchar(void) +{ + T((T_CALLED("killchar()"))); + + if (cur_term != 0) { +#ifdef TERMIOS + returnCode(cur_term->Ottyb.c_cc[VKILL]); +#else + returnCode(cur_term->Ottyb.sg_kill); +#endif + } + returnCode(ERR); +} + + + +/* + * flushinp() + * + * Flush any input on cur_term->Filedes + * + */ + +int flushinp(void) +{ + T((T_CALLED("flushinp()"))); + + if (cur_term != 0) { +#ifdef TERMIOS + tcflush(cur_term->Filedes, TCIFLUSH); +#else + errno = 0; + do { + ioctl(cur_term->Filedes, TIOCFLUSH, 0); + } while + (errno == EINTR); +#endif + if (SP) { + SP->_fifohead = -1; + SP->_fifotail = 0; + SP->_fifopeek = 0; + } + returnCode(OK); + } + returnCode(ERR); +} diff --git a/contrib/ncurses/ncurses/tinfo/lib_longname.c b/contrib/ncurses/ncurses/tinfo/lib_longname.c new file mode 100644 index 0000000..766e56c --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_longname.c @@ -0,0 +1,58 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_longname.c +** +** The routine longname(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_longname.c,v 1.7 1999/01/03 01:47:45 tom Exp $") + +char * +longname(void) +{ +char *ptr; + + T((T_CALLED("longname()"))); + + for (ptr = ttytype + strlen(ttytype); ptr > ttytype; ptr--) + if (*ptr == '|') + returnPtr(ptr + 1); + + returnPtr(ttytype); +} diff --git a/contrib/ncurses/ncurses/tinfo/lib_napms.c b/contrib/ncurses/ncurses/tinfo/lib_napms.c new file mode 100644 index 0000000..6f786c2 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_napms.c @@ -0,0 +1,90 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * lib_napms.c + * + * The routine napms. + * + */ + +#include <curses.priv.h> + +#if HAVE_NANOSLEEP +#include <time.h> +#elif USE_FUNC_POLL +#include <stropts.h> +#include <poll.h> +#if HAVE_SYS_TIME_H +#include <sys/time.h> +#endif +#elif HAVE_SELECT +#if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT +#include <sys/time.h> +#endif +#if HAVE_SYS_SELECT_H +#include <sys/select.h> +#endif +#endif + +MODULE_ID("$Id: lib_napms.c,v 1.5 1999/06/06 00:42:47 R.Lindsay.Todd Exp $") + +int napms(int ms) +{ + T((T_CALLED("napms(%d)"), ms)); + +#if HAVE_NANOSLEEP + { + struct timespec ts; + ts.tv_sec = ms / 1000; + ts.tv_nsec = (ms % 1000) * 1000000; + nanosleep(&ts, NULL); + } +#elif HAVE_USLEEP + usleep(1000*(unsigned)ms); +#elif USE_FUNC_POLL + { + struct pollfd fds[1]; + poll(fds, 0, ms); + } +#elif HAVE_SELECT + { + struct timeval tval; + tval.tv_sec = ms / 1000; + tval.tv_usec = (ms % 1000) * 1000; + select(0, NULL, NULL, NULL, &tval); + } +#endif + returnCode(OK); +} diff --git a/contrib/ncurses/ncurses/tinfo/lib_options.c b/contrib/ncurses/ncurses/tinfo/lib_options.c new file mode 100644 index 0000000..654e0ed --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_options.c @@ -0,0 +1,261 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_options.c +** +** The routines to handle option setting. +** +*/ + +#include <curses.priv.h> + +#include <term.h> /* keypad_xmit, keypad_local, meta_on, meta_off */ + /* cursor_visible,cursor_normal,cursor_invisible */ + +MODULE_ID("$Id: lib_options.c,v 1.35 1999/07/04 00:18:28 tom Exp $") + +int idlok(WINDOW *win, bool flag) +{ + T((T_CALLED("idlok(%p,%d)"), win, flag)); + + if (win) { + _nc_idlok = win->_idlok = flag && (has_il() || change_scroll_region); + returnCode(OK); + } + else + returnCode(ERR); +} + + +void idcok(WINDOW *win, bool flag) +{ + T((T_CALLED("idcok(%p,%d)"), win, flag)); + + if (win) + _nc_idcok = win->_idcok = flag && has_ic(); + + returnVoid; +} + +int halfdelay(int t) +{ + T((T_CALLED("halfdelay(%d)"), t)); + + if (t < 1 || t > 255) + returnCode(ERR); + + cbreak(); + SP->_cbreak = t+1; + returnCode(OK); +} + +int nodelay(WINDOW *win, bool flag) +{ + T((T_CALLED("nodelay(%p,%d)"), win, flag)); + + if (win) { + if (flag == TRUE) + win->_delay = 0; + else win->_delay = -1; + returnCode(OK); + } + else + returnCode(ERR); +} + +int notimeout(WINDOW *win, bool f) +{ + T((T_CALLED("notimout(%p,%d)"), win, f)); + + if (win) { + win->_notimeout = f; + returnCode(OK); + } + else + returnCode(ERR); +} + +void wtimeout(WINDOW *win, int delay) +{ + T((T_CALLED("wtimeout(%p,%d)"), win, delay)); + + if (win) { + win->_delay = delay; + } +} + +int keypad(WINDOW *win, bool flag) +{ + T((T_CALLED("keypad(%p,%d)"), win, flag)); + + if (win) { + win->_use_keypad = flag; + returnCode(_nc_keypad(flag)); + } + else + returnCode(ERR); +} + + +int meta(WINDOW *win GCC_UNUSED, bool flag) +{ + /* 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); + } + returnCode(OK); +} + +/* curs_set() moved here to narrow the kernel interface */ + +int curs_set(int vis) +{ +int cursor = SP->_cursor; + + 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; + } + SP->_cursor = vis; + (void) fflush(SP->_ofp); + + returnCode(cursor==-1 ? 1 : cursor); +} + +int typeahead(int fd) +{ + T((T_CALLED("typeahead(%d)"), fd)); + SP->_checkfd = fd; + returnCode(OK); +} + +/* +** has_key() +** +** Return TRUE if the current terminal has the given key +** +*/ + +#ifdef NCURSES_EXT_FUNCS +static int has_key_internal(int keycode, struct tries *tp) +{ + if (tp == 0) + return(FALSE); + else if (tp->value == keycode) + return(TRUE); + else + return(has_key_internal(keycode, tp->child) + || has_key_internal(keycode, tp->sibling)); +} + +int has_key(int keycode) +{ + T((T_CALLED("has_key(%d)"), keycode)); + returnCode(has_key_internal(keycode, SP->_keytry)); +} +#endif /* NCURSES_EXT_FUNCS */ + +/* Turn the keypad on/off + * + * Note: we flush the output because changing this mode causes some terminals + * to emit different escape sequences for cursor and keypad keys. If we don't + * flush, then the next wgetch may get the escape sequence that corresponds to + * the terminal state _before_ switching modes. + */ +int _nc_keypad(bool flag) +{ + if (flag && keypad_xmit) + { + TPUTS_TRACE("keypad_xmit"); + putp(keypad_xmit); + (void) fflush(SP->_ofp); + } + else if (! flag && keypad_local) + { + TPUTS_TRACE("keypad_local"); + putp(keypad_local); + (void) fflush(SP->_ofp); + } + + if (flag && !SP->_tried) { + _nc_init_keytry(); + SP->_tried = TRUE; + } + return(OK); +} diff --git a/contrib/ncurses/ncurses/tinfo/lib_print.c b/contrib/ncurses/ncurses/tinfo/lib_print.c new file mode 100644 index 0000000..63ac648 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_print.c @@ -0,0 +1,96 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +#include <curses.priv.h> + +#include <term.h> + +MODULE_ID("$Id: lib_print.c,v 1.11 1999/02/27 19:59:05 tom Exp $") + +int mcprint(char *data, int len) +/* ship binary character data to the printer via mc4/mc5/mc5p */ +{ + char *mybuf, *switchon; + size_t onsize, offsize, res; + + errno = 0; + if (!cur_term || (!prtr_non && (!prtr_on || !prtr_off))) + { + errno = ENODEV; + return(ERR); + } + + if (prtr_non) + { + switchon = tparm(prtr_non, len); + onsize = strlen(switchon); + offsize = 0; + } + else + { + switchon = prtr_on; + onsize = strlen(prtr_on); + offsize = strlen(prtr_off); + } + + if ((mybuf = typeMalloc(char, onsize + len + offsize + 1)) == (char *)0) + { + errno = ENOMEM; + return(ERR); + } + + (void) strcpy(mybuf, switchon); + memcpy(mybuf + onsize, data, len); + if (offsize) + (void) strcpy(mybuf + onsize + len, prtr_off); + + /* + * We're relying on the atomicity of UNIX writes here. The + * danger is that output from a refresh() might get interspersed + * with the printer data after the write call returns but before the + * data has actually been shipped to the terminal. If the write(2) + * operation is truly atomic we're protected from this. + */ + res = write(cur_term->Filedes, mybuf, onsize + len + offsize); + + /* + * By giving up our scheduler slot here we increase the odds that the + * kernel will ship the contiguous clist items from the last write + * immediately. + */ + (void) sleep(0); + + free(mybuf); + return(res); +} diff --git a/contrib/ncurses/ncurses/tinfo/lib_raw.c b/contrib/ncurses/ncurses/tinfo/lib_raw.c new file mode 100644 index 0000000..61b422c --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_raw.c @@ -0,0 +1,233 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * raw.c + * + * Routines: + * raw() + * cbreak() + * noraw() + * nocbreak() + * qiflush() + * noqiflush() + * intrflush() + * + */ + +#include <curses.priv.h> +#include <term.h> /* cur_term */ + +MODULE_ID("$Id: lib_raw.c,v 1.3 1999/03/06 22:28:24 tom Exp $") + +#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE) +#define _POSIX_SOURCE +#endif + +#if HAVE_SYS_TERMIO_H +#include <sys/termio.h> /* needed for ISC */ +#endif + +#ifdef __EMX__ +#include <io.h> +#include <fcntl.h> +#endif + +#define COOKED_INPUT (IXON|BRKINT|PARMRK) + +#ifdef TRACE +#define BEFORE(N) if (_nc_tracing&TRACE_BITS) _tracef("%s before bits: %s", N, _nc_tracebits()) +#define AFTER(N) if (_nc_tracing&TRACE_BITS) _tracef("%s after bits: %s", N, _nc_tracebits()) +#else +#define BEFORE(s) +#define AFTER(s) +#endif /* TRACE */ + +int raw(void) +{ + T((T_CALLED("raw()"))); + if (SP != 0 && cur_term != 0) { + + SP->_raw = TRUE; + SP->_cbreak = 1; + +#ifdef __EMX__ + setmode(SP->_ifd, O_BINARY); +#endif + +#ifdef TERMIOS + BEFORE("raw"); + cur_term->Nttyb.c_lflag &= ~(ICANON|ISIG); + cur_term->Nttyb.c_iflag &= ~(COOKED_INPUT); + cur_term->Nttyb.c_cc[VMIN] = 1; + cur_term->Nttyb.c_cc[VTIME] = 0; + AFTER("raw"); +#else + cur_term->Nttyb.sg_flags |= RAW; +#endif + returnCode(_nc_set_tty_mode(&cur_term->Nttyb)); + } + returnCode(ERR); +} + +int cbreak(void) +{ + T((T_CALLED("cbreak()"))); + + SP->_cbreak = 1; + +#ifdef __EMX__ + setmode(SP->_ifd, O_BINARY); +#endif + +#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"); +#else + cur_term->Nttyb.sg_flags |= CBREAK; +#endif + returnCode(_nc_set_tty_mode( &cur_term->Nttyb)); +} + +void qiflush(void) +{ + T((T_CALLED("qiflush()"))); + + /* + * Note: this implementation may be wrong. See the comment under + * intrflush(). + */ + +#ifdef TERMIOS + BEFORE("qiflush"); + cur_term->Nttyb.c_lflag &= ~(NOFLSH); + AFTER("qiflush"); + (void)_nc_set_tty_mode( &cur_term->Nttyb); + returnVoid; +#endif +} + + +int noraw(void) +{ + T((T_CALLED("noraw()"))); + + SP->_raw = FALSE; + SP->_cbreak = 0; + +#ifdef __EMX__ + setmode(SP->_ifd, O_TEXT); +#endif + +#ifdef TERMIOS + BEFORE("noraw"); + cur_term->Nttyb.c_lflag |= ISIG|ICANON; + cur_term->Nttyb.c_iflag |= COOKED_INPUT; + AFTER("noraw"); +#else + cur_term->Nttyb.sg_flags &= ~(RAW|CBREAK); +#endif + returnCode(_nc_set_tty_mode( &cur_term->Nttyb)); +} + + +int nocbreak(void) +{ + T((T_CALLED("nocbreak()"))); + + SP->_cbreak = 0; + +#ifdef __EMX__ + setmode(SP->_ifd, O_TEXT); +#endif + +#ifdef TERMIOS + BEFORE("nocbreak"); + cur_term->Nttyb.c_lflag |= ICANON; + cur_term->Nttyb.c_iflag |= ICRNL; + AFTER("nocbreak"); +#else + cur_term->Nttyb.sg_flags &= ~CBREAK; +#endif + returnCode(_nc_set_tty_mode( &cur_term->Nttyb)); +} + +void noqiflush(void) +{ + T((T_CALLED("noqiflush()"))); + + /* + * Note: this implementation may be wrong. See the comment under + * intrflush(). + */ + +#ifdef TERMIOS + BEFORE("noqiflush"); + cur_term->Nttyb.c_lflag |= NOFLSH; + AFTER("noqiflush"); + (void)_nc_set_tty_mode( &cur_term->Nttyb); + returnVoid; +#endif +} + +int intrflush(WINDOW *win GCC_UNUSED, bool flag) +{ + 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. + */ + +#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)); +#else + returnCode(ERR); +#endif +} diff --git a/contrib/ncurses/ncurses/tinfo/lib_setup.c b/contrib/ncurses/ncurses/tinfo/lib_setup.c new file mode 100644 index 0000000..64aa73f --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_setup.c @@ -0,0 +1,422 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * Terminal setup routines common to termcap and terminfo: + * + * use_env(bool) + * setupterm(char *, int, int *) + */ + +#include <curses.priv.h> +#include <tic.h> /* for MAX_NAME_SIZE */ +#include <term_entry.h> + +#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE) +#define _POSIX_SOURCE +#endif + +#include <term.h> /* lines, columns, cur_term */ + +MODULE_ID("$Id: lib_setup.c,v 1.55 1999/08/21 23:06:08 tom Exp $") + +/**************************************************************************** + * + * Terminal size computation + * + ****************************************************************************/ + +#if HAVE_SIZECHANGE +# if !defined(sun) || !TERMIOS +# if HAVE_SYS_IOCTL_H +# include <sys/ioctl.h> +# endif +# endif +#endif + +#if NEED_PTEM_H + /* On SCO, they neglected to define struct winsize in termios.h -- it's only + * in termio.h and ptem.h (the former conflicts with other definitions). + */ +# include <sys/stream.h> +# include <sys/ptem.h> +#endif + +/* + * SCO defines TIOCGSIZE and the corresponding struct. Other systems (SunOS, + * Solaris, IRIX) define TIOCGWINSZ and struct winsize. + */ +#ifdef TIOCGSIZE +# define IOCTL_WINSIZE TIOCGSIZE +# define STRUCT_WINSIZE struct ttysize +# define WINSIZE_ROWS(n) (int)n.ts_lines +# define WINSIZE_COLS(n) (int)n.ts_cols +#else +# ifdef TIOCGWINSZ +# define IOCTL_WINSIZE TIOCGWINSZ +# define STRUCT_WINSIZE struct winsize +# define WINSIZE_ROWS(n) (int)n.ws_row +# define WINSIZE_COLS(n) (int)n.ws_col +# endif +#endif + +static int _use_env = TRUE; + +static void do_prototype(void); + +void use_env(bool f) +{ + _use_env = f; +} + +int LINES, COLS, TABSIZE; + +static void _nc_get_screensize(int *linep, int *colp) +/* Obtain lines/columns values from the environment and/or terminfo entry */ +{ + /* figure out the size of the screen */ + T(("screen size: terminfo lines = %d columns = %d", lines, columns)); + + if (!_use_env) + { + *linep = (int)lines; + *colp = (int)columns; + } + else /* usually want to query LINES and COLUMNS from environment */ + { + int value; + + *linep = *colp = 0; + + /* first, look for environment variables */ + if ((value = _nc_getenv_num("LINES")) > 0) { + *linep = value; + } + if ((value = _nc_getenv_num("COLUMNS")) > 0) { + *colp = value; + } + T(("screen size: environment LINES = %d COLUMNS = %d",*linep,*colp)); + +#ifdef __EMX__ + if (*linep <= 0 || *colp <= 0) + { + int screendata[2]; + _scrsize(screendata); + *colp = screendata[0]; + *linep = screendata[1]; + T(("EMX screen size: environment LINES = %d COLUMNS = %d",*linep,*colp)); + } +#endif +#if HAVE_SIZECHANGE + /* if that didn't work, maybe we can try asking the OS */ + if (*linep <= 0 || *colp <= 0) + { + if (isatty(cur_term->Filedes)) + { + STRUCT_WINSIZE size; + + errno = 0; + do { + if (ioctl(cur_term->Filedes, IOCTL_WINSIZE, &size) < 0 + && errno != EINTR) + goto failure; + } while + (errno == EINTR); + + /* + * Solaris lets users override either dimension with an + * environment variable. + */ + if (*linep <= 0) + *linep = WINSIZE_ROWS(size); + if (*colp <= 0) + *colp = WINSIZE_COLS(size); + } + /* FALLTHRU */ + failure:; + } +#endif /* HAVE_SIZECHANGE */ + + /* if we can't get dynamic info about the size, use static */ + if (*linep <= 0 || *colp <= 0) + if (lines > 0 && columns > 0) + { + *linep = (int)lines; + *colp = (int)columns; + } + + /* the ultimate fallback, assume fixed 24x80 size */ + if (*linep <= 0 || *colp <= 0) + { + *linep = 24; + *colp = 80; + } + + /* + * Put the derived values back in the screen-size caps, so + * tigetnum() and tgetnum() will do the right thing. + */ + lines = (short)(*linep); + columns = (short)(*colp); + } + + T(("screen size is %dx%d", *linep, *colp)); + + if (init_tabs != -1) + TABSIZE = (int)init_tabs; + else + TABSIZE = 8; + T(("TABSIZE = %d", TABSIZE)); + +} + +#if USE_SIZECHANGE +void _nc_update_screensize(void) +{ + int my_lines, my_cols; + + _nc_get_screensize(&my_lines, &my_cols); + if (SP != 0 && SP->_resize != 0) + SP->_resize(my_lines, my_cols); +} +#endif + +/**************************************************************************** + * + * Terminal setup + * + ****************************************************************************/ + +#define ret_error(code, fmt, arg) if (errret) {\ + *errret = code;\ + returnCode(ERR);\ + } else {\ + fprintf(stderr, fmt, arg);\ + exit(EXIT_FAILURE);\ + } + +#define ret_error0(code, msg) if (errret) {\ + *errret = code;\ + returnCode(ERR);\ + } else {\ + fprintf(stderr, msg);\ + exit(EXIT_FAILURE);\ + } + +#if USE_DATABASE +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 */ +{ + char filename[PATH_MAX]; + int status; + + /* + * $TERM shouldn't contain pathname delimiters. + */ + if (strchr(tn, '/')) + return 0; + + if ((status = _nc_read_entry(tn, filename, tp)) != 1) { + +#ifndef 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 */ + + } + + /* + * If we have an entry, force all of the cancelled strings to null + * pointers so we don't have to test them in the rest of the library. + * (The terminfo compiler bypasses this logic, since it must know if + * a string is cancelled, for merging entries). + */ + if (status == 1) { + int n; + for_each_boolean(n,tp) + if (!VALID_BOOLEAN(tp->Booleans[n])) + tp->Booleans[n] = FALSE; + for_each_string(n,tp) + if (tp->Strings[n] == CANCELLED_STRING) + tp->Strings[n] = ABSENT_STRING; + } + return(status); +} +#endif + +char ttytype[NAMESIZE]; + +/* + * setupterm(termname, Filedes, errret) + * + * Find and read the appropriate object file for the terminal + * Make cur_term point to the structure. + * + */ + +int setupterm(NCURSES_CONST char *tname, int Filedes, int *errret) +{ +struct term *term_ptr; +int status; + + 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"); + } + } + if (strlen(tname) > MAX_NAME_SIZE) { + ret_error(-1, "TERM environment must be <= %d characters.\n", + MAX_NAME_SIZE); + } + + T(("your terminal name is %s", tname)); + + term_ptr = typeCalloc(TERMINAL, 1); + + if (term_ptr == 0) { + ret_error0(-1, "Not enough memory to create terminal structure.\n") ; + } +#if USE_DATABASE + status = grab_entry(tname, &term_ptr->type); +#else + status = 0; +#endif + + /* try fallback list if entry on disk */ + if (status != 1) + { + const TERMTYPE *fallback = _nc_fallback(tname); + + if (fallback) + { + term_ptr->type = *fallback; + status = 1; + } + } + + if (status == -1) + { + ret_error0(-1, "terminals database is inaccessible\n"); + } + else if (status == 0) + { + ret_error(0, "'%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(); + + strncpy(ttytype, cur_term->type.term_names, NAMESIZE - 1); + ttytype[NAMESIZE - 1] = '\0'; + + /* + * 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; + cur_term->Filedes = Filedes; + + _nc_get_screensize(&LINES, &COLS); + + if (errret) + *errret = 1; + + T((T_CREATE("screen %s %dx%d"), tname, LINES, COLS)); + + if (generic_type) { + ret_error(0, "'%s': I need something more specific.\n", tname); + } + if (hard_copy) { + ret_error(1, "'%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) +{ +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; + } + } +} diff --git a/contrib/ncurses/ncurses/tinfo/lib_termcap.c b/contrib/ncurses/ncurses/tinfo/lib_termcap.c new file mode 100644 index 0000000..488b3c9 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_termcap.c @@ -0,0 +1,198 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +#include <curses.priv.h> + +#include <termcap.h> +#include <tic.h> + +#define __INTERNAL_CAPS_VISIBLE +#include <term_entry.h> + +MODULE_ID("$Id: lib_termcap.c,v 1.28 1999/02/27 22:12:58 tom Exp $") + +/* + some of the code in here was contributed by: + Magnus Bengtsson, d6mbeng@dtek.chalmers.se +*/ + +char *UP; +char *BC; + +/*************************************************************************** + * + * tgetent(bufp, term) + * + * In termcap, this function reads in the entry for terminal `term' into the + * buffer pointed to by bufp. It must be called before any of the functions + * below are called. + * In this terminfo emulation, tgetent() simply calls setupterm() (which + * does a bit more than tgetent() in termcap does), and returns its return + * value (1 if successful, 0 if no terminal with the given name could be + * found, or -1 if no terminal descriptions have been installed on the + * system). The bufp argument is ignored. + * + ***************************************************************************/ + +int tgetent(char *bufp GCC_UNUSED, const char *name) +{ +int errcode; + + T((T_CALLED("tgetent()"))); + + setupterm((NCURSES_CONST char *)name, STDOUT_FILENO, &errcode); + + if (errcode == 1) { + + if (cursor_left) + if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0) + backspace_if_not_bs = cursor_left; + + /* we're required to export these */ + if (pad_char != NULL) + PC = pad_char[0]; + if (cursor_up != NULL) + UP = cursor_up; + if (backspace_if_not_bs != NULL) + BC = backspace_if_not_bs; + + (void) baudrate(); /* sets ospeed as a side-effect */ + +/* LINT_PREPRO +#if 0*/ +#include <capdefaults.c> +/* LINT_PREPRO +#endif*/ + + } + returnCode(errcode); +} + +/*************************************************************************** + * + * tgetflag(str) + * + * Look up boolean termcap capability str and return its value (TRUE=1 if + * present, FALSE=0 if not). + * + ***************************************************************************/ + +int tgetflag(NCURSES_CONST char *id) +{ +int i; + + T((T_CALLED("tgetflag(%s)"), id)); + if (cur_term != 0) { + TERMTYPE *tp = &(cur_term->type); + for_each_boolean(i, tp) { + const char *capname = ExtBoolname(tp, i, boolcodes); + if (!strncmp(id, capname, 2)) { + /* setupterm forces invalid booleans to false */ + returnCode(tp->Booleans[i]); + } + } + } + returnCode(0); /* Solaris does this */ +} + +/*************************************************************************** + * + * tgetnum(str) + * + * Look up numeric termcap capability str and return its value, or -1 if + * not given. + * + ***************************************************************************/ + +int tgetnum(NCURSES_CONST char *id) +{ +int i; + + T((T_CALLED("tgetnum(%s)"), id)); + if (cur_term != 0) { + TERMTYPE *tp = &(cur_term->type); + for_each_number(i, tp) { + const char *capname = ExtNumname(tp, i, numcodes); + if (!strncmp(id, capname, 2)) { + if (!VALID_NUMERIC(tp->Numbers[i])) + return -1; + returnCode(tp->Numbers[i]); + } + } + } + returnCode(ERR); +} + +/*************************************************************************** + * + * tgetstr(str, area) + * + * Look up string termcap capability str and return a pointer to its value, + * or NULL if not given. + * + ***************************************************************************/ + +char *tgetstr(NCURSES_CONST char *id, char **area GCC_UNUSED) +{ +int i; + + T((T_CALLED("tgetstr(%s,%p)"), id, area)); + if (cur_term != 0) { + TERMTYPE *tp = &(cur_term->type); + for_each_string(i, tp) { + const char *capname = ExtStrname(tp, i, strcodes); + T(("trying %s", capname)); + if (!strncmp(id, capname, 2)) { + T(("found match : %s", _nc_visbuf(tp->Strings[i]))); + /* setupterm forces cancelled strings to null */ + returnPtr(tp->Strings[i]); + } + } + } + returnPtr(NULL); +} + +/* + * char * + * tgoto(string, x, y) + * + * Retained solely for upward compatibility. Note the intentional + * reversing of the last two arguments. + * + */ + +char *tgoto(const char *string, int x, int y) +{ + T((T_CALLED("tgoto(%s,%d,%d)"), string, x, y)); + returnPtr(tparm((NCURSES_CONST char *)string, y, x)); +} diff --git a/contrib/ncurses/ncurses/tinfo/lib_termname.c b/contrib/ncurses/ncurses/tinfo/lib_termname.c new file mode 100644 index 0000000..e705738 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_termname.c @@ -0,0 +1,46 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +#include <curses.priv.h> +#include <tic.h> /* for MAX_ALIAS */ + +MODULE_ID("$Id: lib_termname.c,v 1.2 1999/07/24 21:02:40 tom Exp $") + +char *termname(void) +{ +char *name = getenv("TERM"); +static char ret[MAX_ALIAS+1]; + + T(("termname() called")); + + if (name != 0) { + (void) strncpy(ret, name, sizeof(ret) - 1); + name = ret; + } + return name; +} diff --git a/contrib/ncurses/ncurses/tinfo/lib_ti.c b/contrib/ncurses/ncurses/tinfo/lib_ti.c new file mode 100644 index 0000000..7b2b2f9 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_ti.c @@ -0,0 +1,101 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +#include <curses.priv.h> + +#include <term_entry.h> +#include <tic.h> + +MODULE_ID("$Id: lib_ti.c,v 1.16 1999/02/28 23:11:28 tom Exp $") + +int tigetflag(NCURSES_CONST char *str) +{ +int i; + + T((T_CALLED("tigetflag(%s)"), str)); + + if (cur_term != 0) { + TERMTYPE *tp = &(cur_term->type); + for_each_boolean(i,tp) { + const char *capname = ExtBoolname(tp, i, boolnames); + if (!strcmp(str, capname)) { + /* setupterm forces invalid booleans to false */ + returnCode(tp->Booleans[i]); + } + } + } + + returnCode(ABSENT_BOOLEAN); +} + +int tigetnum(NCURSES_CONST char *str) +{ +int i; + + T((T_CALLED("tigetnum(%s)"), str)); + + if (cur_term != 0) { + TERMTYPE *tp = &(cur_term->type); + for_each_number(i, tp) { + const char *capname = ExtNumname(tp, i, numnames); + if (!strcmp(str, capname)) { + if (!VALID_NUMERIC(tp->Numbers[i])) + return -1; + returnCode(tp->Numbers[i]); + } + } + } + + returnCode(CANCELLED_NUMERIC); /* Solaris returns a -1 instead */ +} + +char *tigetstr(NCURSES_CONST char *str) +{ +int i; + + T((T_CALLED("tigetstr(%s)"), str)); + + if (cur_term != 0) { + TERMTYPE *tp = &(cur_term->type); + for_each_string(i, tp) { + const char *capname = ExtStrname(tp, i, strnames); + if (!strcmp(str, capname)) { + /* setupterm forces cancelled strings to null */ + returnPtr(tp->Strings[i]); + } + } + } + + returnPtr(CANCELLED_STRING); +} diff --git a/contrib/ncurses/ncurses/tinfo/lib_tparm.c b/contrib/ncurses/ncurses/tinfo/lib_tparm.c new file mode 100644 index 0000000..71b8291 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_tparm.c @@ -0,0 +1,585 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * tparm.c + * + */ + +#include <curses.priv.h> + +#include <ctype.h> +#include <term.h> +#include <tic.h> + +MODULE_ID("$Id: lib_tparm.c,v 1.39 1999/06/06 00:04:55 tom Exp $") + +/* + * char * + * tparm(string, ...) + * + * Substitute the given parameters into the given string by the following + * rules (taken from terminfo(5)): + * + * Cursor addressing and other strings requiring parame- + * ters in the terminal are described by a parameterized string + * capability, with like escapes %x in it. For example, to + * address the cursor, the cup capability is given, using two + * parameters: the row and column to address to. (Rows and + * columns are numbered from zero and refer to the physical + * screen visible to the user, not to any unseen memory.) If + * the terminal has memory relative cursor addressing, that can + * be indicated by + * + * The parameter mechanism uses a stack and special % + * codes to manipulate it. Typically a sequence will push one + * of the parameters onto the stack and then print it in some + * format. Often more complex operations are necessary. + * + * The % encodings have the following meanings: + * + * %% outputs `%' + * %c print pop() like %c in printf() + * %s print pop() like %s in printf() + * %[[:]flags][width[.precision]][doxXs] + * as in printf, flags are [-+#] and space + * + * %p[1-9] push ith parm + * %P[a-z] set dynamic variable [a-z] to pop() + * %g[a-z] get dynamic variable [a-z] and push it + * %P[A-Z] set static variable [A-Z] to pop() + * %g[A-Z] get static variable [A-Z] and push it + * %l push strlen(pop) + * %'c' push char constant c + * %{nn} push integer constant nn + * + * %+ %- %* %/ %m + * arithmetic (%m is mod): push(pop() op pop()) + * %& %| %^ bit operations: push(pop() op pop()) + * %= %> %< logical operations: push(pop() op pop()) + * %A %O logical and & or operations for conditionals + * %! %~ unary operations push(op pop()) + * %i add 1 to first two parms (for ANSI terminals) + * + * %? expr %t thenpart %e elsepart %; + * if-then-else, %e elsepart is optional. + * else-if's are possible ala Algol 68: + * %? c1 %t b1 %e c2 %t b2 %e c3 %t b3 %e c4 %t b4 %e b5 %; + * + * For those of the above operators which are binary and not commutative, + * the stack works in the usual way, with + * %gx %gy %m + * resulting in x mod y, not the reverse. + */ + +#define STACKSIZE 20 + +typedef union { + unsigned int num; + char *str; +} stack_frame; + +static stack_frame stack[STACKSIZE]; +static int stack_ptr; +#ifdef TRACE +static const char *tname; +#endif /* TRACE */ + +static char *out_buff; +static size_t out_size; +static size_t out_used; + +#if NO_LEAKS +void _nc_free_tparm(void) +{ + if (out_buff != 0) { + FreeAndNull(out_buff); + out_size = 0; + out_used = 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 get_space(size_t need) +{ + need += out_used; + if (need > out_size) + really_get_space(need); +} + +static inline void save_text(const char *fmt, char *s, int len) +{ + size_t s_len = strlen(s); + if (len > (int)s_len) + s_len = len; + + get_space(s_len + 1); + + (void)sprintf(out_buff+out_used, fmt, s); + out_used += strlen(out_buff+out_used); +} + +static 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); + + (void)sprintf(out_buff+out_used, fmt, number); + out_used += strlen(out_buff+out_used); +} + +static inline void save_char(int c) +{ + if (c == 0) + c = 0200; + get_space(1); + out_buff[out_used++] = c; +} + +static inline void npush(int x) +{ + if (stack_ptr < STACKSIZE) { + stack[stack_ptr].num = x; + stack_ptr++; + } +} + +static inline int npop(void) +{ + return (stack_ptr > 0 ? stack[--stack_ptr].num : 0); +} + +static inline char *spop(void) +{ + static char dummy[] = ""; /* avoid const-cast */ + return (stack_ptr > 0 ? stack[--stack_ptr].str : dummy); +} + +static inline const char *parse_format(const char *s, char *format, int *len) +{ + bool done = FALSE; + bool allowminus = FALSE; + bool dot = FALSE; + int prec = 0; + int width = 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++; + dot = TRUE; + break; + case '#': + *format++ = *s++; + break; + case ' ': + *format++ = *s++; + break; + case ':': + s++; + allowminus = TRUE; + break; + case '-': + if (allowminus) { + *format++ = *s++; + } else { + done = TRUE; + } + break; + default: + if (isdigit(*s)) { + if (dot) + prec = (prec * 10) + (*s - '0'); + else + width = (width * 10) + (*s - '0'); + *format++ = *s++; + } else { + done = TRUE; + } + } + } + *format = '\0'; + /* return maximum string length in print */ + *len = (prec > width) ? prec : width; + 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) +{ +#define NUM_VARS 26 +int param[9]; +int popcount; +int number; +int len; +int level; +int x, y; +int i; +register const char *cp; +static size_t len_fmt; +static char *format; +static int dynamic_var[NUM_VARS]; +static int static_vars[NUM_VARS]; + + out_used = 0; + if (string == NULL) + return NULL; + + /* + * 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. + */ + for (cp = string, popcount = number = 0; *cp != '\0'; cp++) { + if (cp[0] == '%' && cp[1] != '\0') { + switch (cp[1]) { + case '%': + cp++; + break; + case 'i': + if (popcount < 2) + popcount = 2; + break; + case 'p': + cp++; + if (cp[1] >= '1' && cp[1] <= '9') { + int c = cp[1] - '0'; + if (c > popcount) + popcount = c; + } + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case 'd': case 'c': case 's': + ++number; + break; + } + } + } + if ((size_t)(cp - string) > len_fmt) { + len_fmt = (cp - string) + len_fmt + 2; + if ((format = typeRealloc(char, len_fmt, format)) == 0) + return 0; + } + + if (number > 9) number = 9; + for (i = 0; i < max(popcount, number); i++) { + /* + * FIXME: potential loss here if sizeof(int) != sizeof(char *). + * A few caps (such as plab_norm) have string-valued parms. + */ + param[i] = va_arg(ap, int); + } + + /* + * This is a termcap compatibility hack. If there are no explicit pop + * operations in the string, load the stack in such a way that + * successive pops will grab successive parameters. That will make + * the expansion of (for example) \E[%d;%dH work correctly in termcap + * style, which means tparam() will expand termcap strings OK. + */ + stack_ptr = 0; + if (popcount == 0) { + popcount = number; + for (i = number - 1; i >= 0; i--) + npush(param[i]); + } + +#ifdef TRACE + if (_nc_tracing & TRACE_CALLS) { + for (i = 0; i < popcount; i++) + save_number(", %d", param[i], 0); + _tracef(T_CALLED("%s(%s%s)"), tname, _nc_visbuf(string), out_buff); + out_used = 0; + } +#endif /* TRACE */ + + while (*string) { + if (*string != '%') { + save_char(*string); + } else { + string++; + string = parse_format(string, format, &len); + switch (*string) { + default: + break; + case '%': + save_char('%'); + break; + + case 'd': /* FALLTHRU */ + case 'o': /* FALLTHRU */ + case 'x': /* FALLTHRU */ + case 'X': /* FALLTHRU */ + case 'c': + save_number(format, npop(), len); + break; + + case 'l': + save_number("%d", strlen(spop()), 0); + break; + + case 's': + save_text(format, spop(), len); + break; + + case 'p': + string++; + if (*string >= '1' && *string <= '9') + npush(param[*string - '1']); + break; + + case 'P': + string++; + if (isUPPER(*string)) { + i = (*string - 'A'); + static_vars[i] = npop(); + } else if (isLOWER(*string)) { + i = (*string - 'a'); + dynamic_var[i] = npop(); + } + break; + + case 'g': + string++; + if (isUPPER(*string)) { + i = (*string - 'A'); + npush(static_vars[i]); + } else if (isLOWER(*string)) { + i = (*string - 'a'); + npush(dynamic_var[i]); + } + break; + + case S_QUOTE: + string++; + npush(*string); + string++; + break; + + case L_BRACE: + number = 0; + string++; + while (*string >= '0' && *string <= '9') { + number = number * 10 + *string - '0'; + string++; + } + npush(number); + break; + + case '+': + npush(npop() + npop()); + break; + + case '-': + y = npop(); + x = npop(); + npush(x - y); + break; + + case '*': + npush(npop() * npop()); + break; + + case '/': + y = npop(); + x = npop(); + npush(y ? (x / y) : 0); + break; + + case 'm': + y = npop(); + x = npop(); + npush(y ? (x % y) : 0); + break; + + case 'A': + npush(npop() && npop()); + break; + + case 'O': + npush(npop() || npop()); + break; + + case '&': + npush(npop() & npop()); + break; + + case '|': + npush(npop() | npop()); + break; + + case '^': + npush(npop() ^ npop()); + break; + + case '=': + y = npop(); + x = npop(); + npush(x == y); + break; + + case '<': + y = npop(); + x = npop(); + npush(x < y); + break; + + case '>': + y = npop(); + x = npop(); + npush(x > y); + break; + + case '!': + npush(! npop()); + break; + + case '~': + npush(~ npop()); + break; + + case 'i': + param[0]++; + param[1]++; + break; + + case '?': + break; + + case 't': + x = npop(); + if (!x) { + /* scan forward for %e or %; at level zero */ + string++; + level = 0; + while (*string) { + if (*string == '%') { + string++; + if (*string == '?') + level++; + else if (*string == ';') { + if (level > 0) + level--; + else + break; + } + else if (*string == 'e' && level == 0) + break; + } + + if (*string) + string++; + } + } + break; + + case 'e': + /* scan forward for a %; at level zero */ + string++; + level = 0; + while (*string) { + if (*string == '%') { + string++; + if (*string == '?') + level++; + else if (*string == ';') { + if (level > 0) + level--; + else + break; + } + } + + if (*string) + string++; + } + break; + + case ';': + break; + + } /* endswitch (*string) */ + } /* endelse (*string == '%') */ + + if (*string == '\0') + break; + + string++; + } /* endwhile (*string) */ + + if (out_buff == 0 && (out_buff = typeCalloc(char,1)) == NULL) + return(NULL); + out_buff[out_used] = '\0'; + + T((T_RETURN("%s"), _nc_visbuf(out_buff))); + return(out_buff); +} + +char *tparm(NCURSES_CONST char *string, ...) +{ +va_list ap; +char *result; + + va_start(ap, string); +#ifdef TRACE + tname = "tparm"; +#endif /* TRACE */ + result = tparam_internal(string, ap); + va_end(ap); + return result; +} diff --git a/contrib/ncurses/ncurses/tinfo/lib_tputs.c b/contrib/ncurses/ncurses/tinfo/lib_tputs.c new file mode 100644 index 0000000..4ce176b --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_tputs.c @@ -0,0 +1,243 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * tputs.c + * delay_output() + * _nc_outch() + * tputs() + * + */ + +#include <curses.priv.h> +#include <ctype.h> +#include <term.h> /* padding_baud_rate, xon_xoff */ +#include <termcap.h> /* ospeed */ +#include <tic.h> + +MODULE_ID("$Id: lib_tputs.c,v 1.39 1999/02/25 10:44:29 tom Exp $") + +#define OUTPUT ((SP != 0) ? SP->_ofp : stdout) + +char PC; /* used by termcap library */ +speed_t ospeed; /* used by termcap library */ + +int _nc_nulls_sent; /* used by 'tack' program */ + +static int (*my_outch)(int c) = _nc_outch; + +int delay_output(int ms) +{ + T((T_CALLED("delay_output(%d)"), ms)); + + if (no_pad_char) + napms(ms); + else { + register int nullcount; + + nullcount = (ms * _nc_baudrate(ospeed)) / 10000; + for (_nc_nulls_sent += nullcount; nullcount > 0; nullcount--) + my_outch(PC); + if (my_outch == _nc_outch) + (void) fflush(OUTPUT); + } + + returnCode(OK); +} + +int _nc_outch(int ch) +{ +#ifdef TRACE + _nc_outchars++; +#endif /* TRACE */ + + putc(ch, OUTPUT); + return OK; +} + +int putp(const char *string) +{ + return tputs(string, 1, _nc_outch); +} + +int tputs(const char *string, int affcnt, int (*outc)(int)) +{ +bool always_delay; +bool normal_delay; +int number; +#ifdef BSD_TPUTS +int trailpad; +#endif /* BSD_TPUTS */ + +#ifdef TRACE +char addrbuf[32]; + + if (_nc_tracing & TRACE_TPUTS) + { + if (outc == _nc_outch) + (void) strcpy(addrbuf, "_nc_outch"); + else + (void) sprintf(addrbuf, "%p", outc); + if (_nc_tputs_trace) { + TR(TRACE_MAXIMUM, ("tputs(%s = %s, %d, %s) called", _nc_tputs_trace, _nc_visbuf(string), affcnt, addrbuf)); + } + else { + TR(TRACE_MAXIMUM, ("tputs(%s, %d, %s) called", _nc_visbuf(string), affcnt, addrbuf)); + } + _nc_tputs_trace = (char *)NULL; + } +#endif /* TRACE */ + + if (!VALID_STRING(string)) + return ERR; + + if (cur_term == 0) { + always_delay = FALSE; + normal_delay = TRUE; + } else { + always_delay = (string == bell) || (string == flash_screen); + normal_delay = + !xon_xoff + && padding_baud_rate +#ifdef NCURSES_NO_PADDING + && (SP == 0 || !(SP->_no_padding)) +#endif + && (_nc_baudrate(ospeed) >= padding_baud_rate); + } + +#ifdef BSD_TPUTS + /* + * This ugly kluge deals with the fact that some ancient BSD programs + * (like nethack) actually do the likes of tputs("50") to get delays. + */ + trailpad = 0; + if (isdigit(*string)) { + while (isdigit(*string)) { + trailpad = trailpad * 10 + (*string - '0'); + string++; + } + trailpad *= 10; + if (*string == '.') { + string++; + if (isdigit(*string)) { + trailpad += (*string - '0'); + string++; + } + while (isdigit(*string)) + string++; + } + + if (*string == '*') { + trailpad *= affcnt; + string++; + } + } +#endif /* BSD_TPUTS */ + + my_outch = outc; /* redirect delay_output() */ + while (*string) { + if (*string != '$') + (*outc)(*string); + else { + string++; + if (*string != '<') { + (*outc)('$'); + if (*string) + (*outc)(*string); + } else { + bool mandatory; + + string++; + if ((!isdigit(*string) && *string != '.') || !strchr(string, '>')) { + (*outc)('$'); + (*outc)('<'); + continue; + } + + number = 0; + while (isdigit(*string)) { + number = number * 10 + (*string - '0'); + string++; + } + number *= 10; + if (*string == '.') { + string++; + if (isdigit(*string)) { + number += (*string - '0'); + string++; + } + while (isdigit(*string)) + string++; + } + + mandatory = FALSE; + while (*string == '*' || *string == '/') + { + if (*string == '*') { + number *= affcnt; + string++; + } + else /* if (*string == '/') */ { + mandatory = TRUE; + string++; + } + } + + if (number > 0 + && (always_delay + || normal_delay + || mandatory)) + delay_output(number/10); + + } /* endelse (*string == '<') */ + } /* endelse (*string == '$') */ + + if (*string == '\0') + break; + + string++; + } + +#ifdef BSD_TPUTS + /* + * Emit any BSD-style prefix padding that we've accumulated now. + */ + if (trailpad > 0 + && (always_delay || normal_delay)) + delay_output(trailpad/10); +#endif /* BSD_TPUTS */ + + my_outch = _nc_outch; + return OK; +} diff --git a/contrib/ncurses/ncurses/tinfo/lib_ttyflags.c b/contrib/ncurses/ncurses/tinfo/lib_ttyflags.c new file mode 100644 index 0000000..79397f4 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/lib_ttyflags.c @@ -0,0 +1,163 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/* + * def_prog_mode() + * def_shell_mode() + * reset_prog_mode() + * reset_shell_mode() + * savetty() + * resetty() + */ + +#include <curses.priv.h> +#include <term.h> /* cur_term */ + +MODULE_ID("$Id: lib_ttyflags.c,v 1.2 1999/07/24 22:36:12 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 + +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_tracebits())); + return (OK); +} + +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_tracebits())); + return (OK); +} + +int 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 (_nc_get_tty_mode(&cur_term->Ottyb) != OK) + returnCode(ERR); +#ifdef TERMIOS + if (cur_term->Ottyb.c_oflag & tabs) + tab = back_tab = NULL; +#else + if (cur_term->Ottyb.sg_flags & XTABS) + tab = back_tab = NULL; +#endif + returnCode(OK); +} + +int def_prog_mode(void) +{ + T((T_CALLED("def_prog_mode()"))); + + if (_nc_get_tty_mode(&cur_term->Nttyb) != OK) + returnCode(ERR); +#ifdef TERMIOS + cur_term->Nttyb.c_oflag &= ~tabs; +#else + cur_term->Nttyb.sg_flags &= ~XTABS; +#endif + returnCode(OK); +} + +int reset_prog_mode(void) +{ + T((T_CALLED("reset_prog_mode()"))); + + if (cur_term != 0) { + _nc_set_tty_mode(&cur_term->Nttyb); + if (SP) { + if (stdscr && stdscr->_use_keypad) + _nc_keypad(TRUE); + NC_BUFFERED(TRUE); + } + returnCode(OK); + } + returnCode(ERR); +} + +int reset_shell_mode(void) +{ + T((T_CALLED("reset_shell_mode()"))); + + if (cur_term != 0) { + if (SP) + { + _nc_keypad(FALSE); + fflush(SP->_ofp); + NC_BUFFERED(FALSE); + } + returnCode(_nc_set_tty_mode(&cur_term->Ottyb)); + } + returnCode(ERR); +} + +/* +** savetty() and resetty() +** +*/ + +static TTY buf; + +int savetty(void) +{ + T((T_CALLED("savetty()"))); + + returnCode(_nc_get_tty_mode(&buf)); +} + +int resetty(void) +{ + T((T_CALLED("resetty()"))); + + returnCode(_nc_set_tty_mode(&buf)); +} diff --git a/contrib/ncurses/ncurses/tinfo/make_keys.c b/contrib/ncurses/ncurses/tinfo/make_keys.c new file mode 100644 index 0000000..e627385 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/make_keys.c @@ -0,0 +1,131 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ + +/* + * This replaces an awk script which translated keys.list into keys.tries by + * making the output show the indices into the TERMTYPE Strings array. Doing + * it that way lets us cut down on the size of the init_keytry() function. + */ +#include <curses.priv.h> + +MODULE_ID("$Id: make_keys.c,v 1.6 1999/02/22 16:55:20 tom Exp $") + +#include <names.c> + +#define UNKNOWN (SIZEOF(strnames) + SIZEOF(strfnames)) + +static size_t lookup(const char *name) +{ + size_t n; + bool found = FALSE; + for (n = 0; strnames[n] != 0; n++) { + if (!strcmp(name, strnames[n])) { + found = TRUE; + break; + } + } + if (!found) { + for (n = 0; strfnames[n] != 0; n++) { + if (!strcmp(name, strfnames[n])) { + found = TRUE; + break; + } + } + } + return found ? n : UNKNOWN; +} + +static void make_keys(FILE *ifp, FILE *ofp) +{ + char buffer[BUFSIZ]; + char from[BUFSIZ]; + char to[BUFSIZ]; + int maxlen = 16; + + while (fgets(buffer, sizeof(buffer), ifp) != 0) { + if (*buffer == '#') + continue; + if (sscanf(buffer, "%s %s", to, from) == 2) { + int code = lookup(from); + if (code == UNKNOWN) + continue; + if ((int)strlen(from) > maxlen) + maxlen = strlen(from); + fprintf(ofp, "\t{ %4d, %-*.*s },\t/* %s */\n", + code, + maxlen, maxlen, + to, + from); + } + } +} + +static void write_list(FILE *ofp, const char **list) +{ + while (*list != 0) + fprintf(ofp, "%s\n", *list++); +} + +int main(int argc, char *argv[]) +{ + static const char *prefix[] = { + "#ifndef NCU_KEYS_H", + "#define NCU_KEYS_H 1", + "", + "/* This file was generated by MAKE_KEYS */", + "", + "struct tinfo_fkeys _nc_tinfo_fkeys[] = {", + 0 + }; + static const char *suffix[] = { + "\t{ 0, 0} };", + "", + "#endif /* NCU_KEYS_H */", + 0 + }; + + write_list(stdout, prefix); + if (argc > 1) { + int n; + for (n = 1; n < argc; n++) { + FILE *fp = fopen(argv[n], "r"); + if (fp != 0) { + make_keys(fp, stdout); + fclose(fp); + } + } + } else { + make_keys(stdin, stdout); + } + write_list(stdout, suffix); + return EXIT_SUCCESS; +} diff --git a/contrib/ncurses/ncurses/tinfo/name_match.c b/contrib/ncurses/ncurses/tinfo/name_match.c new file mode 100644 index 0000000..a9e8396 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/name_match.c @@ -0,0 +1,96 @@ +/**************************************************************************** + * Copyright (c) 1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + ****************************************************************************/ + +#include <curses.priv.h> +#include <term.h> +#include <tic.h> + +MODULE_ID("$Id: name_match.c,v 1.8 1999/03/07 01:58:36 tom Exp $") + +/* + * _nc_first_name(char *names) + * + * Extract the primary name from a compiled entry. + */ + +char *_nc_first_name(const char *const sp) +/* get the first name from the given name list */ +{ + static char buf[MAX_NAME_SIZE+1]; + register unsigned n; + + for (n = 0; n < sizeof(buf)-1; n++) { + if ((buf[n] = sp[n]) == '\0' + || (buf[n] == '|')) + break; + } + buf[n] = '\0'; + return(buf); +} + +/* + * int _nc_name_match(namelist, name, delim) + * + * Is the given name matched in namelist? + */ + +int _nc_name_match(const char *const namelst, const char *const name, const char *const delim) +{ + const char *s, *d, *t; + int code, found; + + if ((s = namelst) != 0) { + while (*s != '\0') { + for (d = name; *d != '\0'; d++) { + if (*s != *d) + break; + s++; + } + found = FALSE; + for (code = TRUE; *s != '\0'; code = FALSE, s++) { + for (t = delim; *t != '\0'; t++) { + if (*s == *t) { + found = TRUE; + break; + } + } + if (found) + break; + } + if (code && *d == '\0') + return code; + if (*s++ == 0) + break; + } + } + return FALSE; +} diff --git a/contrib/ncurses/ncurses/tinfo/parse_entry.c b/contrib/ncurses/ncurses/tinfo/parse_entry.c new file mode 100644 index 0000000..07f3868 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/parse_entry.c @@ -0,0 +1,1047 @@ +/**************************************************************************** + * Copyright (c) 1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * parse_entry.c -- compile one terminfo or termcap entry + * + * Get an exact in-core representation of an entry. Don't + * try to resolve use or tc capabilities, that is someone + * else's job. Depends on the lexical analyzer to get tokens + * from the input stream. + */ + +#include <curses.priv.h> + +#include <ctype.h> +#include <tic.h> +#define __INTERNAL_CAPS_VISIBLE +#include <term_entry.h> + +MODULE_ID("$Id: parse_entry.c,v 1.39 1999/03/01 02:28:51 tom Exp $") + +#ifdef LINT +static short const parametrized[] = { 0 }; +#else +#include <parametrized.h> +#endif + +struct token _nc_curr_token; + +static void postprocess_termcap(TERMTYPE *, bool); +static void postprocess_terminfo(TERMTYPE *); +static struct name_table_entry const * lookup_fullname(const char *name); + +#if NCURSES_XNAMES + +static struct name_table_entry const * +_nc_extend_names(ENTRY *entryp, char *name, int token_type) +{ + static struct name_table_entry temp; + TERMTYPE *tp = &(entryp->tterm); + unsigned offset = 0; + unsigned actual; + unsigned tindex; + unsigned first, last, n; + bool found; + + switch (token_type) { + case BOOLEAN: + first = 0; + last = tp->ext_Booleans; + offset = tp->ext_Booleans; + tindex = tp->num_Booleans; + break; + case NUMBER: + first = tp->ext_Booleans; + last = tp->ext_Numbers + first; + offset = tp->ext_Booleans + tp->ext_Numbers; + tindex = tp->num_Numbers; + break; + case STRING: + first = tp->ext_Booleans + tp->ext_Numbers; + last = tp->ext_Strings + first; + offset = tp->ext_Booleans + tp->ext_Numbers + tp->ext_Strings; + tindex = tp->num_Strings; + break; + case CANCEL: + actual = NUM_EXT_NAMES(tp); + for (n = 0; n < actual; n++) { + if (!strcmp(name, tp->ext_Names[n])) { + if (n > (unsigned)(tp->ext_Booleans + tp->ext_Numbers)) { + token_type = STRING; + } else if (n > tp->ext_Booleans) { + token_type = NUMBER; + } else { + token_type = BOOLEAN; + } + return _nc_extend_names(entryp, name, token_type); + } + } + /* Well, we are given a cancel for a name that we don't recognize */ + return _nc_extend_names(entryp, name, STRING); + default: + return 0; + } + + /* Adjust the 'offset' (insertion-point) to keep the lists of extended + * names sorted. + */ + for (n = first, found = FALSE; n < last; n++) { + int cmp = strcmp(tp->ext_Names[n], name); + if (cmp == 0) + found = TRUE; + if (cmp >= 0) { + offset = n; + tindex = n - first; + switch (token_type) { + case BOOLEAN: tindex += BOOLCOUNT; break; + case NUMBER: tindex += NUMCOUNT; break; + case STRING: tindex += STRCOUNT; break; + } + break; + } + } + if (!found) { + switch (token_type) { + case BOOLEAN: + tp->ext_Booleans += 1; + tp->num_Booleans += 1; + tp->Booleans = typeRealloc(char, tp->num_Booleans, tp->Booleans); + for (last = tp->num_Booleans-1; last > tindex; last--) + tp->Booleans[last] = tp->Booleans[last-1]; + break; + case NUMBER: + tp->ext_Numbers += 1; + tp->num_Numbers += 1; + tp->Numbers = typeRealloc(short, tp->num_Numbers, tp->Numbers); + for (last = tp->num_Numbers-1; last > tindex; last--) + tp->Numbers[last] = tp->Numbers[last-1]; + break; + case STRING: + tp->ext_Strings += 1; + tp->num_Strings += 1; + tp->Strings = typeRealloc(char *, tp->num_Strings, tp->Strings); + for (last = tp->num_Strings-1; last > tindex; last--) + tp->Strings[last] = tp->Strings[last-1]; + break; + } + actual = NUM_EXT_NAMES(tp); + tp->ext_Names = typeRealloc(char *, actual, tp->ext_Names); + while (--actual > offset) + tp->ext_Names[actual] = tp->ext_Names[actual-1]; + tp->ext_Names[offset] = _nc_save_str(name); + } + + temp.nte_name = tp->ext_Names[offset]; + temp.nte_type = token_type; + temp.nte_index = tindex; + temp.nte_link = -1; + + return &temp; +} +#endif /* NCURSES_XNAMES */ + +/* + * int + * _nc_parse_entry(entry, literal, silent) + * + * Compile one entry. Doesn't try to resolve use or tc capabilities. + * + * found-forward-use = FALSE + * re-initialise internal arrays + * get_token(); + * if the token was not a name in column 1, complain and die + * save names in entry's string table + * while (get_token() is not EOF and not NAMES) + * check for existance and type-correctness + * enter cap into structure + * if STRING + * save string in entry's string table + * push back token + */ + +int _nc_parse_entry(struct entry *entryp, int literal, bool silent) +{ + int token_type; + struct name_table_entry const *entry_ptr; + char *ptr, namecpy[MAX_NAME_SIZE+1]; + + token_type = _nc_get_token(); + + if (token_type == EOF) + return(EOF); + if (token_type != NAMES) + _nc_err_abort("Entry does not start with terminal names in column one"); + + _nc_init_entry(&entryp->tterm); + + entryp->cstart = _nc_comment_start; + entryp->cend = _nc_comment_end; + entryp->startline = _nc_start_line; + DEBUG(2, ("Comment range is %ld to %ld", entryp->cstart, entryp->cend)); + + /* junk the 2-character termcap name, if present */ + ptr = _nc_curr_token.tk_name; + if (ptr[2] == '|') + { + ptr = _nc_curr_token.tk_name + 3; + _nc_curr_token.tk_name[2] = '\0'; + } + + entryp->tterm.str_table = entryp->tterm.term_names = _nc_save_str(ptr); + + DEBUG(1, ("Starting '%s'", ptr)); + + /* + * We do this because the one-token lookahead in the parse loop + * results in the terminal type getting prematurely set to correspond + * to that of the next entry. + */ + _nc_set_type(_nc_first_name(entryp->tterm.term_names)); + + /* check for overly-long names and aliases */ + (void) strncpy(namecpy, entryp->tterm.term_names, MAX_NAME_SIZE); + namecpy[MAX_NAME_SIZE] = '\0'; + if ((ptr = strrchr(namecpy, '|')) != (char *)0) + *ptr = '\0'; + ptr = strtok(namecpy, "|"); + if (strlen(ptr) > MAX_ALIAS) + _nc_warning("primary name may be too long"); + while ((ptr = strtok((char *)0, "|")) != (char *)0) + if (strlen(ptr) > MAX_ALIAS) + _nc_warning("alias `%s' may be too long", ptr); + + entryp->nuses = 0; + + for (token_type = _nc_get_token(); + token_type != EOF && token_type != NAMES; + token_type = _nc_get_token()) + { + if (strcmp(_nc_curr_token.tk_name, "use") == 0 + || strcmp(_nc_curr_token.tk_name, "tc") == 0) { + entryp->uses[entryp->nuses].parent = (void *)_nc_save_str(_nc_curr_token.tk_valstring); + entryp->uses[entryp->nuses].line = _nc_curr_line; + entryp->nuses++; + } else { + /* normal token lookup */ + entry_ptr = _nc_find_entry(_nc_curr_token.tk_name, + _nc_syntax ? _nc_cap_hash_table : _nc_info_hash_table); + + /* + * Our kluge to handle aliasing. The reason it's done + * this ugly way, with a linear search, is so the hashing + * machinery doesn't have to be made really complicated + * (also we get better warnings this way). No point in + * making this case fast, aliased caps aren't common now + * and will get rarer. + */ + if (entry_ptr == NOTFOUND) + { + const struct alias *ap; + + if (_nc_syntax == SYN_TERMCAP) + { + for (ap = _nc_capalias_table; ap->from; ap++) + if (strcmp(ap->from, _nc_curr_token.tk_name) == 0) + { + if (ap->to == (char *)0) + { + _nc_warning("%s (%s termcap extension) ignored", + ap->from, ap->source); + goto nexttok; + } + + entry_ptr = _nc_find_entry(ap->to, _nc_cap_hash_table); + if (entry_ptr && !silent) + _nc_warning("%s (%s termcap extension) aliased to %s", ap->from, ap->source, ap->to); + break; + } + } + else /* if (_nc_syntax == SYN_TERMINFO) */ + { + for (ap = _nc_infoalias_table; ap->from; ap++) + if (strcmp(ap->from, _nc_curr_token.tk_name) == 0) + { + if (ap->to == (char *)0) + { + _nc_warning("%s (%s terminfo extension) ignored", + ap->from, ap->source); + goto nexttok; + } + + entry_ptr = _nc_find_entry(ap->to, _nc_info_hash_table); + if (entry_ptr && !silent) + _nc_warning("%s (%s terminfo extension) aliased to %s", ap->from, ap->source, ap->to); + break; + } + + if (entry_ptr == NOTFOUND) { + entry_ptr = lookup_fullname(_nc_curr_token.tk_name); + } + } + } + +#if NCURSES_XNAMES + /* + * If we have extended-names active, we will automatically + * define a name based on its context. + */ + if (entry_ptr == NOTFOUND + && _nc_user_definable + && (entry_ptr = _nc_extend_names(entryp, _nc_curr_token.tk_name, token_type)) != 0) { + _nc_warning("extended capability '%s'", _nc_curr_token.tk_name); + } +#endif /* NCURSES_XNAMES */ + + /* can't find this cap name, not even as an alias */ + if (entry_ptr == NOTFOUND) { + if (!silent) + _nc_warning("unknown capability '%s'", + _nc_curr_token.tk_name); + continue; + } + + /* deal with bad type/value combinations. */ + if (token_type != CANCEL && entry_ptr->nte_type != token_type) + { + /* + * Nasty special cases here handle situations in which type + * information can resolve name clashes. Normal lookup + * finds the last instance in the capability table of a + * given name, regardless of type. find_type_entry looks + * for a first matching instance with given type. So as + * long as all ambiguous names occur in pairs of distinct + * type, this will do the job. + */ + + /* tell max_attributes from arrow_key_map */ + 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)) + 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) + token_type = STRING; + /* we couldn't recover; skip this token */ + else + { + if (!silent) + { + const char *type_name; + switch (entry_ptr->nte_type) + { + case BOOLEAN: + type_name = "boolean"; + break; + case STRING: + type_name = "string"; + break; + case NUMBER: + type_name = "numeric"; + break; + default: + type_name = "unknown"; + break; + } + _nc_warning("wrong type used for %s capability '%s'", + type_name, _nc_curr_token.tk_name); + } + continue; + } + } + + /* now we know that the type/value combination is OK */ + switch (token_type) { + case CANCEL: + switch (entry_ptr->nte_type) { + case BOOLEAN: + entryp->tterm.Booleans[entry_ptr->nte_index] = CANCELLED_BOOLEAN; + break; + + case NUMBER: + entryp->tterm.Numbers[entry_ptr->nte_index] = CANCELLED_NUMERIC; + break; + + case STRING: + entryp->tterm.Strings[entry_ptr->nte_index] = CANCELLED_STRING; + break; + } + break; + + case BOOLEAN: + entryp->tterm.Booleans[entry_ptr->nte_index] = TRUE; + break; + + case NUMBER: + entryp->tterm.Numbers[entry_ptr->nte_index] = + _nc_curr_token.tk_valnumber; + break; + + case STRING: + ptr = _nc_curr_token.tk_valstring; + if (_nc_syntax==SYN_TERMCAP) + ptr = _nc_captoinfo(_nc_curr_token.tk_name, + ptr, + parametrized[entry_ptr->nte_index]); + entryp->tterm.Strings[entry_ptr->nte_index] = _nc_save_str(ptr); + break; + + default: + if (!silent) + _nc_warning("unknown token type"); + _nc_panic_mode((_nc_syntax==SYN_TERMCAP) ? ':' : ','); + continue; + } + } /* end else cur_token.name != "use" */ + nexttok: + continue; /* cannot have a label w/o statement */ + } /* endwhile (not EOF and not NAMES) */ + + _nc_push_token(token_type); + _nc_set_type(_nc_first_name(entryp->tterm.term_names)); + + /* + * Try to deduce as much as possible from extension capabilities + * (this includes obsolete BSD capabilities). Sigh...it would be more + * space-efficient to call this after use resolution, but it has + * to be done before entry allocation is wrapped up. + */ + if (!literal) { + if (_nc_syntax == SYN_TERMCAP) + { + bool has_base_entry = FALSE; + int i; + + /* + * Don't insert defaults if this is a `+' entry meant only + * for inclusion in other entries (not sure termcap ever + * had these, actually). + */ + if (strchr(entryp->tterm.term_names, '+')) + has_base_entry = TRUE; + else + /* + * Otherwise, look for a base entry that will already + * have picked up defaults via translation. + */ + for (i = 0; i < entryp->nuses; i++) + if (!strchr((char *)entryp->uses[i].parent, '+')) + has_base_entry = TRUE; + + postprocess_termcap(&entryp->tterm, has_base_entry); + } + else + postprocess_terminfo(&entryp->tterm); + } + _nc_wrap_entry(entryp); + + return(OK); +} + +int _nc_capcmp(const char *s, const char *t) +/* compare two string capabilities, stripping out padding */ +{ + if (!s && !t) + return(0); + else if (!s || !t) + return(1); + + for (;;) + { + if (s[0] == '$' && s[1] == '<') + { + for (s += 2; ; s++) + if (!(isdigit(*s) || *s=='.' || *s=='*' || *s=='/' || *s=='>')) + break; + } + + if (t[0] == '$' && t[1] == '<') + { + for (t += 2; ; t++) + if (!(isdigit(*t) || *t=='.' || *t=='*' || *t=='/' || *t=='>')) + break; + } + + /* we've now pushed s and t past any padding they were pointing at */ + + if (*s == '\0' && *t == '\0') + return(0); + + if (*s != *t) + return(*t - *s); + + /* else *s == *t but one is not NUL, so continue */ + s++, t++; + } +} + +/* + * The ko capability, if present, consists of a comma-separated capability + * list. For each capability, we may assume there is a keycap that sends the + * string which is the value of that capability. + */ +typedef struct {const char *from; const char *to;} assoc; +static assoc const ko_xlate[] = +{ + {"al", "kil1"}, /* insert line key -> KEY_IL */ + {"bt", "kcbt"}, /* back tab -> KEY_BTAB */ + {"cd", "ked"}, /* clear-to-eos key -> KEY_EOL */ + {"ce", "kel"}, /* clear-to-eol key -> KEY_EOS */ + {"cl", "kclr"}, /* clear key -> KEY_CLEAR */ + {"ct", "tbc"}, /* clear all tabs -> KEY_CATAB */ + {"dc", "kdch1"}, /* delete char -> KEY_DC */ + {"dl", "kdl1"}, /* delete line -> KEY_DL */ + {"do", "kcud1"}, /* down key -> KEY_DOWN */ + {"ei", "krmir"}, /* exit insert key -> KEY_EIC */ + {"ho", "khome"}, /* home key -> KEY_HOME */ + {"ic", "kich1"}, /* insert char key -> KEY_IC */ + {"im", "kIC"}, /* insert-mode key -> KEY_SIC */ + {"le", "kcub1"}, /* le key -> KEY_LEFT */ + {"nd", "kcuf1"}, /* nd key -> KEY_RIGHT */ + {"nl", "kent"}, /* new line key -> KEY_ENTER */ + {"st", "khts"}, /* set-tab key -> KEY_STAB */ + {"ta", CANCELLED_STRING}, + {"up", "kcuu1"}, /* up-arrow key -> KEY_UP */ + {(char *)0, (char *)0}, +}; + +/* + * This routine fills in string caps that either had defaults under + * termcap or can be manufactured from obsolete termcap capabilities. + * It was lifted from Ross Ridge's mytinfo package. + */ + +static const char C_CR[] = "\r"; +static const char C_LF[] = "\n"; +static const char C_BS[] = "\b"; +static const char C_HT[] = "\t"; + +/* + * Note that WANTED and PRESENT are not simple inverses! If a capability + * has been explicitly cancelled, it's not considered WANTED. + */ +#define WANTED(s) ((s) == ABSENT_STRING) +#define PRESENT(s) (((s) != ABSENT_STRING) && ((s) != CANCELLED_STRING)) + +/* + * This bit of legerdemain turns all the terminfo variable names into + * references to locations in the arrays Booleans, Numbers, and Strings --- + * precisely what's needed. + */ + +#undef CUR +#define CUR tp-> + +static +void postprocess_termcap(TERMTYPE *tp, bool has_base) +{ + char buf[MAX_LINE * 2 + 2]; + + /* + * TERMCAP DEFAULTS AND OBSOLETE-CAPABILITY TRANSLATIONS + * + * This first part of the code is the functional inverse of the + * fragment in capdefaults.c. + * ---------------------------------------------------------------------- + */ + + /* if there was a tc entry, assume we picked up defaults via that */ + if (!has_base) + { + if (WANTED(init_3string) && termcap_init2) + init_3string = _nc_save_str(termcap_init2); + + if (WANTED(reset_2string) && termcap_reset) + reset_2string = _nc_save_str(termcap_reset); + + if (WANTED(carriage_return)) { + if (carriage_return_delay > 0) { + sprintf(buf, "%s$<%d>", C_CR, carriage_return_delay); + carriage_return = _nc_save_str(buf); + } else + carriage_return = _nc_save_str(C_CR); + } + if (WANTED(cursor_left)) { + if (backspace_delay > 0) { + sprintf(buf, "%s$<%d>", C_BS, backspace_delay); + cursor_left = _nc_save_str(buf); + } else if (backspaces_with_bs == 1) + cursor_left = _nc_save_str(C_BS); + else if (PRESENT(backspace_if_not_bs)) + cursor_left = backspace_if_not_bs; + } + /* vi doesn't use "do", but it does seems to use nl (or '\n') instead */ + if (WANTED(cursor_down)) { + if (PRESENT(linefeed_if_not_lf)) + cursor_down = linefeed_if_not_lf; + else if (linefeed_is_newline != 1) { + if (new_line_delay > 0) { + sprintf(buf, "%s$<%d>", C_LF, new_line_delay); + cursor_down = _nc_save_str(buf); + } else + cursor_down = _nc_save_str(C_LF); + } + } + if (WANTED(scroll_forward) && crt_no_scrolling != 1) { + if (PRESENT(linefeed_if_not_lf)) + cursor_down = linefeed_if_not_lf; + else if (linefeed_is_newline != 1) { + if (new_line_delay > 0) { + sprintf(buf, "%s$<%d>", C_LF, new_line_delay); + scroll_forward = _nc_save_str(buf); + } else + scroll_forward = _nc_save_str(C_LF); + } + } + if (WANTED(newline)) { + if (linefeed_is_newline == 1) { + if (new_line_delay > 0) { + sprintf(buf, "%s$<%d>", C_LF, new_line_delay); + newline = _nc_save_str(buf); + } else + newline = _nc_save_str(C_LF); + } else if (PRESENT(carriage_return) && PRESENT(scroll_forward)) { + strncpy(buf, carriage_return, MAX_LINE-2); + buf[MAX_LINE-1] = '\0'; + strncat(buf, scroll_forward, MAX_LINE-strlen(buf)-1); + buf[MAX_LINE] = '\0'; + newline = _nc_save_str(buf); + } else if (PRESENT(carriage_return) && PRESENT(cursor_down)) { + strncpy(buf, carriage_return, MAX_LINE-2); + buf[MAX_LINE-1] = '\0'; + strncat(buf, cursor_down, MAX_LINE-strlen(buf)-1); + buf[MAX_LINE] = '\0'; + newline = _nc_save_str(buf); + } + } + } + + /* + * Inverse of capdefaults.c code ends here. + * ---------------------------------------------------------------------- + * + * TERMCAP-TO TERMINFO MAPPINGS FOR SOURCE TRANSLATION + * + * These translations will *not* be inverted by tgetent(). + */ + + if (!has_base) + { + /* + * We wait until now to decide if we've got a working cr because even + * one that doesn't work can be used for newline. Unfortunately the + * space allocated for it is wasted. + */ + if (return_does_clr_eol == 1 || no_correctly_working_cr == 1) + carriage_return = ABSENT_STRING; + + /* + * Supposedly most termcap entries have ta now and '\t' is no longer a + * default, but it doesn't seem to be true... + */ + if (WANTED(tab)) { + if (horizontal_tab_delay > 0) { + sprintf(buf, "%s$<%d>", C_HT, horizontal_tab_delay); + tab = _nc_save_str(buf); + } else + tab = _nc_save_str(C_HT); + } + if (init_tabs == ABSENT_NUMERIC && has_hardware_tabs == TRUE) + init_tabs = 8; + + /* + * Assume we can beep with ^G unless we're given bl@. + */ + if (WANTED(bell)) + bell = _nc_save_str("\007"); + } + + /* + * Translate the old termcap :pt: capability to it#8 + ht=\t + */ + if (has_hardware_tabs == TRUE) { + if (init_tabs != 8 && init_tabs != ABSENT_NUMERIC) + _nc_warning("hardware tabs with a width other than 8: %d", init_tabs); + else + { + if (tab && _nc_capcmp(tab, C_HT)) + _nc_warning("hardware tabs with a non-^I tab string %s", + _nc_visbuf(tab)); + else + { + if (WANTED(tab)) + tab = _nc_save_str(C_HT); + init_tabs = 8; + } + } + } + /* + * Now translate the ko capability, if there is one. This + * isn't from mytinfo... + */ + if (PRESENT(other_non_function_keys)) + { + char *dp, *cp = strtok(other_non_function_keys, ","); + struct name_table_entry const *from_ptr; + struct name_table_entry const *to_ptr; + assoc const *ap; + char buf2[MAX_TERMINFO_LENGTH]; + bool foundim; + + /* we're going to use this for a special case later */ + dp = strchr(other_non_function_keys, 'i'); + foundim = dp && dp[1] == 'm'; + + /* look at each comma-separated capability in the ko string... */ + do { + for (ap = ko_xlate; ap->from; ap++) + if (strcmp(ap->from, cp) == 0) + break; + if (!ap->to) + { + _nc_warning("unknown capability `%s' in ko string", cp); + continue; + } + else if (ap->to == CANCELLED_STRING) /* ignore it */ + continue; + + /* now we know we found a match in ko_table, so... */ + + from_ptr = _nc_find_entry(ap->from, _nc_cap_hash_table); + to_ptr = _nc_find_entry(ap->to, _nc_info_hash_table); + + if (!from_ptr || !to_ptr) /* should never happen! */ + _nc_err_abort("ko translation table is invalid, I give up"); + + if (WANTED(tp->Strings[from_ptr->nte_index])) + { + _nc_warning("no value for ko capability %s", ap->from); + continue; + } + + if (tp->Strings[to_ptr->nte_index]) + { + /* There's no point in warning about it if it's the same + * string; that's just an inefficiency. + */ + if (strcmp( + tp->Strings[from_ptr->nte_index], + tp->Strings[to_ptr->nte_index]) != 0) + _nc_warning("%s (%s) already has an explicit value %s, ignoring ko", + ap->to, ap->from, + _nc_visbuf(tp->Strings[to_ptr->nte_index]) ); + continue; + } + + /* + * The magic moment -- copy the mapped key string over, + * stripping out padding. + */ + dp = buf2; + for (cp = tp->Strings[from_ptr->nte_index]; *cp; cp++) + { + if (cp[0] == '$' && cp[1] == '<') + { + while (*cp && *cp != '>') + if (!*cp) + break; + else + ++cp; + } + else + *dp++ = *cp; + } + *dp++ = '\0'; + + tp->Strings[to_ptr->nte_index] = _nc_save_str(buf2); + } while + ((cp = strtok((char *)0, ",")) != 0); + + /* + * Note: ko=im and ko=ic both want to grab the `Insert' + * keycap. There's a kich1 but no ksmir, so the ic capability + * got mapped to kich1 and im to kIC to avoid a collision. + * If the description has im but not ic, hack kIC back to kich1. + */ + if (foundim && WANTED(key_ic) && key_sic) + { + key_ic = key_sic; + key_sic = ABSENT_STRING; + } + } + + if (!hard_copy) + { + if (WANTED(key_backspace)) + key_backspace = _nc_save_str(C_BS); + if (WANTED(key_left)) + key_left = _nc_save_str(C_BS); + if (WANTED(key_down)) + key_down = _nc_save_str(C_LF); + } + + /* + * Translate XENIX forms characters. + */ + if (PRESENT(acs_ulcorner) || + PRESENT(acs_llcorner) || + PRESENT(acs_urcorner) || + PRESENT(acs_lrcorner) || + PRESENT(acs_ltee) || + PRESENT(acs_rtee) || + PRESENT(acs_btee) || + PRESENT(acs_ttee) || + PRESENT(acs_hline) || + PRESENT(acs_vline) || + PRESENT(acs_plus)) + { + char buf2[MAX_TERMCAP_LENGTH], *bp = buf2; + + if (acs_chars) + { + (void)strcpy(bp, acs_chars); + bp += strlen(bp); + } + + if (acs_ulcorner && acs_ulcorner[1] == '\0') + { + *bp++ = 'l'; + *bp++ = *acs_ulcorner; + } + if (acs_llcorner && acs_llcorner[1] == '\0') + { + *bp++ = 'm'; + *bp++ = *acs_llcorner; + } + if (acs_urcorner && acs_urcorner[1] == '\0') + { + *bp++ = 'k'; + *bp++ = *acs_urcorner; + } + if (acs_lrcorner && acs_lrcorner[1] == '\0') + { + *bp++ = 'j'; + *bp++ = *acs_lrcorner; + } + if (acs_ltee && acs_ltee[1] == '\0') + { + *bp++ = 't'; + *bp++ = *acs_ltee; + } + if (acs_rtee && acs_rtee[1] == '\0') + { + *bp++ = 'u'; + *bp++ = *acs_rtee; + } + if (acs_btee && acs_btee[1] == '\0') + { + *bp++ = 'v'; + *bp++ = *acs_btee; + } + if (acs_ttee && acs_ttee[1] == '\0') + { + *bp++ = 'w'; + *bp++ = *acs_ttee; + } + if (acs_hline && acs_hline[1] == '\0') + { + *bp++ = 'q'; + *bp++ = *acs_hline; + } + if (acs_vline && acs_vline[1] == '\0') + { + *bp++ = 'x'; + *bp++ = *acs_vline; + } + if (acs_plus) + { + *bp++ = 'n'; + strcpy(bp, acs_plus); + bp = buf2 + strlen(buf2); + } + + if (bp != buf2) + { + *bp++ = '\0'; + acs_chars = _nc_save_str(buf2); + _nc_warning("acsc string synthesized from XENIX capabilities"); + } + } + else if (acs_chars == 0 + && enter_alt_charset_mode != 0 + && exit_alt_charset_mode != 0) + { + acs_chars = _nc_save_str("``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"); + } +} + +static +void postprocess_terminfo(TERMTYPE *tp) +{ + /* + * TERMINFO-TO-TERMINFO MAPPINGS FOR SOURCE TRANSLATION + * ---------------------------------------------------------------------- + */ + + /* + * Translate AIX forms characters. + */ + if (PRESENT(box_chars_1)) + { + char buf2[MAX_TERMCAP_LENGTH], *bp = buf2; + + if (acs_chars) + { + (void)strcpy(bp, acs_chars); + bp += strlen(bp); + } + + if (box_chars_1[0]) /* ACS_ULCORNER */ + { + *bp++ = 'l'; + *bp++ = box_chars_1[0]; + } + if (box_chars_1[1]) /* ACS_HLINE */ + { + *bp++ = 'q'; + *bp++ = box_chars_1[1]; + } + if (box_chars_1[2]) /* ACS_URCORNER */ + { + *bp++ = 'k'; + *bp++ = box_chars_1[2]; + } + if (box_chars_1[3]) /* ACS_VLINE */ + { + *bp++ = 'x'; + *bp++ = box_chars_1[3]; + } + if (box_chars_1[4]) /* ACS_LRCORNER */ + { + *bp++ = 'j'; + *bp++ = box_chars_1[4]; + } + if (box_chars_1[5]) /* ACS_LLCORNER */ + { + *bp++ = 'm'; + *bp++ = box_chars_1[5]; + } + if (box_chars_1[6]) /* ACS_TTEE */ + { + *bp++ = 'w'; + *bp++ = box_chars_1[6]; + } + if (box_chars_1[7]) /* ACS_RTEE */ + { + *bp++ = 'u'; + *bp++ = box_chars_1[7]; + } + if (box_chars_1[8]) /* ACS_BTEE */ + { + *bp++ = 'v'; + *bp++ = box_chars_1[8]; + } + if (box_chars_1[9]) /* ACS_LTEE */ + { + *bp++ = 't'; + *bp++ = box_chars_1[9]; + } + if (box_chars_1[10]) /* ACS_PLUS */ + { + *bp++ = 'n'; + *bp++ = box_chars_1[10]; + } + + if (bp != buf2) + { + *bp++ = '\0'; + acs_chars = _nc_save_str(buf2); + _nc_warning("acsc string synthesized from AIX capabilities"); + box_chars_1 = ABSENT_STRING; + } + } + /* + * ---------------------------------------------------------------------- + */ +} + +/* + * Do a linear search through the terminfo tables to find a given full-name. + * We don't expect to do this often, so there's no hashing function. + * + * In effect, this scans through the 3 lists of full-names, and looks them + * up in _nc_info_table, which is organized so that the nte_index fields are + * sorted, but the nte_type fields are not necessarily grouped together. + */ +static +struct name_table_entry const * lookup_fullname(const char *find) +{ + int state = -1; + + for (;;) { + int count = 0; + NCURSES_CONST char *const *names; + + switch (++state) { + case BOOLEAN: + names = boolfnames; + break; + case STRING: + names = strfnames; + break; + case NUMBER: + names = numfnames; + break; + default: + return NOTFOUND; + } + + for (count = 0; names[count] != 0; count++) { + if (!strcmp(names[count], find)) { + struct name_table_entry const *entry_ptr = _nc_get_table(FALSE); + while (entry_ptr->nte_type != state + || entry_ptr->nte_index != count) + entry_ptr++; + return entry_ptr; + } + } + } +} + +/* parse_entry.c ends here */ diff --git a/contrib/ncurses/ncurses/tinfo/read_entry.c b/contrib/ncurses/ncurses/tinfo/read_entry.c new file mode 100644 index 0000000..f60a486 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/read_entry.c @@ -0,0 +1,482 @@ +/**************************************************************************** + * Copyright (c) 1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* + * read_entry.c -- Routine for reading in a compiled terminfo file + * + */ + +#include <curses.priv.h> + +#if HAVE_FCNTL_H +#include <fcntl.h> +#endif + +#include <tic.h> +#include <term_entry.h> + +MODULE_ID("$Id: read_entry.c,v 1.61 1999/07/24 20:07:20 tom Exp $") + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +#if 0 +#define TRACE_IN(p) DEBUG(2, p) +#else +#define TRACE_IN(p) /*nothing*/ +#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. + */ +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) { + 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. + */ +void _nc_keep_tic_dir(const char *path) +{ + _nc_tic_dir(path); + keep_tic_directory = TRUE; +} + +static void convert_shorts(char *buf, short *Numbers, int count) +{ + int i; + for (i = 0; i < count; i++) + { + if (IS_NEG1(buf + 2*i)) + Numbers[i] = ABSENT_NUMERIC; + else if (IS_NEG2(buf + 2*i)) + Numbers[i] = CANCELLED_NUMERIC; + else + Numbers[i] = LOW_MSB(buf + 2*i); + TRACE_IN(("get Numbers[%d]=%d", i, Numbers[i])); + } +} + +static void convert_strings(char *buf, char **Strings, int count, int size, char *table) +{ + int i; + char *p; + + for (i = 0; i < count; i++) { + if (IS_NEG1(buf + 2*i)) { + Strings[i] = ABSENT_STRING; + } else if (IS_NEG2(buf + 2*i)) { + Strings[i] = CANCELLED_STRING; + } else if (LOW_MSB(buf + 2*i) > size) { + Strings[i] = ABSENT_STRING; + } else { + Strings[i] = (LOW_MSB(buf+2*i) + table); + TRACE_IN(("Strings[%d] = %s", i, _nc_visbuf(Strings[i]))); + } + + /* make sure all strings are NUL terminated */ + if (VALID_STRING(Strings[i])) { + for (p = Strings[i]; p <= table + size; p++) + if (*p == '\0') + break; + /* if there is no NUL, ignore the string */ + if (p > table + size) + Strings[i] = ABSENT_STRING; + } + } +} + +#define read_shorts(fd, buf, count) (read(fd, buf, (count)*2) == (count)*2) + +#define even_boundary(value) \ + if ((value) % 2 != 0) read(fd, buf, 1) + +static int read_termtype(int fd, TERMTYPE *ptr) +/* return 1 if read, 0 if not found or garbled */ +{ + int name_size, bool_count, num_count, str_count, str_size; + int i; + char buf[MAX_ENTRY_SIZE]; + + TRACE_IN(("READ termtype header @%d", tell(fd))); + + /* grab the header */ + if (!read_shorts(fd, buf, 6) + || LOW_MSB(buf) != MAGIC) { + return(0); + } + + _nc_free_termtype(ptr); + name_size = LOW_MSB(buf + 2); + bool_count = LOW_MSB(buf + 4); + num_count = LOW_MSB(buf + 6); + str_count = LOW_MSB(buf + 8); + str_size = LOW_MSB(buf + 10); + + TRACE_IN(("header is %d/%d/%d/%d(%d)", name_size, bool_count, num_count, str_count, str_size)); + if (name_size < 0 + || bool_count < 0 + || num_count < 0 + || str_count < 0 + || str_size < 0) { + return(0); + } + + 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); + } + } else { + str_count = 0; + } + + /* 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); + } + (void) strcpy(ptr->term_names, buf); + if (name_size > MAX_NAME_SIZE) + lseek(fd, (off_t) (name_size - MAX_NAME_SIZE), 1); + + /* 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 booleans end on an odd byte, skip it. The machine they + * originally wrote terminfo on must have been a 16-bit + * word-oriented machine that would trap out if you tried a + * word access off a 2-byte boundary. + */ + even_boundary(name_size + bool_count); + + /* grab the numbers */ + if ((ptr->Numbers = typeCalloc(short, max(NUMCOUNT, num_count))) == 0 + || !read_shorts(fd, buf, num_count)) { + return(0); + } + convert_shorts(buf, ptr->Numbers, num_count); + + if ((ptr->Strings = typeCalloc(char *, max(STRCOUNT, str_count))) == 0) + return(0); + + if (str_count) + { + /* grab the string offsets */ + if (!read_shorts(fd, buf, str_count)) { + return(0); + } + /* 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 NCURSES_XNAMES + + ptr->num_Booleans = BOOLCOUNT; + ptr->num_Numbers = NUMCOUNT; + ptr->num_Strings = STRCOUNT; + + /* + * Read extended entries, if any, after the normal end of terminfo data. + */ + even_boundary(str_size); + TRACE_IN(("READ extended_header @%d", tell(fd))); + if (_nc_user_definable && read_shorts(fd, 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); + int base = 0; + + if (need >= (int) sizeof(buf) + || ext_str_size >= (int) sizeof(buf) + || ext_str_limit >= (int) sizeof(buf) + || ext_bool_count < 0 + || ext_num_count < 0 + || ext_str_count < 0 + || ext_str_size < 0 + || ext_str_limit < 0) + return(0); + + 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->Numbers = typeRealloc(short, ptr->num_Numbers, ptr->Numbers); + ptr->Strings = typeRealloc(char*, ptr->num_Strings, ptr->Strings); + + TRACE_IN(("extended header is %d/%d/%d(%d:%d)", ext_bool_count, ext_num_count, ext_str_count, ext_str_size, ext_str_limit)); + + TRACE_IN(("READ %d extended-booleans @%d", ext_bool_count, tell(fd))); + if ((ptr->ext_Booleans = ext_bool_count) != 0) { + if (read(fd, ptr->Booleans + BOOLCOUNT, (unsigned)ext_bool_count) != ext_bool_count) + return(0); + } + even_boundary(ext_bool_count); + + TRACE_IN(("READ %d extended-numbers @%d", ext_num_count, tell(fd))); + if ((ptr->ext_Numbers = ext_num_count) != 0) { + if (!read_shorts(fd, buf, ext_num_count)) + return(0); + TRACE_IN(("Before converting extended-numbers")); + convert_shorts(buf, ptr->Numbers + NUMCOUNT, ext_num_count); + } + + TRACE_IN(("READ extended-offsets @%d", tell(fd))); + if ((ext_str_count || need) + && !read_shorts(fd, buf, ext_str_count+need)) + return(0); + + TRACE_IN(("READ %d bytes of extended-strings @%d", ext_str_limit, tell(fd))); + 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); + TRACE_IN(("first extended-string is %s", _nc_visbuf(ptr->ext_str_table))); + } + + if ((ptr->ext_Strings = ext_str_count) != 0) { + TRACE_IN(("Before computing extended-string capabilities str_count=%d, ext_str_count=%d", str_count, ext_str_count)); + convert_strings(buf, ptr->Strings + str_count, ext_str_count, ext_str_limit, ptr->ext_str_table); + for (i = ext_str_count-1; i >= 0; i--) { + TRACE_IN(("MOVE from [%d:%d] %s", i, i+str_count, _nc_visbuf(ptr->Strings[i+str_count]))); + ptr->Strings[i+STRCOUNT] = ptr->Strings[i+str_count]; + if (VALID_STRING(ptr->Strings[i+STRCOUNT])) + base += (strlen(ptr->Strings[i+STRCOUNT]) + 1); + TRACE_IN(("... to [%d] %s", i+STRCOUNT, _nc_visbuf(ptr->Strings[i+STRCOUNT]))); + } + } + + if (need) { + if ((ptr->ext_Names = typeCalloc(char *, need)) == 0) + return(0); + TRACE_IN(("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, ext_str_limit, ptr->ext_str_table + base); + } + + T(("...done reading terminfo bool %d(%d) num %d(%d) str %d(%d)", + ptr->num_Booleans, ptr->ext_Booleans, + ptr->num_Numbers, ptr->ext_Numbers, + ptr->num_Strings, ptr->ext_Strings)); + + TRACE_IN(("extend: num_Booleans:%d", ptr->num_Booleans)); + } else +#endif /* NCURSES_XNAMES */ + { + T(("...done reading terminfo bool %d num %d str %d", + bool_count, + num_count, + str_count)); + TRACE_IN(("normal: num_Booleans:%d", ptr->num_Booleans)); + } + + for (i = bool_count; i < BOOLCOUNT; i++) + ptr->Booleans[i] = FALSE; + for (i = num_count; i < NUMCOUNT; i++) + ptr->Numbers[i] = ABSENT_NUMERIC; + for (i = str_count; i < STRCOUNT; i++) + ptr->Strings[i] = ABSENT_STRING; + + return(1); +} + +int _nc_read_file_entry(const char *const filename, TERMTYPE *ptr) +/* return 1 if read, 0 if not found or garbled */ +{ + int code, fd = -1; + + 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); + } + + T(("read terminfo %s", filename)); + if ((code = read_termtype(fd, ptr)) == 0) + _nc_free_termtype(ptr); + close(fd); + + return (code); +} + +/* + * Build a terminfo pathname and try to read the data. Returns 1 on success, + * 0 on failure. + */ +static int _nc_read_tic_entry(char *const filename, + const char *const dir, const char *ttn, TERMTYPE *const tp) +{ +/* maximum safe length of terminfo root directory name */ +#define MAX_TPATH (PATH_MAX - MAX_ALIAS - 6) + + if (strlen(dir) > MAX_TPATH) + return 0; + (void) sprintf(filename, "%s/%s", dir, ttn); + return _nc_read_file_entry(filename, tp); +} + +/* + * 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 == ':') { + *a = 0; + if ((b + 1) >= a) + b = TERMINFO; + if (_nc_read_tic_entry(filename, b, ttn, tp) == 1) { + code = 1; + break; + } + b = a + 1; + if (c == 0) + break; + } + a++; + } + + free(list); + return(code); +} + +/* + * _nc_read_entry(char *tn, char *filename, TERMTYPE *tp) + * + * Find and read the compiled entry for a given terminal type, + * if it exists. We take pains here to make sure no combination + * of environment variables and terminal type name can be used to + * overrun the file buffer. + */ + +int _nc_read_entry(const char *const tn, 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 ((envp = getenv("TERMINFO")) != 0 + && _nc_read_tic_entry(filename, _nc_tic_dir(envp), ttn, tp) == 1) + return 1; + + if ((envp = _nc_home_terminfo()) != 0) { + if (_nc_read_tic_entry(filename, envp, ttn, tp) == 1) { + return(1); + } + } + + /* 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 +} + diff --git a/contrib/ncurses/ncurses/tinfo/read_termcap.c b/contrib/ncurses/ncurses/tinfo/read_termcap.c new file mode 100644 index 0000000..d60a92d --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/read_termcap.c @@ -0,0 +1,1116 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* + * Termcap compatibility support + * + * If your OS integrator didn't install a terminfo database, you can call + * _nc_read_termcap_entry() to support reading and translating capabilities + * from the system termcap file. This is a kludge; it will bulk up and slow + * down every program that uses ncurses, and translated termcap entries cannot + * use full terminfo capabilities. Don't use it unless you absolutely have to; + * instead, get your system people to run tic(1) from root on the terminfo + * master included with ncurses to translate it into a terminfo database. + * + * If USE_GETCAP is enabled, we use what is effectively a copy of the 4.4BSD + * getcap code to fetch entries. There are disadvantages to this; mainly that + * getcap(3) does its own resolution, meaning that entries read in in this way + * can't reference the terminfo tree. The only thing it buys is faster startup + * time, getcap(3) is much faster than our tic parser. + */ + +#include <curses.priv.h> + +#include <ctype.h> +#include <tic.h> +#include <term_entry.h> + +#if HAVE_FCNTL_H +#include <fcntl.h> +#endif + +MODULE_ID("$Id: read_termcap.c,v 1.43 1999/04/10 20:52:52 tom Exp $") + +#ifndef 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 + +#if USE_GETCAP + +#if HAVE_BSD_CGETENT +#define _nc_cgetcap cgetcap +#define _nc_cgetent(buf, oline, db_array, name) cgetent(buf, db_array, name) +#define _nc_cgetmatch cgetmatch +#define _nc_cgetset cgetset +#else +static int _nc_cgetmatch(char *, const char *); +static int _nc_getent(char **, unsigned int *, int *, int, char **, int, const char *, int, char *); +static int _nc_nfcmp(const char *, char *); + +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Casey Leedom of Lawrence Livermore National Laboratory. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgment: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* static char sccsid[] = "@(#)getcap.c 8.3 (Berkeley) 3/25/94"; */ + +#define BFRAG 1024 +#define BSIZE 1024 +#define ESC ('[' & 037) /* ASCII ESC */ +#define MAX_RECURSION 32 /* maximum getent recursion */ +#define SFRAG 100 /* cgetstr mallocs in SFRAG chunks */ + +#define RECOK (char)0 +#define TCERR (char)1 +#define SHADOW (char)2 + +static size_t topreclen; /* toprec length */ +static char *toprec; /* Additional record specified by cgetset() */ +static int gottoprec; /* Flag indicating retrieval of toprecord */ + +/* + * Cgetset() allows the addition of a user specified buffer to be added to the + * database array, in effect "pushing" the buffer on top of the virtual + * database. 0 is returned on success, -1 on failure. + */ +static int +_nc_cgetset(const char *ent) +{ + if (ent == 0) { + FreeIfNeeded(toprec); + toprec = 0; + topreclen = 0; + return (0); + } + topreclen = strlen(ent); + if ((toprec = typeMalloc(char, topreclen + 1)) == 0) { + errno = ENOMEM; + return (-1); + } + gottoprec = 0; + (void)strcpy(toprec, ent); + return (0); +} + +/* + * Cgetcap searches the capability record buf for the capability cap with type + * `type'. A pointer to the value of cap is returned on success, 0 if the + * requested capability couldn't be found. + * + * Specifying a type of ':' means that nothing should follow cap (:cap:). In + * this case a pointer to the terminating ':' or NUL will be returned if cap is + * found. + * + * If (cap, '@') or (cap, terminator, '@') is found before (cap, terminator) + * return 0. + */ +static char * +_nc_cgetcap(char *buf, const char *cap, int type) +{ + register const char *cp; + register char *bp; + + bp = buf; + for (;;) { + /* + * Skip past the current capability field - it's either the + * name field if this is the first time through the loop, or + * the remainder of a field whose name failed to match cap. + */ + for (;;) { + if (*bp == '\0') + return (0); + else if (*bp++ == ':') + break; + } + + /* + * Try to match (cap, type) in buf. + */ + for (cp = cap; *cp == *bp && *bp != '\0'; cp++, bp++) + continue; + if (*cp != '\0') + continue; + if (*bp == '@') + return (0); + if (type == ':') { + if (*bp != '\0' && *bp != ':') + continue; + return(bp); + } + if (*bp != type) + continue; + bp++; + return (*bp == '@' ? 0 : bp); + } + /* NOTREACHED */ +} + +/* + * Cgetent extracts the capability record name from the NULL terminated file + * array db_array and returns a pointer to a malloc'd copy of it in buf. Buf + * must be retained through all subsequent calls to cgetcap, cgetnum, cgetflag, + * and cgetstr, but may then be freed. + * + * Returns: + * + * positive # on success (i.e., the index in db_array) + * TC_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 + */ +static int +_nc_cgetent(char **buf, int *oline, char **db_array, const char *name) +{ + unsigned int dummy; + + return (_nc_getent(buf, &dummy, oline, 0, db_array, -1, name, 0, 0)); +} + +/* + * Getent implements the functions of cgetent. If fd is non-negative, + * *db_array has already been opened and fd is the open file descriptor. We + * do this to save time and avoid using up file descriptors for tc= + * recursions. + * + * Getent returns the same success/failure codes as cgetent. On success, a + * pointer to a malloc'd capability record with all tc= capabilities fully + * expanded and its length (not including trailing ASCII NUL) are left in + * *cap and *len. + * + * Basic algorithm: + * + Allocate memory incrementally as needed in chunks of size BFRAG + * for capability buffer. + * + Recurse for each tc=name and interpolate result. Stop when all + * names interpolated, a name can't be found, or depth exceeds + * MAX_RECURSION. + */ +#define DOALLOC(size) typeRealloc(char, size, record) +static int +_nc_getent( + char **cap, /* termcap-content */ + unsigned int *len, /* length, needed for recursion */ + int *beginning, /* line-number at match */ + int in_array, /* index in 'db_array[] */ + char **db_array, /* list of files to search */ + int fd, + const char *name, + int depth, + char *nfield) +{ + register char *r_end, *rp; + int myfd = FALSE; + char *record = 0; + int tc_not_resolved; + int current; + int lineno; + + /* + * Return with ``loop detected'' error if we've recurred more than + * MAX_RECURSION times. + */ + if (depth > MAX_RECURSION) + return (TC_REF_LOOP); + + /* + * Check if we have a top record from cgetset(). + */ + if (depth == 0 && toprec != 0 && _nc_cgetmatch(toprec, name) == 0) { + if ((record = DOALLOC(topreclen + BFRAG)) == 0) { + errno = ENOMEM; + return (TC_SYS_ERR); + } + (void)strcpy(record, toprec); + rp = record + topreclen + 1; + r_end = rp + BFRAG; + current = in_array; + } else { + int foundit; + + /* + * Allocate first chunk of memory. + */ + if ((record = DOALLOC(BFRAG)) == 0) { + errno = ENOMEM; + return (TC_SYS_ERR); + } + rp = r_end = record + BFRAG; + foundit = FALSE; + + /* + * Loop through database array until finding the record. + */ + for (current = in_array; db_array[current] != 0; current++) { + int eof = FALSE; + + /* + * Open database if not already open. + */ + if (fd >= 0) { + (void)lseek(fd, (off_t)0, SEEK_SET); + } else if ((_nc_access(db_array[current], R_OK) < 0) + || (fd = open(db_array[current], O_RDONLY, 0)) < 0) { + /* No error on unfound file. */ + if (errno == ENOENT) + continue; + free(record); + return (TC_SYS_ERR); + } else { + myfd = TRUE; + } + lineno = 0; + + /* + * Find the requested capability record ... + */ + { + char buf[2048]; + register char *b_end = buf; + register char *bp = buf; + register int c; + + /* + * Loop invariants: + * There is always room for one more character in record. + * R_end always points just past end of record. + * Rp always points just past last character in record. + * B_end always points just past last character in buf. + * Bp always points at next character in buf. + */ + + for (;;) { + int first = lineno + 1; + + /* + * Read in a line implementing (\, newline) + * line continuation. + */ + rp = record; + for (;;) { + if (bp >= b_end) { + int n; + + n = read(fd, buf, sizeof(buf)); + if (n <= 0) { + if (myfd) + (void)close(fd); + if (n < 0) { + free(record); + return (TC_SYS_ERR); + } + fd = -1; + eof = TRUE; + break; + } + b_end = buf+n; + bp = buf; + } + + c = *bp++; + if (c == '\n') { + lineno++; + if (rp == record || *(rp-1) != '\\') + break; + } + *rp++ = c; + + /* + * Enforce loop invariant: if no room + * left in record buffer, try to get + * some more. + */ + if (rp >= r_end) { + unsigned int pos; + size_t newsize; + + pos = rp - record; + newsize = r_end - record + BFRAG; + record = DOALLOC(newsize); + if (record == 0) { + if (myfd) + (void)close(fd); + errno = ENOMEM; + return (TC_SYS_ERR); + } + r_end = record + newsize; + rp = record + pos; + } + } + /* loop invariant lets us do this */ + *rp++ = '\0'; + + /* + * If encountered eof check next file. + */ + if (eof) + break; + + /* + * Toss blank lines and comments. + */ + if (*record == '\0' || *record == '#') + continue; + + /* + * See if this is the record we want ... + */ + if (_nc_cgetmatch(record, name) == 0 + && (nfield == 0 + || !_nc_nfcmp(nfield, record))) { + foundit = TRUE; + *beginning = first; + break; /* found it! */ + } + } + } + if (foundit) + break; + } + + if (!foundit) + return (TC_NOT_FOUND); + } + + /* + * Got the capability record, but now we have to expand all tc=name + * references in it ... + */ + { + register char *newicap, *s; + register int newilen; + unsigned int ilen; + int diff, iret, tclen, oline; + char *icap, *scan, *tc, *tcstart, *tcend; + + /* + * Loop invariants: + * There is room for one more character in record. + * R_end points just past end of record. + * Rp points just past last character in record. + * Scan points at remainder of record that needs to be + * scanned for tc=name constructs. + */ + scan = record; + tc_not_resolved = FALSE; + for (;;) { + if ((tc = _nc_cgetcap(scan, "tc", '=')) == 0) + break; + + /* + * Find end of tc=name and stomp on the trailing `:' + * (if present) so we can use it to call ourselves. + */ + s = tc; + while (*s != '\0') { + if (*s++ == ':') { + *(s - 1) = '\0'; + break; + } + } + tcstart = tc - 3; + tclen = s - tcstart; + tcend = s; + + iret = _nc_getent(&icap, &ilen, &oline, current, db_array, fd, tc, depth+1, 0); + newicap = icap; /* Put into a register. */ + newilen = ilen; + if (iret != TC_SUCCESS) { + /* an error */ + if (iret < TC_NOT_FOUND) { + if (myfd) + (void)close(fd); + free(record); + return (iret); + } + if (iret == TC_UNRESOLVED) + tc_not_resolved = TRUE; + /* couldn't resolve tc */ + if (iret == TC_NOT_FOUND) { + *(s - 1) = ':'; + scan = s - 1; + tc_not_resolved = TRUE; + continue; + } + } + + /* not interested in name field of tc'ed record */ + s = newicap; + while (*s != '\0' && *s++ != ':') + ; + newilen -= s - newicap; + newicap = s; + + /* make sure interpolated record is `:'-terminated */ + s += newilen; + if (*(s-1) != ':') { + *s = ':'; /* overwrite NUL with : */ + newilen++; + } + + /* + * Make sure there's enough room to insert the + * new record. + */ + diff = newilen - tclen; + if (diff >= r_end - rp) { + unsigned int pos, tcpos, tcposend; + size_t newsize; + + pos = rp - record; + newsize = r_end - record + diff + BFRAG; + tcpos = tcstart - record; + tcposend = tcend - record; + record = DOALLOC(newsize); + if (record == 0) { + if (myfd) + (void)close(fd); + free(icap); + errno = ENOMEM; + return (TC_SYS_ERR); + } + r_end = record + newsize; + rp = record + pos; + tcstart = record + tcpos; + tcend = record + tcposend; + } + + /* + * Insert tc'ed record into our record. + */ + s = tcstart + newilen; + memmove(s, tcend, (size_t)(rp - tcend)); + memmove(tcstart, newicap, (size_t)newilen); + rp += diff; + free(icap); + + /* + * Start scan on `:' so next cgetcap works properly + * (cgetcap always skips first field). + */ + scan = s-1; + } + } + + /* + * Close file (if we opened it), give back any extra memory, and + * return capability, length and success. + */ + if (myfd) + (void)close(fd); + *len = rp - record - 1; /* don't count NUL */ + if (r_end > rp) { + if ((record = DOALLOC((size_t)(rp - record))) == 0) { + errno = ENOMEM; + return (TC_SYS_ERR); + } + } + + *cap = record; + if (tc_not_resolved) + return (TC_UNRESOLVED); + return (current); +} + +/* + * Cgetmatch will return 0 if name is one of the names of the capability + * record buf, -1 if not. + */ +static int +_nc_cgetmatch(char *buf, const char *name) +{ + register const char *np; + register char *bp; + + /* + * Start search at beginning of record. + */ + bp = buf; + for (;;) { + /* + * Try to match a record name. + */ + np = name; + for (;;) { + if (*np == '\0') { + if (*bp == '|' || *bp == ':' || *bp == '\0') + return (0); + else + break; + } else if (*bp++ != *np++) { + break; + } + } + + /* + * Match failed, skip to next name in record. + */ + bp--; /* a '|' or ':' may have stopped the match */ + for (;;) { + if (*bp == '\0' || *bp == ':') + return (-1); /* match failed totally */ + else if (*bp++ == '|') + break; /* found next name */ + } + } +} + +/* + * Compare name field of record. + */ +static int +_nc_nfcmp(const char *nf, char *rec) +{ + char *cp, tmp; + int ret; + + for (cp = rec; *cp != ':'; cp++) + ; + + tmp = *(cp + 1); + *(cp + 1) = '\0'; + ret = strcmp(nf, rec); + *(cp + 1) = tmp; + + return (ret); +} +#endif /* HAVE_BSD_CGETENT */ + +/* + * Since ncurses provides its own 'tgetent()', we cannot use the native one. + * So we reproduce the logic to get down to cgetent() -- or our cut-down + * version of that -- to circumvent the problem of configuring against the + * termcap library. + */ +#define USE_BSD_TGETENT 1 + +#if USE_BSD_TGETENT +/* + * Copyright (c) 1980, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgment: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* static char sccsid[] = "@(#)termcap.c 8.1 (Berkeley) 6/4/93" */ + +#define PBUFSIZ 512 /* max length of filename path */ +#define PVECSIZ 32 /* max number of names in path */ +#define TBUFSIZ (2048*2) + +static char *tbuf; + +/* + * On entry, srcp points to a non ':' character which is the beginning of the + * token, if any. We'll try to return a string that doesn't end with a ':'. + */ +static char * +get_tc_token(char **srcp, int *endp) +{ + int ch; + bool found = FALSE; + char *s, *base; + char *tok = 0; + + *endp = TRUE; + for (s = base = *srcp; *s != '\0'; ) { + ch = *s++; + if (ch == '\\') { + if (*s == '\0') { + break; + } else if (*s++ == '\n') { + while (isspace(*s)) + s++; + } else { + found = TRUE; + } + } else if (ch == ':') { + if (found) { + tok = base; + s[-1] = '\0'; + *srcp = s; + *endp = FALSE; + break; + } + base = s; + } else if (isgraph(ch)) { + found = TRUE; + } + } + + /* malformed entry may end without a ':' */ + if (tok == 0 && found) { + tok = base; + } + + return tok; +} + +static char * +copy_tc_token(char *dst, const char *src, size_t len) +{ + int ch; + + while ((ch = *src++) != '\0') { + if (ch == '\\' && *src == '\n') { + while (isspace(*src)) + src++; + continue; + } + if (--len == 0) { + dst = 0; + break; + } + *dst++ = ch; + } + return dst; +} + +/* + * Get an entry for terminal name in buffer bp from the termcap file. + */ +static int +_nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name) +{ + static char *the_source; + + register char *p; + register char *cp; + char *dummy; + char **fname; + char *home; + int i; + char pathbuf[PBUFSIZ]; /* holds raw path of filenames */ + char *pathvec[PVECSIZ]; /* to point to names in pathbuf */ + char **pvec; /* holds usable tail of path vector */ + char *termpath; + + fname = pathvec; + pvec = pathvec; + tbuf = bp; + p = pathbuf; + cp = getenv("TERMCAP"); + + /* + * TERMCAP can have one of two things in it. It can be the name of a + * file to use instead of /etc/termcap. In this case it better start + * with a "/". Or it can be an entry to use so we don't have to read + * the file. In this case it has to already have the newlines crunched + * out. If TERMCAP does not hold a file name then a path of names is + * searched instead. The path is found in the TERMPATH variable, or + * becomes "$HOME/.termcap /etc/termcap" if no TERMPATH exists. + */ + if (!is_pathname(cp)) { /* no TERMCAP or it holds an entry */ + if ((termpath = getenv("TERMPATH")) != 0) { + strncpy(pathbuf, termpath, PBUFSIZ - 1); + } else { + if ((home = getenv("HOME")) != 0 && + strlen(home) < PBUFSIZ) { /* setup path */ + p += strlen(home); /* path, looking in */ + strcpy(pathbuf, home); /* $HOME first */ + *p++ = '/'; + } /* if no $HOME look in current directory */ +#define MY_PATH_DEF ".termcap /etc/termcap /usr/share/misc/termcap" + strncpy(p, MY_PATH_DEF, (size_t)(PBUFSIZ - (p - pathbuf) - 1)); + } + } + else /* user-defined name in TERMCAP */ + strncpy(pathbuf, cp, PBUFSIZ - 1); /* still can be tokenized */ + pathbuf[PBUFSIZ - 1] = '\0'; + + *fname++ = pathbuf; /* tokenize path into vector of names */ + while (*++p) { + if (*p == ' ' || *p == ':') { + *p = '\0'; + while (*++p) + if (*p != ' ' && *p != ':') + break; + if (*p == '\0') + break; + *fname++ = p; + if (fname >= pathvec + PVECSIZ) { + fname--; + break; + } + } + } + *fname = 0; /* mark end of vector */ + if (is_pathname(cp)) { + if (_nc_cgetset(cp) < 0) { + return(TC_SYS_ERR); + } + } + + i = _nc_cgetent(&dummy, lineno, pathvec, name); + + /* ncurses' termcap-parsing routines cannot handle multiple adjacent + * empty fields, and mistakenly use the last valid cap entry instead of + * the first (breaks tc= includes) + */ + if (i >= 0) { + char *pd, *ps, *tok; + int endflag = FALSE; + char *list[1023]; + size_t n, count = 0; + + pd = bp; + ps = dummy; + while (!endflag && (tok = get_tc_token(&ps, &endflag)) != 0) { + bool ignore = FALSE; + + for (n = 1; n < count; n++) { + char *s = list[n]; + if (s[0] == tok[0] + && s[1] == tok[1]) { + ignore = TRUE; + break; + } + } + if (ignore != TRUE) { + list[count++] = tok; + pd = copy_tc_token(pd, tok, TBUFSIZ - (2+pd-bp)); + if (pd == 0) { + i = -1; + break; + } + *pd++ = ':'; + *pd = '\0'; + } + } + } + + FreeIfNeeded(dummy); + FreeIfNeeded(the_source); + the_source = 0; + + /* This is not related to the BSD cgetent(), but to fake up a suitable + * filename for ncurses' error reporting. (If we are not using BSD + * cgetent, then it is the actual filename). + */ + if (i >= 0) { + if ((the_source = strdup(pathvec[i])) != 0) + *sourcename = the_source; + } + + return(i); +} +#endif /* USE_BSD_TGETENT */ +#endif /* USE_GETCAP */ + +#define MAXPATHS 32 + +/* + * Add a filename to the list in 'termpaths[]', checking that we really have + * a right to open the file. + */ +#if !USE_GETCAP +static int add_tc(char *termpaths[], char *path, int count) +{ + if (count < MAXPATHS + && _nc_access(path, R_OK) == 0) + termpaths[count++] = path; + termpaths[count] = 0; + return count; +} +#define ADD_TC(path, count) filecount = add_tc(termpaths, path, count) +#endif /* !USE_GETCAP */ + +int _nc_read_termcap_entry(const char *const tn, TERMTYPE *const tp) +{ + int found = FALSE; + ENTRY *ep; +#if USE_GETCAP_CACHE + char cwd_buf[PATH_MAX]; +#endif +#if USE_GETCAP + char tc[TBUFSIZ]; + static char *source; + static int lineno; + + /* we're using getcap(3) */ + if (_nc_tgetent(tc, &source, &lineno, tn) < 0) + return (ERR); + + _nc_curr_line = lineno; + _nc_set_source(source); + _nc_read_entry_source((FILE *)0, tc, FALSE, FALSE, NULLHOOK); +#else + /* + * Here is what the 4.4BSD termcap(3) page prescribes: + * + * It will look in the environment for a TERMCAP variable. If found, + * and the value does not begin with a slash, and the terminal type + * name is the same as the environment string TERM, the TERMCAP string + * is used instead of reading a termcap file. If it does begin with a + * slash, the string is used as a path name of the termcap file to + * search. If TERMCAP does not begin with a slash and name is + * different from TERM, tgetent() searches the files $HOME/.termcap and + * /usr/share/misc/termcap, in that order, unless the environment + * variable TERMPATH exists, in which case it specifies a list of file + * pathnames (separated by spaces or colons) to be searched instead. + * + * It goes on to state: + * + * Whenever multiple files are searched and a tc field occurs in the + * requested entry, the entry it names must be found in the same file + * or one of the succeeding files. + * + * However, this restriction is relaxed in ncurses; tc references to + * previous files are permitted. + * + * This routine returns 1 if an entry is found, 0 if not found, and -1 + * if the database is not accessible. + */ + FILE *fp; + char *tc, *termpaths[MAXPATHS]; + int filecount = 0; + bool use_buffer = FALSE; + char tc_buf[1024]; + char pathbuf[PATH_MAX]; + + termpaths[filecount] = 0; + if ((tc = getenv("TERMCAP")) != 0) + { + if (is_pathname(tc)) /* interpret as a filename */ + { + ADD_TC(tc, 0); + } + else if (_nc_name_match(tc, tn, "|:")) /* treat as a capability file */ + { + use_buffer = TRUE; + (void) sprintf(tc_buf, "%.*s\n", (int)sizeof(tc_buf)-2, tc); + } + else if ((tc = getenv("TERMPATH")) != 0) + { + char *cp; + + for (cp = tc; *cp; cp++) + { + if (*cp == ':') + *cp = '\0'; + else if (cp == tc || cp[-1] == '\0') + { + ADD_TC(cp, filecount); + } + } + } + } + else /* normal case */ + { + char envhome[PATH_MAX], *h; + + filecount = 0; + + /* + * Probably /etc/termcap is a symlink to /usr/share/misc/termcap. + * Avoid reading the same file twice. + */ + if (_nc_access("/etc/termcap", F_OK) == 0) + ADD_TC("/etc/termcap", filecount); + else + ADD_TC("/usr/share/misc/termcap", filecount); + +#define PRIVATE_CAP "%s/.termcap" + + if ((h = getenv("HOME")) != NULL + && (strlen(h) + sizeof(PRIVATE_CAP)) < PATH_MAX) + { + /* user's .termcap, if any, should override it */ + (void) strcpy(envhome, h); + (void) sprintf(pathbuf, PRIVATE_CAP, envhome); + ADD_TC(pathbuf, filecount); + } + } + + /* parse the sources */ + if (use_buffer) + { + _nc_set_source("TERMCAP"); + + /* + * We don't suppress warning messages here. The presumption is + * that since it's just a single entry, they won't be a pain. + */ + _nc_read_entry_source((FILE *)0, tc_buf, FALSE, FALSE, NULLHOOK); + } else { + int i; + + for (i = 0; i < filecount; i++) { + + T(("Looking for %s in %s", tn, termpaths[i])); + if ((fp = fopen(termpaths[i], "r")) != (FILE *)0) + { + _nc_set_source(termpaths[i]); + + /* + * Suppress warning messages. Otherwise you + * get 400 lines of crap from archaic termcap + * files as ncurses complains about all the + * obsolete capabilities. + */ + _nc_read_entry_source(fp, (char*)0, FALSE, TRUE, NULLHOOK); + + (void) fclose(fp); + } + } + } +#endif /* USE_GETCAP */ + + if (_nc_head == 0) + return(ERR); + + /* resolve all use references */ + _nc_resolve_uses(); + + /* find a terminal matching tn, if we can */ +#if USE_GETCAP_CACHE + if (getcwd(cwd_buf, sizeof(cwd_buf)) != 0) + { + _nc_set_writedir((char *)0); /* note: this does a chdir */ +#endif + for_entry_list(ep) { + if (_nc_name_match(ep->tterm.term_names, tn, "|:")) + { + /* + * Make a local copy of the terminal + * capabilities. 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). + */ + *tp = ep->tterm; + ep->tterm.str_table = (char *)0; + + /* + * OK, now try to write the type to user's + * terminfo directory. Next time he loads + * this, it will come through terminfo. + * + * Advantage: Second and subsequent fetches of + * this entry will be very fast. + * + * Disadvantage: After the first time a + * termcap type is loaded by its user, editing + * it in the /etc/termcap file, or in TERMCAP, + * or in a local ~/.termcap, will be + * ineffective unless the terminfo entry is + * explicitly removed. + */ +#if USE_GETCAP_CACHE + (void) _nc_write_entry(tp); +#endif + found = TRUE; + break; + } + } +#if USE_GETCAP_CACHE + chdir(cwd_buf); + } +#endif + + _nc_free_entries(_nc_head); + return(found); +} +#else +extern void _nc_read_termcap(void); + void _nc_read_termcap(void) { } +#endif /* PURE_TERMINFO */ diff --git a/contrib/ncurses/ncurses/tinfo/setbuf.c b/contrib/ncurses/ncurses/tinfo/setbuf.c new file mode 100644 index 0000000..c0e7356 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/setbuf.c @@ -0,0 +1,144 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* +** setbuf.c +** +** Support for set_term(), reset_shell_mode(), reset_prog_mode(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("$Id: setbuf.c,v 1.5 1999/02/27 20:00:15 tom Exp $") + +/* + * If the output file descriptor is connected to a tty (the typical case) it + * will probably be line-buffered. Keith Bostic pointed out that we don't want + * this; it hoses people running over networks by forcing out a bunch of small + * packets instead of one big one, so screen updates on ptys look jerky. + * Restore block buffering to prevent this minor lossage. + * + * The buffer size is a compromise. Ideally we'd like a buffer that can hold + * the maximum possible update size (the whole screen plus cup commands to + * change lines as it's painted). On a 66-line xterm this can become + * excessive. So we min it with the amount of data we think we can get through + * two Ethernet packets (maximum packet size - 100 for TCP/IP overhead). + * + * Why two ethernet packets? It used to be one, on the theory that said + * packets define the maximum size of atomic update. But that's less than the + * 2000 chars on a 25 x 80 screen, and we don't want local updates to flicker + * either. Two packet lengths will handle up to a 35 x 80 screen. + * + * The magic '6' is the estimated length of the end-of-line cup sequence to go + * to the next line. It's generous. We used to mess with the buffering in + * init_mvcur() after cost computation, but that lost the sequences emitted by + * init_acs() in setupscreen(). + * + * "The setvbuf function may be used only after the stream pointed to by stream + * has been associated with an open file and before any other operation is + * performed on the stream." (ISO 7.9.5.6.) + * + * Grrrr... + * + * On a lighter note, many implementations do in fact allow an application to + * reset the buffering after it has been written to. We try to do this because + * otherwise we leave stdout in buffered mode after endwin() is called. (This + * also happens with SVr4 curses). + * + * There are pros/cons: + * + * con: + * There is no guarantee that we can reestablish buffering once we've + * dropped it. + * + * We _may_ lose data if the implementation does not coordinate this with + * fflush. + * + * pro: + * An implementation is more likely to refuse to change the buffering than + * to do it in one of the ways mentioned above. + * + * The alternative is to have the application try to change buffering + * itself, which is certainly no improvement. + * + * Just in case it does not work well on a particular system, the calls to + * change buffering are all via the macro NC_BUFFERED. Some implementations + * do indeed get confused by changing setbuf on/off, and will overrun the + * buffer. So we disable this by default (there may yet be a workaround). + */ +void _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 (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! */ + } +#if !USE_SETBUF_0 + else return; +#endif + } else { +#if !USE_SETBUF_0 + return; +#else + buf_len = 0; + buf_ptr = 0; +#endif + } + +#if HAVE_SETVBUF +#ifdef SETVBUF_REVERSED /* pre-svr3? */ + (void) setvbuf(ofp, buf_ptr, buf_len, buf_len ? _IOFBF : _IOLBF); +#else + (void) setvbuf(ofp, buf_ptr, buf_len ? _IOFBF : _IOLBF, buf_len); +#endif +#elif HAVE_SETBUFFER + (void) setbuffer(ofp, buf_ptr, (int)buf_len); +#endif + +#endif /* HAVE_SETVBUF || HAVE_SETBUFFER */ +} diff --git a/contrib/ncurses/ncurses/tinfo/write_entry.c b/contrib/ncurses/ncurses/tinfo/write_entry.c new file mode 100644 index 0000000..4829fa9 --- /dev/null +++ b/contrib/ncurses/ncurses/tinfo/write_entry.c @@ -0,0 +1,557 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* + * write_entry.c -- write a terminfo structure onto the file system + */ + +#include <curses.priv.h> + +#include <sys/stat.h> + +#include <tic.h> +#include <term_entry.h> + +#ifndef S_ISDIR +#define S_ISDIR(mode) ((mode & S_IFMT) == S_IFDIR) +#endif + +#if 0 +#define TRACE_OUT(p) DEBUG(2, p) +#else +#define TRACE_OUT(p) /*nothing*/ +#endif + +MODULE_ID("$Id: write_entry.c,v 1.47 1999/07/10 20:29:22 tom Exp $") + +static int total_written; + +static int write_object(FILE *, TERMTYPE *); + +static void write_file(char *filename, TERMTYPE *tp) +{ + FILE *fp = (_nc_access(filename, W_OK) == 0) ? fopen(filename, "wb") : 0; + if (fp == 0) { + perror(filename); + _nc_syserr_abort("can't open %s/%s", _nc_tic_dir(0), filename); + } + DEBUG(1, ("Created %s", filename)); + + if (write_object(fp, tp) == ERR) { + _nc_syserr_abort("error writing %s/%s", _nc_tic_dir(0), filename); + } + fclose(fp); +} + +/* + * make_directory(char *path) + * + * Make a directory if it doesn't exist. + */ +static int make_directory(const char *path) +{ +int rc; +struct stat statbuf; +char fullpath[PATH_MAX]; +const char *destination = _nc_tic_dir(0); + + if (path == destination || *path == '/') { + if (strlen(path) + 1 > sizeof(fullpath)) + return(-1); + (void)strcpy(fullpath, path); + } else { + if (strlen(destination) + strlen(path) + 2 > sizeof(fullpath)) + return(-1); + (void)sprintf(fullpath, "%s/%s", destination, path); + } + + 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 */ + } + } + return rc; +} + +void _nc_set_writedir(char *dir) +/* set the write directory for compiled entries */ +{ + const char *destination; + char actual[PATH_MAX]; + + if (dir != 0) + (void) _nc_tic_dir(dir); + else if (getenv("TERMINFO") != NULL) + (void) _nc_tic_dir(getenv("TERMINFO")); + + destination = _nc_tic_dir(0); + if (make_directory(destination) < 0) + { + char *home = _nc_home_terminfo(); + + if (home != 0) { + destination = home; + if (make_directory(destination) < 0) + _nc_err_abort("%s: permission denied (errno %d)", + destination, errno); + } + } + + /* + * Note: because of this code, this logic should be exercised + * *once only* per run. + */ + if (chdir(_nc_tic_dir(destination)) < 0 + || getcwd(actual, sizeof(actual)) == 0) + _nc_err_abort("%s: not a directory", destination); + _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; + + 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 + * break it up into first-name and all-but-last-name + * creat(first-name) + * write object information to first-name + * close(first-name) + * for each name in all-but-last-name + * link to first-name + * + * Using 'time()' to obtain a reference for file timestamps is unreliable, + * e.g., with NFS, because the filesystem may have a different time + * reference. We check for pre-existence of links by latching the first + * timestamp from a file that we create. + * + * The _nc_warning() calls will report a correct line number only if + * _nc_curr_line is properly set before the write_entry() call. + */ + +void _nc_write_entry(TERMTYPE *const tp) +{ +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 +char symlinkname[PATH_MAX]; +#endif /* USE_SYMLINKS */ +static int call_count; +static time_t start_time; /* time at start of writes */ + + if (call_count++ == 0) { + start_time = 0; + } + + (void) strcpy(name_list, tp->term_names); + DEBUG(7, ("Name list = '%s'", name_list)); + + first_name = name_list; + + ptr = &name_list[strlen(name_list) - 1]; + other_names = ptr + 1; + + while (ptr > name_list && *ptr != '|') + ptr--; + + if (ptr != name_list) { + *ptr = '\0'; + + for (ptr = name_list; *ptr != '\0' && *ptr != '|'; ptr++) + continue; + + if (*ptr == '\0') + other_names = ptr; + else { + *ptr = '\0'; + other_names = ptr + 1; + } + } + + DEBUG(7, ("First name = '%s'", first_name)); + DEBUG(7, ("Other names = '%s'", other_names)); + + _nc_set_type(first_name); + + if (strlen(first_name) > sizeof(filename)-3) + _nc_warning("terminal name too long."); + + sprintf(filename, "%c/%s", first_name[0], first_name); + + /* + * Has this primary name been written since the first call to + * write_entry()? If so, the newer write will step on the older, + * so warn the user. + */ + if (start_time > 0 && + stat(filename, &statbuf) >= 0 + && statbuf.st_mtime >= start_time) + { + _nc_warning("name multiply defined."); + } + + check_writeable(first_name[0]); + write_file(filename, tp); + + if (start_time == 0) { + if (stat(filename, &statbuf) < 0 + || (start_time = statbuf.st_mtime) == 0) { + _nc_syserr_abort("error obtaining time from %s/%s", + _nc_tic_dir(0), filename); + } + } + while (*other_names != '\0') { + ptr = other_names++; + while (*other_names != '|' && *other_names != '\0') + other_names++; + + if (*other_names != '\0') + *(other_names++) = '\0'; + + if (strlen(ptr) > sizeof(linkname)-3) { + _nc_warning("terminal alias %s too long.", ptr); + continue; + } + if (strchr(ptr, '/') != 0) { + _nc_warning("cannot link alias %s.", ptr); + continue; + } + + check_writeable(ptr[0]); + sprintf(linkname, "%c/%s", ptr[0], ptr); + + if (strcmp(filename, linkname) == 0) { + _nc_warning("self-synonym ignored"); + } + else if (stat(linkname, &statbuf) >= 0 && + statbuf.st_mtime < start_time) + { + _nc_warning("alias %s multiply defined.", ptr); + } + else if (_nc_access(linkname, W_OK) == 0) +#if HAVE_LINK + { + int code; +#if USE_SYMLINKS + strcpy(symlinkname, "../"); + strncat(symlinkname, filename, sizeof(symlinkname) - 4); + symlinkname[sizeof(symlinkname) - 1] = '\0'; +#endif /* USE_SYMLINKS */ +#if HAVE_REMOVE + code = remove(linkname); +#else + code = unlink(linkname); +#endif + if (code != 0 && errno == ENOENT) + code = 0; +#if USE_SYMLINKS + if (symlink(symlinkname, linkname) < 0) +#else + if (link(filename, linkname) < 0) +#endif /* USE_SYMLINKS */ + { + /* + * If there wasn't anything there, and we cannot + * link to the target because it is the same as the + * target, then the source must be on a filesystem + * that uses caseless filenames, such as Win32, etc. + */ + if (code == 0 && errno == EEXIST) + _nc_warning("can't link %s to %s", filename, linkname); + else if (code == 0 && errno == EPERM) + write_file(linkname, tp); + else + _nc_syserr_abort("can't link %s to %s", filename, linkname); + } + else + { + DEBUG(1, ("Linked %s", linkname)); + } + } +#else /* just make copies */ + write_file(linkname, tp); +#endif /* HAVE_LINK */ + } +} + +#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) + +static int compute_offsets(char **Strings, int strmax, short *offsets) +{ + size_t nextfree = 0; + int i; + + for (i = 0; i < strmax; i++) { + if (Strings[i] == ABSENT_STRING) { + offsets[i] = -1; + } else if (Strings[i] == CANCELLED_STRING) { + offsets[i] = -2; + } else { + offsets[i] = nextfree; + nextfree += strlen(Strings[i]) + 1; + TRACE_OUT(("put Strings[%d]=%s(%d)", i, _nc_visbuf(Strings[i]), nextfree)); + } + } + return nextfree; +} + +static void convert_shorts(unsigned char *buf, short *Numbers, int count) +{ + int i; + for (i = 0; i < count; i++) { + if (Numbers[i] == -1) { /* HI/LO won't work */ + buf[2*i] = buf[2*i + 1] = 0377; + } else if (Numbers[i] == -2) { /* HI/LO won't work */ + buf[2*i] = 0376; + buf[2*i + 1] = 0377; + } else { + LITTLE_ENDIAN(buf + 2*i, Numbers[i]); + TRACE_OUT(("put Numbers[%d]=%d", i, Numbers[i])); + } + } +} + +#define even_boundary(value) \ + ((value) % 2 != 0 && fwrite(&zero, sizeof(char), 1, fp) != 1) + +static int write_object(FILE *fp, TERMTYPE *tp) +{ +char *namelist; +size_t namelen, boolmax, nummax, strmax; +char zero = '\0'; +size_t i; +short nextfree; +short offsets[MAX_ENTRY_SIZE/2]; +unsigned char buf[MAX_ENTRY_SIZE]; + + namelist = tp->term_names; + namelen = strlen(namelist) + 1; + + /* + * BOOLWRITE, etc., are less than BOOLCOUNT because we store some + * values internally. + */ + boolmax = 0; + for (i = 0; i < BOOLWRITE; i++) { + if (tp->Booleans[i]) + boolmax = i+1; + } + + nummax = 0; + for (i = 0; i < NUMWRITE; i++) { + if (tp->Numbers[i] != ABSENT_NUMERIC) + nummax = i+1; + } + + strmax = 0; + for (i = 0; i < STRWRITE; i++) { + if (tp->Strings[i] != ABSENT_STRING) + strmax = i+1; + } + + nextfree = compute_offsets(tp->Strings, strmax, offsets); + + /* fill in the header */ + LITTLE_ENDIAN(buf, MAGIC); + LITTLE_ENDIAN(buf+2, min(namelen, MAX_NAME_SIZE + 1)); + LITTLE_ENDIAN(buf+4, boolmax); + LITTLE_ENDIAN(buf+6, nummax); + LITTLE_ENDIAN(buf+8, strmax); + LITTLE_ENDIAN(buf+10, nextfree); + + /* write out the header */ + TRACE_OUT(("Header of %s @%ld", namelist, ftell(fp))); + if (fwrite(buf, 12, 1, fp) != 1 + || fwrite(namelist, sizeof(char), namelen, fp) != namelen + || fwrite(tp->Booleans, sizeof(char), boolmax, fp) != boolmax) + return(ERR); + + if (even_boundary(namelen+boolmax)) + return(ERR); + + TRACE_OUT(("Numerics begin at %04lx", ftell(fp))); + + /* the numerics */ + convert_shorts(buf, tp->Numbers, nummax); + if (fwrite(buf, 2, nummax, fp) != nummax) + return(ERR); + + TRACE_OUT(("String offsets begin at %04lx", ftell(fp))); + + /* the string offsets */ + convert_shorts(buf, offsets, strmax); + if (fwrite(buf, 2, strmax, fp) != strmax) + return(ERR); + + TRACE_OUT(("String table begins at %04lx", ftell(fp))); + + /* the strings */ + for (i = 0; i < strmax; i++) + if (VALID_STRING(tp->Strings[i])) + if (!WRITE_STRING(tp->Strings[i])) + return(ERR); + +#if NCURSES_XNAMES + if (NUM_EXT_NAMES(tp)) { + unsigned extcnt = NUM_EXT_NAMES(tp); + + if (even_boundary(nextfree)) + return(ERR); + + nextfree = compute_offsets(tp->Strings + STRCOUNT, tp->ext_Strings, offsets); + TRACE_OUT(("after extended string capabilities, nextfree=%d", nextfree)); + nextfree += compute_offsets(tp->ext_Names, extcnt, offsets + tp->ext_Strings); + TRACE_OUT(("after extended capnames, nextfree=%d", nextfree)); + strmax = tp->ext_Strings + extcnt; + + /* + * Write the extended header + */ + LITTLE_ENDIAN(buf+0, tp->ext_Booleans); + LITTLE_ENDIAN(buf+2, tp->ext_Numbers); + LITTLE_ENDIAN(buf+4, tp->ext_Strings); + LITTLE_ENDIAN(buf+6, strmax); + LITTLE_ENDIAN(buf+8, nextfree); + TRACE_OUT(("WRITE extended-header @%ld", ftell(fp))); + if (fwrite(buf, 10, 1, fp) != 1) + return(ERR); + + TRACE_OUT(("WRITE %d booleans @%ld", tp->ext_Booleans, ftell(fp))); + if (tp->ext_Booleans + && fwrite(tp->Booleans + BOOLCOUNT, sizeof(char), tp->ext_Booleans, fp) != tp->ext_Booleans) + return(ERR); + + if (even_boundary(tp->ext_Booleans)) + return(ERR); + + TRACE_OUT(("WRITE %d numbers @%ld", tp->ext_Numbers, ftell(fp))); + if (tp->ext_Numbers) { + convert_shorts(buf, tp->Numbers + NUMCOUNT, tp->ext_Numbers); + if (fwrite(buf, 2, tp->ext_Numbers, fp) != tp->ext_Numbers) + return(ERR); + } + + /* + * Convert the offsets for the ext_Strings and ext_Names tables, + * in that order. + */ + convert_shorts(buf, offsets, strmax); + TRACE_OUT(("WRITE offsets @%ld", ftell(fp))); + if (fwrite(buf, 2, strmax, fp) != strmax) + return(ERR); + + /* + * Write the string table after the offset tables so we do not + * have to do anything about alignment. + */ + for (i = 0; i < tp->ext_Strings; i++) { + if (VALID_STRING(tp->Strings[i+STRCOUNT])) { + TRACE_OUT(("WRITE ext_Strings[%d]=%s", i, _nc_visbuf(tp->Strings[i+STRCOUNT]))); + if (!WRITE_STRING(tp->Strings[i+STRCOUNT])) + return(ERR); + } + } + + /* + * Write the extended names + */ + for (i = 0; i < extcnt; i++) { + TRACE_OUT(("WRITE ext_Names[%d]=%s", i, tp->ext_Names[i])); + if (!WRITE_STRING(tp->ext_Names[i])) + return(ERR); + } + + } +#endif /* NCURSES_XNAMES */ + + total_written++; + return(OK); +} + +/* + * Returns the total number of entries written by this process + */ +int _nc_tic_written(void) +{ + return total_written; +} diff --git a/contrib/ncurses/ncurses/trace/README b/contrib/ncurses/ncurses/trace/README new file mode 100644 index 0000000..a627a53 --- /dev/null +++ b/contrib/ncurses/ncurses/trace/README @@ -0,0 +1,5 @@ +-- $Id: README,v 1.1 1998/11/08 00:11:01 tom Exp $ + +The files in this directory (trace) support both the terminfo and ncurses +libraries. Most of the functions are linked in only when the libraries +are compiled with TRACE defined. diff --git a/contrib/ncurses/ncurses/trace/lib_trace.c b/contrib/ncurses/ncurses/trace/lib_trace.c new file mode 100644 index 0000000..aa4b887 --- /dev/null +++ b/contrib/ncurses/ncurses/trace/lib_trace.c @@ -0,0 +1,200 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_trace.c - Tracing/Debugging routines + */ + +#include <curses.priv.h> +#include <tic.h> + +MODULE_ID("$Id: lib_trace.c,v 1.30 1998/10/03 23:41:42 tom Exp $") + +#include <ctype.h> +#if HAVE_FCNTL_H +#include <fcntl.h> +#endif + +unsigned _nc_tracing = 0; /* always define this */ + +#ifdef TRACE +const char *_nc_tputs_trace = ""; +long _nc_outchars; + +static FILE * tracefp; /* default to writing to stderr */ +#endif + +void trace(const unsigned int tracelevel GCC_UNUSED) +{ +#ifdef TRACE +static bool been_here = FALSE; +static char my_name[] = "trace"; + + _nc_tracing = tracelevel; + if (! been_here && tracelevel) { + been_here = TRUE; + + if (_nc_access(my_name, W_OK) < 0 + || (tracefp = fopen(my_name, "w")) == 0) { + perror("curses: Can't open 'trace' file: "); + exit(EXIT_FAILURE); + } + /* Try to set line-buffered mode, or (failing that) unbuffered, + * so that the trace-output gets flushed automatically at the + * end of each line. This is useful in case the program dies. + */ +#if HAVE_SETVBUF /* ANSI */ + (void) setvbuf(tracefp, (char *)0, _IOLBF, 0); +#elif HAVE_SETBUF /* POSIX */ + (void) setbuffer(tracefp, (char *)0); +#endif + _tracef("TRACING NCURSES version %s (%d)", + NCURSES_VERSION, NCURSES_VERSION_PATCH); + } +#endif +} + +const char *_nc_visbuf2(int bufnum, const char *buf) +/* visibilize a given string */ +{ +char *vbuf; +char *tp; +int c; + + if (buf == 0) + return("(null)"); + if (buf == CANCELLED_STRING) + return("(cancelled)"); + + tp = vbuf = _nc_trace_buf(bufnum, (strlen(buf) * 4) + 5); + *tp++ = '"'; + while ((c = *buf++) != '\0') { + if (c == '"') { + *tp++ = '\\'; *tp++ = '"'; + } else if (is7bits(c) && (isgraph(c) || c == ' ')) { + *tp++ = c; + } else if (c == '\n') { + *tp++ = '\\'; *tp++ = 'n'; + } else if (c == '\r') { + *tp++ = '\\'; *tp++ = 'r'; + } else if (c == '\b') { + *tp++ = '\\'; *tp++ = 'b'; + } else if (c == '\033') { + *tp++ = '\\'; *tp++ = 'e'; + } else if (is7bits(c) && iscntrl(c)) { + *tp++ = '\\'; *tp++ = '^'; *tp++ = '@' + c; + } else { + sprintf(tp, "\\%03o", c & 0xff); + tp += strlen(tp); + } + } + *tp++ = '"'; + *tp++ = '\0'; + return(vbuf); +} + +const char *_nc_visbuf(const char *buf) +{ + return _nc_visbuf2(0, buf); +} + +#ifdef TRACE +void +_tracef(const char *fmt, ...) +{ +static const char Called[] = T_CALLED(""); +static const char Return[] = T_RETURN(""); +static int level; +va_list ap; +bool before = FALSE; +bool after = FALSE; +int doit = _nc_tracing; +int save_err = errno; + + if (strlen(fmt) >= sizeof(Called) - 1) { + if (!strncmp(fmt, Called, sizeof(Called)-1)) { + before = TRUE; + level++; + } else if (!strncmp(fmt, Return, sizeof(Return)-1)) { + after = TRUE; + } + if (before || after) { + if ((level <= 1) + || (doit & TRACE_ICALLS) != 0) + doit &= (TRACE_CALLS|TRACE_CCALLS); + else + doit = 0; + } + } + + if (doit != 0) { + if (tracefp == 0) + tracefp = stderr; + if (before || after) { + int n; + for (n = 1; n < level; n++) + fputs("+ ", tracefp); + } + va_start(ap, fmt); + vfprintf(tracefp, fmt, ap); + fputc('\n', tracefp); + va_end(ap); + fflush(tracefp); + } + + if (after && level) + level--; + errno = save_err; +} + +/* Trace 'int' return-values */ +int _nc_retrace_int(int code) +{ + T((T_RETURN("%d"), code)); + return code; +} + +/* Trace 'char*' return-values */ +char * _nc_retrace_ptr(char * code) +{ + T((T_RETURN("%s"), _nc_visbuf(code))); + return code; +} + +/* Trace 'WINDOW *' return-values */ +WINDOW *_nc_retrace_win(WINDOW *code) +{ + T((T_RETURN("%p"), code)); + return code; +} +#endif /* TRACE */ diff --git a/contrib/ncurses/ncurses/trace/lib_traceatr.c b/contrib/ncurses/ncurses/trace/lib_traceatr.c new file mode 100644 index 0000000..d9e0075 --- /dev/null +++ b/contrib/ncurses/ncurses/trace/lib_traceatr.c @@ -0,0 +1,218 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* + * lib_traceatr.c - Tracing/Debugging routines (attributes) + */ + +#include <curses.priv.h> +#include <term.h> /* acs_chars */ + +MODULE_ID("$Id: lib_traceatr.c,v 1.28 1998/03/21 18:39:36 tom Exp $") + +#define COLOR_OF(c) (c < 0 || c > 7 ? "default" : colors[c].name) + +#ifdef TRACE +char *_traceattr2(int bufnum, attr_t newmode) +{ +char *buf = _nc_trace_buf(bufnum, BUFSIZ); +char *tmp = buf; +static const struct {unsigned int val; const char *name;} +names[] = + { + { A_STANDOUT, "A_STANDOUT" }, + { A_UNDERLINE, "A_UNDERLINE" }, + { A_REVERSE, "A_REVERSE" }, + { A_BLINK, "A_BLINK" }, + { A_DIM, "A_DIM" }, + { A_BOLD, "A_BOLD" }, + { A_ALTCHARSET, "A_ALTCHARSET" }, + { A_INVIS, "A_INVIS" }, + { A_PROTECT, "A_PROTECT" }, + { A_CHARTEXT, "A_CHARTEXT" }, + { A_NORMAL, "A_NORMAL" }, + { A_COLOR, "A_COLOR" }, + }, +colors[] = + { + { COLOR_BLACK, "COLOR_BLACK" }, + { COLOR_RED, "COLOR_RED" }, + { COLOR_GREEN, "COLOR_GREEN" }, + { COLOR_YELLOW, "COLOR_YELLOW" }, + { COLOR_BLUE, "COLOR_BLUE" }, + { COLOR_MAGENTA, "COLOR_MAGENTA" }, + { COLOR_CYAN, "COLOR_CYAN" }, + { COLOR_WHITE, "COLOR_WHITE" }, + }; +size_t n; +unsigned save_nc_tracing = _nc_tracing; + _nc_tracing = 0; + + strcpy(tmp++, "{"); + + 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); + + if (names[n].val == A_COLOR) + { + short pairnum = PAIR_NUMBER(newmode); + short fg, bg; + + if (pair_content(pairnum, &fg, &bg) == OK) + (void) sprintf(tmp, + "{%d = {%s, %s}}", + pairnum, + COLOR_OF(fg), + COLOR_OF(bg) + ); + else + (void) sprintf(tmp, "{%d}", pairnum); + } + } + } + if (AttrOf(newmode) == A_NORMAL) { + if (buf[1] != '\0') + strcat(tmp, "|"); + strcat(tmp, "A_NORMAL"); + } + + _nc_tracing = save_nc_tracing; + return (strcat(buf,"}")); +} + +char *_traceattr(attr_t newmode) +{ + return _traceattr2(0, newmode); +} + +/* Trace 'int' return-values */ +attr_t _nc_retrace_attr_t(attr_t code) +{ + T((T_RETURN("%s"), _traceattr(code))); + return code; +} + +char *_tracechtype2(int bufnum, chtype ch) +{ +char *buf = _nc_trace_buf(bufnum, BUFSIZ); +char *found = 0; + + strcpy(buf, "{"); + if (ch & A_ALTCHARSET) + { + char *cp; + static const struct {unsigned int val; const char *name;} + names[] = + { + {'l', "ACS_ULCORNER"}, /* upper left corner */ + {'m', "ACS_LLCORNER"}, /* lower left corner */ + {'k', "ACS_URCORNER"}, /* upper right corner */ + {'j', "ACS_LRCORNER"}, /* lower right corner */ + {'t', "ACS_LTEE"}, /* tee pointing right */ + {'u', "ACS_RTEE"}, /* tee pointing left */ + {'v', "ACS_BTEE"}, /* tee pointing up */ + {'w', "ACS_TTEE"}, /* tee pointing down */ + {'q', "ACS_HLINE"}, /* horizontal line */ + {'x', "ACS_VLINE"}, /* vertical line */ + {'n', "ACS_PLUS"}, /* large plus or crossover */ + {'o', "ACS_S1"}, /* scan line 1 */ + {'s', "ACS_S9"}, /* scan line 9 */ + {'`', "ACS_DIAMOND"}, /* diamond */ + {'a', "ACS_CKBOARD"}, /* checker board (stipple) */ + {'f', "ACS_DEGREE"}, /* degree symbol */ + {'g', "ACS_PLMINUS"}, /* plus/minus */ + {'~', "ACS_BULLET"}, /* bullet */ + {',', "ACS_LARROW"}, /* arrow pointing left */ + {'+', "ACS_RARROW"}, /* arrow pointing right */ + {'.', "ACS_DARROW"}, /* arrow pointing down */ + {'-', "ACS_UARROW"}, /* arrow pointing up */ + {'h', "ACS_BOARD"}, /* board of squares */ + {'i', "ACS_LANTERN"}, /* lantern symbol */ + {'0', "ACS_BLOCK"}, /* solid square block */ + {'p', "ACS_S3"}, /* scan line 3 */ + {'r', "ACS_S7"}, /* scan line 7 */ + {'y', "ACS_LEQUAL"}, /* less/equal */ + {'z', "ACS_GEQUAL"}, /* greater/equal */ + {'{', "ACS_PI"}, /* Pi */ + {'|', "ACS_NEQUAL"}, /* not equal */ + {'}', "ACS_STERLING"}, /* UK pound sign */ + {'\0',(char *)0} + }, + *sp; + + for (cp = acs_chars; cp[0] && cp[1]; cp += 2) + { + if (TextOf(cp[1]) == TextOf(ch)) + { + found = cp; + /* don't exit from loop - there may be redefinitions */ + } + } + + if (found != 0) + { + ch = TextOf(*found); + for (sp = names; sp->val; sp++) + if (sp->val == ch) + { + (void) strcat(buf, sp->name); + ch &= ~A_ALTCHARSET; + break; + } + } + } + + if (found == 0) + (void) strcat(buf, _tracechar(TextOf(ch))); + + if (AttrOf(ch) != A_NORMAL) + (void) sprintf(buf + strlen(buf), " | %s", _traceattr2(bufnum+20,AttrOf(ch))); + + strcat(buf, "}"); + return(buf); +} + +char *_tracechtype(chtype ch) +{ + return _tracechtype2(0, ch); +} +#else +extern void _nc_lib_traceatr(void); + void _nc_lib_traceatr(void) { } +#endif /* TRACE */ diff --git a/contrib/ncurses/ncurses/trace/lib_tracebits.c b/contrib/ncurses/ncurses/trace/lib_tracebits.c new file mode 100644 index 0000000..a92e00a --- /dev/null +++ b/contrib/ncurses/ncurses/trace/lib_tracebits.c @@ -0,0 +1,225 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +#include <curses.priv.h> +#include <term.h> /* cur_term */ + +MODULE_ID("$Id: lib_tracebits.c,v 1.3 1999/08/21 21:43:48 tom Exp $") + +#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE) +#define _POSIX_SOURCE +#endif + +#if HAVE_SYS_TERMIO_H +#include <sys/termio.h> /* needed for ISC */ +#endif + +#ifdef __EMX__ +#include <io.h> +#include <fcntl.h> +#endif + +/* may be undefined if we're using termio.h */ +#ifndef TOSTOP +#define TOSTOP 0 +#endif +#ifndef IEXTEN +#define IEXTEN 0 +#endif + +#ifdef TRACE + +typedef struct {unsigned int val; const char *name;} BITNAMES; + +static void lookup_bits(char *buf, const BITNAMES *table, const char *label, unsigned int val) +{ + const BITNAMES *sp; + + (void) strcat(buf, label); + (void) strcat(buf, ": {"); + for (sp = table; sp->name; sp++) + if (sp->val != 0 + && (val & sp->val) == sp->val) + { + (void) strcat(buf, sp->name); + (void) strcat(buf, ", "); + } + if (buf[strlen(buf) - 2] == ',') + buf[strlen(buf) - 2] = '\0'; + (void) strcat(buf,"} "); +} + +char *_nc_tracebits(void) +/* describe the state of the terminal control bits exactly */ +{ +char *buf; +static const BITNAMES + +#ifdef TERMIOS +iflags[] = + { + {BRKINT, "BRKINT"}, + {IGNBRK, "IGNBRK"}, + {IGNPAR, "IGNPAR"}, + {PARMRK, "PARMRK"}, + {INPCK, "INPCK"}, + {ISTRIP, "ISTRIP"}, + {INLCR, "INLCR"}, + {IGNCR, "IGNC"}, + {ICRNL, "ICRNL"}, + {IXON, "IXON"}, + {IXOFF, "IXOFF"}, + {0, NULL} +#define ALLIN (BRKINT|IGNBRK|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF) + }, +oflags[] = + { + {OPOST, "OPOST"}, + {0, NULL} +#define ALLOUT (OPOST) + }, +cflags[] = + { + {CLOCAL, "CLOCAL"}, + {CREAD, "CREAD"}, + {CSTOPB, "CSTOPB"}, +#if !defined(CS5) || !defined(CS8) + {CSIZE, "CSIZE"}, +#endif + {HUPCL, "HUPCL"}, + {PARENB, "PARENB"}, + {PARODD|PARENB, "PARODD"}, /* concession to readability */ + {0, NULL} +#define ALLCTRL (CLOCAL|CREAD|CSIZE|CSTOPB|HUPCL|PARENB|PARODD) + }, +lflags[] = + { + {ECHO, "ECHO"}, + {ECHOE|ECHO, "ECHOE"}, /* concession to readability */ + {ECHOK|ECHO, "ECHOK"}, /* concession to readability */ + {ECHONL, "ECHONL"}, + {ICANON, "ICANON"}, + {ISIG, "ISIG"}, + {NOFLSH, "NOFLSH"}, + {TOSTOP, "TOSTOP"}, + {IEXTEN, "IEXTEN"}, + {0, NULL} +#define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN) + }; + + + buf = _nc_trace_buf(0, + 8 + sizeof(iflags) + + 8 + sizeof(oflags) + + 8 + sizeof(cflags) + + 8 + sizeof(lflags) + + 8); + + if (cur_term->Nttyb.c_iflag & ALLIN) + lookup_bits(buf, iflags, "iflags", cur_term->Nttyb.c_iflag); + + if (cur_term->Nttyb.c_oflag & ALLOUT) + lookup_bits(buf, oflags, "oflags", cur_term->Nttyb.c_oflag); + + if (cur_term->Nttyb.c_cflag & ALLCTRL) + lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.c_cflag); + +#if defined(CS5) && defined(CS8) + switch (cur_term->Nttyb.c_cflag & CSIZE) { +#if defined(CS5) && (CS5 != 0) + case CS5: strcat(buf, "CS5 "); break; +#endif +#if defined(CS6) && (CS6 != 0) + case CS6: strcat(buf, "CS6 "); break; +#endif +#if defined(CS7) && (CS7 != 0) + case CS7: strcat(buf, "CS7 "); break; +#endif +#if defined(CS8) && (CS8 != 0) + case CS8: strcat(buf, "CS8 "); break; +#endif + default: strcat(buf, "CSIZE? "); break; + } +#endif + + if (cur_term->Nttyb.c_lflag & ALLLOCAL) + lookup_bits(buf, lflags, "lflags", cur_term->Nttyb.c_lflag); + +#else + /* reference: ttcompat(4M) on SunOS 4.1 */ +#ifndef EVENP +#define EVENP 0 +#endif +#ifndef LCASE +#define LCASE 0 +#endif +#ifndef LLITOUT +#define LLITOUT 0 +#endif +#ifndef ODDP +#define ODDP 0 +#endif +#ifndef TANDEM +#define TANDEM 0 +#endif + +cflags[] = + { + {CBREAK, "CBREAK"}, + {CRMOD, "CRMOD"}, + {ECHO, "ECHO"}, + {EVENP, "EVENP"}, + {LCASE, "LCASE"}, + {LLITOUT, "LLITOUT"}, + {ODDP, "ODDP"}, + {RAW, "RAW"}, + {TANDEM, "TANDEM"}, + {XTABS, "XTABS"}, + {0, NULL} +#define ALLCTRL (CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS) + }; + + buf = _nc_trace_buf(0, + 8 + sizeof(cflags)); + + if (cur_term->Nttyb.sg_flags & ALLCTRL) + { + lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.sg_flags); + } + +#endif + return(buf); +} +#else +char *_nc_tracebits(void) { static char tmp[] = ""; return tmp; } +#endif /* TRACE */ diff --git a/contrib/ncurses/ncurses/trace/lib_tracechr.c b/contrib/ncurses/ncurses/trace/lib_tracechr.c new file mode 100644 index 0000000..e97e679 --- /dev/null +++ b/contrib/ncurses/ncurses/trace/lib_tracechr.c @@ -0,0 +1,69 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* + * lib_tracechr.c - Tracing/Debugging routines + */ + +#ifndef TRACE +#define TRACE /* turn on internal defs for this module */ +#endif + +#include <curses.priv.h> + +#include <ctype.h> + +#ifdef TRACE +char *_tracechar(const unsigned char ch) +{ + static char crep[20]; + /* + * We can show the actual character if it's either an ordinary printable + * or one of the high-half characters. + */ + if (isprint(ch) || (ch & 0x80)) + { + crep[0] = '\''; + crep[1] = ch; /* necessary; printf tries too hard on metachars */ + (void) sprintf(crep + 2, "' = 0x%02x", (unsigned)ch); + } + else + (void) sprintf(crep, "0x%02x", (unsigned)ch); + return(crep); +} +#else +extern void _nc_lib_tracechr(void); + void _nc_lib_tracechr(void) { } +#endif diff --git a/contrib/ncurses/ncurses/trace/lib_tracedmp.c b/contrib/ncurses/ncurses/trace/lib_tracedmp.c new file mode 100644 index 0000000..a67a37e --- /dev/null +++ b/contrib/ncurses/ncurses/trace/lib_tracedmp.c @@ -0,0 +1,128 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * lib_tracedmp.c - Tracing/Debugging routines + */ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_tracedmp.c,v 1.13 1998/03/21 18:39:44 tom Exp $") + +#ifdef TRACE +void _tracedump(const char *name, WINDOW *win) +{ + int i, j, n, width; + + /* compute narrowest possible display width */ + for (width = i = 0; i <= win->_maxy; i++) + { + n = 0; + for (j = 0; j <= win->_maxx; j++) + if (win->_line[i].text[j] != ' ') + n = j; + + if (n > width) + width = n; + } + if (width < win->_maxx) + ++width; + + for (n = 0; n <= win->_maxy; n++) + { + char buf[BUFSIZ], *ep; + bool haveattrs, havecolors; + + /* dump A_CHARTEXT part */ + (void) sprintf(buf, "%s[%2d] %3d%3d ='", + name, n, + win->_line[n].firstchar, + win->_line[n].lastchar); + ep = buf + strlen(buf); + for (j = 0; j <= width; j++) { + ep[j] = TextOf(win->_line[n].text[j]); + if (ep[j] == 0) + ep[j] = '.'; + } + ep[j] = '\''; + ep[j+1] = '\0'; + _tracef("%s", buf); + + /* dump A_COLOR part, will screw up if there are more than 96 */ + havecolors = FALSE; + for (j = 0; j <= width; j++) + if (win->_line[n].text[j] & A_COLOR) + { + havecolors = TRUE; + break; + } + if (havecolors) + { + (void) sprintf(buf, "%*s[%2d]%*s='", (int)strlen(name), "colors", n, 8, " "); + ep = buf + strlen(buf); + for (j = 0; j <= width; j++) + ep[j] = ((win->_line[n].text[j] >> 8) & 0xff) + ' '; + ep[j] = '\''; + ep[j+1] = '\0'; + _tracef("%s", buf); + } + + for (i = 0; i < 4; i++) + { + const char *hex = " 123456789ABCDEF"; + chtype mask = (0xf << ((i + 4) * 4)); + + haveattrs = FALSE; + for (j = 0; j <= width; j++) + if (win->_line[n].text[j] & mask) + { + haveattrs = TRUE; + break; + } + if (haveattrs) + { + (void) sprintf(buf, "%*s%d[%2d]%*s='", (int)strlen(name)-1, "attrs", i, n, 8, " "); + ep = buf + strlen(buf); + for (j = 0; j <= width; j++) + ep[j] = hex[(win->_line[n].text[j] & mask) >> ((i + 4) * 4)]; + ep[j] = '\''; + ep[j+1] = '\0'; + _tracef("%s", buf); + } + } + } +} +#else +extern void _nc_lib_tracedmp(void); + void _nc_lib_tracedmp(void) { } +#endif /* TRACE */ diff --git a/contrib/ncurses/ncurses/trace/lib_tracemse.c b/contrib/ncurses/ncurses/trace/lib_tracemse.c new file mode 100644 index 0000000..fbdd2c0 --- /dev/null +++ b/contrib/ncurses/ncurses/trace/lib_tracemse.c @@ -0,0 +1,95 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + + +/* + * lib_tracemse.c - Tracing/Debugging routines (mouse events) + */ + +#include <curses.priv.h> + +MODULE_ID("$Id: lib_tracemse.c,v 1.6 1998/11/16 14:28:17 Alexander.V.Lukyanov Exp $") + +#ifdef TRACE + +char *_tracemouse(MEVENT const *ep) +{ + static char buf[80]; + + (void) sprintf(buf, "id %2d at (%2d, %2d, %2d) state %4lx = {", + ep->id, ep->x, ep->y, ep->z, ep->bstate); + +#define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");} + 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") + SHOW(BUTTON1_RESERVED_EVENT, "reserved-1") + 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") + SHOW(BUTTON2_RESERVED_EVENT, "reserved-2") + 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") + SHOW(BUTTON3_RESERVED_EVENT, "reserved-3") + 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") + SHOW(BUTTON4_RESERVED_EVENT, "reserved-4") + 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] == ' ') + buf[strlen(buf)-2] = '\0'; + (void) strcat(buf, "}"); + return(buf); +} + +#else /* !TRACE */ +/* don't make empty module */ +void _nc_lib_tracemouse(void); +void _nc_lib_tracemouse(void) {} +#endif diff --git a/contrib/ncurses/ncurses/trace/trace_buf.c b/contrib/ncurses/ncurses/trace/trace_buf.c new file mode 100644 index 0000000..48f93d4 --- /dev/null +++ b/contrib/ncurses/ncurses/trace/trace_buf.c @@ -0,0 +1,80 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + ****************************************************************************/ +/* + * trace_buf.c - Tracing/Debugging buffers (attributes) + */ + +#include <curses.priv.h> + +MODULE_ID("$Id: trace_buf.c,v 1.7 1999/02/27 19:50:58 tom Exp $") + +typedef struct { + char *text; + size_t size; +} LIST; + +char * _nc_trace_buf(int bufnum, size_t want) +{ + static LIST *list; + static size_t have; + +#if NO_LEAKS + if (bufnum < 0) { + if (have) { + while (have--) { + free(list[have].text); + } + free(list); + } + return 0; + } +#endif + + 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; + } + + if (list[bufnum].text != 0) + *(list[bufnum].text) = '\0'; + return list[bufnum].text; +} diff --git a/contrib/ncurses/ncurses/trace/trace_tries.c b/contrib/ncurses/ncurses/trace/trace_tries.c new file mode 100644 index 0000000..abd5db4 --- /dev/null +++ b/contrib/ncurses/ncurses/trace/trace_tries.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * Copyright (c) 1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + ****************************************************************************/ +/* + * trace_tries.c - Tracing/Debugging buffers (keycode tries-trees) + */ + +#include <curses.priv.h> + +MODULE_ID("$Id: trace_tries.c,v 1.6 1999/03/06 22:51:07 tom Exp $") + +#ifdef TRACE +static unsigned char *buffer; +static unsigned len; + +static void recur_tries(struct tries *tree, unsigned level) +{ + if (level > len) + buffer = (unsigned char *)realloc(buffer, len = (level + 1) * 4); + + while (tree != 0) { + if ((buffer[level] = tree->ch) == 0) + buffer[level] = 128; + buffer[level+1] = 0; + if (tree->value != 0) { + _tracef("%5d: %s (%s)", tree->value, _nc_visbuf((char *)buffer), keyname(tree->value)); + } + if (tree->child) + recur_tries(tree->child, level+1); + tree = tree->sibling; + } +} + +void _nc_trace_tries(struct tries *tree) +{ + buffer = typeMalloc(unsigned char, len = 80); + _tracef("BEGIN tries %p", tree); + recur_tries(tree, 0); + _tracef(". . . tries %p", tree); + free(buffer); +} +#else +void _nc_trace_tries(struct tries *tree GCC_UNUSED) +{ +} +#endif diff --git a/contrib/ncurses/ncurses/trace/trace_xnames.c b/contrib/ncurses/ncurses/trace/trace_xnames.c new file mode 100644 index 0000000..6287fc8 --- /dev/null +++ b/contrib/ncurses/ncurses/trace/trace_xnames.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * Copyright (c) 1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + ****************************************************************************/ +/* + * trace_xnames.c - Tracing/Debugging buffers (TERMTYPE extended names) + */ + +#include <curses.priv.h> +#include <term_entry.h> + +MODULE_ID("$Id: trace_xnames.c,v 1.3 1999/03/02 01:20:38 tom Exp $") + +void _nc_trace_xnames(TERMTYPE *tp GCC_UNUSED) +{ +#ifdef TRACE +#if NCURSES_XNAMES + int limit = tp->ext_Booleans + tp->ext_Numbers + tp->ext_Strings; + int n, m; + if (limit) { + int begin_num = tp->ext_Booleans; + int begin_str = tp->ext_Booleans + tp->ext_Numbers; + + _tracef("extended names (%s) %d = %d+%d+%d of %d+%d+%d", + tp->term_names, + limit, + tp->ext_Booleans, tp->ext_Numbers, tp->ext_Strings, + tp->num_Booleans, tp->num_Numbers, tp->num_Strings); + for (n = 0; n < limit; n++) { + if ((m = n - begin_str) >= 0) { + _tracef("[%d] %s = %s", n, + tp->ext_Names[n], + _nc_visbuf(tp->Strings[tp->num_Strings + m - tp->ext_Strings])); + } else if ((m = n - begin_num) >= 0) { + _tracef("[%d] %s = %d (num)", n, + tp->ext_Names[n], + tp->Numbers[tp->num_Numbers + m - tp->ext_Numbers]); + } else { + _tracef("[%d] %s = %d (bool)", n, + tp->ext_Names[n], + tp->Booleans[tp->num_Booleans + n - tp->ext_Booleans]); + } + } + } +#endif +#endif +} diff --git a/contrib/ncurses/ncurses/tty/MKexpanded.sh b/contrib/ncurses/ncurses/tty/MKexpanded.sh new file mode 100755 index 0000000..b008bec --- /dev/null +++ b/contrib/ncurses/ncurses/tty/MKexpanded.sh @@ -0,0 +1,103 @@ +#! /bin/sh +############################################################################## +# Copyright (c) 1998 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +# +# Author: Thomas E. Dickey <dickey@clark.net> 1997 +# +# $Id: MKexpanded.sh,v 1.7 1998/11/11 20:15:39 Alexander.V.Lukyanov Exp $ +# +# Script to generate 'expanded.c', a dummy source that contains functions +# corresponding to complex macros used in this library. By making functions, +# we simplify analysis and debugging. + +if test $# != 0; then +preprocessor="$1" +else +preprocessor="cc -E" +fi +shift +if test $# != 0 ; then + preprocessor="$preprocessor $*" +else + preprocessor="$preprocessor -DHAVE_CONFIG_H -I. -I../include" +fi + +TMP=gen$$.c +trap "rm -f $TMP" 0 1 2 5 15 + +cat <<EOF +/* generated by MKexpanded.sh */ +#include <curses.priv.h> +#include <term.h> +#ifdef NCURSES_EXPANDED +EOF + +cat >$TMP <<EOF +#include <ncurses_cfg.h> +#undef NCURSES_EXPANDED /* this probably is set in ncurses_cfg.h */ +#include <curses.priv.h> +/* these are names we'd like to see */ +#undef ALL_BUT_COLOR +#undef PAIR_NUMBER +#undef TRUE +#undef FALSE +/* this is a marker */ +IGNORE +void _nc_toggle_attr_on(attr_t *S, attr_t at) +{ + toggle_attr_on(*S,at); +} +void _nc_toggle_attr_off(attr_t *S, attr_t at) +{ + toggle_attr_off(*S,at); +} +int _nc_can_clear_with(chtype ch) +{ + return can_clear_with(ch); +} +int _nc_DelCharCost(int count) +{ + return DelCharCost(count); +} +int _nc_InsCharCost(int count) +{ + return InsCharCost(count); +} +void _nc_UpdateAttrs(chtype c) +{ + UpdateAttrs(c); +} +EOF + +$preprocessor $TMP 2>/dev/null | sed -e '1,/^IGNORE$/d' + +cat <<EOF +#else /* ! NCURSES_EXPANDED */ +void _nc_expanded(void) { } +#endif /* NCURSES_EXPANDED */ +EOF diff --git a/contrib/ncurses/ncurses/tty/hardscroll.c b/contrib/ncurses/ncurses/tty/hardscroll.c new file mode 100644 index 0000000..b80d08a --- /dev/null +++ b/contrib/ncurses/ncurses/tty/hardscroll.c @@ -0,0 +1,328 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/****************************************************************************** + +NAME + hardscroll.c -- hardware-scrolling optimization for ncurses + +SYNOPSIS + void _nc_scroll_optimize(void) + +DESCRIPTION + OVERVIEW + +This algorithm for computes optimum hardware scrolling to transform an +old screen (curscr) into a new screen (newscr) via vertical line moves. + +Because the screen has a `grain' (there are insert/delete/scroll line +operations but no insert/delete/scroll column operations), it is efficient +break the update algorithm into two pieces: a first stage that does only line +moves, optimizing the end product of user-invoked insertions, deletions, and +scrolls; and a second phase (corresponding to the present doupdate code in +ncurses) that does only line transformations. + +The common case we want hardware scrolling for is to handle line insertions +and deletions in screen-oriented text-editors. This two-stage approach will +accomplish that at a low computation and code-size cost. + + LINE-MOVE COMPUTATION + +Now, to a discussion of the line-move computation. + +For expository purposes, consider the screen lines to be represented by +integers 0..23 (with the understanding that the value of 23 may vary). +Let a new line introduced by insertion, scrolling, or at the bottom of +the screen following a line delete be given the index -1. + +Assume that the real screen starts with lines 0..23. Now, we have +the following possible line-oriented operations on the screen: + +Insertion: inserts a line at a given screen row, forcing all lines below +to scroll forward. The last screen line is lost. For example, an insertion +at line 5 would produce: 0..4 -1 5..23. + +Deletion: deletes a line at a given screen row, forcing all lines below +to scroll forward. The last screen line is made new. For example, a deletion +at line 7 would produce: 0..6 8..23 -1. + +Scroll up: move a range of lines up 1. The bottom line of the range +becomes new. For example, scrolling up the region from 9 to 14 will +produce 0..8 10..14 -1 15..23. + +Scroll down: move a range of lines down 1. The top line of the range +becomes new. For example, scrolling down the region from 12 to 16 will produce +0..11 -1 12..15 17..23. + +Now, an obvious property of all these operations is that they preserve the +order of old lines, though not their position in the sequence. + +The key trick of this algorithm is that the original line indices described +above are actually maintained as _line[].oldindex fields in the window +structure, and stick to each line through scroll and insert/delete operations. + +Thus, it is possible at update time to look at the oldnum fields and compute +an optimal set of il/dl/scroll operations that will take the real screen +lines to the virtual screen lines. Once these vertical moves have been done, +we can hand off to the second stage of the update algorithm, which does line +transformations. + +Note that the move computation does not need to have the full generality +of a diff algorithm (which it superficially resembles) because lines cannot +be moved out of order. + + THE ALGORITHM + +The scrolling is done in two passes. The first pass is from top to bottom +scroling hunks UP. The second one is from bottom to top scrolling hunks DOWN. +Obviously enough, no lines to be scrolled will be destroyed. (lav) + +HOW TO TEST THIS: + +Use the following production: + +hardscroll: hardscroll.c + $(CC) -g -DSCROLLDEBUG hardscroll.c -o hardscroll + +Then just type scramble vectors and watch. The following test loads are +a representative sample of cases: + +----------------------------- CUT HERE ------------------------------------ +# No lines moved + 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 +# +# A scroll up + 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 -1 +# +# A scroll down +-1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 +# +# An insertion (after line 12) + 0 1 2 3 4 5 6 7 8 9 10 11 12 -1 13 14 15 16 17 18 19 20 21 22 +# +# A simple deletion (line 10) + 0 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 20 21 22 23 -1 +# +# A more complex case +-1 -1 -1 -1 -1 3 4 5 6 7 -1 -1 8 9 10 11 12 13 14 15 16 17 -1 -1 +----------------------------- CUT HERE ------------------------------------ + +AUTHOR + Eric S. Raymond <esr@snark.thyrsus.com>, November 1994 + New algorithm by Alexander V. Lukyanov <lav@yars.free.net>, Aug 1997 + +*****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: hardscroll.c,v 1.33 1999/02/27 20:01:29 tom Exp $") + +#if defined(SCROLLDEBUG) || defined(HASHDEBUG) + +# undef screen_lines +# define screen_lines MAXLINES +int oldnums[MAXLINES]; +# define OLDNUM(n) oldnums[n] +# define _tracef printf +# undef TR +# define TR(n, a) if (_nc_tracing & (n)) { _tracef a ; putchar('\n'); } + +#else /* no debug */ + +/* OLDNUM(n) indicates which line will be shifted to the position n. + if OLDNUM(n) == _NEWINDEX, then the line n in new, not shifted from + somewhere. */ +# if USE_HASHMAP +int *_nc_oldnums = 0; +static int oldnums_allocated = 0; +# define oldnums _nc_oldnums +# define OLDNUM(n) oldnums[n] +# else /* !USE_HASHMAP */ +# define OLDNUM(n) newscr->_line[n].oldindex +# endif /* !USE_HASHMAP */ + +#endif /* defined(SCROLLDEBUG) || defined(HASHDEBUG) */ + + +void _nc_scroll_optimize(void) +/* scroll optimization to transform curscr to newscr */ +{ + int i; + int start, end, shift; + + TR(TRACE_ICALLS, ("_nc_scroll_optimize() begins")); + +#if !defined(SCROLLDEBUG) && !defined(HASHDEBUG) +#if USE_HASHMAP + /* get enough storage */ + if (oldnums_allocated < screen_lines) + { + int *new_oldnums = typeRealloc(int, screen_lines, oldnums); + if (!new_oldnums) + return; + oldnums = new_oldnums; + oldnums_allocated = screen_lines; + } + /* calculate the indices */ + _nc_hash_map(); +#endif +#endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */ + +#ifdef TRACE + if (_nc_tracing & (TRACE_UPDATE | TRACE_MOVE)) + _nc_linedump(); +#endif /* TRACE */ + + /* pass 1 - from top to bottom scrolling up */ + for (i = 0; i < screen_lines; ) + { + while (i < screen_lines && (OLDNUM(i) == _NEWINDEX || OLDNUM(i) <= i)) + i++; + if (i >= screen_lines) + break; + + shift = OLDNUM(i) - i; /* shift > 0 */ + start = i; + + i++; + while (i < screen_lines && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i == shift) + i++; + end = i-1 + shift; + + TR(TRACE_UPDATE | TRACE_MOVE, ("scroll [%d, %d] by %d", start, end, shift)); +#if !defined(SCROLLDEBUG) && !defined(HASHDEBUG) + if (_nc_scrolln(shift, start, end, screen_lines - 1) == ERR) + { + TR(TRACE_UPDATE | TRACE_MOVE, ("unable to scroll")); + continue; + } +#endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */ + } + + /* pass 2 - from bottom to top scrolling down */ + for (i = screen_lines-1; i >= 0; ) + { + while (i >= 0 && (OLDNUM(i) == _NEWINDEX || OLDNUM(i) >= i)) + i--; + if (i < 0) + break; + + shift = OLDNUM(i) - i; /* shift < 0 */ + end = i; + + i--; + while (i >= 0 && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i == shift) + i--; + start = i+1 - (-shift); + + TR(TRACE_UPDATE | TRACE_MOVE, ("scroll [%d, %d] by %d", start, end, shift)); +#if !defined(SCROLLDEBUG) && !defined(HASHDEBUG) + if (_nc_scrolln(shift, start, end, screen_lines - 1) == ERR) + { + TR(TRACE_UPDATE | TRACE_MOVE, ("unable to scroll")); + continue; + } +#endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */ + } +} + +#if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG) +void _nc_linedump(void) +/* dump the state of the real and virtual oldnum fields */ +{ + static size_t have; + static char *buf; + + int n; + size_t want = (screen_lines + 1) * 4; + + if (have < want) + buf = typeMalloc(char, have = want); + + (void) strcpy(buf, "virt"); + for (n = 0; n < screen_lines; n++) + (void) sprintf(buf + strlen(buf), " %02d", OLDNUM(n)); + TR(TRACE_UPDATE | TRACE_MOVE, (buf)); +#if NO_LEAKS + free(buf); + have = 0; +#endif +} +#endif /* defined(TRACE) || defined(SCROLLDEBUG) */ + +#ifdef SCROLLDEBUG + +int +main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) +{ + char line[BUFSIZ], *st; + +#ifdef TRACE + _nc_tracing = TRACE_MOVE; +#endif + for (;;) + { + int n; + + for (n = 0; n < screen_lines; n++) + oldnums[n] = _NEWINDEX; + + /* grab the test vector */ + if (fgets(line, sizeof(line), stdin) == (char *)NULL) + exit(EXIT_SUCCESS); + + /* parse it */ + n = 0; + if (line[0] == '#') + { + (void) fputs(line, stderr); + continue; + } + st = strtok(line, " "); + do { + oldnums[n++] = atoi(st); + } while + ((st = strtok((char *)NULL, " ")) != 0); + + /* display it */ + (void) fputs("Initial input:\n", stderr); + _nc_linedump(); + + _nc_scroll_optimize(); + } +} + +#endif /* SCROLLDEBUG */ + +/* hardscroll.c ends here */ diff --git a/contrib/ncurses/ncurses/tty/hashmap.c b/contrib/ncurses/ncurses/tty/hashmap.c new file mode 100644 index 0000000..f6a58bc --- /dev/null +++ b/contrib/ncurses/ncurses/tty/hashmap.c @@ -0,0 +1,567 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/****************************************************************************** + +NAME + hashmap.c -- fill in scramble vector based on text hashes + +SYNOPSIS + void _nc_hash_map(void) + +DESCRIPTION: + This code attempts to recognize pairs of old and new lines in the physical +and virtual screens. When a line pair is recognized, the old line index is +placed in the oldindex member of the virtual screen line, to be used by the +vertical-motion optimizer portion of the update logic (see hardscroll.c). + + Line pairs are recognized by applying a modified Heckel's algorithm, +sped up by hashing. If a line hash is unique in both screens, those +lines must be a pair. Then if the lines just before or after the pair +are the same or similar, they are a pair too. + + We don't worry about false pairs produced by hash collisions, on the +assumption that such cases are rare and will only make the latter stages +of update less efficient, not introduce errors. + +HOW TO TEST THIS: + +Use the following production: + +hashmap: hashmap.c + $(CC) -g -DHASHDEBUG hashmap.c hardscroll.c ../objects/lib_trace.o -o hashmap + +AUTHOR + Eric S. Raymond <esr@snark.thyrsus.com>, May 1996 + Bug fixes and improvements by Alexander V. Lukyanov <lav@yars.free.net>, 1997 + +*****************************************************************************/ + +#include <curses.priv.h> +#include <term.h> /* for back_color_erase */ + +MODULE_ID("$Id: hashmap.c,v 1.33 1999/03/18 02:09:45 Alexander.V.Lukyanov Exp $") + +#ifdef HASHDEBUG + +# define _tracef printf +# undef TR +# define TR(n, a) if (_nc_tracing & (n)) { _tracef a ; putchar('\n'); } +# undef screen_lines +# define screen_lines MAXLINES +# define TEXTWIDTH 1 +int oldnums[MAXLINES], reallines[MAXLINES]; +static chtype oldtext[MAXLINES][TEXTWIDTH], newtext[MAXLINES][TEXTWIDTH]; +# define OLDNUM(n) oldnums[n] +# define OLDTEXT(n) oldtext[n] +# define NEWTEXT(m) newtext[m] +# define PENDING(n) 1 + +#else /* !HASHDEBUG */ + +# define OLDNUM(n) _nc_oldnums[n] +# define OLDTEXT(n) curscr->_line[n].text +# define NEWTEXT(m) newscr->_line[m].text +# define TEXTWIDTH (curscr->_maxx+1) +# define PENDING(n) (newscr->_line[n].firstchar != _NOCHANGE) + +#endif /* !HASHDEBUG */ + +#define oldhash (SP->oldhash) +#define newhash (SP->newhash) + +static inline unsigned long hash(chtype *text) +{ + int i; + chtype ch; + unsigned long result = 0; + for (i = TEXTWIDTH; i>0; i--) + { + ch = *text++; + result += (result<<5) + ch; + } + return result; +} + +/* approximate update cost */ +static int update_cost(chtype *from,chtype *to) +{ + int cost=0; + int i; + + for (i=TEXTWIDTH; i>0; i--) + if (*from++ != *to++) + cost++; + + return cost; +} +static int update_cost_from_blank(chtype *to) +{ + int cost=0; + int i; + chtype blank = BLANK; + + if (back_color_erase) + blank |= (stdscr->_bkgd & A_COLOR); + + for (i=TEXTWIDTH; i>0; i--) + if (blank != *to++) + cost++; + + return cost; +} + +/* + * Returns true when moving line 'from' to line 'to' seems to be cost + * effective. 'blank' indicates whether the line 'to' would become blank. + */ +static inline bool cost_effective(const int from, const int to, const bool blank) +{ + int new_from; + + if (from == to) + return FALSE; + + new_from = OLDNUM(from); + if (new_from == _NEWINDEX) + new_from = from; + + /* + * On the left side of >= is the cost before moving; + * on the right side -- cost after moving. + */ + return (((blank ? update_cost_from_blank(NEWTEXT(to)) + : update_cost(OLDTEXT(to),NEWTEXT(to))) + + update_cost(OLDTEXT(new_from),NEWTEXT(from))) + >= ((new_from==from ? update_cost_from_blank(NEWTEXT(from)) + : update_cost(OLDTEXT(new_from),NEWTEXT(from))) + + update_cost(OLDTEXT(from),NEWTEXT(to)))) ? TRUE : FALSE; +} + + +typedef struct +{ + unsigned long hashval; + int oldcount, newcount; + int oldindex, newindex; +} + sym; + +static sym *hashtab=0; +static int lines_alloc=0; + +static void grow_hunks(void) +{ + int start, end, shift; + int back_limit, forward_limit; /* limits for cells to fill */ + int back_ref_limit, forward_ref_limit; /* limits for refrences */ + int i; + int next_hunk; + + /* + * This is tricky part. We have unique pairs to use as anchors. + * Use these to deduce the presence of spans of identical lines. + */ + back_limit = 0; + back_ref_limit = 0; + + i = 0; + while (i < screen_lines && OLDNUM(i) == _NEWINDEX) + i++; + for ( ; i < screen_lines; i=next_hunk) + { + start = i; + shift = OLDNUM(i) - i; + + /* get forward limit */ + i = start+1; + while (i < screen_lines && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i == shift) + i++; + end = i; + while (i < screen_lines && OLDNUM(i) == _NEWINDEX) + i++; + next_hunk = i; + forward_limit = i; + if (i >= screen_lines || OLDNUM(i) >= i) + forward_ref_limit = i; + else + forward_ref_limit = OLDNUM(i); + + i = start-1; + /* grow back */ + if (shift < 0) + back_limit = back_ref_limit + (-shift); + while (i >= back_limit) + { + if(newhash[i] == oldhash[i+shift] + || cost_effective(i+shift, i, shift<0)) + { + OLDNUM(i) = i+shift; + TR(TRACE_UPDATE | TRACE_MOVE, + ("connected new line %d to old line %d (backward continuation)", + i, i+shift)); + } + else + { + TR(TRACE_UPDATE | TRACE_MOVE, + ("not connecting new line %d to old line %d (backward continuation)", + i, i+shift)); + break; + } + i--; + } + + i = end; + /* grow forward */ + if (shift > 0) + forward_limit = forward_ref_limit - shift; + while (i < forward_limit) + { + if(newhash[i] == oldhash[i+shift] + || cost_effective(i+shift, i, shift>0)) + { + OLDNUM(i) = i+shift; + TR(TRACE_UPDATE | TRACE_MOVE, + ("connected new line %d to old line %d (forward continuation)", + i, i+shift)); + } + else + { + TR(TRACE_UPDATE | TRACE_MOVE, + ("not connecting new line %d to old line %d (forward continuation)", + i, i+shift)); + break; + } + i++; + } + + back_ref_limit = back_limit = i; + if (shift > 0) + back_ref_limit += shift; + } +} + +void _nc_hash_map(void) +{ + sym *sp; + register int i; + int start, shift, size; + + + if (screen_lines > lines_alloc) + { + if (hashtab) + free (hashtab); + hashtab = typeMalloc(sym, (screen_lines+1)*2); + if (!hashtab) + { + if (oldhash) + FreeAndNull(oldhash); + lines_alloc = 0; + return; + } + lines_alloc = screen_lines; + } + + if (oldhash && newhash) + { + /* re-hash only changed lines */ + for (i = 0; i < screen_lines; i++) + { + if (PENDING(i)) + newhash[i] = hash(NEWTEXT(i)); + } + } + else + { + /* re-hash all */ + if (oldhash == 0) + oldhash = typeCalloc (unsigned long, screen_lines); + if (newhash == 0) + newhash = typeCalloc (unsigned long, screen_lines); + if (!oldhash || !newhash) + return; /* malloc failure */ + for (i = 0; i < screen_lines; i++) + { + newhash[i] = hash(NEWTEXT(i)); + oldhash[i] = hash(OLDTEXT(i)); + } + } + +#ifdef HASH_VERIFY + for (i = 0; i < screen_lines; i++) + { + if(newhash[i] != hash(NEWTEXT(i))) + fprintf(stderr,"error in newhash[%d]\n",i); + if(oldhash[i] != hash(OLDTEXT(i))) + fprintf(stderr,"error in oldhash[%d]\n",i); + } +#endif + + /* + * Set up and count line-hash values. + */ + memset(hashtab, '\0', sizeof(*hashtab)*(screen_lines+1)*2); + for (i = 0; i < screen_lines; i++) + { + unsigned long hashval = oldhash[i]; + + for (sp = hashtab; sp->hashval; sp++) + if (sp->hashval == hashval) + break; + sp->hashval = hashval; /* in case this is a new entry */ + sp->oldcount++; + sp->oldindex = i; + } + for (i = 0; i < screen_lines; i++) + { + unsigned long hashval = newhash[i]; + + for (sp = hashtab; sp->hashval; sp++) + if (sp->hashval == hashval) + break; + sp->hashval = hashval; /* in case this is a new entry */ + sp->newcount++; + sp->newindex = i; + + OLDNUM(i) = _NEWINDEX; /* initialize old indices array */ + } + + /* + * Mark line pairs corresponding to unique hash pairs. + * + * We don't mark lines with offset 0, because it can make fail + * extending hunks by cost_effective. Otherwise, it does not + * have any side effects. + */ + for (sp = hashtab; sp->hashval; sp++) + if (sp->oldcount == 1 && sp->newcount == 1 + && sp->oldindex != sp->newindex) + { + TR(TRACE_UPDATE | TRACE_MOVE, + ("new line %d is hash-identical to old line %d (unique)", + sp->newindex, sp->oldindex)); + OLDNUM(sp->newindex) = sp->oldindex; + } + + grow_hunks(); + + /* + * Eliminate bad or impossible shifts -- this includes removing + * those hunks which could not grow because of conflicts, as well + * those which are to be moved too far, they are likely to destroy + * more than carry. + */ + for (i = 0; i < screen_lines; ) + { + while (i < screen_lines && OLDNUM(i) == _NEWINDEX) + i++; + if (i >= screen_lines) + break; + start = i; + shift = OLDNUM(i) - i; + i++; + while (i < screen_lines && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i == shift) + i++; + size = i - start; + if (size < 3 || size+min(size/8,2) < abs(shift)) + { + while (start < i) + { + OLDNUM(start) = _NEWINDEX; + start++; + } + } + } + + /* After clearing invalid hunks, try grow the rest. */ + grow_hunks(); + +#if NO_LEAKS + FreeAndNull(hashtab); + lines_alloc = 0; +#endif +} + +void _nc_make_oldhash(int i) +{ + if (oldhash) + oldhash[i] = hash(OLDTEXT(i)); +} + +void _nc_scroll_oldhash(int n, int top, int bot) +{ + int size; + int i; + + if (!oldhash) + return; + + size = sizeof(*oldhash) * (bot-top+1-abs(n)); + if (n > 0) + { + memmove (oldhash+top, oldhash+top+n, size); + for (i = bot; i > bot-n; i--) + oldhash[i] = hash(OLDTEXT(i)); + } + else + { + memmove (oldhash+top-n, oldhash+top, size); + for (i = top; i < top-n; i++) + oldhash[i] = hash(OLDTEXT(i)); + } +} + + +#ifdef HASHDEBUG +static void +usage(void) +{ + static const char *table[] = { + "hashmap test-driver", + "", + "# comment", + "l get initial line number vector", + "n use following letters as text of new lines", + "o use following letters as text of old lines", + "d dump state of test arrays", + "h apply hash mapper and see scroll optimization", + "? this message" + }; + size_t n; + for (n = 0; n < sizeof(table)/sizeof(table[0]); n++) + fprintf(stderr, "%s\n", table[n]); +} + +int +main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) +{ + char line[BUFSIZ], *st; + int n; + + SP = typeCalloc(SCREEN,1); + for (n = 0; n < screen_lines; n++) + { + reallines[n] = n; + oldnums[n] = _NEWINDEX; + oldtext[n][0] = newtext[n][0] = '.'; + } + + if (isatty(fileno(stdin))) + usage(); + +#ifdef TRACE + _nc_tracing = TRACE_MOVE; +#endif + for (;;) + { + /* grab a test command */ + if (fgets(line, sizeof(line), stdin) == (char *)NULL) + exit(EXIT_SUCCESS); + + switch(line[0]) + { + case '#': /* comment */ + (void) fputs(line, stderr); + break; + + case 'l': /* get initial line number vector */ + for (n = 0; n < screen_lines; n++) + { + reallines[n] = n; + oldnums[n] = _NEWINDEX; + } + n = 0; + st = strtok(line, " "); + do { + oldnums[n++] = atoi(st); + } while + ((st = strtok((char *)NULL, " ")) != 0); + break; + + case 'n': /* use following letters as text of new lines */ + for (n = 0; n < screen_lines; n++) + newtext[n][0] = '.'; + for (n = 0; n < screen_lines; n++) + if (line[n+1] == '\n') + break; + else + newtext[n][0] = line[n+1]; + break; + + case 'o': /* use following letters as text of old lines */ + for (n = 0; n < screen_lines; n++) + oldtext[n][0] = '.'; + for (n = 0; n < screen_lines; n++) + if (line[n+1] == '\n') + break; + else + oldtext[n][0] = line[n+1]; + break; + + case 'd': /* dump state of test arrays */ +#ifdef TRACE + _nc_linedump(); +#endif + (void) fputs("Old lines: [", stdout); + for (n = 0; n < screen_lines; n++) + putchar(oldtext[n][0]); + putchar(']'); + putchar('\n'); + (void) fputs("New lines: [", stdout); + for (n = 0; n < screen_lines; n++) + putchar(newtext[n][0]); + putchar(']'); + putchar('\n'); + break; + + case 'h': /* apply hash mapper and see scroll optimization */ + _nc_hash_map(); + (void) fputs("Result:\n", stderr); +#ifdef TRACE + _nc_linedump(); +#endif + _nc_scroll_optimize(); + (void) fputs("Done.\n", stderr); + break; + case '?': + usage(); + break; + } + } + return EXIT_SUCCESS; +} + +#endif /* HASHDEBUG */ + +/* hashmap.c ends here */ diff --git a/contrib/ncurses/ncurses/tty/lib_mvcur.c b/contrib/ncurses/ncurses/tty/lib_mvcur.c new file mode 100644 index 0000000..9eca026 --- /dev/null +++ b/contrib/ncurses/ncurses/tty/lib_mvcur.c @@ -0,0 +1,1242 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_mvcur.c +** +** The routines for moving the physical cursor and scrolling: +** +** void _nc_mvcur_init(void) +** +** void _nc_mvcur_resume(void) +** +** int mvcur(int old_y, int old_x, int new_y, int new_x) +** +** void _nc_mvcur_wrap(void) +** +** Comparisons with older movement optimizers: +** SVr3 curses mvcur() can't use cursor_to_ll or auto_left_margin. +** 4.4BSD curses can't use cuu/cud/cuf/cub/hpa/vpa/tab/cbt for local +** motions. It doesn't use tactics based on auto_left_margin. Weirdly +** enough, it doesn't use its own hardware-scrolling routine to scroll up +** destination lines for out-of-bounds addresses! +** old ncurses optimizer: less accurate cost computations (in fact, +** it was broken and had to be commented out!). +** +** Compile with -DMAIN to build an interactive tester/timer for the movement +** optimizer. You can use it to investigate the optimizer's behavior. +** You can also use it for tuning the formulas used to determine whether +** or not full optimization is attempted. +** +** This code has a nasty tendency to find bugs in terminfo entries, because it +** exercises the non-cup movement capabilities heavily. If you think you've +** found a bug, try deleting subsets of the following capabilities (arranged +** in decreasing order of suspiciousness): it, tab, cbt, hpa, vpa, cuu, cud, +** cuf, cub, cuu1, cud1, cuf1, cub1. It may be that one or more are wrong. +** +** Note: you should expect this code to look like a resource hog in a profile. +** That's because it does a lot of I/O, through the tputs() calls. The I/O +** cost swamps the computation overhead (and as machines get faster, this +** will become even more true). Comments in the test exerciser at the end +** go into detail about tuning and how you can gauge the optimizer's +** effectiveness. +**/ + +/**************************************************************************** + * + * Constants and macros for optimizer tuning. + * + ****************************************************************************/ + +/* + * The average overhead of a full optimization computation in character + * transmission times. If it's too high, the algorithm will be a bit + * over-biased toward using cup rather than local motions; if it's too + * low, the algorithm may spend more time than is strictly optimal + * looking for non-cup motions. Profile the optimizer using the `t' + * command of the exerciser (see below), and round to the nearest integer. + * + * Yes, I (esr) thought about computing expected overhead dynamically, say + * by derivation from a running average of optimizer times. But the + * whole point of this optimization is to *decrease* the frequency of + * system calls. :-) + */ +#define COMPUTE_OVERHEAD 1 /* I use a 90MHz Pentium @ 9.6Kbps */ + +/* + * LONG_DIST is the distance we consider to be just as costly to move over as a + * cup sequence is to emit. In other words, it's the length of a cup sequence + * adjusted for average computation overhead. The magic number is the length + * of "\033[yy;xxH", the typical cup sequence these days. + */ +#define LONG_DIST (8 - COMPUTE_OVERHEAD) + +/* + * Tell whether a motion is optimizable by local motions. Needs to be cheap to + * compute. In general, all the fast moves go to either the right or left edge + * of the screen. So any motion to a location that is (a) further away than + * LONG_DIST and (b) further inward from the right or left edge than LONG_DIST, + * we'll consider nonlocal. + */ +#define NOT_LOCAL(fy, fx, ty, tx) ((tx > LONG_DIST) && (tx < screen_lines - 1 - LONG_DIST) && (abs(ty-fy) + abs(tx-fx) > LONG_DIST)) + +/**************************************************************************** + * + * External interfaces + * + ****************************************************************************/ + +/* + * For this code to work OK, the following components must live in the + * screen structure: + * + * int _char_padding; // cost of character put + * int _cr_cost; // cost of (carriage_return) + * int _cup_cost; // cost of (cursor_address) + * int _home_cost; // cost of (cursor_home) + * int _ll_cost; // cost of (cursor_to_ll) + *#if USE_HARD_TABS + * int _ht_cost; // cost of (tab) + * int _cbt_cost; // cost of (back_tab) + *#endif USE_HARD_TABS + * int _cub1_cost; // cost of (cursor_left) + * int _cuf1_cost; // cost of (cursor_right) + * int _cud1_cost; // cost of (cursor_down) + * int _cuu1_cost; // cost of (cursor_up) + * int _cub_cost; // cost of (parm_cursor_left) + * int _cuf_cost; // cost of (parm_cursor_right) + * int _cud_cost; // cost of (parm_cursor_down) + * int _cuu_cost; // cost of (parm_cursor_up) + * int _hpa_cost; // cost of (column_address) + * int _vpa_cost; // cost of (row_address) + * int _ech_cost; // cost of (erase_chars) + * int _rep_cost; // cost of (repeat_char) + * + * The USE_HARD_TABS switch controls whether it is reliable to use tab/backtabs + * for local motions. On many systems, it's not, due to uncertainties about + * tab delays and whether or not tabs will be expanded in raw mode. If you + * have parm_right_cursor, tab motions don't win you a lot anyhow. + */ + +#include <curses.priv.h> +#include <term.h> +#include <ctype.h> + +MODULE_ID("$Id: lib_mvcur.c,v 1.57 1999/06/26 22:16:04 tom Exp $") + +#define STRLEN(s) (s != 0) ? strlen(s) : 0 + +#define CURRENT_ATTR SP->_current_attr /* current phys attribute */ +#define CURRENT_ROW SP->_cursrow /* phys cursor row */ +#define CURRENT_COLUMN SP->_curscol /* phys cursor column */ +#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 */ + +#if defined(MAIN) || defined(NCURSES_TEST) +#include <sys/time.h> + +static bool profiling = FALSE; +static float diff; +#endif /* MAIN */ + +#define OPT_SIZE 512 + +static int normalized_cost(const char *const cap, int affcnt); + +#if !HAVE_STRSTR +char * _nc_strstr(const char *haystack, const char *needle) +{ + size_t len1 = strlen(haystack); + size_t len2 = strlen(needle); + char *result = 0; + + while ((len1 != 0) && (len1-- >= len2)) { + if (!strncmp(haystack, needle, len2)) { + result = haystack; + break; + } + haystack++; + } + return result; +} +#endif + +/**************************************************************************** + * + * Initialization/wrapup (including cost pre-computation) + * + ****************************************************************************/ + +#ifdef TRACE +static int +trace_cost_of(const char *capname, const char *cap, int affcnt) +{ + int result = _nc_msec_cost(cap,affcnt); + TR(TRACE_CHARPUT|TRACE_MOVE, ("CostOf %s %d", capname, result)); + return result; +} +#define CostOf(cap,affcnt) trace_cost_of(#cap,cap,affcnt); + +static int +trace_normalized_cost(const char *capname, const char *cap, int affcnt) +{ + int result = normalized_cost(cap,affcnt); + TR(TRACE_CHARPUT|TRACE_MOVE, ("NormalizedCost %s %d", capname, result)); + return result; +} +#define NormalizedCost(cap,affcnt) trace_normalized_cost(#cap,cap,affcnt); + +#else + +#define CostOf(cap,affcnt) _nc_msec_cost(cap,affcnt); +#define NormalizedCost(cap,affcnt) normalized_cost(cap,affcnt); + +#endif + +int _nc_msec_cost(const char *const cap, int affcnt) +/* compute the cost of a given operation */ +{ + if (cap == 0) + return(INFINITY); + else + { + const char *cp; + float cum_cost = 0; + + for (cp = cap; *cp; cp++) + { + /* extract padding, either mandatory or required */ + if (cp[0] == '$' && cp[1] == '<' && strchr(cp, '>')) + { + float number = 0; + + for (cp += 2; *cp != '>'; cp++) + { + if (isdigit(*cp)) + number = number * 10 + (*cp - '0'); + else if (*cp == '.') + number += (*++cp - 10) / 10.0; + else if (*cp == '*') + number *= affcnt; + } + + cum_cost += number * 10; + } + else + cum_cost += SP->_char_padding; + } + + return((int)cum_cost); + } +} + +static int normalized_cost(const char *const cap, int affcnt) +/* compute the effective character-count for an operation (round up) */ +{ + int cost = _nc_msec_cost(cap, affcnt); + if (cost != INFINITY) + cost = (cost + SP->_char_padding - 1) / SP->_char_padding; + return cost; +} + +static void reset_scroll_region(void) +/* Set the scroll-region to a known state (the default) */ +{ + if (change_scroll_region) + { + TPUTS_TRACE("change_scroll_region"); + putp(tparm(change_scroll_region, 0, screen_lines - 1)); + } +} + +void _nc_mvcur_resume(void) +/* what to do at initialization time and after each shellout */ +{ + /* initialize screen for cursor access */ + if (enter_ca_mode) + { + TPUTS_TRACE("enter_ca_mode"); + putp(enter_ca_mode); + } + + /* + * Doing this here rather than in _nc_mvcur_wrap() ensures that + * ncurses programs will see a reset scroll region even if a + * program that messed with it died ungracefully. + * + * This also undoes the effects of terminal init strings that assume + * they know the screen size. This is useful when you're running + * a vt100 emulation through xterm. + */ + reset_scroll_region(); + SP->_cursrow = SP->_curscol = -1; + + /* restore cursor shape */ + if (SP->_cursor != -1) + { + int cursor = SP->_cursor; + SP->_cursor = -1; + curs_set (cursor); + } +} + +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 (SP->_char_padding <= 0) + SP->_char_padding = 1; /* must be nonzero */ + TR(TRACE_CHARPUT|TRACE_MOVE, ("char_padding %d msecs", SP->_char_padding)); + + /* non-parameterized local-motion strings */ + SP->_cr_cost = CostOf(carriage_return, 0); + SP->_home_cost = CostOf(cursor_home, 0); + SP->_ll_cost = CostOf(cursor_to_ll, 0); +#if USE_HARD_TABS + SP->_ht_cost = CostOf(tab, 0); + SP->_cbt_cost = CostOf(back_tab, 0); +#endif /* USE_HARD_TABS */ + SP->_cub1_cost = CostOf(cursor_left, 0); + SP->_cuf1_cost = CostOf(cursor_right, 0); + SP->_cud1_cost = CostOf(cursor_down, 0); + SP->_cuu1_cost = CostOf(cursor_up, 0); + + SP->_smir_cost = CostOf(enter_insert_mode, 0); + SP->_rmir_cost = CostOf(exit_insert_mode, 0); + SP->_ip_cost = 0; + if (insert_padding) { + SP->_ip_cost = CostOf(insert_padding, 0); + } + + /* + * Assumption: if the terminal has memory_relative addressing, the + * initialization strings or smcup will set single-page mode so we + * can treat it like absolute screen addressing. This seems to be true + * for all cursor_mem_address terminal types in the terminfo database. + */ + SP->_address_cursor = cursor_address ? cursor_address : cursor_mem_address; + + /* + * Parametrized local-motion strings. This static cost computation + * depends on the following assumptions: + * + * (1) They never have * padding. In the entire master terminfo database + * as of March 1995, only the obsolete Zenith Z-100 pc violates this. + * (Proportional padding is found mainly in insert, delete and scroll + * capabilities). + * + * (2) The average case of cup has two two-digit parameters. Strictly, + * the average case for a 24 * 80 screen has ((10*10*(1 + 1)) + + * (14*10*(1 + 2)) + (10*70*(2 + 1)) + (14*70*4)) / (24*80) = 3.458 + * digits of parameters. On a 25x80 screen the average is 3.6197. + * On larger screens the value gets much closer to 4. + * + * (3) The average case of cub/cuf/hpa/ech/rep has 2 digits of parameters + * (strictly, (((10 * 1) + (70 * 2)) / 80) = 1.8750). + * + * (4) The average case of cud/cuu/vpa has 2 digits of parameters + * (strictly, (((10 * 1) + (14 * 2)) / 24) = 1.5833). + * + * All these averages depend on the assumption that all parameter values + * are equally probable. + */ + SP->_cup_cost = CostOf(tparm(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); + + /* non-parameterized screen-update strings */ + SP->_ed_cost = NormalizedCost(clr_eos, 1); + SP->_el_cost = NormalizedCost(clr_eol, 1); + SP->_el1_cost = NormalizedCost(clr_bol, 1); + SP->_dch1_cost = NormalizedCost(delete_character, 1); + SP->_ich1_cost = NormalizedCost(insert_character, 1); + + /* 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); + + /* pre-compute some capability lengths */ + SP->_carriage_return_length = STRLEN(carriage_return); + SP->_cursor_home_length = STRLEN(cursor_home); + SP->_cursor_to_ll_length = STRLEN(cursor_to_ll); + + /* + * If save_cursor is used within enter_ca_mode, we should not use it for + * scrolling optimization, since the corresponding restore_cursor is not + * nested on the various terminals (vt100, xterm, etc.) which use this + * feature. + */ + if (save_cursor != 0 + && enter_ca_mode != 0 + && strstr(enter_ca_mode, save_cursor) != 0) { + T(("...suppressed sc/rc capability due to conflict with smcup/rmcup")); + save_cursor = 0; + restore_cursor = 0; + } + + /* + * A different, possibly better way to arrange this would be to set + * SP->_endwin = TRUE at window initialization time and let this be + * called by doupdate's return-from-shellout code. + */ + _nc_mvcur_resume(); +} + +void _nc_mvcur_wrap(void) +/* wrap up cursor-addressing mode */ +{ + /* leave cursor at screen bottom */ + mvcur(-1, -1, screen_lines - 1, 0); + + /* set cursor to normal mode */ + if (SP->_cursor != -1) + curs_set(1); + + if (exit_ca_mode) + { + TPUTS_TRACE("exit_ca_mode"); + putp(exit_ca_mode); + } + /* + * Reset terminal's tab counter. There's a long-time bug that + * if you exit a "curses" program such as vi or more, tab + * forward, and then backspace, the cursor doesn't go to the + * right place. The problem is that the kernel counts the + * escape sequences that reset things as column positions. + * Utter a \r to reset this invisibly. + */ + _nc_outch('\r'); +} + +/**************************************************************************** + * + * Optimized cursor movement + * + ****************************************************************************/ + +/* + * Perform repeated-append, returning cost + */ +static inline int +repeated_append (int total, int num, int repeat, char *dst, const char *src) +{ + register size_t src_len = strlen(src); + register size_t dst_len = STRLEN(dst); + + if ((dst_len + repeat * src_len) < OPT_SIZE-1) { + total += (num * repeat); + if (dst) { + dst += dst_len; + while (repeat-- > 0) { + (void) strcpy(dst, src); + dst += src_len; + } + } + } else { + total = INFINITY; + } + return total; +} + +#ifndef NO_OPTIMIZE +#define NEXTTAB(fr) (fr + init_tabs - (fr % init_tabs)) + +/* + * Assume back_tab (CBT) does not wrap backwards at the left margin, return + * a negative value at that point to simplify the loop. + */ +#define LASTTAB(fr) ((fr > 0) ? ((fr - 1) / init_tabs) * init_tabs : -1) + +/* Note: we'd like to inline this for speed, but GNU C barfs on the attempt. */ + +static int +relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw) +/* move via local motions (cuu/cuu1/cud/cud1/cub1/cub/cuf1/cuf/vpa/hpa) */ +{ + int n, vcost = 0, hcost = 0; + + if (result) + result[0] = '\0'; + + if (to_y != from_y) + { + vcost = INFINITY; + + if (row_address) + { + if (result) + (void) strcpy(result, tparm(row_address, to_y)); + vcost = SP->_vpa_cost; + } + + if (to_y > from_y) + { + n = (to_y - from_y); + + if (parm_down_cursor && SP->_cud_cost < vcost) + { + if (result) + (void) strcpy(result, tparm(parm_down_cursor, n)); + vcost = SP->_cud_cost; + } + + if (cursor_down && (n * SP->_cud1_cost < vcost)) + { + if (result) + result[0] = '\0'; + vcost = repeated_append(0, SP->_cud1_cost, n, result, cursor_down); + } + } + else /* (to_y < from_y) */ + { + n = (from_y - to_y); + + if (parm_up_cursor && SP->_cup_cost < vcost) + { + if (result) + (void) strcpy(result, tparm(parm_up_cursor, n)); + vcost = SP->_cup_cost; + } + + if (cursor_up && (n * SP->_cuu1_cost < vcost)) + { + if (result) + result[0] = '\0'; + vcost = repeated_append(0, SP->_cuu1_cost, n, result, cursor_up); + } + } + + if (vcost == INFINITY) + return(INFINITY); + } + + if (result) + result += strlen(result); + + if (to_x != from_x) + { + char str[OPT_SIZE]; + + hcost = INFINITY; + + if (column_address) + { + if (result) + (void) strcpy(result, tparm(column_address, to_x)); + hcost = SP->_hpa_cost; + } + + if (to_x > from_x) + { + n = to_x - from_x; + + if (parm_right_cursor && SP->_cuf_cost < hcost) + { + if (result) + (void) strcpy(result, tparm(parm_right_cursor, n)); + hcost = SP->_cuf_cost; + } + + if (cursor_right) + { + int lhcost = 0; + + str[0] = '\0'; + +#if USE_HARD_TABS + /* use hard tabs, if we have them, to do as much as possible */ + if (init_tabs > 0 && tab) + { + int nxt, fr; + + for (fr = from_x; (nxt = NEXTTAB(fr)) <= to_x; fr = nxt) + { + lhcost = repeated_append(lhcost, SP->_ht_cost, 1, str, tab); + if (lhcost == INFINITY) + break; + } + + n = to_x - fr; + from_x = fr; + } +#endif /* USE_HARD_TABS */ + +#if defined(REAL_ATTR) && defined(WANT_CHAR) +#ifdef BSD_TPUTS + /* + * If we're allowing BSD-style padding in tputs, don't generate + * a string with a leading digit. Otherwise, that will be + * interpreted as a padding value rather than sent to the + * screen. + */ + if (ovw + && n > 0 + && vcost == 0 + && str[0] == '\0' + && isdigit(TextOf(WANT_CHAR(to_y, from_x)))) + ovw = FALSE; +#endif + /* + * If we have no attribute changes, overwrite is cheaper. + * Note: must suppress this by passing in ovw = FALSE whenever + * WANT_CHAR would return invalid data. In particular, this + * is true between the time a hardware scroll has been done + * and the time the structure WANT_CHAR would access has been + * updated. + */ + if (ovw) + { + int i; + + for (i = 0; i < n; i++) + if ((WANT_CHAR(to_y, from_x + i) & A_ATTRIBUTES) != CURRENT_ATTR) + { + ovw = FALSE; + break; + } + } + if (ovw) + { + char *sp; + int i; + + sp = str + strlen(str); + + for (i = 0; i < n; i++) + *sp++ = WANT_CHAR(to_y, from_x + i); + *sp = '\0'; + lhcost += n * SP->_char_padding; + } + else +#endif /* defined(REAL_ATTR) && defined(WANT_CHAR) */ + { + lhcost = repeated_append(lhcost, SP->_cuf1_cost, n, str, cursor_right); + } + + if (lhcost < hcost) + { + if (result) + (void) strcpy(result, str); + hcost = lhcost; + } + } + } + else /* (to_x < from_x) */ + { + n = from_x - to_x; + + if (parm_left_cursor && SP->_cub_cost < hcost) + { + if (result) + (void) strcpy(result, tparm(parm_left_cursor, n)); + hcost = SP->_cub_cost; + } + + if (cursor_left) + { + int lhcost = 0; + + str[0] = '\0'; + +#if USE_HARD_TABS + if (init_tabs > 0 && back_tab) + { + int nxt, fr; + + for (fr = from_x; (nxt = LASTTAB(fr)) >= to_x; fr = nxt) + { + lhcost = repeated_append(lhcost, SP->_cbt_cost, 1, str, back_tab); + if (lhcost == INFINITY) + break; + } + + n = fr - to_x; + } +#endif /* USE_HARD_TABS */ + + lhcost = repeated_append(lhcost, SP->_cub1_cost, n, str, cursor_left); + + if (lhcost < hcost) + { + if (result) + (void) strcpy(result, str); + hcost = lhcost; + } + } + } + + if (hcost == INFINITY) + return(INFINITY); + } + + return(vcost + hcost); +} +#endif /* !NO_OPTIMIZE */ + +/* + * With the machinery set up above, it's conceivable that + * onscreen_mvcur could be modified into a recursive function that does + * an alpha-beta search of motion space, as though it were a chess + * move tree, with the weight function being boolean and the search + * depth equated to length of string. However, this would jack up the + * computation cost a lot, especially on terminals without a cup + * capability constraining the search tree depth. So we settle for + * the simpler method below. + */ + +static inline int +onscreen_mvcur(int yold,int xold,int ynew,int xnew, bool ovw) +/* onscreen move from (yold, xold) to (ynew, xnew) */ +{ + char use[OPT_SIZE], *sp; + int tactic = 0, newcost, usecost = INFINITY; + +#if defined(MAIN) || defined(NCURSES_TEST) + struct timeval before, after; + + gettimeofday(&before, NULL); +#endif /* MAIN */ + + /* tactic #0: use direct cursor addressing */ + sp = tparm(SP->_address_cursor, ynew, xnew); + if (sp) + { + tactic = 0; + (void) strcpy(use, sp); + usecost = SP->_cup_cost; + +#if defined(TRACE) || defined(NCURSES_TEST) + if (!(_nc_optimize_enable & OPTIMIZE_MVCUR)) + goto nonlocal; +#endif /* TRACE */ + + /* + * We may be able to tell in advance that the full optimization + * will probably not be worth its overhead. Also, don't try to + * use local movement if the current attribute is anything but + * A_NORMAL...there are just too many ways this can screw up + * (like, say, local-movement \n getting mapped to some obscure + * character because A_ALTCHARSET is on). + */ + if (yold == -1 || xold == -1 || NOT_LOCAL(yold, xold, ynew, xnew)) + { +#if defined(MAIN) || defined(NCURSES_TEST) + if (!profiling) + { + (void) fputs("nonlocal\n", stderr); + goto nonlocal; /* always run the optimizer if profiling */ + } +#else + goto nonlocal; +#endif /* MAIN */ + } + } + +#ifndef NO_OPTIMIZE + /* tactic #1: use local movement */ + if (yold != -1 && xold != -1 + && ((newcost=relative_move(NULL, yold, xold, ynew, xnew, ovw))!=INFINITY) + && newcost < usecost) + { + tactic = 1; + usecost = newcost; + } + + /* tactic #2: use carriage-return + local movement */ + if (yold != -1 && carriage_return + && ((newcost=relative_move(NULL, yold,0,ynew,xnew, ovw)) != INFINITY) + && SP->_cr_cost + newcost < usecost) + { + tactic = 2; + usecost = SP->_cr_cost + newcost; + } + + /* tactic #3: use home-cursor + local movement */ + if (cursor_home + && ((newcost=relative_move(NULL, 0, 0, ynew, xnew, ovw)) != INFINITY) + && SP->_home_cost + newcost < usecost) + { + tactic = 3; + usecost = SP->_home_cost + newcost; + } + + /* tactic #4: use home-down + local movement */ + if (cursor_to_ll + && ((newcost=relative_move(NULL, screen_lines-1, 0, ynew, xnew, ovw)) != INFINITY) + && SP->_ll_cost + newcost < usecost) + { + tactic = 4; + usecost = SP->_ll_cost + newcost; + } + + /* + * tactic #5: use left margin for wrap to right-hand side, + * unless strange wrap behavior indicated by xenl might hose us. + */ + if (auto_left_margin && !eat_newline_glitch + && yold > 0 && cursor_left + && ((newcost=relative_move(NULL, yold-1, screen_columns-1, ynew, xnew, ovw)) != INFINITY) + && SP->_cr_cost + SP->_cub1_cost + newcost + newcost < usecost) + { + tactic = 5; + usecost = SP->_cr_cost + SP->_cub1_cost + newcost; + } + + /* + * These cases are ordered by estimated relative frequency. + */ + if (tactic) + { + if (tactic == 1) + (void) relative_move(use, yold, xold, ynew, xnew, ovw); + else if (tactic == 2) + { + (void) strcpy(use, carriage_return); + (void) relative_move(use + SP->_carriage_return_length, + yold,0,ynew,xnew, ovw); + } + else if (tactic == 3) + { + (void) strcpy(use, cursor_home); + (void) relative_move(use + SP->_cursor_home_length, + 0, 0, ynew, xnew, ovw); + } + else if (tactic == 4) + { + (void) strcpy(use, cursor_to_ll); + (void) relative_move(use + SP->_cursor_to_ll_length, + screen_lines-1, 0, ynew, xnew, ovw); + } + else /* if (tactic == 5) */ + { + use[0] = '\0'; + if (xold > 0) + (void) strcat(use, carriage_return); + (void) strcat(use, cursor_left); + (void) relative_move(use + strlen(use), + yold-1, screen_columns-1, ynew, xnew, ovw); + } + } +#endif /* !NO_OPTIMIZE */ + +#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", + (int)diff, diff/288); +#endif /* MAIN */ + + nonlocal: + if (usecost != INFINITY) + { + TPUTS_TRACE("mvcur"); + tputs(use, 1, _nc_outch); + return(OK); + } + else + return(ERR); +} + +int mvcur(int yold, int xold, int ynew, int xnew) +/* optimized cursor move from (yold, xold) to (ynew, xnew) */ +{ + TR(TRACE_MOVE, ("mvcur(%d,%d,%d,%d) called", yold, xold, ynew, xnew)); + + if (yold == ynew && xold == xnew) + return(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; + } + if (xold >= screen_columns) + { + int l; + + 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 (carriage_return) + { + TPUTS_TRACE("carriage_return"); + tputs(carriage_return, 0, _nc_outch); + } + else + putchar('\r'); + xold = 0; + } + } + } + + if (yold > screen_lines - 1) + yold = screen_lines - 1; + if (ynew > screen_lines - 1) + ynew = screen_lines - 1; + + /* destination location is on screen now */ + return(onscreen_mvcur(yold, xold, ynew, xnew, TRUE)); +} + +#if defined(TRACE) || defined(NCURSES_TEST) +int _nc_optimize_enable = OPTIMIZE_ALL; +#endif + +#if defined(MAIN) || defined(NCURSES_TEST) +/**************************************************************************** + * + * Movement optimizer test code + * + ****************************************************************************/ + +#include <tic.h> +#include <dump_entry.h> + +const char *_nc_progname = "mvcur"; + +static unsigned long xmits; + +int tputs(const char *string, int affcnt GCC_UNUSED, int (*outc)(int) GCC_UNUSED) +/* stub tputs() that dumps sequences in a visible form */ +{ + if (profiling) + xmits += strlen(string); + else + (void) fputs(_nc_visbuf(string), stdout); + return(OK); +} + +int putp(const char *string) +{ + return(tputs(string, 1, _nc_outch)); +} + +int _nc_outch(int ch) +{ + putc(ch, stdout); + return OK; +} + +static char tname[MAX_ALIAS]; + +static void load_term(void) +{ + (void) setupterm(tname, STDOUT_FILENO, NULL); +} + +static int roll(int n) +{ + int i, j; + + i = (RAND_MAX / n) * n; + while ((j = rand()) >= i) + continue; + return (j % n); +} + +int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) +{ + (void) strcpy(tname, termname()); + load_term(); + _nc_setupscreen(lines, columns, stdout); + baudrate(); + + _nc_mvcur_init(); + NC_BUFFERED(FALSE); + + (void) puts("The mvcur tester. Type ? for help"); + + fputs("smcup:", stdout); + putchar('\n'); + + for (;;) + { + int fy, fx, ty, tx, n, i; + char buf[BUFSIZ], capname[BUFSIZ]; + + (void) fputs("> ", stdout); + (void) fgets(buf, sizeof(buf), stdin); + + if (buf[0] == '?') + { +(void) puts("? -- display this help message"); +(void) puts("fy fx ty tx -- (4 numbers) display (fy,fx)->(ty,tx) move"); +(void) puts("s[croll] n t b m -- display scrolling sequence"); +(void) printf("r[eload] -- reload terminal info for %s\n", termname()); +(void) puts("l[oad] <term> -- load terminal info for type <term>"); +(void) puts("d[elete] <cap> -- delete named capability"); +(void) puts("i[nspect] -- display terminal capabilities"); +(void) puts("c[ost] -- dump cursor-optimization cost table"); +(void) puts("o[optimize] -- toggle movement optimization"); +(void) puts("t[orture] <num> -- torture-test with <num> random moves"); +(void) puts("q[uit] -- quit the program"); + } + else if (sscanf(buf, "%d %d %d %d", &fy, &fx, &ty, &tx) == 4) + { + struct timeval before, after; + + putchar('"'); + + gettimeofday(&before, NULL); + mvcur(fy, fx, ty, tx); + gettimeofday(&after, NULL); + + printf("\" (%ld msec)\n", + (long)(after.tv_usec - before.tv_usec + (after.tv_sec - before.tv_sec) * 1000000)); + } + else if (sscanf(buf, "s %d %d %d %d", &fy, &fx, &ty, &tx) == 4) + { + struct timeval before, after; + + putchar('"'); + + gettimeofday(&before, NULL); + _nc_scrolln(fy, fx, ty, tx); + gettimeofday(&after, NULL); + + printf("\" (%ld msec)\n", + (long)(after.tv_usec - before.tv_usec + (after.tv_sec - before.tv_sec) * 1000000)); + } + else if (buf[0] == 'r') + { + (void) strcpy(tname, termname()); + load_term(); + } + else if (sscanf(buf, "l %s", tname) == 1) + { + load_term(); + } + else if (sscanf(buf, "d %s", capname) == 1) + { + struct name_table_entry const *np = _nc_find_entry(capname, + _nc_info_hash_table); + + if (np == NULL) + (void) printf("No such capability as \"%s\"\n", capname); + else + { + switch(np->nte_type) + { + case BOOLEAN: + cur_term->type.Booleans[np->nte_index] = FALSE; + (void) printf("Boolean capability `%s' (%d) turned off.\n", + np->nte_name, np->nte_index); + break; + + case NUMBER: + cur_term->type.Numbers[np->nte_index] = -1; + (void) printf("Number capability `%s' (%d) set to -1.\n", + np->nte_name, np->nte_index); + break; + + case STRING: + cur_term->type.Strings[np->nte_index] = (char *)NULL; + (void) printf("String capability `%s' (%d) deleted.\n", + np->nte_name, np->nte_index); + break; + } + } + } + else if (buf[0] == 'i') + { + dump_init((char *)NULL, F_TERMINFO, S_TERMINFO, 70, 0, FALSE); + dump_entry(&cur_term->type, FALSE, TRUE, 0); + putchar('\n'); + } + else if (buf[0] == 'o') + { + if (_nc_optimize_enable & OPTIMIZE_MVCUR) + { + _nc_optimize_enable &=~ OPTIMIZE_MVCUR; + (void) puts("Optimization is now off."); + } + else + { + _nc_optimize_enable |= OPTIMIZE_MVCUR; + (void) puts("Optimization is now on."); + } + } + /* + * You can use the `t' test to profile and tune the movement + * optimizer. Use iteration values in three digits or more. + * At above 5000 iterations the profile timing averages are stable + * to within a millisecond or three. + * + * The `overhead' field of the report will help you pick a + * COMPUTE_OVERHEAD figure appropriate for your processor and + * expected line speed. The `total estimated time' is + * computation time plus a character-transmission time + * estimate computed from the number of transmits and the baud + * rate. + * + * Use this together with the `o' command to get a read on the + * optimizer's effectiveness. Compare the total estimated times + * for `t' runs of the same length in both optimized and un-optimized + * modes. As long as the optimized times are less, the optimizer + * is winning. + */ + else if (sscanf(buf, "t %d", &n) == 1) + { + float cumtime = 0, perchar; + int speeds[] = {2400, 9600, 14400, 19200, 28800, 38400, 0}; + + srand((unsigned)(getpid() + time((time_t *)0))); + profiling = TRUE; + xmits = 0; + for (i = 0; i < n; i++) + { + /* + * This does a move test between two random locations, + * Random moves probably short-change the optimizer, + * which will work better on the short moves probably + * typical of doupdate()'s usage pattern. Still, + * until we have better data... + */ +#ifdef FIND_COREDUMP + int from_y = roll(lines); + int to_y = roll(lines); + int from_x = roll(columns); + int to_x = roll(columns); + + printf("(%d,%d) -> (%d,%d)\n", from_y, from_x, to_y, to_x); + mvcur(from_y, from_x, to_y, to_x); +#else + mvcur(roll(lines), roll(columns), roll(lines), roll(columns)); +#endif /* FIND_COREDUMP */ + if (diff) + cumtime += diff; + } + profiling = FALSE; + + /* + * Average milliseconds per character optimization time. + * This is the key figure to watch when tuning the optimizer. + */ + perchar = cumtime / n; + + (void) printf("%d moves (%ld chars) in %d msec, %f msec each:\n", + n, xmits, (int)cumtime, perchar); + + for (i = 0; speeds[i]; i++) + { + /* + * Total estimated time for the moves, computation and + * transmission both. Transmission time is an estimate + * assuming 9 bits/char, 8 bits + 1 stop bit. + */ + float totalest = cumtime + xmits * 9 * 1e6 / speeds[i]; + + /* + * Per-character optimization overhead in character transmits + * at the current speed. Round this to the nearest integer + * to figure COMPUTE_OVERHEAD for the speed. + */ + float overhead = speeds[i] * perchar / 1e6; + + (void) printf("%6d bps: %3.2f char-xmits overhead; total estimated time %15.2f\n", + speeds[i], overhead, totalest); + } + } + else if (buf[0] == 'c') + { + (void) printf("char padding: %d\n", SP->_char_padding); + (void) printf("cr cost: %d\n", SP->_cr_cost); + (void) printf("cup cost: %d\n", SP->_cup_cost); + (void) printf("home cost: %d\n", SP->_home_cost); + (void) printf("ll cost: %d\n", SP->_ll_cost); +#if USE_HARD_TABS + (void) printf("ht cost: %d\n", SP->_ht_cost); + (void) printf("cbt cost: %d\n", SP->_cbt_cost); +#endif /* USE_HARD_TABS */ + (void) printf("cub1 cost: %d\n", SP->_cub1_cost); + (void) printf("cuf1 cost: %d\n", SP->_cuf1_cost); + (void) printf("cud1 cost: %d\n", SP->_cud1_cost); + (void) printf("cuu1 cost: %d\n", SP->_cuu1_cost); + (void) printf("cub cost: %d\n", SP->_cub_cost); + (void) printf("cuf cost: %d\n", SP->_cuf_cost); + (void) printf("cud cost: %d\n", SP->_cud_cost); + (void) printf("cuu cost: %d\n", SP->_cuu_cost); + (void) printf("hpa cost: %d\n", SP->_hpa_cost); + (void) printf("vpa cost: %d\n", SP->_vpa_cost); + } + else if (buf[0] == 'x' || buf[0] == 'q') + break; + else + (void) puts("Invalid command."); + } + + (void) fputs("rmcup:", stdout); + _nc_mvcur_wrap(); + putchar('\n'); + + return(0); +} + +#endif /* MAIN */ + +/* lib_mvcur.c ends here */ diff --git a/contrib/ncurses/ncurses/tty/lib_tstp.c b/contrib/ncurses/ncurses/tty/lib_tstp.c new file mode 100644 index 0000000..c241993 --- /dev/null +++ b/contrib/ncurses/ncurses/tty/lib_tstp.c @@ -0,0 +1,361 @@ +/**************************************************************************** + * Copyright (c) 1998,1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/* +** lib_tstp.c +** +** The routine _nc_signal_handler(). +** +*/ + +#include <curses.priv.h> + +#include <signal.h> +#include <SigAction.h> + +#if defined(SVR4_ACTION) && !defined(_POSIX_SOURCE) +#define _POSIX_SOURCE +#endif + +MODULE_ID("$Id: lib_tstp.c,v 1.19 1999/07/24 22:47:20 tom Exp $") + +#if defined(SIGTSTP) && (HAVE_SIGACTION || HAVE_SIGVEC) +#define USE_SIGTSTP 1 +#else +#define USE_SIGTSTP 0 +#endif + +/* + * Note: This code is fragile! Its problem is that different OSs + * handle restart of system calls interrupted by signals differently. + * The ncurses code needs signal-call restart to happen -- otherwise, + * interrupted wgetch() calls will return FAIL, probably making the + * application think the input stream has ended and it should + * terminate. In particular, you know you have this problem if, when + * you suspend an ncurses-using lynx with ^Z and resume, it dies + * immediately. + * + * Default behavior of POSIX sigaction(2) is not to restart + * interrupted system calls, but Linux's sigaction does it anyway (at + * least, on and after the 1.1.47 I (esr) use). Thus this code works + * OK under Linux. The 4.4BSD sigaction(2) supports a (non-portable) + * SA_RESTART flag that forces the right behavior. Thus, this code + * should work OK under BSD/OS, NetBSD, and FreeBSD (let us know if it + * does not). + * + * Stock System Vs (and anything else using a strict-POSIX + * sigaction(2) without SA_RESTART) may have a problem. Possible + * solutions: + * + * sigvec restarts by default (SV_INTERRUPT flag to not restart) + * signal restarts by default in SVr4 (assuming you link with -lucb) + * and BSD, but not SVr3. + * sigset restarts, but is only available under SVr4/Solaris. + * + * The signal(3) call is mandated by the ANSI standard, and its + * interaction with sigaction(2) is described in the POSIX standard + * (3.3.4.2, page 72,line 934). According to section 8.1, page 191, + * however, signal(3) itself is not required by POSIX.1. And POSIX is + * silent on whether it is required to restart signals. + * + * So. The present situation is, we use sigaction(2) with no + * guarantee of restart anywhere but on Linux and BSD. We could + * switch to signal(3) and collar Linux, BSD, and SVr4. Any way + * we slice it, System V UNIXes older than SVr4 will probably lose + * (this may include XENIX). + * + * This implementation will probably be changed to use signal(3) in + * the future. If nothing else, it's simpler... + */ + +#if USE_SIGTSTP +static void tstp(int dummy GCC_UNUSED) +{ + sigset_t mask, omask; + sigaction_t act, oact; + +#ifdef SIGTTOU + int sigttou_blocked; +#endif + + T(("tstp() called")); + + /* + * The user may have changed the prog_mode tty bits, so save them. + * + * But first try to detect whether we still are in the foreground + * process group - if not, an interactive shell may already have + * taken ownership of the tty and modified the settings when our + * parent was stopped before us, and we would likely pick up the + * settings already modified by the shell. + */ + if (SP != 0 && !SP->_endwin) /* don't do this if we're not in curses */ +#if HAVE_TCGETPGRP + if (tcgetpgrp(STDIN_FILENO) == getpgrp()) +#endif + def_prog_mode(); + + /* + * Block window change and timer signals. The latter + * is because applications use timers to decide when + * to repaint the screen. + */ + (void)sigemptyset(&mask); + (void)sigaddset(&mask, SIGALRM); +#if USE_SIGWINCH + (void)sigaddset(&mask, SIGWINCH); +#endif + (void)sigprocmask(SIG_BLOCK, &mask, &omask); + +#ifdef SIGTTOU + sigttou_blocked = sigismember(&omask, SIGTTOU); + if (!sigttou_blocked) { + (void)sigemptyset(&mask); + (void)sigaddset(&mask, SIGTTOU); + (void)sigprocmask(SIG_BLOCK, &mask, NULL); + } +#endif + + /* + * End window mode, which also resets the terminal state to the + * original (pre-curses) modes. + */ + endwin(); + + /* Unblock SIGTSTP. */ + (void)sigemptyset(&mask); + (void)sigaddset(&mask, SIGTSTP); +#ifdef SIGTTOU + if (!sigttou_blocked) { + /* Unblock this too if it wasn't blocked on entry */ + (void)sigaddset(&mask, SIGTTOU); + } +#endif + (void)sigprocmask(SIG_UNBLOCK, &mask, NULL); + + /* Now we want to resend SIGSTP to this process and suspend it */ + act.sa_handler = SIG_DFL; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; +#ifdef SA_RESTART + act.sa_flags |= SA_RESTART; +#endif /* SA_RESTART */ + sigaction(SIGTSTP, &act, &oact); + kill(getpid(), SIGTSTP); + + /* Process gets suspended...time passes...process resumes */ + + T(("SIGCONT received")); + sigaction(SIGTSTP, &oact, NULL); + flushinp(); + + /* + * If the user modified the tty state while suspended, he wants + * those changes to stick. So save the new "default" terminal state. + */ + def_shell_mode(); + + /* + * This relies on the fact that doupdate() will restore the + * program-mode tty state, and issue enter_ca_mode if need be. + */ + doupdate(); + + /* Reset the signals. */ + (void)sigprocmask(SIG_SETMASK, &omask, NULL); +} +#endif /* USE_SIGTSTP */ + +static void cleanup(int sig) +{ + /* + * Actually, doing any sort of I/O from within an signal handler is + * "unsafe". But we'll _try_ to clean up the screen and terminal + * settings on the way out. + */ + if (sig == SIGINT + || sig == SIGQUIT) { +#if HAVE_SIGACTION || HAVE_SIGVEC + sigaction_t act; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + act.sa_handler = SIG_IGN; + if (sigaction(sig, &act, (sigaction_t *)0) == 0) +#else + if (signal(sig, SIG_IGN) != SIG_ERR) +#endif + { + SCREEN *scan = _nc_screen_chain; + while(scan) + { + set_term(scan); + endwin(); + if (SP) + SP->_endwin = FALSE; /* in case we have an atexit! */ + scan = scan->_next_screen; + } + } + } + exit(EXIT_FAILURE); +} + +#if USE_SIGWINCH +static void sigwinch(int sig GCC_UNUSED) +{ + SCREEN *scan = _nc_screen_chain; + while(scan) + { + scan->_sig_winch = TRUE; + scan = scan->_next_screen; + } +} +#endif /* USE_SIGWINCH */ + +/* + * If the given signal is still in its default state, set it to the given + * handler. + */ +#if HAVE_SIGACTION || HAVE_SIGVEC +static int CatchIfDefault(int sig, sigaction_t *act) +{ + sigaction_t old_act; + + if (sigaction(sig, (sigaction_t *)0, &old_act) == 0 + && (old_act.sa_handler == SIG_DFL +#if USE_SIGWINCH + || (sig == SIGWINCH && old_act.sa_handler == SIG_IGN) +#endif + )) { + (void)sigaction(sig, act, (sigaction_t *)0); + return TRUE; + } + return FALSE; +} +#else +static int CatchIfDefault(int sig, RETSIGTYPE (*handler)(int)) +{ + void (*ohandler)(int); + + ohandler = signal(sig, SIG_IGN); + if (ohandler == SIG_DFL +#if USE_SIGWINCH + || (sig == SIGWINCH && ohandler == SIG_IGN) +#endif + ) { + signal(sig, handler); + return TRUE; + } else { + signal(sig, ohandler); + return FALSE; + } +} +#endif + +/* + * This is invoked once at the beginning (e.g., from 'initscr()'), to + * initialize the signal catchers, and thereafter when spawning a shell (and + * returning) to disable/enable the SIGTSTP (i.e., ^Z) catcher. + * + * If the application has already set one of the signals, we'll not modify it + * (during initialization). + * + * The XSI document implies that we shouldn't keep the SIGTSTP handler if + * the caller later changes its mind, but that doesn't seem correct. + */ +void _nc_signal_handler(bool enable) +{ +#if USE_SIGTSTP /* Xenix 2.x doesn't have SIGTSTP, for example */ +static sigaction_t act, oact; +static int ignore; + + if (!ignore) + { + if (!enable) + { + act.sa_handler = SIG_IGN; + sigaction(SIGTSTP, &act, &oact); + } + else if (act.sa_handler) + { + sigaction(SIGTSTP, &oact, NULL); + } + else /*initialize */ + { + sigemptyset(&act.sa_mask); + act.sa_flags = 0; +#if USE_SIGWINCH + act.sa_handler = sigwinch; + CatchIfDefault(SIGWINCH, &act); +#endif + +#ifdef SA_RESTART + act.sa_flags |= SA_RESTART; +#endif /* SA_RESTART */ + act.sa_handler = cleanup; + CatchIfDefault(SIGINT, &act); + CatchIfDefault(SIGTERM, &act); + + act.sa_handler = tstp; + if (!CatchIfDefault(SIGTSTP, &act)) + ignore = TRUE; + } + } +#else /* !USE_SIGTSTP */ + if (enable) + { +#if HAVE_SIGACTION || HAVE_SIGVEC + static sigaction_t act; + sigemptyset(&act.sa_mask); +#if USE_SIGWINCH + act.sa_handler = sigwinch; + CatchIfDefault(SIGWINCH, &act); +#endif +#ifdef SA_RESTART + act.sa_flags |= SA_RESTART; +#endif /* SA_RESTART */ + act.sa_handler = cleanup; + CatchIfDefault(SIGINT, &act); + CatchIfDefault(SIGTERM, &act); + +#else /* !(HAVE_SIGACTION || HAVE_SIGVEC) */ + + CatchIfDefault(SIGINT, cleanup); + CatchIfDefault(SIGTERM, cleanup); +#if USE_SIGWINCH + CatchIfDefault(SIGWINCH, sigwinch); +#endif +#endif /* !(HAVE_SIGACTION || HAVE_SIGVEC) */ + } +#endif /* !USE_SIGTSTP */ +} diff --git a/contrib/ncurses/ncurses/tty/lib_twait.c b/contrib/ncurses/ncurses/tty/lib_twait.c new file mode 100644 index 0000000..40bd2cd --- /dev/null +++ b/contrib/ncurses/ncurses/tty/lib_twait.c @@ -0,0 +1,221 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* +** lib_twait.c +** +** The routine _nc_timed_wait(). +** +** (This file was originally written by Eric Raymond; however except for +** comments, none of the original code remains - T.Dickey). +*/ + +#include <curses.priv.h> + +#if USE_FUNC_POLL +# include <stropts.h> +# include <poll.h> +# if HAVE_SYS_TIME_H +# include <sys/time.h> +# endif +#elif HAVE_SELECT +# if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT +# include <sys/time.h> +# endif +# if HAVE_SYS_SELECT_H +# include <sys/select.h> +# endif +#endif + +#ifdef __BEOS__ +/* BeOS select() only works on sockets. Use the tty hack instead */ +#include <socket.h> +#define select check_select +#endif + +MODULE_ID("$Id: lib_twait.c,v 1.32 1998/06/06 22:44:14 tom Exp $") + +static int _nc_gettime(void) +{ + int res; + +#if HAVE_GETTIMEOFDAY +# define PRECISE_GETTIME 1 + struct timeval t; + gettimeofday(&t, (struct timezone *)0); + res = t.tv_sec*1000 + t.tv_usec/1000; +#else +# define PRECISE_GETTIME 0 + res = time(0)*1000; +#endif + T(("time: %d msec", res)); + return res; +} + +/* + * Wait a specified number of milliseconds, returning nonzero if the timer + * didn't expire before there is activity on the specified file descriptors. + * The file-descriptors are specified by the mode: + * 0 - none (absolute time) + * 1 - ncurses' normal input-descriptor + * 2 - mouse descriptor, if any + * 3 - either input or mouse. + * 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. + */ +int _nc_timed_wait(int mode, int milliseconds, int *timeleft) +{ +int fd; +int count; + +int result; + +#if USE_FUNC_POLL +struct pollfd fds[2]; +#elif HAVE_SELECT +static fd_set set; +#endif + +int starttime, returntime; + + T(("start twait: %d milliseconds, mode: %d", milliseconds, mode)); + +#if PRECISE_GETTIME +retry: +#endif + starttime = _nc_gettime(); + + count = 0; + +#if USE_FUNC_POLL + if (mode & 1) { + fds[count].fd = SP->_ifd; + fds[count].events = POLLIN; + count++; + } + if ((mode & 2) + && (fd = SP->_mouse_fd) >= 0) { + fds[count].fd = fd; + fds[count].events = POLLIN; + count++; + } + result = poll(fds, count, milliseconds); + +#elif HAVE_SELECT + /* + * select() modifies the fd_set arguments; do this in the + * loop. + */ + FD_ZERO(&set); + + if (mode & 1) { + FD_SET(SP->_ifd, &set); + count = SP->_ifd + 1; + } + if ((mode & 2) + && (fd = SP->_mouse_fd) >= 0) { + FD_SET(fd, &set); + count = max(fd, count) + 1; + } + + if (milliseconds >= 0) { + struct timeval ntimeout; + ntimeout.tv_sec = milliseconds / 1000; + ntimeout.tv_usec = (milliseconds % 1000) * 1000; + result = select(count, &set, NULL, NULL, &ntimeout); + } else { + result = select(count, &set, NULL, NULL, NULL); + } +#endif + + returntime = _nc_gettime(); + + if (milliseconds >= 0) + milliseconds -= returntime-starttime; + +#if PRECISE_GETTIME + /* + * If the timeout hasn't expired, and we've gotten no data, + * this is probably a system where 'select()' needs to be left + * alone so that it can complete. Make this process sleep, + * then come back for more. + */ + if (result == 0 && milliseconds > 100) { + napms(100); + milliseconds -= 100; + goto retry; + } +#endif + + /* return approximate time left in milliseconds */ + if (timeleft) + *timeleft = milliseconds; + + T(("end twait: returned %d (%d), remaining time %d msec", + result, errno, milliseconds)); + + /* + * Both 'poll()' and 'select()' return the number of file descriptors + * that are active. Translate this back to the mask that denotes which + * file-descriptors, so that we don't need all of this system-specific + * code everywhere. + */ + if (result != 0) { + if (result > 0) { + result = 0; +#if USE_FUNC_POLL + for (count = 0; count < 2; count++) { + if ((mode & (1 << count)) + && (fds[count].revents & POLLIN)) { + result |= (1 << count); + count++; + } + } +#elif HAVE_SELECT + if ((mode & 2) + && (fd = SP->_mouse_fd) >= 0 + && FD_ISSET(fd, &set)) + result |= 2; + if ((mode & 1) + && FD_ISSET(SP->_ifd, &set)) + result |= 1; +#endif + } + else + result = 0; + } + + return (result); +} diff --git a/contrib/ncurses/ncurses/tty/lib_vidattr.c b/contrib/ncurses/ncurses/tty/lib_vidattr.c new file mode 100644 index 0000000..20cc2b1 --- /dev/null +++ b/contrib/ncurses/ncurses/tty/lib_vidattr.c @@ -0,0 +1,278 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * vidputs(newmode, outc) + * + * newmode is taken to be the logical 'or' of the symbols in curses.h + * representing graphic renditions. The terminal is set to be in all of + * the given modes, if possible. + * + * if the new attribute is normal + * if exit-alt-char-set exists + * emit it + * emit exit-attribute-mode + * else if set-attributes exists + * use it to set exactly what you want + * else + * if exit-attribute-mode exists + * turn off everything + * else + * turn off those which can be turned off and aren't in + * newmode. + * turn on each mode which should be on and isn't, one by one + * + * NOTE that this algorithm won't achieve the desired mix of attributes + * in some cases, but those are probably just those cases in which it is + * actually impossible, anyway, so... + * + * NOTE that we cannot assume that there's no interaction between color + * and other attribute resets. So each time we reset color (or other + * attributes) we'll have to be prepared to restore the other. + */ + +#include <curses.priv.h> +#include <term.h> + +MODULE_ID("$Id: lib_vidattr.c,v 1.23 1999/06/12 21:20:41 tom Exp $") + +#define doPut(mode) TPUTS_TRACE(#mode); tputs(mode, 1, outc) + +#define TurnOn(mask,mode) \ + if ((turn_on & mask) && mode) { doPut(mode); } + +#define TurnOff(mask,mode) \ + if ((turn_off & mask) && mode) { doPut(mode); turn_off &= ~mask; } + + /* if there is no current screen, assume we *can* do color */ +#define SetColorsIf(why,old_attr) \ + if ((!SP || SP->_coloron) && (why)) { \ + int old_pair = PAIR_NUMBER(old_attr); \ + T(("old pair = %d -- new pair = %d", old_pair, pair)); \ + if ((pair != old_pair) \ + || (reverse ^ ((old_attr & A_REVERSE) != 0))) { \ + _nc_do_color(pair, reverse, outc); \ + } \ + } + +int vidputs(attr_t newmode, int (*outc)(int)) +{ +static attr_t previous_attr = A_NORMAL; +attr_t turn_on, turn_off; +int pair; +bool reverse = FALSE; +bool used_ncv = FALSE; + + T((T_CALLED("vidputs(%s)"), _traceattr(newmode))); + + /* this allows us to go on whether or not newterm() has been called */ + if (SP) + previous_attr = SP->_current_attr; + + T(("previous attribute was %s", _traceattr(previous_attr))); + +#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 ((newmode & A_COLOR) + && (no_color_video > 0)) { + static const struct { + attr_t video; + unsigned bit; + } table[] = { + { A_STANDOUT, 1 }, + { A_UNDERLINE, 2 }, + { A_REVERSE, 4 }, + { A_BLINK, 8 }, + { A_DIM, 16 }, + { A_BOLD, 32 }, + { A_INVIS, 64 }, + { A_PROTECT, 128 }, + { A_ALTCHARSET, 256 }, + }; + size_t n; + for (n = 0; n < SIZEOF(table); n++) { + if ((table[n].bit & no_color_video) + && (table[n].video & newmode)) { + used_ncv = TRUE; + if (table[n].video == A_REVERSE) + reverse = TRUE; + else + newmode &= ~table[n].video; + } + } + } + + if (newmode == previous_attr) + returnCode(OK); + + pair = PAIR_NUMBER(newmode); + + if (reverse) { + newmode &= ~A_REVERSE; + } + + turn_off = (~newmode & previous_attr) & ALL_BUT_COLOR; + turn_on = (newmode & ~previous_attr) & ALL_BUT_COLOR; + + SetColorsIf(pair == 0, previous_attr); + + 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) { + doPut(exit_attribute_mode); + previous_attr &= ~A_COLOR; + } + + SetColorsIf(pair != 0, previous_attr); + } else if (set_attributes && !used_ncv) { + if (turn_on || turn_off) { + TPUTS_TRACE("set_attributes"); + tputs(tparm(set_attributes, + (newmode & A_STANDOUT) != 0, + (newmode & A_UNDERLINE) != 0, + (newmode & A_REVERSE) != 0, + (newmode & A_BLINK) != 0, + (newmode & A_DIM) != 0, + (newmode & A_BOLD) != 0, + (newmode & A_INVIS) != 0, + (newmode & A_PROTECT) != 0, + (newmode & A_ALTCHARSET) != 0), 1, outc); + previous_attr &= ~A_COLOR; + } + SetColorsIf(pair != 0, previous_attr); + } else { + + T(("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 & (chtype)(~A_COLOR)); + previous_attr &= ~A_COLOR; + } + SetColorsIf(pair != 0, previous_attr); + + T(("turning %s on", _traceattr(turn_on))); + + 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); + 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); + } + + if (reverse) + newmode |= A_REVERSE; + + if (SP) + SP->_current_attr = newmode; + else + previous_attr = newmode; + + returnCode(OK); +} + +int vidattr(attr_t newmode) +{ + T((T_CALLED("vidattr(%s)"), _traceattr(newmode))); + + returnCode(vidputs(newmode, _nc_outch)); +} + +chtype termattrs(void) +{ + chtype attrs = A_NORMAL; + + if (enter_alt_charset_mode) + attrs |= A_ALTCHARSET; + + if (enter_blink_mode) + attrs |= A_BLINK; + + if (enter_bold_mode) + attrs |= A_BOLD; + + if (enter_dim_mode) + attrs |= A_DIM; + + if (enter_reverse_mode) + attrs |= A_REVERSE; + + if (enter_standout_mode) + attrs |= A_STANDOUT; + + if (enter_protected_mode) + attrs |= A_PROTECT; + + if (enter_secure_mode) + attrs |= A_INVIS; + + if (enter_underline_mode) + attrs |= A_UNDERLINE; + + if (SP->_coloron) + attrs |= A_COLOR; + + return(attrs); +} + diff --git a/contrib/ncurses/ncurses/tty/tty_display.h b/contrib/ncurses/ncurses/tty/tty_display.h new file mode 100644 index 0000000..1bc0d2d --- /dev/null +++ b/contrib/ncurses/ncurses/tty/tty_display.h @@ -0,0 +1,146 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ************************************************************************** */ + +#ifndef TTY_DISPLAY_H +#define TTY_DISPLAY_H 1 + +extern bool _nc_tty_beep(void); +extern bool _nc_tty_check_resize(void); +extern bool _nc_tty_cursor(int); +extern bool _nc_tty_flash(void); +extern bool _nc_tty_init_color(int,int,int,int); +extern bool _nc_tty_init_pair(int,int,int); +extern bool _nc_tty_slk_hide(bool); +extern bool _nc_tty_slk_update(int,const char *); +extern bool _nc_tty_start_color(void); +extern void _nc_tty_display_resume(void); +extern void _nc_tty_display_suspend(void); +extern void _nc_tty_dispose(void); /* frees SP->_term */ +extern void _nc_tty_switch_to(void); +extern void _nc_tty_update(void); + +struct tty_display_data { + int _fifohold; /* set if breakout marked */ + unsigned long _current_attr; /* terminal attribute current set */ + int _cursrow; /* physical cursor row (-1=unknown) */ + int _curscol; /* physical cursor column */ + + /* cursor movement costs; units are 10ths of milliseconds */ + int _char_padding; /* cost of character put */ + int _cr_cost; /* cost of (carriage_return) */ + int _cup_cost; /* cost of (cursor_address) */ + int _home_cost; /* cost of (cursor_home) */ + int _ll_cost; /* cost of (cursor_to_ll) */ +#if USE_HARD_TABS + int _ht_cost; /* cost of (tab) */ + int _cbt_cost; /* cost of (backtab) */ +#endif /* USE_HARD_TABS */ + int _cub1_cost; /* cost of (cursor_left) */ + int _cuf1_cost; /* cost of (cursor_right) */ + int _cud1_cost; /* cost of (cursor_down) */ + int _cuu1_cost; /* cost of (cursor_up) */ + int _cub_cost; /* cost of (parm_cursor_left) */ + int _cuf_cost; /* cost of (parm_cursor_right) */ + int _cud_cost; /* cost of (parm_cursor_down) */ + int _cuu_cost; /* cost of (parm_cursor_up) */ + int _hpa_cost; /* cost of (column_address) */ + int _vpa_cost; /* cost of (row_address) */ + /* used in lib_doupdate.c, must be chars */ + int _ed_cost; /* cost of (clr_eos) */ + int _el_cost; /* cost of (clr_eol) */ + int _el1_cost; /* cost of (clr_bol) */ + int _dch1_cost; /* cost of (delete_character) */ + int _ich1_cost; /* cost of (insert_character) */ + int _dch_cost; /* cost of (parm_dch) */ + int _ich_cost; /* cost of (parm_ich) */ + int _ech_cost; /* cost of (erase_chars) */ + int _rep_cost; /* cost of (repeat_char) */ + int _hpa_ch_cost; /* cost of (column_address) */ + int _cup_ch_cost; /* cost of (cursor_address) */ + int _smir_cost; /* cost of (enter_insert_mode) */ + int _rmir_cost; /* cost of (exit_insert_mode) */ + int _ip_cost; /* cost of (insert_padding) */ + /* used in lib_mvcur.c */ + char * _address_cursor; + int _carriage_return_length; + int _cursor_home_length; + int _cursor_to_ll_length; + + chtype _xmc_suppress; /* attributes to suppress if xmc */ + chtype _xmc_triggers; /* attributes to process if xmc */ + + bool _sig_winch; +}; + + +#define DelCharCost(count) \ + ((parm_dch != 0) \ + ? D->_dch_cost \ + : ((delete_character != 0) \ + ? (D->_dch1_cost * count) \ + : INFINITY)) + +#define InsCharCost(count) \ + ((parm_ich != 0) \ + ? D->_ich_cost \ + : ((enter_insert_mode && exit_insert_mode) \ + ? D->_smir_cost + D->_rmir_cost + (D->_ip_cost * count) \ + : ((insert_character != 0) \ + ? (D->_ich1_cost * count) \ + : INFINITY))) + +#if USE_XMC_SUPPORT +#define UpdateAttrs(c) if (D->_current_attr != AttrOf(c)) { \ + attr_t chg = D->_current_attr; \ + vidattr(AttrOf(c)); \ + if (magic_cookie_glitch > 0 \ + && XMC_CHANGES((chg ^ D->_current_attr))) { \ + T(("%s @%d before glitch %d,%d", \ + __FILE__, __LINE__, \ + D->_cursrow, \ + D->_curscol)); \ + _nc_do_xmc_glitch(chg); \ + } \ + } +#else +#define UpdateAttrs(c) if (D->_current_attr != AttrOf(c)) \ + vidattr(AttrOf(c)); +#endif + +/* + * Check whether the given character can be output by clearing commands. This + * includes test for being a space and not including any 'bad' attributes, such + * as A_REVERSE. All attribute flags which don't affect appearance of a space + * or can be output by clearing (A_COLOR in case of bce-terminal) are excluded. + */ +#define can_clear_with(ch) \ + ((ch & ~(NONBLANK_ATTR|(back_color_erase ? A_COLOR:0))) == BLANK) + +#define XMC_CHANGES(c) ((c) & D->_xmc_suppress) + +#endif /* TTY_DISPLAY_H */ diff --git a/contrib/ncurses/ncurses/tty/tty_input.h b/contrib/ncurses/ncurses/tty/tty_input.h new file mode 100644 index 0000000..41c2283 --- /dev/null +++ b/contrib/ncurses/ncurses/tty/tty_input.h @@ -0,0 +1,61 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/* + * $Id: tty_input.h,v 1.1 1998/12/19 22:42:57 tom Exp $ + */ + +#ifndef TTY_INPUT_H +#define TTY_INPUT_H 1 + +extern bool _nc_tty_mouse_mask(mmask_t); +extern bool _nc_tty_pending(void); +extern int _nc_tty_next_event(int); +extern void _nc_tty_flags_changed(void); +extern void _nc_tty_flush(void); +extern void _nc_tty_input_resume(void); +extern void _nc_tty_input_suspend(void); + +struct tty_input_data { + int _ifd; /* input file ptr for screen */ + int _keypad_xmit; /* current terminal state */ + int _meta_on; /* current terminal state */ + + /* + * These are the data that support the mouse interface. + */ + bool (*_mouse_event) (SCREEN *); + bool (*_mouse_inline)(SCREEN *); + bool (*_mouse_parse) (int); + void (*_mouse_resume)(SCREEN *); + void (*_mouse_wrap) (SCREEN *); + int _mouse_fd; /* file-descriptor, if any */ + int mousetype; +}; + +#endif /* TTY_INPUT_H */ diff --git a/contrib/ncurses/ncurses/tty/tty_update.c b/contrib/ncurses/ncurses/tty/tty_update.c new file mode 100644 index 0000000..4118d35 --- /dev/null +++ b/contrib/ncurses/ncurses/tty/tty_update.c @@ -0,0 +1,1738 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + + +/*----------------------------------------------------------------- + * + * lib_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). + * + *-----------------------------------------------------------------*/ + +#include <curses.priv.h> + +#if defined(TRACE) && HAVE_SYS_TIMES_H && HAVE_TIMES +#define USE_TRACE_TIMES 1 +#else +#define USE_TRACE_TIMES 0 +#endif + +#if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT +#include <sys/time.h> +#endif + +#if USE_TRACE_TIMES +#include <sys/times.h> +#endif + +#if USE_FUNC_POLL +#include <stropts.h> +#include <poll.h> +#elif HAVE_SELECT +#if HAVE_SYS_SELECT_H +#include <sys/select.h> +#endif +#endif + +#ifdef __BEOS__ +/* BeOS select() only works on sockets. Use the tty hack instead */ +#include <socket.h> +#define select check_select +#endif + +#include <term.h> + +MODULE_ID("$Id: tty_update.c,v 1.111 1999/02/27 20:07:56 tom Exp $") + +/* + * This define controls the line-breakout optimization. Every once in a + * while during screen refresh, we want to check for input and abort the + * update if there's some waiting. CHECK_INTERVAL controls the number of + * changed lines to be emitted between input checks. + * + * Note: Input-check-and-abort is no longer done if the screen is being + * updated from scratch. This is a feature, not a bug. + */ +#define CHECK_INTERVAL 5 + +/* + * Enable checking to see if doupdate and friends are tracking the true + * cursor position correctly. NOTE: this is a debugging hack which will + * work ONLY on ANSI-compatible terminals! + */ +/* #define POSITION_DEBUG */ + +static inline chtype ClrBlank ( WINDOW *win ); +static int ClrBottom(int total); +static int InsStr( chtype *line, int count ); +static void ClearScreen( chtype blank ); +static void ClrUpdate( void ); +static void DelChar( int count ); +static void TransformLine( int const lineno ); + +#ifdef POSITION_DEBUG +/**************************************************************************** + * + * Debugging code. Only works on ANSI-standard terminals. + * + ****************************************************************************/ + +void position_check(int expected_y, int expected_x, char *legend) +/* check to see if the real cursor position matches the virtual */ +{ + static char buf[9]; + int y, x; + + if (_nc_tracing) + return; + + memset(buf, '\0', sizeof(buf)); + (void) write(1, "\033[6n", 4); /* only works on ANSI-compatibles */ + (void) read(0, (void *)buf, 8); + _tracef("probe returned %s", _nc_visbuf(buf)); + + /* try to interpret as a position report */ + if (sscanf(buf, "\033[%d;%dR", &y, &x) != 2) + _tracef("position probe failed in %s", legend); + else if (y - 1 != expected_y || x - 1 != expected_x) + _tracef("position seen (%d, %d) doesn't match expected one (%d, %d) in %s", + y-1, x-1, expected_y, expected_x, legend); + else + _tracef("position matches OK in %s", legend); +} +#endif /* POSITION_DEBUG */ + +/**************************************************************************** + * + * Optimized update code + * + ****************************************************************************/ + +static inline void GoTo(int const row, int const col) +{ + chtype oldattr = SP->_current_attr; + + TR(TRACE_MOVE, ("GoTo(%d, %d) from (%d, %d)", + row, col, SP->_cursrow, SP->_curscol)); + +#ifdef POSITION_DEBUG + position_check(SP->_cursrow, SP->_curscol, "GoTo"); +#endif /* POSITION_DEBUG */ + + /* + * 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; +} + +static inline void PutAttrChar(chtype ch) +{ + if (tilde_glitch && (TextOf(ch) == '~')) + ch = ('`' | AttrOf(ch)); + + TR(TRACE_CHARPUT, ("PutAttrChar(%s) at (%d, %d)", + _tracechtype(ch), + SP->_cursrow, SP->_curscol)); + UpdateAttrs(ch); + putc((int)TextOf(ch), SP->_ofp); +#ifdef TRACE + _nc_outchars++; +#endif /* TRACE */ + SP->_curscol++; + if (char_padding) { + TPUTS_TRACE("char_padding"); + putp(char_padding); + } +} + +static bool check_pending(void) +/* check for pending input */ +{ + bool have_pending = FALSE; + + /* + * Only carry out this check when the flag is zero, otherwise we'll + * have the refreshing slow down drastically (or stop) if there's an + * unread character available. + */ + if(SP->_fifohold != 0) + return FALSE; + + if (SP->_checkfd >= 0) { +#if USE_FUNC_POLL + struct pollfd fds[1]; + fds[0].fd = SP->_checkfd; + fds[0].events = POLLIN; + if (poll(fds, 1, 0) > 0) + { + have_pending = TRUE; + } +#elif HAVE_SELECT + fd_set fdset; + struct timeval ktimeout; + + ktimeout.tv_sec = + ktimeout.tv_usec = 0; + + FD_ZERO(&fdset); + FD_SET(SP->_checkfd, &fdset); + if (select(SP->_checkfd+1, &fdset, NULL, NULL, &ktimeout) != 0) + { + have_pending = TRUE; + } +#endif + } + if (have_pending) { + SP->_fifohold = 5; + fflush(SP->_ofp); + } + return FALSE; +} + +/* + * No one supports recursive inline functions. However, gcc is quieter if we + * instantiate the recursive part separately. + */ +#if CC_HAS_INLINE_FUNCS +static void callPutChar(chtype const); +#else +#define callPutChar(ch) PutChar(ch) +#endif + +static inline void PutChar(chtype const ch); /* forward declaration */ + +/* put char at lower right corner */ +static void PutCharLR(chtype const ch) +{ + if (!auto_right_margin) + { + /* we can put the char directly */ + PutAttrChar(ch); + } + else if (enter_am_mode && exit_am_mode) + { + /* we can suppress automargin */ + TPUTS_TRACE("exit_am_mode"); + putp(exit_am_mode); + + PutAttrChar(ch); + + TPUTS_TRACE("enter_am_mode"); + putp(enter_am_mode); + } + else if ((enter_insert_mode && exit_insert_mode) + || insert_character || parm_ich) + { + GoTo(screen_lines-1,screen_columns-2); + callPutChar(ch); + GoTo(screen_lines-1,screen_columns-2); + InsStr(newscr->_line[screen_lines-1].text+screen_columns-2,1); + } +} + +static void wrap_cursor(void) +{ + if (eat_newline_glitch) + { + /* + * xenl can manifest two different ways. The vt100 + * way is that, when you'd expect the cursor to wrap, + * it stays hung at the right margin (on top of the + * character just emitted) and doesn't wrap until the + * *next* graphic char is emitted. The c100 way is + * to ignore LF received just after an am wrap. + * + * An aggressive way to handle this would be to + * emit CR/LF after the char and then assume the wrap + * is done, you're on the first position of the next + * line, and the terminal out of its weird state. + * Here it's safe to just tell the code that the + * cursor is in hyperspace and let the next mvcur() + * call straighten things out. + */ + SP->_curscol = -1; + SP->_cursrow = -1; + } + else if (auto_right_margin) + { + SP->_curscol = 0; + SP->_cursrow++; + } + else + { + SP->_curscol--; + } +} + +static inline void PutChar(chtype const ch) +/* insert character, handling automargin stuff */ +{ + if (SP->_cursrow == screen_lines-1 && SP->_curscol == screen_columns-1) + PutCharLR(ch); + else + PutAttrChar(ch); + + if (SP->_curscol >= screen_columns) + wrap_cursor(); + +#ifdef POSITION_DEBUG + position_check(SP->_cursrow, SP->_curscol, "PutChar"); +#endif /* POSITION_DEBUG */ +} + +/* + * Issue a given span of characters from an array. + * Must be functionally equivalent to: + * for (i = 0; i < num; i++) + * PutChar(ntext[i]); + * but can leave the cursor positioned at the middle of the interval. + * + * Returns: 0 - cursor is at the end of interval + * 1 - cursor is somewhere in the middle + * + * This code is optimized using ech and rep. + */ +static int EmitRange(const chtype *ntext, int num) +{ + int i; + + if (erase_chars || repeat_char) + { + while (num > 0) + { + int runcount; + chtype ntext0; + + while (num>1 && ntext[0]!=ntext[1]) + { + PutChar(ntext[0]); + ntext++; + num--; + } + ntext0 = ntext[0]; + if (num==1) + { + PutChar(ntext0); + return 0; + } + runcount = 2; + + while (runcount < num && ntext[runcount] == ntext0) + runcount++; + + /* + * The cost expression in the middle isn't exactly right. + * _cup_cost is an upper bound on the cost for moving to the + * end of the erased area, but not the cost itself (which we + * can't compute without emitting the move). This may result + * in erase_chars not getting used in some situations for + * which it would be marginally advantageous. + */ + if (erase_chars + && runcount > SP->_ech_cost + SP->_cup_cost + && can_clear_with(ntext0)) + { + UpdateAttrs(ntext0); + putp(tparm(erase_chars, runcount)); + + /* + * If this is the last part of the given interval, + * don't bother moving cursor, since it can be the + * last update on the line. + */ + if (runcount < num) + GoTo(SP->_cursrow, SP->_curscol + runcount); + else + return 1; /* cursor stays in the middle */ + } + else if (repeat_char && runcount > SP->_rep_cost) + { + bool wrap_possible = (SP->_curscol + runcount >= screen_columns); + int rep_count = runcount; + + if (wrap_possible) + rep_count--; + + UpdateAttrs(ntext0); + putp(tparm(repeat_char, TextOf(ntext0), rep_count)); + SP->_curscol += rep_count; + + if (wrap_possible) + PutChar(ntext0); + } + else + { + for (i = 0; i < runcount; i++) + PutChar(ntext[i]); + } + ntext += runcount; + num -= runcount; + } + return 0; + } + + for (i = 0; i < num; i++) + PutChar(ntext[i]); + return 0; +} + +/* + * Output the line in the given range [first .. last] + * + * If there's a run of identical characters that's long enough to justify + * cursor movement, use that also. + * + * Returns: same as EmitRange + */ +static int PutRange( + const chtype *otext, + const chtype *ntext, + int row, + int first, int last) +{ + int j, run; + int cost = min(SP->_cup_ch_cost, SP->_hpa_ch_cost); + + TR(TRACE_CHARPUT, ("PutRange(%p, %p, %d, %d, %d)", + otext, ntext, row, first, last)); + + if (otext != ntext + && (last-first+1) > cost) { + for (j = first, run = 0; j <= last; j++) { + if (otext[j] == ntext[j]) { + run++; + } else { + if (run > cost) { + int before_run = (j - run); + EmitRange(ntext+first, before_run-first); + GoTo(row, first = j); + } + run = 0; + } + } + } + return EmitRange(ntext + first, last-first+1); +} + +#if CC_HAS_INLINE_FUNCS +static void callPutChar(chtype const ch) +{ + PutChar(ch); +} +#endif + +#define MARK_NOCHANGE(win,row) \ + { \ + win->_line[row].firstchar = _NOCHANGE; \ + win->_line[row].lastchar = _NOCHANGE; \ + if_USE_SCROLL_HINTS(win->_line[row].oldindex = row); \ + } + +int doupdate(void) +{ +int i; +int nonempty; +#if USE_TRACE_TIMES +struct tms before, after; +#endif /* USE_TRACE_TIMES */ + + T((T_CALLED("doupdate()"))); + +#ifdef TRACE + if (_nc_tracing & TRACE_UPDATE) + { + if (curscr->_clear) + _tracef("curscr is clear"); + else + _tracedump("curscr", curscr); + _tracedump("newscr", newscr); + } +#endif /* TRACE */ + + _nc_signal_handler(FALSE); + + if (SP->_fifohold) + SP->_fifohold--; + +#if USE_SIZECHANGE + if (SP->_endwin || SP->_sig_winch) + { + /* + * This is a transparent extension: XSI does not address it, + * and applications need not know that ncurses can do it. + * + * Check if the terminal size has changed while curses was off + * (this can happen in an xterm, for example), and resize the + * ncurses data structures accordingly. + */ + _nc_update_screensize(); + } +#endif + + if (SP->_endwin) { + + T(("coming back from shell mode")); + reset_prog_mode(); + + _nc_mvcur_resume(); + _nc_screen_resume(); + SP->_mouse_resume(SP); + + SP->_endwin = FALSE; + } + +#if USE_TRACE_TIMES + /* zero the metering machinery */ + _nc_outchars = 0; + (void) times(&before); +#endif /* USE_TRACE_TIMES */ + + /* + * This is the support for magic-cookie terminals. The + * theory: we scan the virtual screen looking for attribute + * turnons. Where we find one, check to make sure it's + * realizable by seeing if the required number of + * un-attributed blanks are present before and after the + * attributed range; try to shift the range boundaries over + * blanks (not changing the screen display) so this becomes + * true. If it is, shift the beginning attribute change + * appropriately (the end one, if we've gotten this far, is + * guaranteed room for its cookie). If not, nuke the added + * attributes out of the span. + */ +#if USE_XMC_SUPPORT + if (magic_cookie_glitch > 0) { + int j, k; + attr_t rattr = A_NORMAL; + + for (i = 0; i < screen_lines; i++) + for (j = 0; j < screen_columns; j++) + { + bool failed = FALSE; + chtype turnon = AttrOf(newscr->_line[i].text[j]) & ~rattr; + + /* is an attribute turned on here? */ + if (turnon == 0) { + rattr = AttrOf(newscr->_line[i].text[j]); + continue; + } + + T(("At (%d, %d): from %s...", i, j, _traceattr(rattr))); + T(("...to %s",_traceattr(turnon))); + + /* + * If the attribute change location is a blank with a + * "safe" attribute, undo the attribute turnon. This may + * ensure there's enough room to set the attribute before + * the first non-blank in the run. + */ +#define SAFE(a) !((a) & (chtype)~NONBLANK_ATTR) + if (TextOf(newscr->_line[i].text[j])==' ' && SAFE(turnon)) + { + newscr->_line[i].text[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 + || TextOf(newscr->_line[i].text[j-k]) != ' ' + || !SAFE(AttrOf(newscr->_line[i].text[j-k]))) + failed = TRUE; + if (!failed) + { + bool end_onscreen = FALSE; + int m, n = j; + + /* find end of span, if it's onscreen */ + for (m = i; m < screen_lines; m++) + { + for ( ; n < screen_columns; n++) + { + if (AttrOf(newscr->_line[m].text[n]) == rattr) + { + end_onscreen = TRUE; + T(("Range attributed with %s ends at (%d, %d)", + _traceattr(turnon),m,n)); + goto foundit; + } + } + n = 0; + } + T(("Range attributed with %s ends offscreen", + _traceattr(turnon))); + foundit:; + + if (end_onscreen) + { + chtype *lastline = newscr->_line[m].text; + + /* + * If there are safely-attributed blanks at the + * end of the range, shorten the range. This will + * help ensure that there is enough room at end + * of span. + */ + while (n >= 0 + && TextOf(lastline[n]) == ' ' + && SAFE(AttrOf(lastline[n]))) + lastline[n--] &= ~turnon; + + /* check that there's enough room at end of span */ + for (k = 1; k <= magic_cookie_glitch; k++) + if (n + k >= screen_columns + || TextOf(lastline[n + k]) != ' ' + || !SAFE(AttrOf(lastline[n+k]))) + failed = TRUE; + } + } + + if (failed) + { + int p, q = j; + + T(("Clearing %s beginning at (%d, %d)", + _traceattr(turnon), i, j)); + + /* turn off new attributes over span */ + for (p = i; p < screen_lines; p++) + { + for ( ; q < screen_columns; q++) + { + if (AttrOf(newscr->_line[p].text[q]) == rattr) + goto foundend; + newscr->_line[p].text[q] &= ~turnon; + } + q = 0; + } + foundend:; + } + else + { + T(("Cookie space for %s found before (%d, %d)", + _traceattr(turnon), i, j)); + + /* + * back up the start of range so there's room + * for cookies before the first nonblank character + */ + for (k = 1; k <= magic_cookie_glitch; k++) + newscr->_line[i].text[j-k] |= turnon; + } + + rattr = AttrOf(newscr->_line[i].text[j]); + } + +#ifdef TRACE + /* show altered highlights after magic-cookie check */ + if (_nc_tracing & TRACE_UPDATE) + { + _tracef("After magic-cookie check..."); + _tracedump("newscr", newscr); + } +#endif /* TRACE */ + } +#endif /* USE_XMC_SUPPORT */ + + nonempty = 0; + if (curscr->_clear || newscr->_clear) { /* force refresh ? */ + T(("clearing and updating from scratch")); + ClrUpdate(); + curscr->_clear = FALSE; /* reset flag */ + newscr->_clear = FALSE; /* reset flag */ + } else { + int changedlines = CHECK_INTERVAL; + + if(check_pending()) + goto cleanup; + + nonempty = min(screen_lines, newscr->_maxy+1); + + if (SP->_scrolling) { + _nc_scroll_optimize(); + } + + nonempty = ClrBottom(nonempty); + + T(("Transforming lines, nonempty %d", nonempty)); + for (i = 0; i < nonempty; i++) { + /* + * Here is our line-breakout optimization. + */ + if (changedlines == CHECK_INTERVAL) + { + if (check_pending()) + goto cleanup; + changedlines = 0; + } + + /* + * newscr->line[i].firstchar is normally set + * by wnoutrefresh. curscr->line[i].firstchar + * is normally set by _nc_scroll_window in the + * vertical-movement optimization code, + */ + if (newscr->_line[i].firstchar != _NOCHANGE + || curscr->_line[i].firstchar != _NOCHANGE) + { + TransformLine(i); + changedlines++; + } + + /* mark line changed successfully */ + if (i <= newscr->_maxy) + MARK_NOCHANGE(newscr,i) + if (i <= curscr->_maxy) + MARK_NOCHANGE(curscr,i) + } + } + + /* put everything back in sync */ + for (i = nonempty; i <= newscr->_maxy; i++) + MARK_NOCHANGE(newscr,i) + for (i = nonempty; i <= curscr->_maxy; i++) + MARK_NOCHANGE(curscr,i) + + if (!newscr->_leaveok) + { + curscr->_curx = newscr->_curx; + curscr->_cury = newscr->_cury; + + GoTo(curscr->_cury, curscr->_curx); + } + + cleanup: + /* + * Keep the physical screen in normal mode in case we get other + * processes writing to the screen. + */ + UpdateAttrs(A_NORMAL); + + fflush(SP->_ofp); + curscr->_attrs = newscr->_attrs; +/* curscr->_bkgd = newscr->_bkgd; */ + +#if USE_TRACE_TIMES + (void) times(&after); + TR(TRACE_TIMES, ("Update cost: %ld chars, %ld clocks system time, %ld clocks user time", + _nc_outchars, + after.tms_stime-before.tms_stime, + after.tms_utime-before.tms_utime)); +#endif /* USE_TRACE_TIMES */ + + _nc_signal_handler(TRUE); + + returnCode(OK); +} + +/* + * ClrBlank(win) + * + * Returns the attributed character that corresponds to the "cleared" + * screen. If the terminal has the back-color-erase feature, this will be + * colored according to the wbkgd() call. + * + * We treat 'curscr' specially because it isn't supposed to be set directly + * in the wbkgd() call. Assume 'stdscr' for this case. + */ +#define BCE_ATTRS (A_NORMAL|A_COLOR) +#define BCE_BKGD(win) (((win) == curscr ? stdscr : (win))->_bkgd) + +static inline chtype ClrBlank (WINDOW *win) +{ +chtype blank = BLANK; + if (back_color_erase) + blank |= (BCE_BKGD(win) & BCE_ATTRS); + return blank; +} + +/* +** ClrUpdate() +** +** Update by clearing and redrawing the entire screen. +** +*/ + +static void ClrUpdate(void) +{ + int i; + chtype blank = ClrBlank(stdscr); + int nonempty = min(screen_lines, newscr->_maxy+1); + + T(("ClrUpdate() called")); + + ClearScreen(blank); + + T(("updating screen from scratch")); + + nonempty = ClrBottom(nonempty); + + for (i = 0; i < nonempty; i++) + TransformLine(i); +} + +/* +** ClrToEOL(blank) +** +** Clear to end of current line, starting at the cursor position +*/ + +static void ClrToEOL(chtype blank) +{ +int j; +bool needclear = FALSE; + + for (j = SP->_curscol; j < screen_columns; j++) + { + chtype *cp = &(curscr->_line[SP->_cursrow].text[j]); + + if (*cp != blank) + { + *cp = blank; + needclear = TRUE; + } + } + + if (needclear) + { + UpdateAttrs(blank); + TPUTS_TRACE("clr_eol"); + if (SP->_el_cost > (screen_columns - SP->_curscol)) + { + int count = (screen_columns - SP->_curscol); + while (count-- > 0) + PutChar(blank); + } + else + putp(clr_eol); + } +} + +/* +** ClrToEOS(blank) +** +** Clear to end of screen, starting at the cursor position +*/ + +static void ClrToEOS(chtype blank) +{ +int row, col; + + UpdateAttrs(blank); + TPUTS_TRACE("clr_eos"); + row = SP->_cursrow; + tputs(clr_eos, screen_lines-row, _nc_outch); + + for (col = SP->_curscol; col < screen_columns; col++) + curscr->_line[row].text[col] = blank; + + for (row++; row < screen_lines; row++) + { + for (col = 0; col < screen_columns; col++) + curscr->_line[row].text[col] = blank; + } +} + +/* + * ClrBottom(total) + * + * Test if clearing the end of the screen would satisfy part of the + * screen-update. Do this by scanning backwards through the lines in the + * screen, checking if each is blank, and one or more are changed. + */ +static int ClrBottom(int total) +{ +static chtype *tstLine; +static size_t lenLine; + +int row, col; +int top = total; +int last = min(screen_columns, newscr->_maxx+1); +size_t length = sizeof(chtype) * last; +chtype blank = newscr->_line[total-1].text[last-1]; /* lower right char */ + + if(!clr_eos || !can_clear_with(blank)) + return total; + + if ((tstLine == 0) || (last > (int)lenLine)) { + tstLine = typeRealloc(chtype, last, tstLine); + } + + if (tstLine != 0) { + lenLine = last; + for (col = 0; col < last; col++) + tstLine[col] = blank; + + for (row = total-1; row >= 0; row--) { + if (memcmp(tstLine, newscr->_line[row].text, length)) + break; + if (memcmp(tstLine, curscr->_line[row].text, length)) + top = row; + } + + /* don't use clr_eos for just one line if clr_eol available */ + if (top < total-1 || (top < total && !clr_eol && !clr_bol)) { + 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]; + } + } + } +#if NO_LEAKS + if (tstLine != 0) + FreeAndNull(tstLine); +#endif + return total; +} + + +/* +** TransformLine(lineno) +** +** Transform the given line in curscr to the one in newscr, using +** Insert/Delete Character if _nc_idcok && has_ic(). +** +** firstChar = position of first different character in line +** oLastChar = position of last different character in old line +** nLastChar = position of last different character in new line +** +** move to firstChar +** overwrite chars up to min(oLastChar, nLastChar) +** if oLastChar < nLastChar +** insert newLine[oLastChar+1..nLastChar] +** else +** delete oLastChar - nLastChar spaces +*/ + +static void TransformLine(int const lineno) +{ +int firstChar, oLastChar, nLastChar; +chtype *newLine = newscr->_line[lineno].text; +chtype *oldLine = curscr->_line[lineno].text; +int n; +bool attrchanged = FALSE; + + T(("TransformLine(%d) called", lineno)); + + /* copy new hash value to old one */ + if (SP->oldhash && SP->newhash) + SP->oldhash[lineno] = SP->newhash[lineno]; + + if(ceol_standout_glitch && clr_eol) { + firstChar = 0; + while(firstChar < screen_columns) { + if(AttrOf(newLine[firstChar]) != AttrOf(oldLine[firstChar])) + attrchanged = TRUE; + firstChar++; + } + } + + firstChar = 0; + + if (attrchanged) { /* we may have to disregard the whole line */ + GoTo(lineno, firstChar); + ClrToEOL(ClrBlank(curscr)); + PutRange(oldLine, newLine, lineno, 0, (screen_columns-1)); +#if USE_XMC_SUPPORT + +#define NEW(r,c) newscr->_line[r].text[c] +#define xmc_turn_on(a,b) ((((a)^(b)) & ~(a) & SP->_xmc_triggers) != 0) +#define xmc_turn_off(a,b) xmc_turn_on(b,a) + + /* + * This is a very simple loop to paint characters which may have the + * magic cookie glitch embedded. It doesn't know much about video + * attributes which are continued from one line to the next. It + * assumes that we have filtered out requests for attribute changes + * that do not get mapped to blank positions. + * + * FIXME: we are not keeping track of where we put the cookies, so this + * will work properly only once, since we may overwrite a cookie in a + * following operation. + */ + } else if (magic_cookie_glitch > 0) { + GoTo(lineno, firstChar); + for (n = 0; n < screen_columns; n++) { + int m = n + magic_cookie_glitch; + + /* check for turn-on: + * If we are writing an attributed blank, where the + * previous cell is not attributed. + */ + if (TextOf(newLine[n]) == ' ' + && ((n > 0 + && xmc_turn_on(newLine[n-1], newLine[n])) + || (n == 0 + && lineno > 0 + && xmc_turn_on(NEW(lineno-1,screen_columns-1), newLine[n])))) { + n = m; + } + + PutChar(newLine[n]); + + /* check for turn-off: + * If we are writing an attributed non-blank, where the + * next cell is blank, and not attributed. + */ + if (TextOf(newLine[n]) != ' ' + && ((n+1 < screen_columns + && xmc_turn_off(newLine[n], newLine[n+1])) + || (n+1 >= screen_columns + && lineno+1 < screen_lines + && xmc_turn_off(newLine[n], NEW(lineno+1,0))))) { + n = m; + } + + } +#undef NEW +#endif + } else { + chtype blank; + + /* find the first differing character */ + while (firstChar < screen_columns && + 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 && can_clear_with(blank=newLine[0])) + { + int oFirstChar, nFirstChar; + + for (oFirstChar = 0; oFirstChar < screen_columns; oFirstChar++) + if (oldLine[oFirstChar] != blank) + break; + for (nFirstChar = 0; nFirstChar < screen_columns; nFirstChar++) + if (newLine[nFirstChar] != blank) + break; + + if (nFirstChar > oFirstChar + SP->_el1_cost) + { + if (nFirstChar >= screen_columns && SP->_el_cost <= SP->_el1_cost) + { + GoTo(lineno, 0); + UpdateAttrs(blank); + TPUTS_TRACE("clr_eol"); + putp(clr_eol); + } + else + { + GoTo(lineno, nFirstChar - 1); + UpdateAttrs(blank); + TPUTS_TRACE("clr_bol"); + putp(clr_bol); + } + + while (firstChar < nFirstChar) + oldLine[firstChar++] = blank; + + if (firstChar >= screen_columns) + return; + } + } + + blank = newLine[screen_columns-1]; + + if(!can_clear_with(blank)) + { + /* find the last differing character */ + nLastChar = screen_columns - 1; + + while (nLastChar > firstChar + && newLine[nLastChar] == oldLine[nLastChar]) + nLastChar--; + + if (nLastChar >= firstChar) { + GoTo(lineno, firstChar); + PutRange(oldLine, newLine, lineno, firstChar, nLastChar); + memcpy( oldLine + firstChar, + newLine + firstChar, + (nLastChar - firstChar + 1) * sizeof(chtype)); + } + return; + } + + /* find last non-blank character on old line */ + oLastChar = screen_columns - 1; + while (oLastChar > firstChar && oldLine[oLastChar] == blank) + oLastChar--; + + /* find last non-blank character on new line */ + nLastChar = screen_columns - 1; + while (nLastChar > firstChar && newLine[nLastChar] == blank) + nLastChar--; + + if((nLastChar == firstChar) + && (SP->_el_cost < (oLastChar - nLastChar))) { + GoTo(lineno, firstChar); + if(newLine[firstChar] != blank ) + PutChar(newLine[firstChar]); + ClrToEOL(blank); + } else if( (nLastChar != oLastChar) + && (newLine[nLastChar] != oldLine[oLastChar] + || !(_nc_idcok && has_ic())) ) { + GoTo(lineno, firstChar); + if ((oLastChar - nLastChar) > SP->_el_cost) { + if(PutRange(oldLine, newLine, lineno, firstChar, nLastChar)) + GoTo(lineno, nLastChar+1); + ClrToEOL(blank); + } else { + n = max( nLastChar , oLastChar ); + PutRange(oldLine, newLine, lineno, firstChar, n); + } + } else { + int nLastNonblank = nLastChar; + int oLastNonblank = oLastChar; + + /* find the last characters that really differ */ + while (newLine[nLastChar] == oldLine[oLastChar]) { + if (nLastChar != 0 + && oLastChar != 0) { + nLastChar--; + oLastChar--; + } else { + break; + } + } + + n = min(oLastChar, nLastChar); + if (n >= firstChar) { + GoTo(lineno, firstChar); + PutRange(oldLine, newLine, lineno, firstChar, n); + } + + if (oLastChar < nLastChar) { + int m = max(nLastNonblank, oLastNonblank); + GoTo(lineno, n+1); + if (InsCharCost(nLastChar - oLastChar) + > (m - n)) { + PutRange(oldLine, newLine, lineno, n+1, m); + } else { + InsStr(&newLine[n+1], nLastChar - oLastChar); + } + } else if (oLastChar > nLastChar ) { + GoTo(lineno, n+1); + if (DelCharCost(oLastChar - nLastChar) + > SP->_el_cost + nLastNonblank - (n+1)) { + if(PutRange(oldLine, newLine, lineno, + n+1, nLastNonblank)) + GoTo(lineno, nLastNonblank+1); + ClrToEOL(blank); + } else { + /* + * The delete-char sequence will + * effectively shift in blanks from the + * right margin of the screen. Ensure + * that they are the right color by + * setting the video attributes from + * the last character on the row. + */ + UpdateAttrs(blank); + DelChar(oLastChar - nLastChar); + } + } + } + } + + /* update the code's internal representation */ + if (screen_columns > firstChar) + memcpy( oldLine + firstChar, + newLine + firstChar, + (screen_columns - firstChar) * sizeof(chtype)); +} + +/* +** ClearScreen(blank) +** +** Clear the physical screen and put cursor at home +** +*/ + +static void ClearScreen(chtype blank) +{ + int i, j; + + T(("ClearScreen() called")); + + if (clear_screen) { + UpdateAttrs(blank); + TPUTS_TRACE("clear_screen"); + putp(clear_screen); + SP->_cursrow = SP->_curscol = 0; +#ifdef POSITION_DEBUG + position_check(SP->_cursrow, SP->_curscol, "ClearScreen"); +#endif /* POSITION_DEBUG */ + } else if (clr_eos) { + SP->_cursrow = SP->_curscol = -1; + GoTo(0,0); + + UpdateAttrs(blank); + TPUTS_TRACE("clr_eos"); + putp(clr_eos); + } else if (clr_eol) { + SP->_cursrow = SP->_curscol = -1; + + for (i = 0; i < screen_lines; i++) { + GoTo(i, 0); + UpdateAttrs(blank); + TPUTS_TRACE("clr_eol"); + putp(clr_eol); + } + GoTo(0,0); + } else { + T(("cannot clear screen")); + return; + } + + for (i = 0; i < screen_lines; i++) { + for (j = 0; j < screen_columns; j++) + curscr->_line[i].text[j] = blank; + } + + T(("screen cleared")); +} + +/* +** InsStr(line, count) +** +** Insert the count characters pointed to by line. +** +*/ + +static int InsStr(chtype *line, int count) +{ + T(("InsStr(%p,%d) called", line, count)); + + /* Prefer parm_ich as it has the smallest cost - no need to shift + * the whole line on each character. */ + /* The order must match that of InsCharCost. */ + if (parm_ich) { + TPUTS_TRACE("parm_ich"); + tputs(tparm(parm_ich, count), count, _nc_outch); + while (count) { + PutAttrChar(*line); + line++; + count--; + } + return(OK); + } else if (enter_insert_mode && exit_insert_mode) { + TPUTS_TRACE("enter_insert_mode"); + putp(enter_insert_mode); + while (count) { + PutAttrChar(*line); + if (insert_padding) + { + TPUTS_TRACE("insert_padding"); + putp(insert_padding); + } + line++; + count--; + } + TPUTS_TRACE("exit_insert_mode"); + putp(exit_insert_mode); + return(OK); + } else { + while (count) { + TPUTS_TRACE("insert_character"); + putp(insert_character); + PutAttrChar(*line); + if (insert_padding) + { + TPUTS_TRACE("insert_padding"); + putp(insert_padding); + } + line++; + count--; + } + return(OK); + } +} + +/* +** DelChar(count) +** +** Delete count characters at current position +** +*/ + +static void DelChar(int count) +{ + T(("DelChar(%d) called, position = (%d,%d)", count, newscr->_cury, newscr->_curx)); + + if (parm_dch) { + TPUTS_TRACE("parm_dch"); + tputs(tparm(parm_dch, count), count, _nc_outch); + } else { + while (count--) + { + TPUTS_TRACE("delete_character"); + putp(delete_character); + } + } +} + +/* +** _nc_outstr(char *str) +** +** Emit a string without waiting for update. +*/ + +void _nc_outstr(const char *str) +{ + FILE *ofp = SP ? SP->_ofp : stdout; + + (void) fputs(str, ofp); + (void) fflush(ofp); + +#ifdef TRACE + _nc_outchars += strlen(str); +#endif /* TRACE */ +} + +/* + * Physical-scrolling support + * + * This code was adapted from Keith Bostic's hardware scrolling + * support for 4.4BSD curses. I (esr) translated it to use terminfo + * capabilities, narrowed the call interface slightly, and cleaned + * up some convoluted tests. I also added support for the memory_above + * memory_below, and non_dest_scroll_region capabilities. + * + * For this code to work, we must have either + * change_scroll_region and scroll forward/reverse commands, or + * insert and delete line capabilities. + * When the scrolling region has been set, the cursor has to + * be at the last line of the region to make the scroll up + * happen, or on the first line of region to scroll down. + * + * This code makes one aesthetic decision in the opposite way from + * BSD curses. BSD curses preferred pairs of il/dl operations + * over scrolls, allegedly because il/dl looked faster. We, on + * the other hand, prefer scrolls because (a) they're just as fast + * on many terminals and (b) using them avoids bouncing an + * unchanged bottom section of the screen up and down, which is + * visually nasty. + * + * (lav): added more cases, used dl/il when bot==maxy and in csr case. + * + * I used assumption that capabilities il/il1/dl/dl1 work inside + * changed scroll region not shifting screen contents outside of it. + * If there are any terminals behaving different way, it would be + * necessary to add some conditions to scroll_csr_forward/backward. + */ + +/* Try to scroll up assuming given csr (miny, maxy). Returns ERR on failure */ +static int scroll_csr_forward(int n, int top, int bot, int miny, int maxy, chtype blank) +{ + int i; + + if (n == 1 && scroll_forward && top == miny && bot == maxy) + { + GoTo(bot, 0); + UpdateAttrs(blank); + TPUTS_TRACE("scroll_forward"); + tputs(scroll_forward, 0, _nc_outch); + } + else if (n == 1 && delete_line && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + TPUTS_TRACE("delete_line"); + tputs(delete_line, 0, _nc_outch); + } + else if (parm_index && top == miny && bot == maxy) + { + GoTo(bot, 0); + UpdateAttrs(blank); + TPUTS_TRACE("parm_index"); + tputs(tparm(parm_index, n, 0), n, _nc_outch); + } + else if (parm_delete_line && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + TPUTS_TRACE("parm_delete_line"); + tputs(tparm(parm_delete_line, n, 0), n, _nc_outch); + } + else if (scroll_forward && top == miny && bot == maxy) + { + GoTo(bot, 0); + UpdateAttrs(blank); + for (i = 0; i < n; i++) + { + TPUTS_TRACE("scroll_forward"); + tputs(scroll_forward, 0, _nc_outch); + } + } + else if (delete_line && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + for (i = 0; i < n; i++) + { + TPUTS_TRACE("delete_line"); + tputs(delete_line, 0, _nc_outch); + } + } + else + return ERR; + + return OK; +} + +/* Try to scroll down assuming given csr (miny, maxy). Returns ERR on failure */ +/* n > 0 */ +static int scroll_csr_backward(int n, int top, int bot, int miny, int maxy, chtype blank) +{ + int i; + + if (n == 1 && scroll_reverse && top == miny && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + TPUTS_TRACE("scroll_reverse"); + tputs(scroll_reverse, 0, _nc_outch); + } + else if (n == 1 && insert_line && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + TPUTS_TRACE("insert_line"); + tputs(insert_line, 0, _nc_outch); + } + else if (parm_rindex && top == miny && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + TPUTS_TRACE("parm_rindex"); + tputs(tparm(parm_rindex, n, 0), n, _nc_outch); + } + else if (parm_insert_line && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + TPUTS_TRACE("parm_insert_line"); + tputs(tparm(parm_insert_line, n, 0), n, _nc_outch); + } + else if (scroll_reverse && top == miny && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + for (i = 0; i < n; i++) + { + TPUTS_TRACE("scroll_reverse"); + tputs(scroll_reverse, 0, _nc_outch); + } + } + else if (insert_line && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + for (i = 0; i < n; i++) + { + TPUTS_TRACE("insert_line"); + tputs(insert_line, 0, _nc_outch); + } + } + else + return ERR; + + return OK; +} + +/* scroll by using delete_line at del and insert_line at ins */ +/* n > 0 */ +static int scroll_idl(int n, int del, int ins, chtype blank) +{ + int i; + + if(!((parm_delete_line || delete_line) && (parm_insert_line || insert_line))) + return ERR; + + GoTo(del, 0); + UpdateAttrs(blank); + if (n == 1 && delete_line) + { + TPUTS_TRACE("delete_line"); + tputs(delete_line, 0, _nc_outch); + } + else if (parm_delete_line) + { + TPUTS_TRACE("parm_delete_line"); + tputs(tparm(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); + } + } + + GoTo(ins, 0); + UpdateAttrs(blank); + if (n == 1 && insert_line) + { + TPUTS_TRACE("insert_line"); + tputs(insert_line, 0, _nc_outch); + } + else if (parm_insert_line) + { + TPUTS_TRACE("parm_insert_line"); + tputs(tparm(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); + } + } + + return OK; +} + +int _nc_scrolln(int n, int top, int bot, int maxy) +/* scroll region from top to bot by n lines */ +{ + chtype blank=ClrBlank(stdscr); + int i; + bool cursor_saved=FALSE; + int res; + + TR(TRACE_MOVE, ("mvcur_scrolln(%d, %d, %d, %d)", n, top, bot, maxy)); + +#if USE_XMC_SUPPORT + /* + * If we scroll, we might remove a cookie. + */ + if (magic_cookie_glitch > 0) { + return (ERR); + } +#endif + + if (n > 0) /* scroll up (forward) */ + { + /* + * Explicitly clear if stuff pushed off top of region might + * be saved by the terminal. + */ + if (non_dest_scroll_region || (memory_above && top == 0)) { + for (i = 0; i < n; i++) + { + GoTo(i, 0); + ClrToEOL(BLANK); + } + } + + res = scroll_csr_forward(n, top, bot, 0, maxy, blank); + + if (res == ERR && change_scroll_region) + { + if ((((n==1 && scroll_forward) || parm_index) + && (SP->_cursrow == bot || SP->_cursrow == bot-1)) + && save_cursor && restore_cursor) + { + cursor_saved=TRUE; + TPUTS_TRACE("save_cursor"); + tputs(save_cursor, 0, _nc_outch); + } + TPUTS_TRACE("change_scroll_region"); + tputs(tparm(change_scroll_region, top, bot), 0, _nc_outch); + if (cursor_saved) + { + TPUTS_TRACE("restore_cursor"); + tputs(restore_cursor, 0, _nc_outch); + } + else + { + SP->_cursrow = SP->_curscol = -1; + } + + 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); + SP->_cursrow = SP->_curscol = -1; + } + + if (res == ERR && _nc_idlok) + res = scroll_idl(n, top, bot-n+1, blank); + } + else /* (n < 0) - scroll down (backward) */ + { + /* + * Do explicit clear to end of region if it's possible that the + * terminal might hold on to stuff we push off the end. + */ + if (non_dest_scroll_region || (memory_below && bot == maxy)) + { + if (bot == maxy && clr_eos) + { + GoTo(maxy + n, 0); + ClrToEOS(BLANK); + } + else if (clr_eol) + { + for (i = 0; i < -n; i++) + { + GoTo(maxy + n + i, 0); + ClrToEOL(BLANK); + } + } + } + + res = scroll_csr_backward(-n, top, bot, 0, maxy, blank); + + if (res == ERR && change_scroll_region) + { + if (top != 0 && (SP->_cursrow == top || SP->_cursrow == top-1) + && save_cursor && restore_cursor) + { + cursor_saved=TRUE; + TPUTS_TRACE("save_cursor"); + tputs(save_cursor, 0, _nc_outch); + } + TPUTS_TRACE("change_scroll_region"); + tputs(tparm(change_scroll_region, top, bot), 0, _nc_outch); + if (cursor_saved) + { + TPUTS_TRACE("restore_cursor"); + tputs(restore_cursor, 0, _nc_outch); + } + else + { + SP->_cursrow = SP->_curscol = -1; + } + + 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); + SP->_cursrow = SP->_curscol = -1; + } + + if (res == ERR && _nc_idlok) + res = scroll_idl(-n, bot+n+1, top, blank); + } + + if (res == ERR) + return(ERR); + + _nc_scroll_window(curscr, n, top, bot, blank); + + /* shift hash values too - they can be reused */ + _nc_scroll_oldhash(n, top, bot); + + return(OK); +} + + +void _nc_screen_resume() +{ + /* make sure terminal is in a sane known state */ + SP->_current_attr = A_NORMAL; + newscr->_clear = TRUE; + + if (SP->_coloron == TRUE && orig_pair) + putp(orig_pair); + if (exit_attribute_mode) + putp(exit_attribute_mode); + else + { + /* turn off attributes */ + if (exit_alt_charset_mode) + putp(exit_alt_charset_mode); + if (exit_standout_mode) + putp(exit_standout_mode); + if (exit_underline_mode) + putp(exit_underline_mode); + } + if (exit_insert_mode) + putp(exit_insert_mode); + if (enter_am_mode && exit_am_mode) + putp(auto_right_margin ? enter_am_mode : exit_am_mode); +} + +void _nc_screen_init() +{ + _nc_screen_resume(); +} + +/* wrap up screen handling */ +void _nc_screen_wrap() +{ + UpdateAttrs(A_NORMAL); +} + +#if USE_XMC_SUPPORT +void _nc_do_xmc_glitch(attr_t previous) +{ + attr_t chg = XMC_CHANGES(previous ^ SP->_current_attr); + + while (chg != 0) { + if (chg & 1) { + SP->_curscol += magic_cookie_glitch; + if (SP->_curscol >= SP->_columns) + wrap_cursor(); + T(("bumped to %d,%d after cookie", SP->_cursrow, SP->_curscol)); + } + chg >>= 1; + } +} +#endif /* USE_XMC_SUPPORT */ |