aboutsummaryrefslogtreecommitdiff
path: root/contrib/ncurses/ncurses/tinfo
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ncurses/ncurses/tinfo')
-rw-r--r--contrib/ncurses/ncurses/tinfo/MKcaptab.awk29
-rwxr-xr-xcontrib/ncurses/ncurses/tinfo/MKfallback.sh31
-rwxr-xr-xcontrib/ncurses/ncurses/tinfo/MKkeys_list.sh8
-rw-r--r--contrib/ncurses/ncurses/tinfo/MKnames.awk29
-rw-r--r--contrib/ncurses/ncurses/tinfo/README30
-rw-r--r--contrib/ncurses/ncurses/tinfo/access.c77
-rw-r--r--contrib/ncurses/ncurses/tinfo/add_tries.c6
-rw-r--r--contrib/ncurses/ncurses/tinfo/alloc_entry.c103
-rw-r--r--contrib/ncurses/ncurses/tinfo/alloc_ttype.c48
-rw-r--r--contrib/ncurses/ncurses/tinfo/captoinfo.c51
-rw-r--r--contrib/ncurses/ncurses/tinfo/comp_error.c32
-rw-r--r--contrib/ncurses/ncurses/tinfo/comp_expand.c16
-rw-r--r--contrib/ncurses/ncurses/tinfo/comp_hash.c22
-rw-r--r--contrib/ncurses/ncurses/tinfo/comp_parse.c167
-rw-r--r--contrib/ncurses/ncurses/tinfo/comp_scan.c526
-rw-r--r--contrib/ncurses/ncurses/tinfo/db_iterator.c227
-rw-r--r--contrib/ncurses/ncurses/tinfo/doalloc.c4
-rw-r--r--contrib/ncurses/ncurses/tinfo/free_ttype.c16
-rw-r--r--contrib/ncurses/ncurses/tinfo/hashed_db.c260
-rw-r--r--contrib/ncurses/ncurses/tinfo/home_terminfo.c15
-rw-r--r--contrib/ncurses/ncurses/tinfo/init_keytry.c50
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_acs.c185
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_cur_term.c10
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_data.c20
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_has_cap.c5
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_kernel.c8
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_napms.c19
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_options.c121
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_print.c9
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_raw.c226
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_setup.c411
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_termcap.c210
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_termname.c16
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_tgoto.c23
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_ti.c10
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_tparm.c477
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_tputs.c21
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_ttyflags.c94
-rw-r--r--contrib/ncurses/ncurses/tinfo/make_keys.c10
-rw-r--r--contrib/ncurses/ncurses/tinfo/name_match.c17
-rw-r--r--contrib/ncurses/ncurses/tinfo/parse_entry.c74
-rw-r--r--contrib/ncurses/ncurses/tinfo/read_entry.c455
-rw-r--r--contrib/ncurses/ncurses/tinfo/read_termcap.c91
-rw-r--r--contrib/ncurses/ncurses/tinfo/setbuf.c58
-rw-r--r--contrib/ncurses/ncurses/tinfo/strings.c23
-rw-r--r--contrib/ncurses/ncurses/tinfo/trim_sgr0.c328
-rw-r--r--contrib/ncurses/ncurses/tinfo/write_entry.c372
47 files changed, 3416 insertions, 1624 deletions
diff --git a/contrib/ncurses/ncurses/tinfo/MKcaptab.awk b/contrib/ncurses/ncurses/tinfo/MKcaptab.awk
index ff9601ba62c5..57087b820e3b 100644
--- a/contrib/ncurses/ncurses/tinfo/MKcaptab.awk
+++ b/contrib/ncurses/ncurses/tinfo/MKcaptab.awk
@@ -1,5 +1,32 @@
#!/bin/sh
-# $Id: MKcaptab.awk,v 1.12 2000/12/10 00:14:12 tom Exp $
+##############################################################################
+# Copyright (c) 1998-2000,2006 Free Software Foundation, Inc. #
+# #
+# Permission is hereby granted, free of charge, to any person obtaining a #
+# copy of this software and associated documentation files (the "Software"), #
+# to deal in the Software without restriction, including without limitation #
+# the rights to use, copy, modify, merge, publish, distribute, distribute #
+# with modifications, sublicense, and/or sell copies of the Software, and to #
+# permit persons to whom the Software is furnished to do so, subject to the #
+# following conditions: #
+# #
+# The above copyright notice and this permission notice shall be included in #
+# all copies or substantial portions of the Software. #
+# #
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
+# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
+# DEALINGS IN THE SOFTWARE. #
+# #
+# Except as contained in this notice, the name(s) of the above copyright #
+# holders shall not be used in advertising or otherwise to promote the sale, #
+# use or other dealings in this Software without prior written #
+# authorization. #
+##############################################################################
+# $Id: MKcaptab.awk,v 1.13 2006/04/22 21:46:17 tom Exp $
AWK=${1-awk}
DATA=${2-../include/Caps}
diff --git a/contrib/ncurses/ncurses/tinfo/MKfallback.sh b/contrib/ncurses/ncurses/tinfo/MKfallback.sh
index d1abcd2eed3f..9feab3507cc0 100755
--- a/contrib/ncurses/ncurses/tinfo/MKfallback.sh
+++ b/contrib/ncurses/ncurses/tinfo/MKfallback.sh
@@ -1,5 +1,32 @@
#!/bin/sh
-# $Id: MKfallback.sh,v 1.11 2001/12/02 01:55:30 tom Exp $
+##############################################################################
+# Copyright (c) 1998-2001,2006 Free Software Foundation, Inc. #
+# #
+# Permission is hereby granted, free of charge, to any person obtaining a #
+# copy of this software and associated documentation files (the "Software"), #
+# to deal in the Software without restriction, including without limitation #
+# the rights to use, copy, modify, merge, publish, distribute, distribute #
+# with modifications, sublicense, and/or sell copies of the Software, and to #
+# permit persons to whom the Software is furnished to do so, subject to the #
+# following conditions: #
+# #
+# The above copyright notice and this permission notice shall be included in #
+# all copies or substantial portions of the Software. #
+# #
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
+# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
+# DEALINGS IN THE SOFTWARE. #
+# #
+# Except as contained in this notice, the name(s) of the above copyright #
+# holders shall not be used in advertising or otherwise to promote the sale, #
+# use or other dealings in this Software without prior written #
+# authorization. #
+##############################################################################
+# $Id: MKfallback.sh,v 1.13 2006/07/15 16:54:20 tom Exp $
#
# MKfallback.sh -- create fallback table for entry reads
#
@@ -25,7 +52,7 @@ if test $# != 0 ; then
TERMINFO_DIRS=$TERMINFO:$terminfo_dir
export TERMINFO_DIRS
- tic $terminfo_src >&2
+ tic -x $terminfo_src >&2
else
tmp_info=
fi
diff --git a/contrib/ncurses/ncurses/tinfo/MKkeys_list.sh b/contrib/ncurses/ncurses/tinfo/MKkeys_list.sh
index 98d5b1379a1c..14017b016896 100755
--- a/contrib/ncurses/ncurses/tinfo/MKkeys_list.sh
+++ b/contrib/ncurses/ncurses/tinfo/MKkeys_list.sh
@@ -1,7 +1,7 @@
#! /bin/sh
-# $Id: MKkeys_list.sh,v 1.2 2001/06/16 16:50:35 tom Exp $
+# $Id: MKkeys_list.sh,v 1.4 2003/10/25 16:19:54 tom Exp $
##############################################################################
-# Copyright (c) 2001 Free Software Foundation, Inc. #
+# Copyright (c) 2001,2003 Free Software Foundation, Inc. #
# #
# Permission is hereby granted, free of charge, to any person obtaining a #
# copy of this software and associated documentation files (the "Software"), #
@@ -30,7 +30,7 @@
#
# MKkey_defs.sh -- generate list of function-keys for terminfo database
#
-# Author: Thomas E. Dickey <dickey@herndon4.his.com> 2001
+# Author: Thomas E. Dickey 2001
#
# Extract function-key names from the Caps file
#
@@ -39,7 +39,7 @@ DATA=${1-../../include/Caps}
data=data$$
trap 'rm -f $data' 0 1 2 5 15
-sed -e 's/[ ]\+/ /g' < $DATA >$data
+sed -e 's/[ ][ ]*/ /g' < $DATA >$data
cat <<EOF
# These definitions were generated by $0 $DATA
diff --git a/contrib/ncurses/ncurses/tinfo/MKnames.awk b/contrib/ncurses/ncurses/tinfo/MKnames.awk
index 455efc01dea3..6be00ad4488d 100644
--- a/contrib/ncurses/ncurses/tinfo/MKnames.awk
+++ b/contrib/ncurses/ncurses/tinfo/MKnames.awk
@@ -1,4 +1,31 @@
-# $Id: MKnames.awk,v 1.11 2000/12/09 23:46:13 tom Exp $
+##############################################################################
+# Copyright (c) 1998-2000,2006 Free Software Foundation, Inc. #
+# #
+# Permission is hereby granted, free of charge, to any person obtaining a #
+# copy of this software and associated documentation files (the "Software"), #
+# to deal in the Software without restriction, including without limitation #
+# the rights to use, copy, modify, merge, publish, distribute, distribute #
+# with modifications, sublicense, and/or sell copies of the Software, and to #
+# permit persons to whom the Software is furnished to do so, subject to the #
+# following conditions: #
+# #
+# The above copyright notice and this permission notice shall be included in #
+# all copies or substantial portions of the Software. #
+# #
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
+# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
+# DEALINGS IN THE SOFTWARE. #
+# #
+# Except as contained in this notice, the name(s) of the above copyright #
+# holders shall not be used in advertising or otherwise to promote the sale, #
+# use or other dealings in this Software without prior written #
+# authorization. #
+##############################################################################
+# $Id: MKnames.awk,v 1.12 2006/04/22 21:46:17 tom Exp $
BEGIN {
print "/* This file was generated by MKnames.awk */" > "namehdr"
print "" > "namehdr"
diff --git a/contrib/ncurses/ncurses/tinfo/README b/contrib/ncurses/ncurses/tinfo/README
index 8b092c1ba41c..14c4220c4431 100644
--- a/contrib/ncurses/ncurses/tinfo/README
+++ b/contrib/ncurses/ncurses/tinfo/README
@@ -1,4 +1,32 @@
--- $Id: README,v 1.1 1998/11/07 22:59:07 tom Exp $
+-------------------------------------------------------------------------------
+-- Copyright (c) 1998,2006 Free Software Foundation, Inc. --
+-- --
+-- Permission is hereby granted, free of charge, to any person obtaining a --
+-- copy of this software and associated documentation files (the --
+-- "Software"), to deal in the Software without restriction, including --
+-- without limitation the rights to use, copy, modify, merge, publish, --
+-- distribute, distribute with modifications, sublicense, and/or sell copies --
+-- of the Software, and to permit persons to whom the Software is furnished --
+-- to do so, subject to the following conditions: --
+-- --
+-- The above copyright notice and this permission notice shall be included --
+-- in all copies or substantial portions of the Software. --
+-- --
+-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
+-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
+-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN --
+-- NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
+-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
+-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE --
+-- USE OR OTHER DEALINGS IN THE SOFTWARE. --
+-- --
+-- Except as contained in this notice, the name(s) of the above copyright --
+-- holders shall not be used in advertising or otherwise to promote the --
+-- sale, use or other dealings in this Software without prior written --
+-- authorization. --
+-------------------------------------------------------------------------------
+-- $Id: README,v 1.2 2006/04/22 22:19:37 tom Exp $
+-------------------------------------------------------------------------------
The files in this directory (tinfo) are those that support the terminfo
database and interfaces for ncurses. The terminfo library can be built
diff --git a/contrib/ncurses/ncurses/tinfo/access.c b/contrib/ncurses/ncurses/tinfo/access.c
index f5240c121c26..c10b7e0af556 100644
--- a/contrib/ncurses/ncurses/tinfo/access.c
+++ b/contrib/ncurses/ncurses/tinfo/access.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2003,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -27,14 +27,17 @@
****************************************************************************/
/****************************************************************************
- * Author: Thomas E. Dickey <dickey@clark.net> 1998,2000,2001 *
+ * Author: Thomas E. Dickey *
****************************************************************************/
#include <curses.priv.h>
+
+#include <sys/stat.h>
+
#include <tic.h>
#include <nc_alloc.h>
-MODULE_ID("$Id: access.c,v 1.9 2001/06/23 22:11:49 tom Exp $")
+MODULE_ID("$Id: access.c,v 1.12 2006/08/05 17:18:14 tom Exp $")
#define LOWERCASE(c) ((isalpha(UChar(c)) && isupper(UChar(c))) ? tolower(UChar(c)) : (c))
@@ -64,19 +67,43 @@ _nc_rootname(char *path)
return result;
}
-NCURSES_EXPORT(char *)
-_nc_basename(char *path)
+/*
+ * Check if a string appears to be an absolute pathname.
+ */
+NCURSES_EXPORT(bool)
+_nc_is_abs_path(const char *path)
{
- char *result = strrchr(path, '/');
+#if defined(__EMX__) || defined(__DJGPP__)
+#define is_pathname(s) ((((s) != 0) && ((s)[0] == '/')) \
+ || (((s)[0] != 0) && ((s)[1] == ':')))
+#else
+#define is_pathname(s) ((s) != 0 && (s)[0] == '/')
+#endif
+ return is_pathname(path);
+}
+
+/*
+ * Return index of the basename
+ */
+NCURSES_EXPORT(unsigned)
+_nc_pathlast(const char *path)
+{
+ const char *test = strrchr(path, '/');
#ifdef __EMX__
- if (result == 0)
- result = strrchr(path, '\\');
+ if (test == 0)
+ test = strrchr(path, '\\');
#endif
- if (result == 0)
- result = path;
+ if (test == 0)
+ test = path;
else
- result++;
- return result;
+ test++;
+ return (test - path);
+}
+
+NCURSES_EXPORT(char *)
+_nc_basename(char *path)
+{
+ return path + _nc_pathlast(path);
}
NCURSES_EXPORT(int)
@@ -102,6 +129,32 @@ _nc_access(const char *path, int mode)
return 0;
}
+NCURSES_EXPORT(bool)
+_nc_is_dir_path(const char *path)
+{
+ bool result = FALSE;
+ struct stat sb;
+
+ if (stat(path, &sb) == 0
+ && (sb.st_mode & S_IFMT) == S_IFDIR) {
+ result = TRUE;
+ }
+ return result;
+}
+
+NCURSES_EXPORT(bool)
+_nc_is_file_path(const char *path)
+{
+ bool result = FALSE;
+ struct stat sb;
+
+ if (stat(path, &sb) == 0
+ && (sb.st_mode & S_IFMT) == S_IFREG) {
+ result = TRUE;
+ }
+ return result;
+}
+
#ifndef USE_ROOT_ENVIRON
/*
* Returns true if we allow application to use environment variables that are
diff --git a/contrib/ncurses/ncurses/tinfo/add_tries.c b/contrib/ncurses/ncurses/tinfo/add_tries.c
index f83249ccf01a..46c93b8fecc7 100644
--- a/contrib/ncurses/ncurses/tinfo/add_tries.c
+++ b/contrib/ncurses/ncurses/tinfo/add_tries.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -39,13 +39,13 @@
#include <curses.priv.h>
-MODULE_ID("$Id: add_tries.c,v 1.4 2000/12/10 02:55:07 tom Exp $")
+MODULE_ID("$Id: add_tries.c,v 1.5 2005/11/20 01:32:48 tom Exp $")
#define SET_TRY(dst,src) if ((dst->ch = *src++) == 128) dst->ch = '\0'
#define CMP_TRY(a,b) ((a)? (a == b) : (b == 128))
NCURSES_EXPORT(void)
-_nc_add_to_try(struct tries **tree, const char *str, unsigned short code)
+_nc_add_to_try(struct tries **tree, const char *str, unsigned code)
{
static bool out_of_memory = FALSE;
struct tries *ptr, *savedptr;
diff --git a/contrib/ncurses/ncurses/tinfo/alloc_entry.c b/contrib/ncurses/ncurses/tinfo/alloc_entry.c
index 5c064cfd8246..1496752f1956 100644
--- a/contrib/ncurses/ncurses/tinfo/alloc_entry.c
+++ b/contrib/ncurses/ncurses/tinfo/alloc_entry.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,6 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
****************************************************************************/
/*
@@ -47,7 +48,7 @@
#include <tic.h>
#include <term_entry.h>
-MODULE_ID("$Id: alloc_entry.c,v 1.36 2001/09/22 21:10:26 tom Exp $")
+MODULE_ID("$Id: alloc_entry.c,v 1.47 2006/12/16 19:06:58 tom Exp $")
#define ABSENT_OFFSET -1
#define CANCELLED_OFFSET -2
@@ -58,13 +59,20 @@ static char *stringbuf; /* buffer for string capabilities */
static size_t next_free; /* next free character in stringbuf */
NCURSES_EXPORT(void)
-_nc_init_entry(TERMTYPE * const tp)
+_nc_init_entry(TERMTYPE *const tp)
/* initialize a terminal type data block */
{
- int i;
+ unsigned i;
+
+#if NO_LEAKS
+ if (tp == 0 && stringbuf != 0) {
+ FreeAndNull(stringbuf);
+ return;
+ }
+#endif
if (stringbuf == 0)
- stringbuf = malloc(MAX_STRTAB);
+ stringbuf = (char *) malloc(MAX_STRTAB);
#if NCURSES_XNAMES
tp->num_Booleans = BOOLCOUNT;
@@ -75,7 +83,7 @@ _nc_init_entry(TERMTYPE * const tp)
tp->ext_Strings = 0;
#endif
if (tp->Booleans == 0)
- tp->Booleans = typeMalloc(char, BOOLCOUNT);
+ tp->Booleans = typeMalloc(NCURSES_SBOOL, BOOLCOUNT);
if (tp->Numbers == 0)
tp->Numbers = typeMalloc(short, NUMCOUNT);
if (tp->Strings == 0)
@@ -105,20 +113,32 @@ _nc_copy_entry(ENTRY * oldp)
return newp;
}
+/* save a copy of string in the string buffer */
NCURSES_EXPORT(char *)
_nc_save_str(const char *const string)
-/* save a copy of string in the string buffer */
{
+ char *result = 0;
size_t old_next_free = next_free;
size_t len = strlen(string) + 1;
- if (next_free + len < MAX_STRTAB) {
+ if (len == 1 && next_free != 0) {
+ /*
+ * Cheat a little by making an empty string point to the end of the
+ * previous string.
+ */
+ if (next_free < MAX_STRTAB) {
+ result = (stringbuf + next_free - 1);
+ }
+ } else if (next_free + len < MAX_STRTAB) {
strcpy(&stringbuf[next_free], string);
DEBUG(7, ("Saved string %s", _nc_visbuf(string)));
DEBUG(7, ("at location %d", (int) next_free));
next_free += len;
+ result = (stringbuf + old_next_free);
+ } else {
+ _nc_warning("Too much data, some is lost");
}
- return (stringbuf + old_next_free);
+ return result;
}
NCURSES_EXPORT(void)
@@ -126,7 +146,8 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings)
/* copy the string parts to allocated storage, preserving pointers to it */
{
int offsets[MAX_ENTRY_SIZE / 2], useoffsets[MAX_USES];
- int i, n;
+ unsigned i, n;
+ unsigned nuses = ep->nuses;
TERMTYPE *tp = &(ep->tterm);
if (copy_strings) {
@@ -141,7 +162,7 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings)
}
}
- for (i = 0; i < ep->nuses; i++) {
+ for (i = 0; i < nuses; i++) {
if (ep->uses[i].name == 0) {
ep->uses[i].name = _nc_save_str(ep->uses[i].name);
}
@@ -160,7 +181,7 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings)
offsets[i] = tp->Strings[i] - stringbuf;
}
- for (i = 0; i < ep->nuses; i++) {
+ for (i = 0; i < nuses; i++) {
if (ep->uses[i].name == 0)
useoffsets[i] = ABSENT_OFFSET;
else
@@ -168,7 +189,7 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings)
}
if ((tp->str_table = typeMalloc(char, next_free)) == (char *) 0)
- _nc_err_abort("Out of memory");
+ _nc_err_abort(MSG_NO_MEMORY);
(void) memcpy(tp->str_table, stringbuf, next_free);
tp->term_names = tp->str_table + n;
@@ -190,7 +211,7 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings)
offsets[i] = tp->ext_Names[i] - stringbuf;
}
if ((tp->ext_str_table = typeMalloc(char, length)) == 0)
- _nc_err_abort("Out of memory");
+ _nc_err_abort(MSG_NO_MEMORY);
for (i = 0, length = 0; i < n; i++) {
tp->ext_Names[i] = tp->ext_str_table + length;
strcpy(tp->ext_Names[i], stringbuf + offsets[i]);
@@ -200,7 +221,7 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings)
}
#endif
- for (i = 0; i < ep->nuses; i++) {
+ for (i = 0; i < nuses; i++) {
if (useoffsets[i] == ABSENT_OFFSET)
ep->uses[i].name = 0;
else
@@ -209,31 +230,34 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings)
}
NCURSES_EXPORT(void)
-_nc_merge_entry
-(TERMTYPE * const to, TERMTYPE * const from)
+_nc_merge_entry(TERMTYPE *const to, TERMTYPE *const from)
/* merge capabilities from `from' entry into `to' entry */
{
- int i;
+ unsigned i;
#if NCURSES_XNAMES
_nc_align_termtype(to, from);
#endif
for_each_boolean(i, from) {
- int mergebool = from->Booleans[i];
+ if (to->Booleans[i] != (char) CANCELLED_BOOLEAN) {
+ int mergebool = from->Booleans[i];
- if (mergebool == CANCELLED_BOOLEAN)
- to->Booleans[i] = FALSE;
- else if (mergebool == TRUE)
- to->Booleans[i] = mergebool;
+ if (mergebool == CANCELLED_BOOLEAN)
+ to->Booleans[i] = FALSE;
+ else if (mergebool == TRUE)
+ to->Booleans[i] = mergebool;
+ }
}
for_each_number(i, from) {
- int mergenum = from->Numbers[i];
+ if (to->Numbers[i] != CANCELLED_NUMERIC) {
+ int mergenum = from->Numbers[i];
- if (mergenum == CANCELLED_NUMERIC)
- to->Numbers[i] = ABSENT_NUMERIC;
- else if (mergenum != ABSENT_NUMERIC)
- to->Numbers[i] = mergenum;
+ if (mergenum == CANCELLED_NUMERIC)
+ to->Numbers[i] = ABSENT_NUMERIC;
+ else if (mergenum != ABSENT_NUMERIC)
+ to->Numbers[i] = mergenum;
+ }
}
/*
@@ -242,11 +266,24 @@ _nc_merge_entry
* we ever want to deallocate entries.
*/
for_each_string(i, from) {
- char *mergestring = from->Strings[i];
+ if (to->Strings[i] != CANCELLED_STRING) {
+ char *mergestring = from->Strings[i];
- if (mergestring == CANCELLED_STRING)
- to->Strings[i] = ABSENT_STRING;
- else if (mergestring != ABSENT_STRING)
- to->Strings[i] = mergestring;
+ if (mergestring == CANCELLED_STRING)
+ to->Strings[i] = ABSENT_STRING;
+ else if (mergestring != ABSENT_STRING)
+ to->Strings[i] = mergestring;
+ }
+ }
+}
+
+#if NO_LEAKS
+NCURSES_EXPORT(void)
+_nc_alloc_entry_leaks(void)
+{
+ if (stringbuf != 0) {
+ FreeAndNull(stringbuf);
}
+ next_free = 0;
}
+#endif
diff --git a/contrib/ncurses/ncurses/tinfo/alloc_ttype.c b/contrib/ncurses/ncurses/tinfo/alloc_ttype.c
index c13c5d6c29ed..9f31ed3ffab7 100644
--- a/contrib/ncurses/ncurses/tinfo/alloc_ttype.c
+++ b/contrib/ncurses/ncurses/tinfo/alloc_ttype.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1999,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1999-2003,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -27,7 +27,7 @@
****************************************************************************/
/****************************************************************************
- * Author: Thomas E. Dickey <dickey@clark.net> 1999 *
+ * Author: Thomas E. Dickey <dickey@clark.net> 1999-on *
****************************************************************************/
/*
@@ -43,7 +43,7 @@
#include <tic.h>
#include <term_entry.h>
-MODULE_ID("$Id: alloc_ttype.c,v 1.12 2000/12/10 02:55:07 tom Exp $")
+MODULE_ID("$Id: alloc_ttype.c,v 1.16 2006/07/08 19:18:38 tom Exp $")
#if NCURSES_XNAMES
/*
@@ -92,15 +92,17 @@ find_name(char **table, int length, char *name)
}
static void
-realign_data(TERMTYPE * to, char **ext_Names, int ext_Booleans, int
- ext_Numbers, int ext_Strings)
+realign_data(TERMTYPE *to, char **ext_Names,
+ int ext_Booleans,
+ int ext_Numbers,
+ int ext_Strings)
{
int n, m, base;
int limit = (to->ext_Booleans + to->ext_Numbers + to->ext_Strings);
if (to->ext_Booleans != ext_Booleans) {
to->num_Booleans += (ext_Booleans - to->ext_Booleans);
- to->Booleans = typeRealloc(char, to->num_Booleans, to->Booleans);
+ to->Booleans = typeRealloc(NCURSES_SBOOL, to->num_Booleans, to->Booleans);
for (n = to->ext_Booleans - 1,
m = ext_Booleans - 1,
base = to->num_Booleans - (m + 1); m >= 0; m--) {
@@ -146,7 +148,7 @@ realign_data(TERMTYPE * to, char **ext_Names, int ext_Booleans, int
* Returns the first index in ext_Names[] for the given token-type
*/
static int
-_nc_first_ext_name(TERMTYPE * tp, int token_type)
+_nc_first_ext_name(TERMTYPE *tp, int token_type)
{
int first;
@@ -171,7 +173,7 @@ _nc_first_ext_name(TERMTYPE * tp, int token_type)
* Returns the last index in ext_Names[] for the given token-type
*/
static int
-_nc_last_ext_name(TERMTYPE * tp, int token_type)
+_nc_last_ext_name(TERMTYPE *tp, int token_type)
{
int last;
@@ -194,7 +196,7 @@ _nc_last_ext_name(TERMTYPE * tp, int token_type)
* Lookup an entry from extended-names, returning -1 if not found
*/
static int
-_nc_find_ext_name(TERMTYPE * tp, char *name, int token_type)
+_nc_find_ext_name(TERMTYPE *tp, char *name, int token_type)
{
unsigned j;
unsigned first = _nc_first_ext_name(tp, token_type);
@@ -213,7 +215,7 @@ _nc_find_ext_name(TERMTYPE * tp, char *name, int token_type)
* (e.g., Booleans[]).
*/
static int
-_nc_ext_data_index(TERMTYPE * tp, int n, int token_type)
+_nc_ext_data_index(TERMTYPE *tp, int n, int token_type)
{
switch (token_type) {
case BOOLEAN:
@@ -236,7 +238,7 @@ _nc_ext_data_index(TERMTYPE * tp, int n, int token_type)
* data.
*/
static bool
-_nc_del_ext_name(TERMTYPE * tp, char *name, int token_type)
+_nc_del_ext_name(TERMTYPE *tp, char *name, int token_type)
{
int j;
int first, last;
@@ -280,7 +282,7 @@ _nc_del_ext_name(TERMTYPE * tp, char *name, int token_type)
* index into the corresponding data array is returned.
*/
static int
-_nc_ins_ext_name(TERMTYPE * tp, char *name, int token_type)
+_nc_ins_ext_name(TERMTYPE *tp, char *name, int token_type)
{
unsigned first = _nc_first_ext_name(tp, token_type);
unsigned last = _nc_last_ext_name(tp, token_type);
@@ -291,7 +293,7 @@ _nc_ins_ext_name(TERMTYPE * tp, char *name, int token_type)
int cmp = strcmp(name, tp->ext_Names[j]);
if (cmp == 0)
/* already present */
- return _nc_ext_data_index(tp, j, token_type);
+ return _nc_ext_data_index(tp, (int) j, token_type);
if (cmp < 0) {
break;
}
@@ -301,13 +303,13 @@ _nc_ins_ext_name(TERMTYPE * tp, char *name, int token_type)
for (k = total - 1; k > j; k--)
tp->ext_Names[k] = tp->ext_Names[k - 1];
tp->ext_Names[j] = name;
- j = _nc_ext_data_index(tp, j, token_type);
+ j = _nc_ext_data_index(tp, (int) j, token_type);
switch (token_type) {
case BOOLEAN:
tp->ext_Booleans += 1;
tp->num_Booleans += 1;
- tp->Booleans = typeRealloc(char, tp->num_Booleans, tp->Booleans);
+ tp->Booleans = typeRealloc(NCURSES_SBOOL, tp->num_Booleans, tp->Booleans);
for (k = tp->num_Booleans - 1; k > j; k--)
tp->Booleans[k] = tp->Booleans[k - 1];
break;
@@ -335,7 +337,7 @@ _nc_ins_ext_name(TERMTYPE * tp, char *name, int token_type)
* cancellation of a name that is inherited from another entry.
*/
static void
-adjust_cancels(TERMTYPE * to, TERMTYPE * from)
+adjust_cancels(TERMTYPE *to, TERMTYPE *from)
{
int first = to->ext_Booleans + to->ext_Numbers;
int last = first + to->ext_Strings;
@@ -371,8 +373,7 @@ adjust_cancels(TERMTYPE * to, TERMTYPE * from)
}
NCURSES_EXPORT(void)
-_nc_align_termtype
-(TERMTYPE * to, TERMTYPE * from)
+_nc_align_termtype(TERMTYPE *to, TERMTYPE *from)
{
int na = NUM_EXT_NAMES(to);
int nb = NUM_EXT_NAMES(from);
@@ -380,6 +381,7 @@ _nc_align_termtype
bool same;
char **ext_Names;
int ext_Booleans, ext_Numbers, ext_Strings;
+ bool used_ext_Names = FALSE;
DEBUG(2, ("align_termtype to(%d:%s), from(%d:%s)", na, to->term_names,
nb, from->term_names));
@@ -443,6 +445,7 @@ _nc_align_termtype
to->ext_Names = ext_Names;
DEBUG(2, ("realigned %d extended names for '%s' (to)",
NUM_EXT_NAMES(to), to->term_names));
+ used_ext_Names = TRUE;
}
if (nb != (ext_Booleans + ext_Numbers + ext_Strings)) {
nb = (ext_Booleans + ext_Numbers + ext_Strings);
@@ -452,18 +455,19 @@ _nc_align_termtype
DEBUG(2, ("realigned %d extended names for '%s' (from)",
NUM_EXT_NAMES(from), from->term_names));
}
+ if (!used_ext_Names)
+ free(ext_Names);
}
}
#endif
NCURSES_EXPORT(void)
-_nc_copy_termtype
-(TERMTYPE * dst, TERMTYPE * src)
+_nc_copy_termtype(TERMTYPE *dst, TERMTYPE *src)
{
- int i;
+ unsigned i;
*dst = *src; /* ...to copy the sizes and string-tables */
- dst->Booleans = typeMalloc(char, NUM_BOOLEANS(dst));
+ dst->Booleans = typeMalloc(NCURSES_SBOOL, NUM_BOOLEANS(dst));
dst->Numbers = typeMalloc(short, NUM_NUMBERS(dst));
dst->Strings = typeMalloc(char *, NUM_STRINGS(dst));
diff --git a/contrib/ncurses/ncurses/tinfo/captoinfo.c b/contrib/ncurses/ncurses/tinfo/captoinfo.c
index bf3116ae24f9..0e3baa845693 100644
--- a/contrib/ncurses/ncurses/tinfo/captoinfo.c
+++ b/contrib/ncurses/ncurses/tinfo/captoinfo.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,6 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
****************************************************************************/
/*
@@ -39,7 +40,7 @@
*
* There is just one entry point:
*
- * char *_nc_captoinfo(n, s, parametrized)
+ * char *_nc_captoinfo(n, s, parameterized)
*
* Convert value s for termcap string capability named n into terminfo
* format.
@@ -92,7 +93,7 @@
#include <ctype.h>
#include <tic.h>
-MODULE_ID("$Id: captoinfo.c,v 1.41 2001/06/02 22:50:31 skimo Exp $")
+MODULE_ID("$Id: captoinfo.c,v 1.49 2006/12/16 19:16:53 tom Exp $")
#define MAX_PUSHED 16 /* max # args we can push onto the stack */
@@ -115,7 +116,7 @@ init_string(void)
if (my_string == 0)
my_string = typeMalloc(char, my_length = 256);
if (my_string == 0)
- _nc_err_abort("Out of memory");
+ _nc_err_abort(MSG_NO_MEMORY);
*my_string = '\0';
return my_string;
@@ -129,18 +130,18 @@ save_string(char *d, const char *const s)
if (need > my_length) {
my_string = (char *) realloc(my_string, my_length = (need + need));
if (my_string == 0)
- _nc_err_abort("Out of memory");
+ _nc_err_abort(MSG_NO_MEMORY);
d = my_string + have;
}
(void) strcpy(d, s);
return d + strlen(d);
}
-static inline char *
-save_char(char *s, char c)
+static NCURSES_INLINE char *
+save_char(char *s, int c)
{
static char temp[2];
- temp[0] = c;
+ temp[0] = (char) c;
return save_string(s, temp);
}
@@ -272,12 +273,12 @@ getparm(int parm, int n)
* Convert a termcap string to terminfo format.
* 'cap' is the relevant terminfo capability index.
* 's' is the string value of the capability.
- * 'parametrized' tells what type of translations to do:
+ * 'parameterized' tells what type of translations to do:
* % translations if 1
* pad translations if >=0
*/
-char *
-_nc_captoinfo(const char *cap, const char *s, int const parametrized)
+NCURSES_EXPORT(char *)
+_nc_captoinfo(const char *cap, const char *s, int const parameterized)
{
const char *capstart;
@@ -294,7 +295,7 @@ _nc_captoinfo(const char *cap, const char *s, int const parametrized)
capstart = 0;
if (s == 0)
s = "";
- if (parametrized >= 0 && isdigit(UChar(*s)))
+ if (parameterized >= 0 && isdigit(UChar(*s)))
for (capstart = s;; s++)
if (!(isdigit(UChar(*s)) || *s == '*' || *s == '.'))
break;
@@ -303,7 +304,7 @@ _nc_captoinfo(const char *cap, const char *s, int const parametrized)
switch (*s) {
case '%':
s++;
- if (parametrized < 1) {
+ if (parameterized < 1) {
dp = save_char(dp, '%');
break;
}
@@ -464,7 +465,7 @@ _nc_captoinfo(const char *cap, const char *s, int const parametrized)
dp = save_char(dp, '%');
s--;
_nc_warning("unknown %% code %s (%#x) in %s",
- unctrl((chtype) * s), UChar(*s), cap);
+ unctrl((chtype) *s), UChar(*s), cap);
break;
}
break;
@@ -636,8 +637,8 @@ save_tc_inequality(char *bufptr, int c1, int c2)
* Convert a terminfo string to termcap format. Parameters are as in
* _nc_captoinfo().
*/
-char *
-_nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parametrized)
+NCURSES_EXPORT(char *)
+_nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameterized)
{
int seenone = 0, seentwo = 0, saw_m = 0, saw_n = 0;
const char *padding;
@@ -649,11 +650,11 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parametrize
/* we may have to move some trailing mandatory padding up front */
padding = str + strlen(str) - 1;
- if (*padding == '>' && *--padding == '/') {
+ if (padding > str && *padding == '>' && *--padding == '/') {
--padding;
while (isdigit(UChar(*padding)) || *padding == '.' || *padding == '*')
padding--;
- if (*padding == '<' && *--padding == '$')
+ if (padding > str && *padding == '<' && *--padding == '$')
trimmed = padding;
padding += 2;
@@ -678,7 +679,8 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parametrize
--str;
} else if (str[0] == '%' && str[1] == '%') { /* escaped '%' */
bufptr = save_string(bufptr, "%%");
- } else if (*str != '%' || (parametrized < 1)) {
+ ++str;
+ } else if (*str != '%' || (parameterized < 1)) {
bufptr = save_char(bufptr, *str);
} else if (sscanf(str, "%%?%%{%d}%%>%%t%%{%d}%%+%%;", &c1, &c2) == 2) {
str = strchr(str, ';');
@@ -833,4 +835,13 @@ main(int argc, char *argv[])
}
#endif /* MAIN */
-/* captoinfo.c ends here */
+#if NO_LEAKS
+NCURSES_EXPORT(void)
+_nc_captoinfo_leaks(void)
+{
+ if (my_string != 0) {
+ FreeAndNull(my_string);
+ }
+ my_length = 0;
+}
+#endif
diff --git a/contrib/ncurses/ncurses/tinfo/comp_error.c b/contrib/ncurses/ncurses/tinfo/comp_error.c
index e67cb795dd33..015f34886eb1 100644
--- a/contrib/ncurses/ncurses/tinfo/comp_error.c
+++ b/contrib/ncurses/ncurses/tinfo/comp_error.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2002,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,6 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
****************************************************************************/
/*
@@ -40,7 +41,7 @@
#include <tic.h>
-MODULE_ID("$Id: comp_error.c,v 1.23 2001/09/23 00:58:30 tom Exp $")
+MODULE_ID("$Id: comp_error.c,v 1.30 2005/11/26 15:28:47 tom Exp $")
NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings = FALSE;
NCURSES_EXPORT_VAR(int) _nc_curr_line = 0; /* current line # in input */
@@ -49,6 +50,12 @@ NCURSES_EXPORT_VAR(int) _nc_curr_col = 0; /* current column # in input */
static const char *sourcename;
static char *termtype;
+NCURSES_EXPORT(const char *)
+_nc_get_source(void)
+{
+ return sourcename;
+}
+
NCURSES_EXPORT(void)
_nc_set_source(const char *const name)
{
@@ -59,19 +66,28 @@ NCURSES_EXPORT(void)
_nc_set_type(const char *const name)
{
if (termtype == 0)
- termtype = _nc_doalloc(termtype, MAX_NAME_SIZE + 1);
- termtype[0] = '\0';
- if (name)
- strncat(termtype, name, MAX_NAME_SIZE);
+ termtype = typeMalloc(char, MAX_NAME_SIZE + 1);
+ if (termtype != 0) {
+ termtype[0] = '\0';
+ if (name)
+ strncat(termtype, name, MAX_NAME_SIZE);
+ }
}
NCURSES_EXPORT(void)
_nc_get_type(char *name)
{
- strcpy(name, termtype != 0 ? termtype : "");
+#if NO_LEAKS
+ if (name == 0 && termtype != 0) {
+ FreeAndNull(termtype);
+ return;
+ }
+#endif
+ if (name != 0)
+ strcpy(name, termtype != 0 ? termtype : "");
}
-static inline void
+static NCURSES_INLINE void
where_is_problem(void)
{
fprintf(stderr, "\"%s\"", sourcename);
diff --git a/contrib/ncurses/ncurses/tinfo/comp_expand.c b/contrib/ncurses/ncurses/tinfo/comp_expand.c
index 7ba438aff8e2..ef419d84cd2c 100644
--- a/contrib/ncurses/ncurses/tinfo/comp_expand.c
+++ b/contrib/ncurses/ncurses/tinfo/comp_expand.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -35,7 +35,7 @@
#include <ctype.h>
#include <tic.h>
-MODULE_ID("$Id: comp_expand.c,v 1.17 2001/09/22 19:16:52 tom Exp $")
+MODULE_ID("$Id: comp_expand.c,v 1.18 2006/06/17 19:37:14 tom Exp $")
static int
trailing_spaces(const char *src)
@@ -50,8 +50,7 @@ trailing_spaces(const char *src)
#define REALPRINT(s) (UChar(*(s)) < 127 && isprint(UChar(*(s))))
NCURSES_EXPORT(char *)
-_nc_tic_expand
-(const char *srcp, bool tic_format, int numbers)
+_nc_tic_expand(const char *srcp, bool tic_format, int numbers)
{
static char *buffer;
static size_t length;
@@ -62,6 +61,15 @@ _nc_tic_expand
size_t need = (2 + strlen(str)) * 4;
int ch;
+#if NO_LEAKS
+ if (srcp == 0) {
+ if (buffer != 0) {
+ FreeAndNull(buffer);
+ length = 0;
+ }
+ return 0;
+ }
+#endif
if (buffer == 0 || need > length) {
if ((buffer = typeRealloc(char, length = need, buffer)) == 0)
return 0;
diff --git a/contrib/ncurses/ncurses/tinfo/comp_hash.c b/contrib/ncurses/ncurses/tinfo/comp_hash.c
index 9f2ee71041e4..d4d9eaa62e13 100644
--- a/contrib/ncurses/ncurses/tinfo/comp_hash.c
+++ b/contrib/ncurses/ncurses/tinfo/comp_hash.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,6 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
****************************************************************************/
/*
@@ -37,6 +38,7 @@
*
*/
+#define USE_TERMLIB 1
#include <curses.priv.h>
#include <tic.h>
@@ -48,7 +50,7 @@
#define DEBUG(level, params) /*nothing */
#endif
-MODULE_ID("$Id: comp_hash.c,v 1.25 2001/06/02 22:50:42 skimo Exp $")
+MODULE_ID("$Id: comp_hash.c,v 1.28 2005/08/20 19:58:18 tom Exp $")
static int hash_function(const char *);
@@ -97,12 +99,11 @@ _nc_make_hash_table(struct name_table_entry *table,
* Computes the hashing function on the given string.
*
* The current hash function is the sum of each consectutive pair
- * of characters, taken as two-byte integers, mod Hashtabsize.
+ * of characters, taken as two-byte integers, mod HASHTABSIZE.
*
*/
-static
-int
+static int
hash_function(const char *string)
{
long sum = 0;
@@ -128,8 +129,8 @@ hash_function(const char *string)
#ifndef MAIN_PROGRAM
NCURSES_EXPORT(struct name_table_entry const *)
-_nc_find_entry
-(const char *string, const struct name_table_entry *const *hash_table)
+_nc_find_entry(const char *string,
+ const struct name_table_entry *const *hash_table)
{
int hashvalue;
struct name_table_entry const *ptr;
@@ -159,10 +160,9 @@ _nc_find_entry
*/
NCURSES_EXPORT(struct name_table_entry const *)
-_nc_find_type_entry
-(const char *string,
- int type,
- const struct name_table_entry *table)
+_nc_find_type_entry(const char *string,
+ int type,
+ const struct name_table_entry *table)
{
struct name_table_entry const *ptr;
diff --git a/contrib/ncurses/ncurses/tinfo/comp_parse.c b/contrib/ncurses/ncurses/tinfo/comp_parse.c
index f11843828e09..667b3257f25a 100644
--- a/contrib/ncurses/ncurses/tinfo/comp_parse.c
+++ b/contrib/ncurses/ncurses/tinfo/comp_parse.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,18 +29,19 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
****************************************************************************/
/*
* comp_parse.c -- parser driver loop and use handling.
*
* _nc_read_entry_source(FILE *, literal, bool, bool (*hook)())
- * _nc_resolve_uses(void)
+ * _nc_resolve_uses2(void)
* _nc_free_entries(void)
*
* Use this code by calling _nc_read_entry_source() on as many source
* files as you like (either terminfo or termcap syntax). If you
- * want use-resolution, call _nc_resolve_uses(). To free the list
+ * want use-resolution, call _nc_resolve_uses2(). To free the list
* storage, do _nc_free_entries().
*
*/
@@ -52,8 +53,12 @@
#include <tic.h>
#include <term_entry.h>
-MODULE_ID("$Id: comp_parse.c,v 1.50 2001/06/16 17:52:18 tom Exp $")
+MODULE_ID("$Id: comp_parse.c,v 1.63 2006/07/08 18:55:14 tom Exp $")
+static void sanity_check2(TERMTYPE *, bool);
+NCURSES_IMPEXP void NCURSES_API(*_nc_check_termtype2) (TERMTYPE *, bool) = sanity_check2;
+
+/* obsolete: 20040705 */
static void sanity_check(TERMTYPE *);
NCURSES_IMPEXP void NCURSES_API(*_nc_check_termtype) (TERMTYPE *) = sanity_check;
@@ -81,14 +86,14 @@ NCURSES_IMPEXP void NCURSES_API(*_nc_check_termtype) (TERMTYPE *) = sanity_check
NCURSES_EXPORT_VAR(ENTRY *) _nc_head = 0;
NCURSES_EXPORT_VAR(ENTRY *) _nc_tail = 0;
- static void
- enqueue(ENTRY * ep)
+static void
+enqueue(ENTRY * ep)
/* add an entry to the in-core list */
{
ENTRY *newp = _nc_copy_entry(ep);
if (newp == 0)
- _nc_err_abort("Out of memory");
+ _nc_err_abort(MSG_NO_MEMORY);
newp->last = _nc_tail;
_nc_tail = newp;
@@ -102,24 +107,44 @@ NCURSES_EXPORT(void)
_nc_free_entries(ENTRY * headp)
/* free the allocated storage consumed by list entries */
{
- ENTRY *ep, *next;
+ (void) headp; /* unused - _nc_head is altered here! */
- for (ep = headp; ep; ep = next) {
- /*
- * This conditional lets us disconnect storage from the list.
- * To do this, copy an entry out of the list, then null out
- * the string-table member in the original and any use entries
- * it references.
- */
- FreeIfNeeded(ep->tterm.str_table);
+ while (_nc_head != 0) {
+ _nc_free_termtype(&(_nc_head->tterm));
+ }
+}
+
+NCURSES_EXPORT(ENTRY *)
+_nc_delink_entry(ENTRY * headp, TERMTYPE *tterm)
+/* delink the allocated storage for the given list entry */
+{
+ ENTRY *ep, *last;
+
+ for (last = 0, ep = headp; ep != 0; last = ep, ep = ep->next) {
+ if (&(ep->tterm) == tterm) {
+ if (last != 0) {
+ last->next = ep->next;
+ }
+ if (ep == _nc_head) {
+ _nc_head = ep->next;
+ }
+ if (ep == _nc_tail) {
+ _nc_tail = last;
+ }
+ break;
+ }
+ }
+ return ep;
+}
- next = ep->next;
+NCURSES_EXPORT(void)
+_nc_free_entry(ENTRY * headp, TERMTYPE *tterm)
+/* free the allocated storage consumed by the given list entry */
+{
+ ENTRY *ep;
+ if ((ep = _nc_delink_entry(headp, tterm)) != 0) {
free(ep);
- if (ep == _nc_head)
- _nc_head = 0;
- if (ep == _nc_tail)
- _nc_tail = 0;
}
}
@@ -163,7 +188,7 @@ _nc_entry_match(char *n1, char *n2)
****************************************************************************/
NCURSES_EXPORT(void)
-_nc_read_entry_source(FILE * fp, char *buf,
+_nc_read_entry_source(FILE *fp, char *buf,
int literal, bool silent,
bool(*hook) (ENTRY *))
/* slurp all entries in the given file into core */
@@ -184,14 +209,25 @@ _nc_read_entry_source(FILE * fp, char *buf,
_nc_err_abort("terminal names must start with letter or digit");
/*
- * This can be used for immediate compilation of entries with no
- * use references to disk, so as to avoid chewing up a lot of
- * core when the resolution code could fetch entries off disk.
+ * This can be used for immediate compilation of entries with no "use="
+ * references to disk. That avoids consuming a lot of memory when the
+ * resolution code could fetch entries off disk.
*/
- if (hook != NULLHOOK && (*hook) (&thisentry))
+ if (hook != NULLHOOK && (*hook) (&thisentry)) {
immediate++;
- else
+ } else {
enqueue(&thisentry);
+ /*
+ * The enqueued entry is copied with _nc_copy_termtype(), so we can
+ * free some of the data from thisentry, i.e., the arrays.
+ */
+ FreeIfNeeded(thisentry.tterm.Booleans);
+ FreeIfNeeded(thisentry.tterm.Numbers);
+ FreeIfNeeded(thisentry.tterm.Strings);
+#if NCURSES_XNAMES
+ FreeIfNeeded(thisentry.tterm.ext_Names);
+#endif
+ }
}
if (_nc_tail) {
@@ -211,12 +247,12 @@ _nc_read_entry_source(FILE * fp, char *buf,
}
NCURSES_EXPORT(int)
-_nc_resolve_uses(bool fullresolve)
+_nc_resolve_uses2(bool fullresolve, bool literal)
/* try to resolve all use capabilities */
{
ENTRY *qp, *rp, *lastread = 0;
bool keepgoing;
- int i, j, unresolved, total_unresolved, multiples;
+ int i, unresolved, total_unresolved, multiples;
DEBUG(2, ("RESOLUTION BEGINNING"));
@@ -289,7 +325,7 @@ _nc_resolve_uses(bool fullresolve)
rp = typeMalloc(ENTRY, 1);
if (rp == 0)
- _nc_err_abort("Out of memory");
+ _nc_err_abort(MSG_NO_MEMORY);
rp->tterm = thisterm;
rp->nuses = 0;
rp->next = lastread;
@@ -320,8 +356,8 @@ _nc_resolve_uses(bool fullresolve)
DEBUG(2, ("NAME RESOLUTION COMPLETED OK"));
/*
- * OK, at this point all (char *) references in `name' mwmbers
- * have been successfully converred to (ENTRY *) pointers in
+ * OK, at this point all (char *) references in `name' members
+ * have been successfully converted to (ENTRY *) pointers in
* `link' members. Time to do the actual merges.
*/
if (fullresolve) {
@@ -347,10 +383,10 @@ _nc_resolve_uses(bool fullresolve)
}
/*
- * First, make sure there's no garbage in the
- * merge block. as a side effect, copy into
- * the merged entry the name field and string
- * table pointer.
+ * First, make sure there is no garbage in the
+ * merge block. As a side effect, copy into
+ * the merged entry the name field and string
+ * table pointer.
*/
_nc_copy_termtype(&merged, &(qp->tterm));
@@ -373,6 +409,9 @@ _nc_resolve_uses(bool fullresolve)
FreeIfNeeded(qp->tterm.Booleans);
FreeIfNeeded(qp->tterm.Numbers);
FreeIfNeeded(qp->tterm.Strings);
+#if NCURSES_XNAMES
+ FreeIfNeeded(qp->tterm.ext_Names);
+#endif
qp->tterm = merged;
_nc_wrap_entry(qp, TRUE);
@@ -389,26 +428,6 @@ _nc_resolve_uses(bool fullresolve)
(keepgoing);
DEBUG(2, ("MERGES COMPLETED OK"));
-
- /*
- * The exit condition of the loop above is such that all entries
- * must now be resolved. Now handle cancellations. In a resolved
- * entry there should be no cancellation markers.
- */
- for_entry_list(qp) {
- for_each_boolean(j, &(qp->tterm)) {
- if ((int) qp->tterm.Booleans[j] == CANCELLED_BOOLEAN)
- qp->tterm.Booleans[j] = ABSENT_BOOLEAN;
- }
- for_each_number(j, &(qp->tterm)) {
- if (qp->tterm.Numbers[j] == CANCELLED_NUMERIC)
- qp->tterm.Numbers[j] = ABSENT_NUMERIC;
- }
- for_each_string(j, &(qp->tterm)) {
- if (qp->tterm.Strings[j] == CANCELLED_STRING)
- qp->tterm.Strings[j] = ABSENT_STRING;
- }
- }
}
/*
@@ -426,7 +445,7 @@ _nc_resolve_uses(bool fullresolve)
for_entry_list(qp) {
_nc_curr_line = qp->startline;
_nc_set_type(_nc_first_name(qp->tterm.term_names));
- _nc_check_termtype(&qp->tterm);
+ _nc_check_termtype2(&qp->tterm, literal);
}
DEBUG(2, ("SANITY CHECK FINISHED"));
}
@@ -434,6 +453,13 @@ _nc_resolve_uses(bool fullresolve)
return (TRUE);
}
+/* obsolete: 20040705 */
+NCURSES_EXPORT(int)
+_nc_resolve_uses(bool fullresolve)
+{
+ return _nc_resolve_uses2(fullresolve, FALSE);
+}
+
/*
* This bit of legerdemain turns all the terminfo variable names into
* references to locations in the arrays Booleans, Numbers, and Strings ---
@@ -444,7 +470,7 @@ _nc_resolve_uses(bool fullresolve)
#define CUR tp->
static void
-sanity_check(TERMTYPE * tp)
+sanity_check2(TERMTYPE *tp, bool literal)
{
if (!PRESENT(exit_attribute_mode)) {
#ifdef __UNUSED__ /* this casts too wide a net */
@@ -461,22 +487,24 @@ sanity_check(TERMTYPE * tp)
|| PRESENT(enter_reverse_mode)))
_nc_warning("no exit_attribute_mode");
#endif /* __UNUSED__ */
- PAIRED(enter_standout_mode, exit_standout_mode)
- PAIRED(enter_underline_mode, exit_underline_mode)
+ PAIRED(enter_standout_mode, exit_standout_mode);
+ PAIRED(enter_underline_mode, exit_underline_mode);
}
/* we do this check/fix in postprocess_termcap(), but some packagers
* prefer to bypass it...
*/
- if (acs_chars == 0
- && enter_alt_charset_mode != 0
- && exit_alt_charset_mode != 0)
- acs_chars = strdup(VT_ACSC);
+ if (!literal) {
+ if (acs_chars == 0
+ && enter_alt_charset_mode != 0
+ && exit_alt_charset_mode != 0)
+ acs_chars = strdup(VT_ACSC);
+ ANDMISSING(enter_alt_charset_mode, acs_chars);
+ ANDMISSING(exit_alt_charset_mode, acs_chars);
+ }
/* listed in structure-member order of first argument */
PAIRED(enter_alt_charset_mode, exit_alt_charset_mode);
- ANDMISSING(enter_alt_charset_mode, acs_chars);
- ANDMISSING(exit_alt_charset_mode, acs_chars);
ANDMISSING(enter_blink_mode, exit_attribute_mode);
ANDMISSING(enter_bold_mode, exit_attribute_mode);
PAIRED(exit_ca_mode, enter_ca_mode);
@@ -499,3 +527,10 @@ sanity_check(TERMTYPE * tp)
#endif
ANDMISSING(set_color_pair, initialize_pair);
}
+
+/* obsolete: 20040705 */
+static void
+sanity_check(TERMTYPE *tp)
+{
+ sanity_check2(tp, FALSE);
+}
diff --git a/contrib/ncurses/ncurses/tinfo/comp_scan.c b/contrib/ncurses/ncurses/tinfo/comp_scan.c
index 52fb13a7f76e..e937f7eb5ada 100644
--- a/contrib/ncurses/ncurses/tinfo/comp_scan.c
+++ b/contrib/ncurses/ncurses/tinfo/comp_scan.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,6 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996 on *
****************************************************************************/
/*
@@ -50,7 +51,7 @@
#include <term_entry.h>
#include <tic.h>
-MODULE_ID("$Id: comp_scan.c,v 1.59 2001/09/23 00:56:29 tom Exp $")
+MODULE_ID("$Id: comp_scan.c,v 1.78 2006/12/16 19:17:01 tom Exp $")
/*
* Maximum length of string capability we'll accept before raising an error.
@@ -84,6 +85,7 @@ _nc_curr_token =
*****************************************************************************/
static bool first_column; /* See 'next_char()' below */
+static bool had_newline;
static char separator; /* capability separator */
static int pushtype; /* type of pushback token */
static char *pushname;
@@ -93,14 +95,196 @@ NCURSES_EXPORT_VAR(bool)
_nc_disable_period = FALSE; /* used by tic -a option */
#endif
-static int last_char(void);
-static int next_char(void);
-static long stream_pos(void);
-static bool end_of_stream(void);
-static void push_back(char c);
+/*****************************************************************************
+ *
+ * Character-stream handling
+ *
+ *****************************************************************************/
+
+#define LEXBUFSIZ 1024
+
+static char *bufptr; /* otherwise, the input buffer pointer */
+static char *bufstart; /* start of buffer so we can compute offsets */
+static FILE *yyin; /* scanner's input file descriptor */
+
+/*
+ * _nc_reset_input()
+ *
+ * Resets the input-reading routines. Used on initialization,
+ * or after a seek has been done. Exactly one argument must be
+ * non-null.
+ */
+
+NCURSES_EXPORT(void)
+_nc_reset_input(FILE *fp, char *buf)
+{
+ pushtype = NO_PUSHBACK;
+ if (pushname != 0)
+ pushname[0] = '\0';
+ yyin = fp;
+ bufstart = bufptr = buf;
+ _nc_curr_file_pos = 0L;
+ if (fp != 0)
+ _nc_curr_line = 0;
+ _nc_curr_col = 0;
+}
+
+/*
+ * int last_char()
+ *
+ * Returns the final nonblank character on the current input buffer
+ */
+static int
+last_char(void)
+{
+ size_t len = strlen(bufptr);
+ while (len--) {
+ if (!isspace(UChar(bufptr[len])))
+ return bufptr[len];
+ }
+ return 0;
+}
+
+/*
+ * int next_char()
+ *
+ * Returns the next character in the input stream. Comments and leading
+ * white space are stripped.
+ *
+ * The global state variable 'firstcolumn' is set TRUE if the character
+ * returned is from the first column of the input line.
+ *
+ * The global variable _nc_curr_line is incremented for each new line.
+ * The global variable _nc_curr_file_pos is set to the file offset of the
+ * beginning of each line.
+ */
+
+static int
+next_char(void)
+{
+ static char *result;
+ static size_t allocated;
+ int the_char;
+
+ if (!yyin) {
+ if (result != 0) {
+ FreeAndNull(result);
+ FreeAndNull(pushname);
+ allocated = 0;
+ }
+ /*
+ * An string with an embedded null will truncate the input. This is
+ * intentional (we don't read binary files here).
+ */
+ if (bufptr == 0 || *bufptr == '\0')
+ return (EOF);
+ if (*bufptr == '\n') {
+ _nc_curr_line++;
+ _nc_curr_col = 0;
+ } else if (*bufptr == '\t') {
+ _nc_curr_col = (_nc_curr_col | 7);
+ }
+ } else if (!bufptr || !*bufptr) {
+ /*
+ * In theory this could be recoded to do its I/O one character at a
+ * time, saving the buffer space. In practice, this turns out to be
+ * quite hard to get completely right. Try it and see. If you
+ * succeed, don't forget to hack push_back() correspondingly.
+ */
+ size_t used;
+ size_t len;
+
+ do {
+ bufstart = 0;
+ used = 0;
+ do {
+ if (used + (LEXBUFSIZ / 4) >= allocated) {
+ allocated += (allocated + LEXBUFSIZ);
+ result = typeRealloc(char, allocated, result);
+ if (result == 0)
+ return (EOF);
+ }
+ if (used == 0)
+ _nc_curr_file_pos = ftell(yyin);
+
+ if (fgets(result + used, (int) (allocated - used), yyin) != 0) {
+ bufstart = result;
+ if (used == 0) {
+ _nc_curr_line++;
+ _nc_curr_col = 0;
+ }
+ } else {
+ if (used != 0)
+ strcat(result, "\n");
+ }
+ if ((bufptr = bufstart) != 0) {
+ used = strlen(bufptr);
+ while (iswhite(*bufptr)) {
+ if (*bufptr == '\t') {
+ _nc_curr_col = (_nc_curr_col | 7) + 1;
+ } else {
+ _nc_curr_col++;
+ }
+ bufptr++;
+ }
+
+ /*
+ * Treat a trailing <cr><lf> the same as a <newline> so we
+ * can read files on OS/2, etc.
+ */
+ if ((len = strlen(bufptr)) > 1) {
+ if (bufptr[len - 1] == '\n'
+ && bufptr[len - 2] == '\r') {
+ len--;
+ bufptr[len - 1] = '\n';
+ bufptr[len] = '\0';
+ }
+ }
+ } else {
+ return (EOF);
+ }
+ } while (bufptr[len - 1] != '\n'); /* complete a line */
+ } while (result[0] == '#'); /* ignore comments */
+ } else if (*bufptr == '\t') {
+ _nc_curr_col = (_nc_curr_col | 7);
+ }
+
+ first_column = (bufptr == bufstart);
+ if (first_column)
+ had_newline = FALSE;
+
+ _nc_curr_col++;
+ the_char = *bufptr++;
+ return UChar(the_char);
+}
+
+static void
+push_back(char c)
+/* push a character back onto the input stream */
+{
+ if (bufptr == bufstart)
+ _nc_syserr_abort("Can't backspace off beginning of line");
+ *--bufptr = c;
+ _nc_curr_col--;
+}
+
+static long
+stream_pos(void)
+/* return our current character position in the input stream */
+{
+ return (yyin ? ftell(yyin) : (bufptr ? bufptr - bufstart : 0));
+}
+
+static bool
+end_of_stream(void)
+/* are we at end of input? */
+{
+ return ((yyin ? feof(yyin) : (bufptr && *bufptr == '\0'))
+ ? TRUE : FALSE);
+}
/* Assume we may be looking at a termcap-style continuation */
-static inline int
+static NCURSES_INLINE int
eat_escaped_newline(int ch)
{
if (ch == '\\')
@@ -148,8 +332,11 @@ _nc_get_token(bool silent)
static const char terminfo_punct[] = "@%&*!#";
static char *buffer;
+ char *after_list;
+ char *after_name;
char *numchk;
char *ptr;
+ char *s;
char numbuf[80];
int ch;
int dot_flag = FALSE;
@@ -157,6 +344,10 @@ _nc_get_token(bool silent)
long number;
long token_start;
unsigned found;
+#ifdef TRACE
+ int old_line;
+ int old_col;
+#endif
if (pushtype != NO_PUSHBACK) {
int retval = pushtype;
@@ -173,16 +364,31 @@ _nc_get_token(bool silent)
return (retval);
}
- if (end_of_stream())
+ if (end_of_stream()) {
+ yyin = 0;
+ next_char(); /* frees its allocated memory */
+ if (buffer != 0) {
+ if (_nc_curr_token.tk_name == buffer)
+ _nc_curr_token.tk_name = 0;
+ FreeAndNull(buffer);
+ }
return (EOF);
+ }
start_token:
token_start = stream_pos();
- while ((ch = next_char()) == '\n' || iswhite(ch))
+ while ((ch = next_char()) == '\n' || iswhite(ch)) {
+ if (ch == '\n')
+ had_newline = TRUE;
continue;
+ }
ch = eat_escaped_newline(ch);
+#ifdef TRACE
+ old_line = _nc_curr_line;
+ old_col = _nc_curr_col;
+#endif
if (ch == EOF)
type = EOF;
else {
@@ -208,36 +414,44 @@ _nc_get_token(bool silent)
}
/* have to make some punctuation chars legal for terminfo */
- if (!isalnum(ch)
+ if (!isalnum(UChar(ch))
#if NCURSES_EXT_FUNCS
&& !(ch == '.' && _nc_disable_period)
#endif
&& !strchr(terminfo_punct, (char) ch)) {
if (!silent)
- _nc_warning("Illegal character (expected alphanumeric or %s) - %s",
+ _nc_warning("Illegal character (expected alphanumeric or %s) - '%s'",
terminfo_punct, unctrl((chtype) ch));
_nc_panic_mode(separator);
goto start_token;
}
if (buffer == 0)
- buffer = _nc_doalloc(buffer, MAX_ENTRY_SIZE);
+ buffer = typeMalloc(char, MAX_ENTRY_SIZE);
+#ifdef TRACE
+ old_line = _nc_curr_line;
+ old_col = _nc_curr_col;
+#endif
ptr = buffer;
*(ptr++) = ch;
if (first_column) {
- char *desc;
-
_nc_comment_start = token_start;
_nc_comment_end = _nc_curr_file_pos;
_nc_start_line = _nc_curr_line;
_nc_syntax = ERR;
+ after_name = 0;
+ after_list = 0;
while ((ch = next_char()) != '\n') {
- if (ch == EOF)
- _nc_err_abort("premature EOF");
- else if (ch == ':' && last_char() != ',') {
+ if (ch == EOF) {
+ _nc_err_abort(MSG_NO_INPUTS);
+ } else if (ch == '|') {
+ after_list = ptr;
+ if (after_name == 0)
+ after_name = ptr;
+ } else if (ch == ':' && last_char() != ',') {
_nc_syntax = SYN_TERMCAP;
separator = ':';
break;
@@ -245,14 +459,18 @@ _nc_get_token(bool silent)
_nc_syntax = SYN_TERMINFO;
separator = ',';
/*
- * Fall-through here is not an accident. The idea is that
- * if we see a comma, we figure this is terminfo unless we
- * subsequently run into a colon -- but we don't stop
- * looking for that colon until hitting a newline. This
+ * If we did not see a '|', then we found a name with no
+ * aliases or description.
+ */
+ if (after_name == 0)
+ break;
+ /*
+ * If we see a comma, we assume this is terminfo unless we
+ * subsequently run into a colon. But we don't stop
+ * looking for a colon until hitting a newline. This
* allows commas to be embedded in description fields of
* either syntax.
*/
- /* FALLTHRU */
} else
ch = eat_escaped_newline(ch);
@@ -277,58 +495,62 @@ _nc_get_token(bool silent)
/*
* This is the soonest we have the terminal name fetched. Set up
- * for following warning messages.
+ * for following warning messages. If there's no '|', then there
+ * is no description.
*/
- ptr = strchr(buffer, '|');
- if (ptr == (char *) NULL)
- ptr = buffer + strlen(buffer);
- ch = *ptr;
- *ptr = '\0';
- _nc_set_type(buffer);
- *ptr = ch;
+ if (after_name != 0) {
+ ch = *after_name;
+ *after_name = '\0';
+ _nc_set_type(buffer);
+ *after_name = ch;
+ }
/*
* Compute the boundary between the aliases and the description
* field for syntax-checking purposes.
*/
- desc = strrchr(buffer, '|');
- if (!silent && desc) {
- if (*desc == '\0')
- _nc_warning("empty longname field");
- else if (strchr(desc, ' ') == (char *) NULL)
- _nc_warning("older tic versions may treat the description field as an alias");
+ if (after_list != 0) {
+ if (!silent) {
+ if (*after_list == '\0')
+ _nc_warning("empty longname field");
+ else if (strchr(after_list, ' ') == 0)
+ _nc_warning("older tic versions may treat the description field as an alias");
+ }
+ } else {
+ after_list = buffer + strlen(buffer);
+ DEBUG(1, ("missing description"));
}
- if (!desc)
- desc = buffer + strlen(buffer);
/*
* Whitespace in a name field other than the long name can confuse
* rdist and some termcap tools. Slashes are a no-no. Other
* special characters can be dangerous due to shell expansion.
*/
- for (ptr = buffer; ptr < desc; ptr++) {
- if (isspace(UChar(*ptr))) {
+ for (s = buffer; s < after_list; ++s) {
+ if (isspace(UChar(*s))) {
if (!silent)
_nc_warning("whitespace in name or alias field");
break;
- } else if (*ptr == '/') {
+ } else if (*s == '/') {
if (!silent)
_nc_warning("slashes aren't allowed in names or aliases");
break;
- } else if (strchr("$[]!*?", *ptr)) {
+ } else if (strchr("$[]!*?", *s)) {
if (!silent)
- _nc_warning("dubious character `%c' in name or alias field", *ptr);
+ _nc_warning("dubious character `%c' in name or alias field", *s);
break;
}
}
- ptr = buffer;
-
_nc_curr_token.tk_name = buffer;
type = NAMES;
} else {
+ if (had_newline && _nc_syntax == SYN_TERMCAP) {
+ _nc_warning("Missing backslash before newline");
+ had_newline = FALSE;
+ }
while ((ch = next_char()) != EOF) {
- if (!isalnum(ch)) {
+ if (!isalnum(UChar(ch))) {
if (_nc_syntax == SYN_TERMINFO) {
if (ch != '_')
break;
@@ -393,7 +615,7 @@ _nc_get_token(bool silent)
/* just to get rid of the compiler warning */
type = UNDEF;
if (!silent)
- _nc_warning("Illegal character - %s", unctrl((chtype) ch));
+ _nc_warning("Illegal character - '%s'", unctrl((chtype) ch));
}
} /* end else (first_column == FALSE) */
} /* end else (ch != EOF) */
@@ -404,6 +626,11 @@ _nc_get_token(bool silent)
if (dot_flag == TRUE)
DEBUG(8, ("Commented out "));
+ if (_nc_tracing >= DEBUG_LEVEL(8)) {
+ _tracef("parsed %d.%d to %d.%d",
+ old_line, old_col,
+ _nc_curr_line, _nc_curr_col);
+ }
if (_nc_tracing >= DEBUG_LEVEL(7)) {
switch (type) {
case BOOLEAN:
@@ -448,8 +675,9 @@ _nc_get_token(bool silent)
type = _nc_get_token(silent);
DEBUG(3, ("token: `%s', class %d",
- _nc_curr_token.tk_name != 0 ? _nc_curr_token.tk_name :
- "<null>",
+ ((_nc_curr_token.tk_name != 0)
+ ? _nc_curr_token.tk_name
+ : "<null>"),
type));
return (type);
@@ -474,7 +702,7 @@ _nc_get_token(bool silent)
*
*/
-NCURSES_EXPORT(char)
+NCURSES_EXPORT(int)
_nc_trans_string(char *ptr, char *last)
{
int count = 0;
@@ -492,10 +720,10 @@ _nc_trans_string(char *ptr, char *last)
if (ch == '^' && last_ch != '%') {
ch = c = next_char();
if (c == EOF)
- _nc_err_abort("Premature EOF");
+ _nc_err_abort(MSG_NO_INPUTS);
if (!(is7bits(ch) && isprint(ch))) {
- _nc_warning("Illegal ^ character - %s", unctrl(ch));
+ _nc_warning("Illegal ^ character - '%s'", unctrl(ch));
}
if (ch == '?') {
*(ptr++) = '\177';
@@ -509,14 +737,14 @@ _nc_trans_string(char *ptr, char *last)
} else if (ch == '\\') {
ch = c = next_char();
if (c == EOF)
- _nc_err_abort("Premature EOF");
+ _nc_err_abort(MSG_NO_INPUTS);
if (ch >= '0' && ch <= '7') {
number = ch - '0';
for (i = 0; i < 2; i++) {
ch = c = next_char();
if (c == EOF)
- _nc_err_abort("Premature EOF");
+ _nc_err_abort(MSG_NO_INPUTS);
if (c < '0' || c > '7') {
if (isdigit(c)) {
@@ -590,21 +818,31 @@ _nc_trans_string(char *ptr, char *last)
continue;
default:
- _nc_warning("Illegal character %s in \\ sequence",
+ _nc_warning("Illegal character '%s' in \\ sequence",
unctrl(ch));
+ /* FALLTHRU */
+ case '|':
*(ptr++) = (char) ch;
} /* endswitch (ch) */
} /* endelse (ch < '0' || ch > '7') */
}
/* end else if (ch == '\\') */
else if (ch == '\n' && (_nc_syntax == SYN_TERMINFO)) {
- /* newlines embedded in a terminfo string are ignored */
+ /*
+ * Newlines embedded in a terminfo string are ignored, provided
+ * that the next line begins with whitespace.
+ */
ignored = TRUE;
} else {
*(ptr++) = (char) ch;
}
if (!ignored) {
+ if (_nc_curr_col <= 1) {
+ push_back(ch);
+ ch = '\n';
+ break;
+ }
last_ch = ch;
count++;
}
@@ -639,11 +877,14 @@ _nc_push_token(int tokclass)
*/
pushtype = tokclass;
if (pushname == 0)
- pushname = _nc_doalloc(pushname, MAX_NAME_SIZE + 1);
+ pushname = typeMalloc(char, MAX_NAME_SIZE + 1);
_nc_get_type(pushname);
DEBUG(3, ("pushing token: `%s', class %d",
- _nc_curr_token.tk_name, pushtype));
+ ((_nc_curr_token.tk_name != 0)
+ ? _nc_curr_token.tk_name
+ : "<null>"),
+ pushtype));
}
/*
@@ -663,169 +904,12 @@ _nc_panic_mode(char ch)
}
}
-/*****************************************************************************
- *
- * Character-stream handling
- *
- *****************************************************************************/
-
-#define LEXBUFSIZ 1024
-
-static char *bufptr; /* otherwise, the input buffer pointer */
-static char *bufstart; /* start of buffer so we can compute offsets */
-static FILE *yyin; /* scanner's input file descriptor */
-
-/*
- * _nc_reset_input()
- *
- * Resets the input-reading routines. Used on initialization,
- * or after a seek has been done. Exactly one argument must be
- * non-null.
- */
-
+#if NO_LEAKS
NCURSES_EXPORT(void)
-_nc_reset_input(FILE * fp, char *buf)
-{
- pushtype = NO_PUSHBACK;
- if (pushname != 0)
- pushname[0] = '\0';
- yyin = fp;
- bufstart = bufptr = buf;
- _nc_curr_file_pos = 0L;
- if (fp != 0)
- _nc_curr_line = 0;
- _nc_curr_col = 0;
-}
-
-/*
- * int last_char()
- *
- * Returns the final nonblank character on the current input buffer
- */
-static int
-last_char(void)
+_nc_comp_scan_leaks(void)
{
- size_t len = strlen(bufptr);
- while (len--) {
- if (!isspace(UChar(bufptr[len])))
- return bufptr[len];
- }
- return 0;
-}
-
-/*
- * int next_char()
- *
- * Returns the next character in the input stream. Comments and leading
- * white space are stripped.
- *
- * The global state variable 'firstcolumn' is set TRUE if the character
- * returned is from the first column of the input line.
- *
- * The global variable _nc_curr_line is incremented for each new line.
- * The global variable _nc_curr_file_pos is set to the file offset of the
- * beginning of each line.
- */
-
-static int
-next_char(void)
-{
- if (!yyin) {
- /*
- * An string with an embedded null will truncate the input. This is
- * intentional (we don't read binary files here).
- */
- if (*bufptr == '\0')
- return (EOF);
- if (*bufptr == '\n') {
- _nc_curr_line++;
- _nc_curr_col = 0;
- }
- } else if (!bufptr || !*bufptr) {
- /*
- * In theory this could be recoded to do its I/O one character at a
- * time, saving the buffer space. In practice, this turns out to be
- * quite hard to get completely right. Try it and see. If you
- * succeed, don't forget to hack push_back() correspondingly.
- */
- static char *result;
- static size_t allocated;
- size_t used;
- size_t len;
-
- do {
- bufstart = 0;
- used = 0;
- do {
- if (used + (LEXBUFSIZ / 4) >= allocated) {
- allocated += (allocated + LEXBUFSIZ);
- result = _nc_doalloc(result, allocated);
- if (result == 0)
- return (EOF);
- }
- if (used == 0)
- _nc_curr_file_pos = ftell(yyin);
-
- if (fgets(result + used, allocated - used, yyin) != NULL) {
- bufstart = result;
- if (used == 0) {
- _nc_curr_line++;
- _nc_curr_col = 0;
- }
- } else {
- if (used != 0)
- strcat(result, "\n");
- }
- if ((bufptr = bufstart) != 0) {
- used = strlen(bufptr);
- while (iswhite(*bufptr))
- bufptr++;
-
- /*
- * Treat a trailing <cr><lf> the same as a <newline> so we
- * can read files on OS/2, etc.
- */
- if ((len = strlen(bufptr)) > 1) {
- if (bufptr[len - 1] == '\n'
- && bufptr[len - 2] == '\r') {
- len--;
- bufptr[len - 1] = '\n';
- bufptr[len] = '\0';
- }
- }
- } else {
- return (EOF);
- }
- } while (bufptr[len - 1] != '\n'); /* complete a line */
- } while (result[0] == '#'); /* ignore comments */
+ if (pushname != 0) {
+ FreeAndNull(pushname);
}
-
- first_column = (bufptr == bufstart);
-
- _nc_curr_col++;
- return (*bufptr++);
-}
-
-static void
-push_back(char c)
-/* push a character back onto the input stream */
-{
- if (bufptr == bufstart)
- _nc_syserr_abort("Can't backspace off beginning of line");
- *--bufptr = c;
-}
-
-static long
-stream_pos(void)
-/* return our current character position in the input stream */
-{
- return (yyin ? ftell(yyin) : (bufptr ? bufptr - bufstart : 0));
-}
-
-static bool
-end_of_stream(void)
-/* are we at end of input? */
-{
- return ((yyin ? feof(yyin) : (bufptr && *bufptr == '\0'))
- ? TRUE : FALSE);
}
+#endif
diff --git a/contrib/ncurses/ncurses/tinfo/db_iterator.c b/contrib/ncurses/ncurses/tinfo/db_iterator.c
new file mode 100644
index 000000000000..e69aa5e18834
--- /dev/null
+++ b/contrib/ncurses/ncurses/tinfo/db_iterator.c
@@ -0,0 +1,227 @@
+/****************************************************************************
+ * Copyright (c) 2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey 2006 *
+ ****************************************************************************/
+
+/*
+ * Iterators for terminal databases.
+ */
+
+#include <curses.priv.h>
+
+#include <tic.h>
+
+MODULE_ID("$Id: db_iterator.c,v 1.5 2006/12/16 19:06:42 tom Exp $")
+
+static bool have_tic_directory = FALSE;
+static bool keep_tic_directory = FALSE;
+
+/*
+ * Record the "official" location of the terminfo directory, according to
+ * the place where we're writing to, or the normal default, if not.
+ */
+NCURSES_EXPORT(const char *)
+_nc_tic_dir(const char *path)
+{
+ static const char *result = TERMINFO;
+
+ if (!keep_tic_directory) {
+ if (path != 0) {
+ result = path;
+ have_tic_directory = TRUE;
+ } else if (!have_tic_directory && use_terminfo_vars()) {
+ char *envp;
+ if ((envp = getenv("TERMINFO")) != 0)
+ return _nc_tic_dir(envp);
+ }
+ }
+ return result;
+}
+
+/*
+ * Special fix to prevent the terminfo directory from being moved after tic
+ * has chdir'd to it. If we let it be changed, then if $TERMINFO has a
+ * relative path, we'll lose track of the actual directory.
+ */
+NCURSES_EXPORT(void)
+_nc_keep_tic_dir(const char *path)
+{
+ _nc_tic_dir(path);
+ keep_tic_directory = TRUE;
+}
+
+/*
+ * Process the list of :-separated directories, looking for the terminal type.
+ * We don't use strtok because it does not show us empty tokens.
+ */
+
+static char *this_db_list = 0;
+static int size_db_list;
+
+/*
+ * Cleanup.
+ */
+NCURSES_EXPORT(void)
+_nc_last_db(void)
+{
+ if (this_db_list != 0) {
+ FreeAndNull(this_db_list);
+ }
+ size_db_list = 0;
+}
+
+/* The TERMINFO_DIRS value, if defined by the configure script, begins with a
+ * ":", which will be interpreted as TERMINFO.
+ */
+static const char *
+next_list_item(const char *source, int *offset)
+{
+ if (source != 0) {
+ FreeIfNeeded(this_db_list);
+ this_db_list = strdup(source);
+ size_db_list = strlen(source);
+ }
+
+ if (this_db_list != 0 && size_db_list && *offset < size_db_list) {
+ static char system_db[] = TERMINFO;
+ char *result = this_db_list + *offset;
+ char *marker = strchr(result, NCURSES_PATHSEP);
+
+ /*
+ * Put a null on the marker if a separator was found. Set the offset
+ * to the next position after the marker so we can call this function
+ * again, using the data at the offset.
+ */
+ if (marker == 0) {
+ *offset += strlen(result) + 1;
+ marker = result + *offset;
+ } else {
+ *marker++ = 0;
+ *offset = marker - this_db_list;
+ }
+ if (*result == 0 && result != (this_db_list + size_db_list))
+ result = system_db;
+ return result;
+ }
+ return 0;
+}
+
+#define NEXT_DBD(var, offset) next_list_item((*offset == 0) ? var : 0, offset)
+
+/*
+ * This is a simple iterator which allows the caller to step through the
+ * possible locations for a terminfo directory. ncurses uses this to find
+ * terminfo files to read.
+ */
+NCURSES_EXPORT(const char *)
+_nc_next_db(DBDIRS * state, int *offset)
+{
+ const char *result;
+ char *envp;
+
+ while (*state < dbdLAST) {
+ DBDIRS next = (DBDIRS) ((int) (*state) + 1);
+
+ result = 0;
+
+ switch (*state) {
+ case dbdTIC:
+ if (have_tic_directory)
+ result = _nc_tic_dir(0);
+ break;
+#if USE_DATABASE
+ case dbdEnvOnce:
+ if (use_terminfo_vars()) {
+ if ((envp = getenv("TERMINFO")) != 0)
+ result = _nc_tic_dir(envp);
+ }
+ break;
+ case dbdHome:
+ if (use_terminfo_vars()) {
+ result = _nc_home_terminfo();
+ }
+ break;
+ case dbdEnvList:
+ if (use_terminfo_vars()) {
+ if ((result = NEXT_DBD(getenv("TERMINFO_DIRS"), offset)) != 0)
+ next = *state;
+ }
+ break;
+ case dbdCfgList:
+#ifdef TERMINFO_DIRS
+ if ((result = NEXT_DBD(TERMINFO_DIRS, offset)) != 0)
+ next = *state;
+#endif
+ break;
+ case dbdCfgOnce:
+#ifndef TERMINFO_DIRS
+ result = TERMINFO;
+#endif
+ break;
+#endif /* USE_DATABASE */
+#if USE_TERMCAP
+ case dbdEnvOnce2:
+ if (use_terminfo_vars()) {
+ if ((envp = getenv("TERMCAP")) != 0)
+ result = _nc_tic_dir(envp);
+ }
+ break;
+ case dbdEnvList2:
+ if (use_terminfo_vars()) {
+ if ((result = NEXT_DBD(getenv("TERMPATH"), offset)) != 0)
+ next = *state;
+ }
+ break;
+ case dbdCfgList2:
+ if ((result = NEXT_DBD(TERMPATH, offset)) != 0)
+ next = *state;
+ break;
+#endif /* USE_TERMCAP */
+ case dbdLAST:
+ break;
+ }
+ if (*state != next) {
+ *state = next;
+ *offset = 0;
+ _nc_last_db();
+ }
+ if (result != 0) {
+ return result;
+ }
+ }
+ return 0;
+}
+
+NCURSES_EXPORT(void)
+_nc_first_db(DBDIRS * state, int *offset)
+{
+ *state = dbdTIC;
+ *offset = 0;
+}
diff --git a/contrib/ncurses/ncurses/tinfo/doalloc.c b/contrib/ncurses/ncurses/tinfo/doalloc.c
index 634469cdf4ac..fe2a009d19b4 100644
--- a/contrib/ncurses/ncurses/tinfo/doalloc.c
+++ b/contrib/ncurses/ncurses/tinfo/doalloc.c
@@ -39,7 +39,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: doalloc.c,v 1.7 2000/12/10 02:55:07 tom Exp $")
+MODULE_ID("$Id: doalloc.c,v 1.8 2002/08/31 21:48:11 Philippe.Blain Exp $")
NCURSES_EXPORT(void *)
_nc_doalloc(void *oldp, size_t amount)
@@ -52,7 +52,7 @@ _nc_doalloc(void *oldp, size_t amount)
errno = ENOMEM; /* just in case 'free' reset */
}
} else {
- newp = typeMalloc(char, amount);
+ newp = malloc(amount);
}
return newp;
}
diff --git a/contrib/ncurses/ncurses/tinfo/free_ttype.c b/contrib/ncurses/ncurses/tinfo/free_ttype.c
index df604e41a681..fa0fff1b83fb 100644
--- a/contrib/ncurses/ncurses/tinfo/free_ttype.c
+++ b/contrib/ncurses/ncurses/tinfo/free_ttype.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1999,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1999-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -27,7 +27,7 @@
****************************************************************************/
/****************************************************************************
- * Author: Thomas E. Dickey <dickey@clark.net> 1999 *
+ * Author: Thomas E. Dickey 1999-on *
****************************************************************************/
/*
@@ -43,13 +43,14 @@
#include <tic.h>
#include <term_entry.h>
-MODULE_ID("$Id: free_ttype.c,v 1.7 2000/12/10 02:55:07 tom Exp $")
+MODULE_ID("$Id: free_ttype.c,v 1.13 2006/06/25 10:46:02 tom Exp $")
NCURSES_EXPORT(void)
-_nc_free_termtype(TERMTYPE * ptr)
+_nc_free_termtype(TERMTYPE *ptr)
{
+ T(("_nc_free_termtype(%s)", ptr->term_names));
+
FreeIfNeeded(ptr->str_table);
- FreeIfNeeded(ptr->term_names);
FreeIfNeeded(ptr->Booleans);
FreeIfNeeded(ptr->Numbers);
FreeIfNeeded(ptr->Strings);
@@ -58,6 +59,7 @@ _nc_free_termtype(TERMTYPE * ptr)
FreeIfNeeded(ptr->ext_Names);
#endif
memset(ptr, 0, sizeof(TERMTYPE));
+ _nc_free_entry(_nc_head, ptr);
}
#if NCURSES_XNAMES
@@ -67,7 +69,9 @@ NCURSES_EXPORT(int)
use_extended_names(bool flag)
{
int oldflag = _nc_user_definable;
+
+ T((T_CALLED("use_extended_names(%d)"), flag));
_nc_user_definable = flag;
- return oldflag;
+ returnBool(oldflag);
}
#endif
diff --git a/contrib/ncurses/ncurses/tinfo/hashed_db.c b/contrib/ncurses/ncurses/tinfo/hashed_db.c
new file mode 100644
index 000000000000..3fc04eae3cca
--- /dev/null
+++ b/contrib/ncurses/ncurses/tinfo/hashed_db.c
@@ -0,0 +1,260 @@
+/****************************************************************************
+ * Copyright (c) 2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey 2006 *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#include <tic.h>
+#include <hashed_db.h>
+
+#if USE_HASHED_DB
+
+MODULE_ID("$Id: hashed_db.c,v 1.13 2006/08/19 19:48:38 tom Exp $")
+
+#if HASHED_DB_API >= 2
+static DBC *cursor;
+#endif
+
+/*
+ * Open the database.
+ */
+NCURSES_EXPORT(DB *)
+_nc_db_open(const char *path, bool modify)
+{
+ DB *result = 0;
+
+#if HASHED_DB_API >= 4
+ db_create(&result, NULL, 0);
+ result->open(result,
+ NULL,
+ path,
+ NULL,
+ DB_HASH,
+ modify ? DB_CREATE : DB_RDONLY,
+ 0644);
+#elif HASHED_DB_API >= 3
+ db_create(&result, NULL, 0);
+ result->open(result,
+ path,
+ NULL,
+ DB_HASH,
+ modify ? DB_CREATE : DB_RDONLY,
+ 0644);
+#elif HASHED_DB_API >= 2
+ int code;
+
+ if ((code = db_open(path,
+ DB_HASH,
+ modify ? DB_CREATE : DB_RDONLY,
+ 0644,
+ (DB_ENV *) 0,
+ (DB_INFO *) 0,
+ &result)) != 0) {
+ T(("cannot open %s: %s", path, strerror(code)));
+ result = 0;
+ } else {
+ T(("opened %s", path));
+ }
+#else
+ result = dbopen(path,
+ modify ? (O_CREAT | O_RDWR) : O_RDONLY,
+ 0644,
+ DB_HASH,
+ NULL);
+ if (result != 0) {
+ T(("opened %s", path));
+ }
+#endif
+ return result;
+}
+
+/*
+ * Close the database. Do not attempt to use the 'db' handle after this call.
+ */
+NCURSES_EXPORT(int)
+_nc_db_close(DB * db)
+{
+ int result;
+
+#if HASHED_DB_API >= 2
+ result = db->close(db, 0);
+#else
+ result = db->close(db);
+#endif
+ return result;
+}
+
+/*
+ * Write a record to the database.
+ *
+ * Returns 0 on success.
+ *
+ * FIXME: the FreeBSD cap_mkdb program assumes the database could have
+ * duplicates. There appears to be no good reason for that (review/fix).
+ */
+NCURSES_EXPORT(int)
+_nc_db_put(DB * db, DBT * key, DBT * data)
+{
+ int result;
+#if HASHED_DB_API >= 2
+ /* remove any pre-existing value, since we do not want duplicates */
+ (void) db->del(db, NULL, key, 0);
+ result = db->put(db, NULL, key, data, DB_NOOVERWRITE);
+#else
+ result = db->put(db, key, data, R_NOOVERWRITE);
+#endif
+ return result;
+}
+
+/*
+ * Read a record from the database.
+ *
+ * Returns 0 on success.
+ */
+NCURSES_EXPORT(int)
+_nc_db_get(DB * db, DBT * key, DBT * data)
+{
+ int result;
+
+ memset(data, 0, sizeof(*data));
+#if HASHED_DB_API >= 2
+ result = db->get(db, NULL, key, data, 0);
+#else
+ result = db->get(db, key, data, 0);
+#endif
+ return result;
+}
+
+/*
+ * Read the first record from the database, ignoring order.
+ *
+ * Returns 0 on success.
+ */
+NCURSES_EXPORT(int)
+_nc_db_first(DB * db, DBT * key, DBT * data)
+{
+ int result;
+
+ memset(key, 0, sizeof(*key));
+ memset(data, 0, sizeof(*data));
+#if HASHED_DB_API >= 2
+ if ((result = db->cursor(db, NULL, &cursor, 0)) == 0) {
+ result = cursor->c_get(cursor, key, data, DB_FIRST);
+ }
+#else
+ result = db->seq(db, key, data, 0);
+#endif
+ return result;
+}
+
+/*
+ * Read the next record from the database, ignoring order.
+ *
+ * Returns 0 on success.
+ */
+NCURSES_EXPORT(int)
+_nc_db_next(DB * db, DBT * key, DBT * data)
+{
+ int result;
+
+#if HASHED_DB_API >= 2
+ (void) db;
+ if (cursor != 0) {
+ result = cursor->c_get(cursor, key, data, DB_NEXT);
+ } else {
+ result = -1;
+ }
+#else
+ result = db->seq(db, key, data, 0);
+#endif
+ return result;
+}
+
+/*
+ * Check if a record is a terminfo index record. Index records are those that
+ * contain only an alias pointing to a list of aliases.
+ */
+NCURSES_EXPORT(bool)
+_nc_db_have_index(DBT * key, DBT * data, char **buffer, int *size)
+{
+ bool result = FALSE;
+ int used = data->size - 1;
+ char *have = (char *) data->data;
+
+ (void) key;
+ if (*have++ == 2) {
+ result = TRUE;
+ }
+ /*
+ * Update params in any case for consistency with _nc_db_have_data().
+ */
+ *buffer = have;
+ *size = used;
+ return result;
+}
+
+/*
+ * Check if a record is the terminfo data record. Ignore index records, e.g.,
+ * those that contain only an alias pointing to a list of aliases.
+ */
+NCURSES_EXPORT(bool)
+_nc_db_have_data(DBT * key, DBT * data, char **buffer, int *size)
+{
+ bool result = FALSE;
+ int used = data->size - 1;
+ char *have = (char *) data->data;
+
+ if (*have++ == 0) {
+ if (data->size > key->size
+ && IS_TIC_MAGIC(have)) {
+ result = TRUE;
+ }
+ }
+ /*
+ * Update params in any case to make it simple to follow a index record
+ * to the data record.
+ */
+ *buffer = have;
+ *size = used;
+ return result;
+}
+
+#else
+
+extern
+NCURSES_EXPORT(void)
+_nc_hashed_db(void);
+
+NCURSES_EXPORT(void)
+_nc_hashed_db(void)
+{
+}
+
+#endif /* USE_HASHED_DB */
diff --git a/contrib/ncurses/ncurses/tinfo/home_terminfo.c b/contrib/ncurses/ncurses/tinfo/home_terminfo.c
index 47b3e382ef7e..ce6576a82f82 100644
--- a/contrib/ncurses/ncurses/tinfo/home_terminfo.c
+++ b/contrib/ncurses/ncurses/tinfo/home_terminfo.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -27,7 +27,7 @@
****************************************************************************/
/****************************************************************************
- * Author: Thomas E. Dickey <dickey@clark.net> 1998,2000 *
+ * Author: Thomas E. Dickey 1998,2000,2004,2005 *
****************************************************************************/
/*
@@ -37,7 +37,7 @@
#include <curses.priv.h>
#include <tic.h>
-MODULE_ID("$Id: home_terminfo.c,v 1.6 2000/12/10 02:55:07 tom Exp $")
+MODULE_ID("$Id: home_terminfo.c,v 1.9 2005/07/02 19:43:38 tom Exp $")
#define my_length (strlen(home) + sizeof(PRIVATE_INFO))
@@ -46,6 +46,8 @@ MODULE_ID("$Id: home_terminfo.c,v 1.6 2000/12/10 02:55:07 tom Exp $")
NCURSES_EXPORT(char *)
_nc_home_terminfo(void)
{
+ char *result = 0;
+#ifdef USE_HOME_TERMINFO
char *home;
static char *temp = 0;
@@ -55,11 +57,12 @@ _nc_home_terminfo(void)
&& my_length <= PATH_MAX) {
temp = typeMalloc(char, my_length);
if (temp == 0)
- _nc_err_abort("Out of memory");
+ _nc_err_abort(MSG_NO_MEMORY);
(void) sprintf(temp, PRIVATE_INFO, home);
}
}
- return temp;
+ result = temp;
}
- return 0;
+#endif
+ return result;
}
diff --git a/contrib/ncurses/ncurses/tinfo/init_keytry.c b/contrib/ncurses/ncurses/tinfo/init_keytry.c
index cf840e8e93b3..3461dd4d5e51 100644
--- a/contrib/ncurses/ncurses/tinfo/init_keytry.c
+++ b/contrib/ncurses/ncurses/tinfo/init_keytry.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1999,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1999-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -28,11 +28,15 @@
#include <curses.priv.h>
-#include <term.h> /* keypad_xmit, keypad_local, meta_on, meta_off */
- /* cursor_visible,cursor_normal,cursor_invisible */
+#include <term.h>
+/* keypad_xmit, keypad_local, meta_on, meta_off */
+/* cursor_visible,cursor_normal,cursor_invisible */
+
#include <tic.h> /* struct tinfo_fkeys */
-MODULE_ID("$Id: init_keytry.c,v 1.5 2000/12/10 02:55:07 tom Exp $")
+#include <term_entry.h>
+
+MODULE_ID("$Id: init_keytry.c,v 1.8 2006/01/21 23:43:28 tom Exp $")
/*
** _nc_init_keytry()
@@ -69,12 +73,38 @@ _nc_init_keytry(void)
* mouse_activate() (which will call keyok()) are first called.
*/
- for (n = 0; _nc_tinfo_fkeys[n].code; n++)
- if (_nc_tinfo_fkeys[n].offset < STRCOUNT)
- _nc_add_to_try(&(SP->_keytry),
- CUR Strings[_nc_tinfo_fkeys[n].offset],
- _nc_tinfo_fkeys[n].code);
+ if (SP != 0) {
+ for (n = 0; _nc_tinfo_fkeys[n].code; n++) {
+ if (_nc_tinfo_fkeys[n].offset < STRCOUNT) {
+ _nc_add_to_try(&(SP->_keytry),
+ CUR Strings[_nc_tinfo_fkeys[n].offset],
+ _nc_tinfo_fkeys[n].code);
+ }
+ }
+#if NCURSES_XNAMES
+ /*
+ * Add any of the extended strings to the tries if their name begins
+ * with 'k', i.e., they follow the convention of other terminfo key
+ * names.
+ */
+ {
+ TERMTYPE *tp = &(SP->_term->type);
+ for (n = STRCOUNT; n < NUM_STRINGS(tp); ++n) {
+ const char *name = ExtStrname(tp, n, strnames);
+ char *value = tp->Strings[n];
+ if (name != 0
+ && *name == 'k'
+ && value != 0
+ && key_defined(value) == 0) {
+ _nc_add_to_try(&(SP->_keytry),
+ value,
+ n - STRCOUNT + KEY_MAX);
+ }
+ }
+ }
+#endif
#ifdef TRACE
- _nc_trace_tries(SP->_keytry);
+ _nc_trace_tries(SP->_keytry);
#endif
+ }
}
diff --git a/contrib/ncurses/ncurses/tinfo/lib_acs.c b/contrib/ncurses/ncurses/tinfo/lib_acs.c
index b84d8e262a2f..2719795d9d4f 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_acs.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_acs.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,12 +29,13 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
****************************************************************************/
#include <curses.priv.h>
#include <term.h> /* ena_acs, acs_chars */
-MODULE_ID("$Id: lib_acs.c,v 1.21 2001/12/23 00:15:10 tom Exp $")
+MODULE_ID("$Id: lib_acs.c,v 1.30 2006/01/07 21:27:15 tom Exp $")
#if BROKEN_LINKER
NCURSES_EXPORT_VAR(chtype *)
@@ -55,98 +56,120 @@ NCURSES_EXPORT_VAR(chtype) acs_map[ACS_LEN] =
NCURSES_EXPORT(void)
_nc_init_acs(void)
{
+ chtype *fake_map = acs_map;
+ chtype *real_map = SP != 0 ? SP->_acs_map : fake_map;
+ int j;
+
T(("initializing ACS map"));
/*
+ * If we're using this from curses (rather than terminfo), we are storing
+ * the mapping information in the SCREEN struct so we can decide how to
+ * render it.
+ */
+ if (real_map != fake_map) {
+ for (j = 1; j < ACS_LEN; ++j) {
+ real_map[j] = 0;
+ fake_map[j] = A_ALTCHARSET | j;
+ SP->_screen_acs_map[j] = FALSE;
+ }
+ } else {
+ for (j = 1; j < ACS_LEN; ++j) {
+ real_map[j] = 0;
+ }
+ }
+
+ /*
* Initializations for a UNIX-like multi-terminal environment. Use
* ASCII chars and count on the terminfo description to do better.
*/
- ACS_ULCORNER = '+'; /* should be upper left corner */
- ACS_LLCORNER = '+'; /* should be lower left corner */
- ACS_URCORNER = '+'; /* should be upper right corner */
- ACS_LRCORNER = '+'; /* should be lower right corner */
- ACS_RTEE = '+'; /* should be tee pointing left */
- ACS_LTEE = '+'; /* should be tee pointing right */
- ACS_BTEE = '+'; /* should be tee pointing up */
- ACS_TTEE = '+'; /* should be tee pointing down */
- ACS_HLINE = '-'; /* should be horizontal line */
- ACS_VLINE = '|'; /* should be vertical line */
- ACS_PLUS = '+'; /* should be large plus or crossover */
- ACS_S1 = '~'; /* should be scan line 1 */
- ACS_S9 = '_'; /* should be scan line 9 */
- ACS_DIAMOND = '+'; /* should be diamond */
- ACS_CKBOARD = ':'; /* should be checker board (stipple) */
- ACS_DEGREE = '\''; /* should be degree symbol */
- ACS_PLMINUS = '#'; /* should be plus/minus */
- ACS_BULLET = 'o'; /* should be bullet */
- ACS_LARROW = '<'; /* should be arrow pointing left */
- ACS_RARROW = '>'; /* should be arrow pointing right */
- ACS_DARROW = 'v'; /* should be arrow pointing down */
- ACS_UARROW = '^'; /* should be arrow pointing up */
- ACS_BOARD = '#'; /* should be board of squares */
- ACS_LANTERN = '#'; /* should be lantern symbol */
- ACS_BLOCK = '#'; /* should be solid square block */
+ real_map['l'] = '+'; /* should be upper left corner */
+ real_map['m'] = '+'; /* should be lower left corner */
+ real_map['k'] = '+'; /* should be upper right corner */
+ real_map['j'] = '+'; /* should be lower right corner */
+ real_map['u'] = '+'; /* should be tee pointing left */
+ real_map['t'] = '+'; /* should be tee pointing right */
+ real_map['v'] = '+'; /* should be tee pointing up */
+ real_map['w'] = '+'; /* should be tee pointing down */
+ real_map['q'] = '-'; /* should be horizontal line */
+ real_map['x'] = '|'; /* should be vertical line */
+ real_map['n'] = '+'; /* should be large plus or crossover */
+ real_map['o'] = '~'; /* should be scan line 1 */
+ real_map['s'] = '_'; /* should be scan line 9 */
+ real_map['`'] = '+'; /* should be diamond */
+ real_map['a'] = ':'; /* should be checker board (stipple) */
+ real_map['f'] = '\''; /* should be degree symbol */
+ real_map['g'] = '#'; /* should be plus/minus */
+ real_map['~'] = 'o'; /* should be bullet */
+ real_map[','] = '<'; /* should be arrow pointing left */
+ real_map['+'] = '>'; /* should be arrow pointing right */
+ real_map['.'] = 'v'; /* should be arrow pointing down */
+ real_map['-'] = '^'; /* should be arrow pointing up */
+ real_map['h'] = '#'; /* should be board of squares */
+ real_map['i'] = '#'; /* should be lantern symbol */
+ real_map['0'] = '#'; /* should be solid square block */
/* these defaults were invented for ncurses */
- ACS_S3 = '-'; /* should be scan line 3 */
- ACS_S7 = '-'; /* should be scan line 7 */
- ACS_LEQUAL = '<'; /* should be less-than-or-equal-to */
- ACS_GEQUAL = '>'; /* should be greater-than-or-equal-to */
- ACS_PI = '*'; /* should be greek pi */
- ACS_NEQUAL = '!'; /* should be not-equal */
- ACS_STERLING = 'f'; /* should be pound-sterling symbol */
+ real_map['p'] = '-'; /* should be scan line 3 */
+ real_map['r'] = '-'; /* should be scan line 7 */
+ real_map['y'] = '<'; /* should be less-than-or-equal-to */
+ real_map['z'] = '>'; /* should be greater-than-or-equal-to */
+ real_map['{'] = '*'; /* should be greek pi */
+ real_map['|'] = '!'; /* should be not-equal */
+ real_map['}'] = 'f'; /* should be pound-sterling symbol */
+
+#if !USE_WIDEC_SUPPORT
+ if (_nc_unicode_locale() && _nc_locale_breaks_acs()) {
+ acs_chars = NULL;
+ ena_acs = NULL;
+ enter_alt_charset_mode = NULL;
+ exit_alt_charset_mode = NULL;
+ set_attributes = NULL;
+ }
+#endif
if (ena_acs != NULL) {
TPUTS_TRACE("ena_acs");
putp(ena_acs);
}
-#define ALTCHAR(c) ((chtype)(((unsigned char)(c)) | A_ALTCHARSET))
+#if NCURSES_EXT_FUNCS
+ /*
+ * Linux console "supports" the "PC ROM" character set by the coincidence
+ * that smpch/rmpch and smacs/rmacs have the same values. ncurses has
+ * no codepage support (see SCO Merge for an example). Outside of the
+ * values defined in acsc, there are no definitions for the "PC ROM"
+ * character set (assumed by some applications to be codepage 437), but we
+ * allow those applications to use those codepoints.
+ *
+ * test/blue.c uses this feature.
+ */
+#define PCH_KLUDGE(a,b) (a != 0 && b != 0 && !strcmp(a,b))
+ if (PCH_KLUDGE(enter_pc_charset_mode, enter_alt_charset_mode) &&
+ PCH_KLUDGE(exit_pc_charset_mode, exit_alt_charset_mode)) {
+ size_t i;
+ for (i = 1; i < ACS_LEN; ++i) {
+ if (real_map[i] == 0) {
+ real_map[i] = i;
+ if (real_map != fake_map) {
+ if (SP != 0)
+ SP->_screen_acs_map[i] = TRUE;
+ }
+ }
+ }
+ }
+#endif
if (acs_chars != NULL) {
size_t i = 0;
size_t length = strlen(acs_chars);
- while (i < length)
- switch (acs_chars[i]) {
- case 'l':
- case 'm':
- case 'k':
- case 'j':
- case 'u':
- case 't':
- case 'v':
- case 'w':
- case 'q':
- case 'x':
- case 'n':
- case 'o':
- case 's':
- case '`':
- case 'a':
- case 'f':
- case 'g':
- case '~':
- case ',':
- case '+':
- case '.':
- case '-':
- case 'h':
- case 'i':
- case '0':
- case 'p':
- case 'r':
- case 'y':
- case 'z':
- case '{':
- case '|':
- case '}':
- acs_map[(unsigned int) acs_chars[i]] =
- ALTCHAR(acs_chars[i + 1]);
- i++;
- /* FALLTHRU */
- default:
- i++;
- break;
+ while (i + 1 < length) {
+ if (acs_chars[i] != 0 && UChar(acs_chars[i]) < ACS_LEN) {
+ real_map[UChar(acs_chars[i])] = UChar(acs_chars[i + 1]) | A_ALTCHARSET;
+ if (SP != 0)
+ SP->_screen_acs_map[UChar(acs_chars[i])] = TRUE;
}
+ i += 2;
+ }
}
#ifdef TRACE
/* Show the equivalent mapping, noting if it does not match the
@@ -154,14 +177,18 @@ _nc_init_acs(void)
*/
if (_nc_tracing & TRACE_CALLS) {
size_t n, m;
- char show[ACS_LEN + 1];
+ char show[ACS_LEN * 2 + 1];
for (n = 1, m = 0; n < ACS_LEN; n++) {
- if (acs_map[n] != 0) {
+ if (real_map[n] != 0) {
show[m++] = (char) n;
- show[m++] = ChCharOf(acs_map[n]);
+ show[m++] = ChCharOf(real_map[n]);
}
}
show[m] = 0;
+ if (acs_chars == NULL || strcmp(acs_chars, show))
+ _tracef("%s acs_chars %s",
+ (acs_chars == NULL) ? "NULL" : "READ",
+ _nc_visbuf(acs_chars));
_tracef("%s acs_chars %s",
(acs_chars == NULL)
? "NULL"
diff --git a/contrib/ncurses/ncurses/tinfo/lib_cur_term.c b/contrib/ncurses/ncurses/tinfo/lib_cur_term.c
index 8f269e591d0c..8fccc2f88d08 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_cur_term.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_cur_term.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2000,2003 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -40,7 +40,7 @@
#include <term_entry.h> /* TTY, cur_term */
#include <termcap.h> /* ospeed */
-MODULE_ID("$Id: lib_cur_term.c,v 1.11 2000/12/10 02:55:07 tom Exp $")
+MODULE_ID("$Id: lib_cur_term.c,v 1.13 2003/12/27 18:21:30 tom Exp $")
NCURSES_EXPORT_VAR(TERMINAL *) cur_term = 0;
@@ -49,11 +49,14 @@ set_curterm(TERMINAL * termp)
{
TERMINAL *oldterm = cur_term;
+ T((T_CALLED("set_curterm(%p)"), termp));
+
if ((cur_term = termp) != 0) {
ospeed = _nc_ospeed(cur_term->_baudrate);
PC = (pad_char != NULL) ? pad_char[0] : 0;
}
- return oldterm;
+ T((T_RETURN("%p"), oldterm));
+ return (oldterm);
}
NCURSES_EXPORT(int)
@@ -63,6 +66,7 @@ del_curterm(TERMINAL * termp)
if (termp != 0) {
_nc_free_termtype(&(termp->type));
+ FreeIfNeeded(termp->_termname);
free(termp);
if (termp == cur_term)
cur_term = 0;
diff --git a/contrib/ncurses/ncurses/tinfo/lib_data.c b/contrib/ncurses/ncurses/tinfo/lib_data.c
index 87d60edf6ed9..34f033a79021 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_data.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_data.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,6 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
****************************************************************************/
/*
@@ -40,18 +41,15 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_data.c,v 1.16 2000/12/10 02:55:07 tom Exp $")
+MODULE_ID("$Id: lib_data.c,v 1.17 2005/01/22 17:39:22 tom Exp $")
/*
* OS/2's native linker complains if we don't initialize public data when
* constructing a dll (reported by J.J.G.Ripoll).
*/
-NCURSES_EXPORT_VAR(WINDOW *)
-stdscr = 0;
-NCURSES_EXPORT_VAR(WINDOW *)
-curscr = 0;
-NCURSES_EXPORT_VAR(WINDOW *)
-newscr = 0;
+NCURSES_EXPORT_VAR(WINDOW *) stdscr = 0;
+NCURSES_EXPORT_VAR(WINDOW *) curscr = 0;
+NCURSES_EXPORT_VAR(WINDOW *) newscr = 0;
NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain = 0;
@@ -66,7 +64,7 @@ NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain = 0;
* module coupling that increases the size of the executable.
*/
#if BROKEN_LINKER
- static SCREEN *my_screen;
+static SCREEN *my_screen;
NCURSES_EXPORT(SCREEN *)
_nc_screen(void)
@@ -81,11 +79,11 @@ _nc_alloc_screen(void)
}
NCURSES_EXPORT(void)
-_nc_set_screen(SCREEN * sp)
+_nc_set_screen(SCREEN *sp)
{
my_screen = sp;
}
#else
-NCURSES_EXPORT_VAR(SCREEN *) SP = NULL; /* Some linkers require initialized data... */
+NCURSES_EXPORT_VAR(SCREEN *) SP = NULL; /* Some linkers require initialized data... */
#endif
diff --git a/contrib/ncurses/ncurses/tinfo/lib_has_cap.c b/contrib/ncurses/ncurses/tinfo/lib_has_cap.c
index 6fb7b3a9c8c0..0dc66bd9b918 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_has_cap.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_has_cap.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2000,2003 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,6 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-2003 *
****************************************************************************/
/*
@@ -42,7 +43,7 @@
#include <term.h>
-MODULE_ID("$Id: lib_has_cap.c,v 1.3 2000/12/10 02:55:07 tom Exp $")
+MODULE_ID("$Id: lib_has_cap.c,v 1.4 2003/10/25 19:43:55 tom Exp $")
NCURSES_EXPORT(bool)
has_ic(void)
diff --git a/contrib/ncurses/ncurses/tinfo/lib_kernel.c b/contrib/ncurses/ncurses/tinfo/lib_kernel.c
index b4d3c7f45aca..89dc1e80ea8e 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_kernel.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_kernel.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2000,2002 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -48,13 +48,13 @@
#include <curses.priv.h>
#include <term.h> /* cur_term */
-MODULE_ID("$Id: lib_kernel.c,v 1.22 2002/05/11 20:32:18 tom Exp $")
+MODULE_ID("$Id: lib_kernel.c,v 1.24 2004/05/08 17:11:21 tom Exp $")
static int
_nc_vdisable(void)
{
- int value;
-#if defined(_POSIX_VDISABLE) && defined(HAVE_UNISTD_H)
+ int value = -1;
+#if defined(_POSIX_VDISABLE) && HAVE_UNISTD_H
value = _POSIX_VDISABLE;
#endif
#if defined(_PC_VDISABLE)
diff --git a/contrib/ncurses/ncurses/tinfo/lib_napms.c b/contrib/ncurses/ncurses/tinfo/lib_napms.c
index 20537be4dfe0..926afa836db4 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_napms.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_napms.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -36,6 +36,8 @@
*
* The routine napms.
*
+ * (This file was originally written by Eric Raymond; however except for
+ * comments, none of the original code remains - T.Dickey).
*/
#include <curses.priv.h>
@@ -47,7 +49,7 @@
#endif
#endif
-MODULE_ID("$Id: lib_napms.c,v 1.12 2001/12/22 22:20:40 tom Exp $")
+MODULE_ID("$Id: lib_napms.c,v 1.15 2005/04/03 13:58:14 tom Exp $")
NCURSES_EXPORT(int)
napms(int ms)
@@ -56,13 +58,16 @@ napms(int ms)
#if HAVE_NANOSLEEP
{
- struct timespec ts;
- ts.tv_sec = ms / 1000;
- ts.tv_nsec = (ms % 1000) * 1000000;
- nanosleep(&ts, NULL);
+ struct timespec request, remaining;
+ request.tv_sec = ms / 1000;
+ request.tv_nsec = (ms % 1000) * 1000000;
+ while (nanosleep(&request, &remaining) == -1
+ && errno == EINTR) {
+ request = remaining;
+ }
}
#else
- _nc_timed_wait(0, ms, (int *) 0);
+ _nc_timed_wait(0, ms, (int *) 0 EVENTLIST_2nd(0));
#endif
returnCode(OK);
diff --git a/contrib/ncurses/ncurses/tinfo/lib_options.c b/contrib/ncurses/ncurses/tinfo/lib_options.c
index 05bd47685dd6..bdb0b7024d7c 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_options.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_options.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000,2001,2002 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,6 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
****************************************************************************/
/*
@@ -42,7 +43,7 @@
#include <term.h>
-MODULE_ID("$Id: lib_options.c,v 1.46 2002/02/02 19:40:54 tom Exp $")
+MODULE_ID("$Id: lib_options.c,v 1.49 2006/03/04 19:28:25 tom Exp $")
NCURSES_EXPORT(int)
idlok(WINDOW *win, bool flag)
@@ -72,7 +73,7 @@ halfdelay(int t)
{
T((T_CALLED("halfdelay(%d)"), t));
- if (t < 1 || t > 255)
+ if (t < 1 || t > 255 || SP == 0)
returnCode(ERR);
cbreak();
@@ -98,7 +99,7 @@ nodelay(WINDOW *win, bool flag)
NCURSES_EXPORT(int)
notimeout(WINDOW *win, bool f)
{
- T((T_CALLED("notimout(%p,%d)"), win, f));
+ T((T_CALLED("notimeout(%p,%d)"), win, f));
if (win) {
win->_notimeout = f;
@@ -133,19 +134,24 @@ keypad(WINDOW *win, bool flag)
NCURSES_EXPORT(int)
meta(WINDOW *win GCC_UNUSED, bool flag)
{
+ int result = ERR;
+
/* Ok, we stay relaxed and don't signal an error if win is NULL */
T((T_CALLED("meta(%p,%d)"), win, flag));
- SP->_use_meta = flag;
-
- if (flag && meta_on) {
- TPUTS_TRACE("meta_on");
- putp(meta_on);
- } else if (!flag && meta_off) {
- TPUTS_TRACE("meta_off");
- putp(meta_off);
+ if (SP != 0) {
+ SP->_use_meta = flag;
+
+ if (flag && meta_on) {
+ TPUTS_TRACE("meta_on");
+ putp(meta_on);
+ } else if (!flag && meta_off) {
+ TPUTS_TRACE("meta_off");
+ putp(meta_off);
+ }
+ result = OK;
}
- returnCode(OK);
+ returnCode(result);
}
/* curs_set() moved here to narrow the kernel interface */
@@ -153,51 +159,56 @@ meta(WINDOW *win GCC_UNUSED, bool flag)
NCURSES_EXPORT(int)
curs_set(int vis)
{
- int cursor = SP->_cursor;
+ int result = ERR;
T((T_CALLED("curs_set(%d)"), vis));
-
- if (vis < 0 || vis > 2)
- returnCode(ERR);
-
- if (vis == cursor)
- returnCode(cursor);
-
- switch (vis) {
- case 2:
- if (cursor_visible) {
- TPUTS_TRACE("cursor_visible");
- putp(cursor_visible);
- } else
- returnCode(ERR);
- break;
- case 1:
- if (cursor_normal) {
- TPUTS_TRACE("cursor_normal");
- putp(cursor_normal);
- } else
- returnCode(ERR);
- break;
- case 0:
- if (cursor_invisible) {
- TPUTS_TRACE("cursor_invisible");
- putp(cursor_invisible);
- } else
- returnCode(ERR);
- break;
+ if (SP != 0 && vis >= 0 && vis <= 2) {
+ int cursor = SP->_cursor;
+
+ if (vis == cursor) {
+ result = cursor;
+ } else {
+ result = (cursor == -1 ? 1 : cursor);
+ switch (vis) {
+ case 2:
+ if (cursor_visible) {
+ TPUTS_TRACE("cursor_visible");
+ putp(cursor_visible);
+ } else
+ result = ERR;
+ break;
+ case 1:
+ if (cursor_normal) {
+ TPUTS_TRACE("cursor_normal");
+ putp(cursor_normal);
+ } else
+ result = ERR;
+ break;
+ case 0:
+ if (cursor_invisible) {
+ TPUTS_TRACE("cursor_invisible");
+ putp(cursor_invisible);
+ } else
+ result = ERR;
+ break;
+ }
+ SP->_cursor = vis;
+ _nc_flush();
+ }
}
- SP->_cursor = vis;
- _nc_flush();
-
- returnCode(cursor == -1 ? 1 : cursor);
+ returnCode(result);
}
NCURSES_EXPORT(int)
typeahead(int fd)
{
T((T_CALLED("typeahead(%d)"), fd));
- SP->_checkfd = fd;
- returnCode(OK);
+ if (SP != 0) {
+ SP->_checkfd = fd;
+ returnCode(OK);
+ } else {
+ returnCode(ERR);
+ }
}
/*
@@ -224,7 +235,7 @@ NCURSES_EXPORT(int)
has_key(int keycode)
{
T((T_CALLED("has_key(%d)"), keycode));
- returnCode(has_key_internal(keycode, SP->_keytry));
+ returnCode(SP != 0 ? has_key_internal(keycode, SP->_keytry) : FALSE);
}
#endif /* NCURSES_EXT_FUNCS */
@@ -248,10 +259,12 @@ _nc_keypad(bool flag)
_nc_flush();
}
- if (flag && !SP->_tried) {
- _nc_init_keytry();
- SP->_tried = TRUE;
+ if (SP != 0) {
+ if (flag && !SP->_tried) {
+ _nc_init_keytry();
+ SP->_tried = TRUE;
+ }
+ SP->_keypad_on = flag;
}
- SP->_keypad_on = flag;
return (OK);
}
diff --git a/contrib/ncurses/ncurses/tinfo/lib_print.c b/contrib/ncurses/ncurses/tinfo/lib_print.c
index 01540eacdc14..975b46d85773 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_print.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_print.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2000,2002 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2002,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -35,7 +35,7 @@
#include <term.h>
-MODULE_ID("$Id: lib_print.c,v 1.14 2002/03/16 21:45:08 tom Exp $")
+MODULE_ID("$Id: lib_print.c,v 1.16 2006/11/26 00:26:34 tom Exp $")
NCURSES_EXPORT(int)
mcprint(char *data, int len)
@@ -51,7 +51,7 @@ mcprint(char *data, int len)
}
if (prtr_non) {
- switchon = tparm(prtr_non, len);
+ switchon = TPARM_1(prtr_non, len);
onsize = strlen(switchon);
offsize = 0;
} else {
@@ -60,7 +60,8 @@ mcprint(char *data, int len)
offsize = strlen(prtr_off);
}
- if ((mybuf = typeMalloc(char, onsize + len + offsize + 1)) == (char *) 0) {
+ if (switchon == 0
+ || (mybuf = typeMalloc(char, onsize + len + offsize + 1)) == 0) {
errno = ENOMEM;
return (ERR);
}
diff --git a/contrib/ncurses/ncurses/tinfo/lib_raw.c b/contrib/ncurses/ncurses/tinfo/lib_raw.c
index 97cf0cbd0249..aa09f52c8c8d 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_raw.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_raw.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,6 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1998 on *
****************************************************************************/
/*
@@ -48,7 +49,7 @@
#include <curses.priv.h>
#include <term.h> /* cur_term */
-MODULE_ID("$Id: lib_raw.c,v 1.12 2001/08/04 17:18:38 tom Exp $")
+MODULE_ID("$Id: lib_raw.c,v 1.13 2002/07/06 22:00:45 tom Exp $")
#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
#define _POSIX_SOURCE
@@ -60,6 +61,9 @@ MODULE_ID("$Id: lib_raw.c,v 1.12 2001/08/04 17:18:38 tom Exp $")
#ifdef __EMX__
#include <io.h>
+#define _nc_setmode(mode) setmode(SP->_ifd, mode)
+#else
+#define _nc_setmode(mode) /* nothing */
#endif
#define COOKED_INPUT (IXON|BRKINT|PARMRK)
@@ -75,162 +79,218 @@ MODULE_ID("$Id: lib_raw.c,v 1.12 2001/08/04 17:18:38 tom Exp $")
NCURSES_EXPORT(int)
raw(void)
{
+ int result = ERR;
+
T((T_CALLED("raw()")));
- if (SP != 0 && cur_term != 0) {
- SP->_raw = TRUE;
- SP->_cbreak = 1;
+ if (SP != 0 && cur_term != 0) {
+ TTY buf;
-#ifdef __EMX__
- setmode(SP->_ifd, O_BINARY);
-#endif
+ BEFORE("raw");
+ _nc_setmode(O_BINARY);
+ buf = cur_term->Nttyb;
#ifdef TERMIOS
- BEFORE("raw");
- cur_term->Nttyb.c_lflag &= ~(ICANON | ISIG | IEXTEN);
- cur_term->Nttyb.c_iflag &= ~(COOKED_INPUT);
- cur_term->Nttyb.c_cc[VMIN] = 1;
- cur_term->Nttyb.c_cc[VTIME] = 0;
- AFTER("raw");
+ buf.c_lflag &= ~(ICANON | ISIG | IEXTEN);
+ buf.c_iflag &= ~(COOKED_INPUT);
+ buf.c_cc[VMIN] = 1;
+ buf.c_cc[VTIME] = 0;
#else
- cur_term->Nttyb.sg_flags |= RAW;
+ buf.sg_flags |= RAW;
#endif
- returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
+ if ((result = _nc_set_tty_mode(&buf)) == OK) {
+ SP->_raw = TRUE;
+ SP->_cbreak = 1;
+ cur_term->Nttyb = buf;
+ }
+ AFTER("raw");
}
- returnCode(ERR);
+ returnCode(result);
}
NCURSES_EXPORT(int)
cbreak(void)
{
+ int result = ERR;
+
T((T_CALLED("cbreak()")));
- SP->_cbreak = 1;
+ if (SP != 0 && cur_term != 0) {
+ TTY buf;
-#ifdef __EMX__
- setmode(SP->_ifd, O_BINARY);
-#endif
+ BEFORE("cbreak");
+ _nc_setmode(O_BINARY);
+ buf = cur_term->Nttyb;
#ifdef TERMIOS
- BEFORE("cbreak");
- cur_term->Nttyb.c_lflag &= ~ICANON;
- cur_term->Nttyb.c_iflag &= ~ICRNL;
- cur_term->Nttyb.c_lflag |= ISIG;
- cur_term->Nttyb.c_cc[VMIN] = 1;
- cur_term->Nttyb.c_cc[VTIME] = 0;
- AFTER("cbreak");
+ buf.c_lflag &= ~ICANON;
+ buf.c_iflag &= ~ICRNL;
+ buf.c_lflag |= ISIG;
+ buf.c_cc[VMIN] = 1;
+ buf.c_cc[VTIME] = 0;
#else
- cur_term->Nttyb.sg_flags |= CBREAK;
+ buf.sg_flags |= CBREAK;
#endif
- returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
+ if ((result = _nc_set_tty_mode(&buf)) == OK) {
+ SP->_cbreak = 1;
+ cur_term->Nttyb = buf;
+ }
+ AFTER("cbreak");
+ }
+ returnCode(result);
}
+/*
+ * Note:
+ * this implementation may be wrong. See the comment under intrflush().
+ */
NCURSES_EXPORT(void)
qiflush(void)
{
+ int result = ERR;
+
T((T_CALLED("qiflush()")));
- /*
- * Note: this implementation may be wrong. See the comment under
- * intrflush().
- */
+ if (cur_term != 0) {
+ TTY buf;
+ BEFORE("qiflush");
+ buf = cur_term->Nttyb;
#ifdef TERMIOS
- BEFORE("qiflush");
- cur_term->Nttyb.c_lflag &= ~(NOFLSH);
- AFTER("qiflush");
- (void) _nc_set_tty_mode(&cur_term->Nttyb);
+ buf.c_lflag &= ~(NOFLSH);
+ result = _nc_set_tty_mode(&buf);
+#else
+ /* FIXME */
#endif
+ if (result == OK)
+ cur_term->Nttyb = buf;
+ AFTER("qiflush");
+ }
returnVoid;
}
NCURSES_EXPORT(int)
noraw(void)
{
+ int result = ERR;
+
T((T_CALLED("noraw()")));
- SP->_raw = FALSE;
- SP->_cbreak = 0;
+ if (SP != 0 && cur_term != 0) {
+ TTY buf;
-#ifdef __EMX__
- setmode(SP->_ifd, O_TEXT);
-#endif
+ BEFORE("noraw");
+ _nc_setmode(O_TEXT);
+ buf = cur_term->Nttyb;
#ifdef TERMIOS
- BEFORE("noraw");
- cur_term->Nttyb.c_lflag |= ISIG | ICANON |
- (cur_term->Ottyb.c_lflag & IEXTEN);
- cur_term->Nttyb.c_iflag |= COOKED_INPUT;
- AFTER("noraw");
+ buf.c_lflag |= ISIG | ICANON |
+ (cur_term->Ottyb.c_lflag & IEXTEN);
+ buf.c_iflag |= COOKED_INPUT;
#else
- cur_term->Nttyb.sg_flags &= ~(RAW | CBREAK);
+ buf.sg_flags &= ~(RAW | CBREAK);
#endif
- returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
+ if ((result = _nc_set_tty_mode(&buf)) == OK) {
+ SP->_raw = FALSE;
+ SP->_cbreak = 0;
+ cur_term->Nttyb = buf;
+ }
+ AFTER("noraw");
+ }
+ returnCode(result);
}
NCURSES_EXPORT(int)
nocbreak(void)
{
+ int result = ERR;
+
T((T_CALLED("nocbreak()")));
- SP->_cbreak = 0;
+ if (SP != 0 && cur_term != 0) {
+ TTY buf;
-#ifdef __EMX__
- setmode(SP->_ifd, O_TEXT);
-#endif
+ BEFORE("nocbreak");
+ _nc_setmode(O_TEXT);
+ buf = cur_term->Nttyb;
#ifdef TERMIOS
- BEFORE("nocbreak");
- cur_term->Nttyb.c_lflag |= ICANON;
- cur_term->Nttyb.c_iflag |= ICRNL;
- AFTER("nocbreak");
+ buf.c_lflag |= ICANON;
+ buf.c_iflag |= ICRNL;
#else
- cur_term->Nttyb.sg_flags &= ~CBREAK;
+ buf.sg_flags &= ~CBREAK;
#endif
- returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
+ if ((result = _nc_set_tty_mode(&buf)) == OK) {
+ SP->_cbreak = 0;
+ cur_term->Nttyb = buf;
+ }
+ AFTER("nocbreak");
+ }
+ returnCode(result);
}
+/*
+ * Note:
+ * this implementation may be wrong. See the comment under intrflush().
+ */
NCURSES_EXPORT(void)
noqiflush(void)
{
+ int result = ERR;
+
T((T_CALLED("noqiflush()")));
- /*
- * Note: this implementation may be wrong. See the comment under
- * intrflush().
- */
+ if (cur_term != 0) {
+ TTY buf;
+ BEFORE("noqiflush");
+ buf = cur_term->Nttyb;
#ifdef TERMIOS
- BEFORE("noqiflush");
- cur_term->Nttyb.c_lflag |= NOFLSH;
- AFTER("noqiflush");
- (void) _nc_set_tty_mode(&cur_term->Nttyb);
+ buf.c_lflag |= NOFLSH;
+ result = _nc_set_tty_mode(&buf);
+#else
+ /* FIXME */
#endif
+ if (result == OK) {
+ cur_term->Nttyb = buf;
+ }
+ AFTER("noqiflush");
+ }
returnVoid;
}
+/*
+ * This call does the same thing as the qiflush()/noqiflush() pair. We know
+ * for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the other hand,
+ * the match (in the SVr4 man pages) between the language describing NOFLSH in
+ * termio(7) and the language describing qiflush()/noqiflush() in
+ * curs_inopts(3x) is too exact to be coincidence.
+ */
NCURSES_EXPORT(int)
intrflush(WINDOW *win GCC_UNUSED, bool flag)
{
+ int result = ERR;
+
T((T_CALLED("intrflush(%d)"), flag));
- /*
- * This call does the same thing as the qiflush()/noqiflush() pair. We
- * know for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the
- * other hand, the match (in the SVr4 man pages) between the language
- * describing NOFLSH in termio(7) and the language describing
- * qiflush()/noqiflush() in curs_inopts(3x) is too exact to be coincidence.
- */
+ if (cur_term != 0) {
+ TTY buf;
+ BEFORE("intrflush");
+ buf = cur_term->Nttyb;
#ifdef TERMIOS
- BEFORE("intrflush");
- if (flag)
- cur_term->Nttyb.c_lflag &= ~(NOFLSH);
- else
- cur_term->Nttyb.c_lflag |= (NOFLSH);
- AFTER("intrflush");
- returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
+ if (flag)
+ buf.c_lflag &= ~(NOFLSH);
+ else
+ buf.c_lflag |= (NOFLSH);
+ result = _nc_set_tty_mode(&buf);
#else
- returnCode(ERR);
+ /* FIXME */
#endif
+ if (result == OK) {
+ cur_term->Nttyb = buf;
+ }
+ AFTER("intrflush");
+ }
+ returnCode(result);
}
diff --git a/contrib/ncurses/ncurses/tinfo/lib_setup.c b/contrib/ncurses/ncurses/tinfo/lib_setup.c
index 1e49b2b6ce07..350824208830 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_setup.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_setup.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,6 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-2003 *
****************************************************************************/
/*
@@ -46,9 +47,13 @@
#define _POSIX_SOURCE
#endif
+#if HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
#include <term.h> /* lines, columns, cur_term */
-MODULE_ID("$Id: lib_setup.c,v 1.68 2001/12/08 22:14:18 tom Exp $")
+MODULE_ID("$Id: lib_setup.c,v 1.95 2006/07/28 22:58:13 tom Exp $")
/****************************************************************************
*
@@ -72,6 +77,10 @@ MODULE_ID("$Id: lib_setup.c,v 1.68 2001/12/08 22:14:18 tom Exp $")
# include <sys/ptem.h>
#endif
+#if HAVE_LANGINFO_CODESET
+#include <langinfo.h>
+#endif
+
/*
* SCO defines TIOCGSIZE and the corresponding struct. Other systems (SunOS,
* Solaris, IRIX) define TIOCGWINSZ and struct winsize.
@@ -90,9 +99,58 @@ MODULE_ID("$Id: lib_setup.c,v 1.68 2001/12/08 22:14:18 tom Exp $")
# endif
#endif
+NCURSES_EXPORT_VAR(char) ttytype[NAMESIZE] = "";
+NCURSES_EXPORT_VAR(int) LINES = 0;
+NCURSES_EXPORT_VAR(int) COLS = 0;
+NCURSES_EXPORT_VAR(int) TABSIZE = 0;
+
static int _use_env = TRUE;
-static void do_prototype(void);
+#if USE_SIGWINCH
+int
+_nc_handle_sigwinch(int enable)
+{
+ static int have_sigwinch = 0; /* initially no SIGWINCH's */
+ static int can_resizeall = 1; /* initially enabled */
+ SCREEN *scan;
+ int result;
+
+ switch (enable) {
+ default:
+ /* record a SIGWINCH */
+ have_sigwinch = 1;
+ break;
+ case 0:
+ /* temporarily disable the next block */
+ --can_resizeall;
+ break;
+ case 1:
+ /* temporarily enable the next block */
+ ++can_resizeall;
+ break;
+ }
+
+ /*
+ * If we have a pending SIGWINCH, set the flag in each screen.
+ * But do this only if the block is enabled.
+ */
+ if (can_resizeall-- >= 0) { /* test and disable */
+ if (have_sigwinch) {
+ scan = _nc_screen_chain;
+ while (scan) {
+ scan->_sig_winch = TRUE;
+ scan = scan->_next_screen;
+ }
+ have_sigwinch = 0;
+ }
+ }
+ result = can_resizeall + 1; /* reenable (unless disables are nested) */
+ can_resizeall = result;
+
+ return result;
+}
+
+#endif
NCURSES_EXPORT(void)
use_env(bool f)
@@ -102,10 +160,6 @@ use_env(bool f)
returnVoid;
}
-NCURSES_EXPORT_VAR(int) LINES = 0;
-NCURSES_EXPORT_VAR(int) COLS = 0;
-NCURSES_EXPORT_VAR(int) TABSIZE = 0;
-
static void
_nc_get_screensize(int *linep, int *colp)
/* Obtain lines/columns values from the environment and/or terminfo entry */
@@ -113,6 +167,7 @@ _nc_get_screensize(int *linep, int *colp)
/* figure out the size of the screen */
T(("screen size: terminfo lines = %d columns = %d", lines, columns));
+ _nc_handle_sigwinch(0);
if (!_use_env) {
*linep = (int) lines;
*colp = (int) columns;
@@ -159,7 +214,7 @@ _nc_get_screensize(int *linep, int *colp)
* environment variable.
*/
if (*linep <= 0)
- *linep = WINSIZE_ROWS(size);
+ *linep = (SP != 0 && SP->_filtered) ? 1 : WINSIZE_ROWS(size);
if (*colp <= 0)
*colp = WINSIZE_COLS(size);
}
@@ -191,6 +246,7 @@ _nc_get_screensize(int *linep, int *colp)
lines = (short) (*linep);
columns = (short) (*colp);
}
+ _nc_handle_sigwinch(1);
T(("screen size is %dx%d", *linep, *colp));
@@ -199,18 +255,30 @@ _nc_get_screensize(int *linep, int *colp)
else
TABSIZE = 8;
T(("TABSIZE = %d", TABSIZE));
-
}
#if USE_SIZECHANGE
NCURSES_EXPORT(void)
_nc_update_screensize(void)
{
- int my_lines, my_cols;
+ int old_lines = lines;
+ int new_lines;
+ int old_cols = columns;
+ int new_cols;
- _nc_get_screensize(&my_lines, &my_cols);
- if (SP != 0 && SP->_resize != 0)
- SP->_resize(my_lines, my_cols);
+ _nc_get_screensize(&new_lines, &new_cols);
+
+ /*
+ * See is_term_resized() and resizeterm().
+ * We're doing it this way because those functions belong to the upper
+ * ncurses library, while this resides in the lower terminfo library.
+ */
+ if (SP != 0
+ && SP->_resize != 0) {
+ if ((new_lines != old_lines) || (new_cols != old_cols))
+ SP->_resize(new_lines, new_cols);
+ SP->_sig_winch = FALSE;
+ }
}
#endif
@@ -237,36 +305,15 @@ _nc_update_screensize(void)
}
#if USE_DATABASE || USE_TERMCAP
+/*
+ * Return 1 if entry found, 0 if not found, -1 if database not accessible,
+ * just like tgetent().
+ */
static int
-grab_entry(const char *const tn, TERMTYPE * const tp)
-/* return 1 if entry found, 0 if not found, -1 if database not accessible */
+grab_entry(const char *const tn, TERMTYPE *const tp)
{
char filename[PATH_MAX];
- int status;
-
- /*
- * $TERM shouldn't contain pathname delimiters.
- */
- if (strchr(tn, '/'))
- return 0;
-
-#if USE_DATABASE
- if ((status = _nc_read_entry(tn, filename, tp)) != 1) {
-
-#if !PURE_TERMINFO
- /*
- * Try falling back on the termcap file.
- * Note: allowing this call links the entire terminfo/termcap
- * compiler into the startup code. It's preferable to build a
- * real terminfo database and use that.
- */
- status = _nc_read_termcap_entry(tn, tp);
-#endif /* PURE_TERMINFO */
-
- }
-#else
- status = _nc_read_termcap_entry(tn, tp);
-#endif
+ int status = _nc_read_entry(tn, filename, tp);
/*
* If we have an entry, force all of the cancelled strings to null
@@ -274,8 +321,8 @@ grab_entry(const char *const tn, TERMTYPE * const tp)
* (The terminfo compiler bypasses this logic, since it must know if
* a string is cancelled, for merging entries).
*/
- if (status == 1) {
- int n;
+ if (status == TGETENT_YES) {
+ unsigned n;
for_each_boolean(n, tp) {
if (!VALID_BOOLEAN(tp->Booleans[n]))
tp->Booleans[n] = FALSE;
@@ -289,139 +336,251 @@ grab_entry(const char *const tn, TERMTYPE * const tp)
}
#endif
-NCURSES_EXPORT_VAR(char) ttytype[NAMESIZE] = "";
+/*
+** do_prototype()
+**
+** Take the real command character out of the CC environment variable
+** and substitute it in for the prototype given in 'command_character'.
+*/
+static void
+do_prototype(void)
+{
+ int i;
+ char CC;
+ char proto;
+ char *tmp;
+
+ tmp = getenv("CC");
+ CC = *tmp;
+ proto = *command_character;
+
+ for_each_string(i, &(cur_term->type)) {
+ for (tmp = cur_term->type.Strings[i]; *tmp; tmp++) {
+ if (*tmp == proto)
+ *tmp = CC;
+ }
+ }
+}
/*
- * setupterm(termname, Filedes, errret)
- *
- * Find and read the appropriate object file for the terminal
- * Make cur_term point to the structure.
- *
+ * Find the locale which is in effect.
+ */
+NCURSES_EXPORT(char *)
+_nc_get_locale(void)
+{
+ char *env;
+#if HAVE_LOCALE_H
+ /*
+ * This is preferable to using getenv() since it ensures that we are using
+ * the locale which was actually initialized by the application.
+ */
+ env = setlocale(LC_CTYPE, 0);
+#else
+ if (((env = getenv("LC_ALL")) != 0 && *env != '\0')
+ || ((env = getenv("LC_CTYPE")) != 0 && *env != '\0')
+ || ((env = getenv("LANG")) != 0 && *env != '\0')) {
+ ;
+ }
+#endif
+ T(("_nc_get_locale %s", _nc_visbuf(env)));
+ return env;
+}
+
+/*
+ * Check if we are running in a UTF-8 locale.
*/
+NCURSES_EXPORT(int)
+_nc_unicode_locale(void)
+{
+ int result = 0;
+#if HAVE_LANGINFO_CODESET
+ char *env = nl_langinfo(CODESET);
+ result = !strcmp(env, "UTF-8");
+ T(("_nc_unicode_locale(%s) ->%d", env, result));
+#else
+ char *env = _nc_get_locale();
+ if (env != 0) {
+ if (strstr(env, ".UTF-8") != 0) {
+ result = 1;
+ T(("_nc_unicode_locale(%s) ->%d", env, result));
+ }
+ }
+#endif
+ return result;
+}
+#define CONTROL_N(s) ((s) != 0 && strstr(s, "\016") != 0)
+#define CONTROL_O(s) ((s) != 0 && strstr(s, "\017") != 0)
+
+/*
+ * Check for known broken cases where a UTF-8 locale breaks the alternate
+ * character set.
+ */
NCURSES_EXPORT(int)
-setupterm(NCURSES_CONST char *tname, int Filedes, int *errret)
+_nc_locale_breaks_acs(void)
+{
+ char *env;
+
+ if ((env = getenv("NCURSES_NO_UTF8_ACS")) != 0) {
+ return atoi(env);
+ } else if ((env = getenv("TERM")) != 0) {
+ if (strstr(env, "linux"))
+ return 1; /* always broken */
+ if (strstr(env, "screen") != 0
+ && ((env = getenv("TERMCAP")) != 0
+ && strstr(env, "screen") != 0)
+ && strstr(env, "hhII00") != 0) {
+ if (CONTROL_N(enter_alt_charset_mode) ||
+ CONTROL_O(enter_alt_charset_mode) ||
+ CONTROL_N(set_attributes) ||
+ CONTROL_O(set_attributes))
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * This entrypoint is called from tgetent() to allow a special case of reusing
+ * the same TERMINAL data (see comment).
+ */
+NCURSES_EXPORT(int)
+_nc_setupterm(NCURSES_CONST char *tname, int Filedes, int *errret, bool reuse)
{
- struct term *term_ptr;
int status;
+ START_TRACE();
T((T_CALLED("setupterm(%s,%d,%p)"), _nc_visbuf(tname), Filedes, errret));
if (tname == 0) {
tname = getenv("TERM");
if (tname == 0 || *tname == '\0') {
- ret_error0(-1, "TERM environment variable not set.\n");
+ ret_error0(TGETENT_ERR, "TERM environment variable not set.\n");
}
}
+
if (strlen(tname) > MAX_NAME_SIZE) {
- ret_error(-1, "TERM environment must be <= %d characters.\n",
+ ret_error(TGETENT_ERR,
+ "TERM environment must be <= %d characters.\n",
MAX_NAME_SIZE);
}
T(("your terminal name is %s", tname));
- term_ptr = typeCalloc(TERMINAL, 1);
+ /*
+ * Allow output redirection. This is what SVr3 does. If stdout is
+ * directed to a file, screen updates go to standard error.
+ */
+ if (Filedes == STDOUT_FILENO && !isatty(Filedes))
+ Filedes = STDERR_FILENO;
- if (term_ptr == 0) {
- ret_error0(-1, "Not enough memory to create terminal structure.\n");
- }
+ /*
+ * Check if we have already initialized to use this terminal. If so, we
+ * do not need to re-read the terminfo entry, or obtain TTY settings.
+ *
+ * This is an improvement on SVr4 curses. If an application mixes curses
+ * and termcap calls, it may call both initscr and tgetent. This is not
+ * really a good thing to do, but can happen if someone tries using ncurses
+ * with the readline library. The problem we are fixing is that when
+ * tgetent calls setupterm, the resulting Ottyb struct in cur_term is
+ * zeroed. A subsequent call to endwin uses the zeroed terminal settings
+ * rather than the ones saved in initscr. So we check if cur_term appears
+ * to contain terminal settings for the same output file as our current
+ * call - and copy those terminal settings. (SVr4 curses does not do this,
+ * however applications that are working around the problem will still work
+ * properly with this feature).
+ */
+ if (reuse
+ && cur_term != 0
+ && cur_term->Filedes == Filedes
+ && cur_term->_termname != 0
+ && !strcmp(cur_term->_termname, tname)
+ && _nc_name_match(cur_term->type.term_names, tname, "|")) {
+ T(("reusing existing terminal information and mode-settings"));
+ } else {
+ TERMINAL *term_ptr;
+
+ term_ptr = typeCalloc(TERMINAL, 1);
+
+ if (term_ptr == 0) {
+ ret_error0(TGETENT_ERR,
+ "Not enough memory to create terminal structure.\n");
+ }
#if USE_DATABASE || USE_TERMCAP
- status = grab_entry(tname, &term_ptr->type);
+ status = grab_entry(tname, &term_ptr->type);
#else
- status = 0;
+ status = TGETENT_NO;
#endif
- /* try fallback list if entry on disk */
- if (status != 1) {
- const TERMTYPE *fallback = _nc_fallback(tname);
+ /* try fallback list if entry on disk */
+ if (status != TGETENT_YES) {
+ const TERMTYPE *fallback = _nc_fallback(tname);
- if (fallback) {
- term_ptr->type = *fallback;
- status = 1;
+ if (fallback) {
+ term_ptr->type = *fallback;
+ status = TGETENT_YES;
+ }
}
- }
- if (status == -1) {
- ret_error0(-1, "terminals database is inaccessible\n");
- } else if (status == 0) {
- ret_error(0, "'%s': unknown terminal type.\n", tname);
- }
+ if (status != TGETENT_YES) {
+ del_curterm(term_ptr);
+ if (status == TGETENT_ERR) {
+ ret_error0(status, "terminals database is inaccessible\n");
+ } else if (status == TGETENT_NO) {
+ ret_error(status, "'%s': unknown terminal type.\n", tname);
+ }
+ }
- /*
- * Improve on SVr4 curses. If an application mixes curses and termcap
- * calls, it may call both initscr and tgetent. This is not really a
- * good thing to do, but can happen if someone tries using ncurses with
- * the readline library. The problem we are fixing is that when
- * tgetent calls setupterm, the resulting Ottyb struct in cur_term is
- * zeroed. A subsequent call to endwin uses the zeroed terminal
- * settings rather than the ones saved in initscr. So we check if
- * cur_term appears to contain terminal settings for the same output
- * file as our current call - and copy those terminal settings. (SVr4
- * curses does not do this, however applications that are working
- * around the problem will still work properly with this feature).
- */
- if (cur_term != 0) {
- if (cur_term->Filedes == Filedes)
- term_ptr->Ottyb = cur_term->Ottyb;
- }
+ set_curterm(term_ptr);
+
+ if (command_character && getenv("CC"))
+ do_prototype();
- set_curterm(term_ptr);
+ strncpy(ttytype, cur_term->type.term_names, NAMESIZE - 1);
+ ttytype[NAMESIZE - 1] = '\0';
- if (command_character && getenv("CC"))
- do_prototype();
+ cur_term->Filedes = Filedes;
+ cur_term->_termname = strdup(tname);
- strncpy(ttytype, cur_term->type.term_names, NAMESIZE - 1);
- ttytype[NAMESIZE - 1] = '\0';
+ /*
+ * If an application calls setupterm() rather than initscr() or
+ * newterm(), we will not have the def_prog_mode() call in
+ * _nc_setupscreen(). Do it now anyway, so we can initialize the
+ * baudrate.
+ */
+ if (isatty(Filedes)) {
+ def_prog_mode();
+ baudrate();
+ }
+ }
/*
- * Allow output redirection. This is what SVr3 does.
- * If stdout is directed to a file, screen updates go
- * to standard error.
+ * We should always check the screensize, just in case.
*/
- if (Filedes == STDOUT_FILENO && !isatty(Filedes))
- Filedes = STDERR_FILENO;
- cur_term->Filedes = Filedes;
-
_nc_get_screensize(&LINES, &COLS);
if (errret)
- *errret = 1;
+ *errret = TGETENT_YES;
T((T_CREATE("screen %s %dx%d"), tname, LINES, COLS));
if (generic_type) {
- ret_error(0, "'%s': I need something more specific.\n", tname);
+ ret_error(TGETENT_NO, "'%s': I need something more specific.\n", tname);
}
if (hard_copy) {
- ret_error(1, "'%s': I can't handle hardcopy terminals.\n", tname);
+ ret_error(TGETENT_YES, "'%s': I can't handle hardcopy terminals.\n", tname);
}
returnCode(OK);
}
/*
-** do_prototype()
-**
-** Take the real command character out of the CC environment variable
-** and substitute it in for the prototype given in 'command_character'.
-**
-*/
-
-static void
-do_prototype(void)
+ * setupterm(termname, Filedes, errret)
+ *
+ * Find and read the appropriate object file for the terminal
+ * Make cur_term point to the structure.
+ */
+NCURSES_EXPORT(int)
+setupterm(NCURSES_CONST char *tname, int Filedes, int *errret)
{
- int i;
- char CC;
- char proto;
- char *tmp;
-
- tmp = getenv("CC");
- CC = *tmp;
- proto = *command_character;
-
- for_each_string(i, &(cur_term->type)) {
- for (tmp = cur_term->type.Strings[i]; *tmp; tmp++) {
- if (*tmp == proto)
- *tmp = CC;
- }
- }
+ return _nc_setupterm(tname, Filedes, errret, FALSE);
}
diff --git a/contrib/ncurses/ncurses/tinfo/lib_termcap.c b/contrib/ncurses/ncurses/tinfo/lib_termcap.c
index c03a601f4968..33e15c55c179 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_termcap.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_termcap.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,9 +29,11 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
* *
* some of the code in here was contributed by: *
* Magnus Bengtsson, d6mbeng@dtek.chalmers.se (Nov'93) *
+ * (but it has changed a lot) *
****************************************************************************/
#define __INTERNAL_CAPS_VISIBLE
@@ -43,66 +45,26 @@
#include <term_entry.h>
-MODULE_ID("$Id: lib_termcap.c,v 1.43 2002/05/25 12:24:13 tom Exp $")
-
-#define CSI 233
-#define ESC 033 /* ^[ */
-#define L_BRACK '['
-#define SHIFT_OUT 017 /* ^N */
+MODULE_ID("$Id: lib_termcap.c,v 1.58 2006/09/02 19:39:46 Miroslav.Lichvar Exp $")
NCURSES_EXPORT_VAR(char *) UP = 0;
NCURSES_EXPORT_VAR(char *) BC = 0;
-static char *fix_me = 0;
-
-static char *
-set_attribute_9(int flag)
-{
- const char *result;
-
- if ((result = tparm(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, flag)) == 0)
- result = "";
- return strdup(result);
-}
-
-static int
-is_csi(char *s)
-{
- if (UChar(s[0]) == CSI)
- return 1;
- else if (s[0] == ESC && s[1] == L_BRACK)
- return 2;
- return 0;
-}
+typedef struct {
+ long sequence;
+ char *fix_sgr0; /* this holds the filtered sgr0 string */
+ char *last_bufp; /* help with fix_sgr0 leak */
+ TERMINAL *last_term;
+} CACHE;
-static char *
-skip_zero(char *s)
-{
- if (s[0] == '0') {
- if (s[1] == ';')
- s += 2;
- else if (isalpha(UChar(s[1])))
- s += 1;
- }
- return s;
-}
+#define MAX_CACHE 4
+static CACHE cache[MAX_CACHE];
+static int in_cache = 0;
-static bool
-similar_sgr(char *a, char *b)
-{
- int csi_a = is_csi(a);
- int csi_b = is_csi(b);
-
- if (csi_a != 0 && csi_b != 0 && csi_a == csi_b) {
- a += csi_a;
- b += csi_b;
- if (*a != *b) {
- a = skip_zero(a);
- b = skip_zero(b);
- }
- }
- return strcmp(a, b) == 0;
-}
+#define FIX_SGR0 cache[in_cache].fix_sgr0
+#define LAST_TRM cache[in_cache].last_term
+#define LAST_BUF cache[in_cache].last_bufp
+#define LAST_SEQ cache[in_cache].sequence
/***************************************************************************
*
@@ -120,18 +82,64 @@ similar_sgr(char *a, char *b)
***************************************************************************/
NCURSES_EXPORT(int)
-tgetent(char *bufp GCC_UNUSED, const char *name)
+tgetent(char *bufp, const char *name)
{
+ static long sequence;
+
int errcode;
+ int n;
+ bool found_cache = FALSE;
+ START_TRACE();
T((T_CALLED("tgetent()")));
- setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode);
+ _nc_setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode, TRUE);
+
+ /*
+ * In general we cannot tell if the fixed sgr0 is still used by the
+ * caller, but if tgetent() is called with the same buffer, that is
+ * good enough, since the previous data would be invalidated by the
+ * current call.
+ */
+ for (n = 0; n < MAX_CACHE; ++n) {
+ bool same_result = (bufp != 0 && cache[n].last_bufp == bufp);
+ if (same_result) {
+ in_cache = n;
+ if (FIX_SGR0 != 0) {
+ FreeAndNull(FIX_SGR0);
+ }
+ /*
+ * Also free the terminfo data that we loaded (much bigger leak).
+ */
+ if (LAST_TRM != 0 && LAST_TRM != cur_term) {
+ TERMINAL *trm = LAST_TRM;
+ del_curterm(LAST_TRM);
+ for (in_cache = 0; in_cache < MAX_CACHE; ++in_cache)
+ if (LAST_TRM == trm)
+ LAST_TRM = 0;
+ in_cache = n;
+ }
+ found_cache = TRUE;
+ break;
+ }
+ }
+ if (!found_cache) {
+ int best = 0;
+
+ for (in_cache = 0; in_cache < MAX_CACHE; ++in_cache) {
+ if (LAST_SEQ < cache[best].sequence) {
+ best = in_cache;
+ }
+ }
+ in_cache = best;
+ }
+ LAST_TRM = cur_term;
+ LAST_SEQ = ++sequence;
PC = 0;
UP = 0;
BC = 0;
- fix_me = 0;
+ FIX_SGR0 = 0; /* don't free it - application may still use */
if (errcode == 1) {
@@ -147,67 +155,15 @@ tgetent(char *bufp GCC_UNUSED, const char *name)
if (backspace_if_not_bs != NULL)
BC = backspace_if_not_bs;
- /*
- * While 'sgr0' is the "same" as termcap 'me', there is a compatibility
- * issue. The sgr/sgr0 capabilities include setting/clearing alternate
- * character set mode. A termcap application cannot use sgr, so sgr0
- * strings that reset alternate character set mode will be
- * misinterpreted. Here, we remove those from the more common
- * ISO/ANSI/VT100 entries, which have sgr0 agreeing with sgr.
- */
- if (exit_attribute_mode != 0
- && set_attributes != 0) {
- char *on = set_attribute_9(1);
- char *off = set_attribute_9(0);
- char *tmp;
- size_t i, j, k;
-
- if (similar_sgr(off, exit_attribute_mode)
- && !similar_sgr(off, on)) {
- TR(TRACE_DATABASE, ("adjusting sgr0 : %s", _nc_visbuf(off)));
- FreeIfNeeded(fix_me);
- fix_me = off;
- for (i = 0; off[i] != '\0'; ++i) {
- if (on[i] != off[i]) {
- j = strlen(off);
- k = strlen(on);
- while (j != 0
- && k != 0
- && off[j - 1] == on[k - 1]) {
- --j, --k;
- }
- while (off[j] != '\0') {
- off[i++] = off[j++];
- }
- off[i] = '\0';
- break;
- }
- }
- /* SGR 10 would reset to normal font */
- if ((i = is_csi(off)) != 0
- && off[strlen(off) - 1] == 'm') {
- tmp = skip_zero(off + i);
- if (tmp[0] == '1'
- && skip_zero(tmp + 1) != tmp + 1) {
- i = tmp - off;
- if (off[i - 1] == ';')
- i--;
- j = skip_zero(tmp + 1) - off;
- while (off[j] != '\0') {
- off[i++] = off[j++];
- }
- off[i] = '\0';
- }
- }
- TR(TRACE_DATABASE, ("...adjusted me : %s", _nc_visbuf(fix_me)));
- if (!strcmp(fix_me, exit_attribute_mode)) {
- TR(TRACE_DATABASE, ("...same result, discard"));
- free(fix_me);
- fix_me = 0;
+ if ((FIX_SGR0 = _nc_trim_sgr0(&(cur_term->type))) != 0) {
+ if (!strcmp(FIX_SGR0, exit_attribute_mode)) {
+ if (FIX_SGR0 != exit_attribute_mode) {
+ free(FIX_SGR0);
}
+ FIX_SGR0 = 0;
}
- free(on);
}
+ LAST_BUF = bufp;
(void) baudrate(); /* sets ospeed as a side-effect */
@@ -233,7 +189,7 @@ tgetent(char *bufp GCC_UNUSED, const char *name)
NCURSES_EXPORT(int)
tgetflag(NCURSES_CONST char *id)
{
- int i;
+ unsigned i;
T((T_CALLED("tgetflag(%s)"), id));
if (cur_term != 0) {
@@ -261,7 +217,7 @@ tgetflag(NCURSES_CONST char *id)
NCURSES_EXPORT(int)
tgetnum(NCURSES_CONST char *id)
{
- int i;
+ unsigned i;
T((T_CALLED("tgetnum(%s)"), id));
if (cur_term != 0) {
@@ -290,7 +246,7 @@ tgetnum(NCURSES_CONST char *id)
NCURSES_EXPORT(char *)
tgetstr(NCURSES_CONST char *id, char **area)
{
- int i;
+ unsigned i;
char *result = NULL;
T((T_CALLED("tgetstr(%s,%p)"), id, area));
@@ -304,13 +260,14 @@ tgetstr(NCURSES_CONST char *id, char **area)
/* setupterm forces canceled strings to null */
if (VALID_STRING(result)) {
if (result == exit_attribute_mode
- && fix_me != 0) {
- result = fix_me;
+ && FIX_SGR0 != 0) {
+ result = FIX_SGR0;
TR(TRACE_DATABASE, ("altered to : %s", _nc_visbuf(result)));
}
if (area != 0
&& *area != 0) {
(void) strcpy(*area, result);
+ result = *area;
*area += strlen(*area) + 1;
}
}
@@ -320,3 +277,14 @@ tgetstr(NCURSES_CONST char *id, char **area)
}
returnPtr(result);
}
+
+#if NO_LEAKS
+NCURSES_EXPORT(void)
+_nc_tgetent_leaks(void)
+{
+ for (in_cache = 0; in_cache < MAX_CACHE; ++in_cache) {
+ FreeIfNeeded(FIX_SGR0);
+ del_curterm(LAST_TRM);
+ }
+}
+#endif
diff --git a/contrib/ncurses/ncurses/tinfo/lib_termname.c b/contrib/ncurses/ncurses/tinfo/lib_termname.c
index 57ce807a9e5f..713d0be8c360 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_termname.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_termname.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2001,2003 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -27,22 +27,18 @@
****************************************************************************/
#include <curses.priv.h>
-#include <tic.h> /* for MAX_ALIAS */
-MODULE_ID("$Id: lib_termname.c,v 1.7 2001/08/04 19:29:38 tom Exp $")
+MODULE_ID("$Id: lib_termname.c,v 1.8 2003/12/27 18:23:01 tom Exp $")
NCURSES_EXPORT(char *)
termname(void)
{
- char *name = getenv("TERM");
- static char ret[MAX_ALIAS + 1];
+ char *name = 0;
T((T_CALLED("termname()")));
- if (name != 0) {
- ret[0] = '\0';
- (void) strncat(ret, name, sizeof(ret) - 1);
- name = ret;
- }
+ if (cur_term != 0)
+ name = cur_term->_termname;
+
returnPtr(name);
}
diff --git a/contrib/ncurses/ncurses/tinfo/lib_tgoto.c b/contrib/ncurses/ncurses/tinfo/lib_tgoto.c
index 17649d53f68f..37553f712394 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_tgoto.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_tgoto.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 2000-2003,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -35,7 +35,7 @@
#include <ctype.h>
#include <termcap.h>
-MODULE_ID("$Id: lib_tgoto.c,v 1.8 2001/06/02 22:44:42 tom Exp $")
+MODULE_ID("$Id: lib_tgoto.c,v 1.12 2006/11/26 00:26:24 tom Exp $")
#if !PURE_TERMINFO
static bool
@@ -88,7 +88,7 @@ tgoto_internal(const char *string, int x, int y)
while (*string != 0) {
if ((used + need) > length) {
length += (used + need);
- if ((result = _nc_doalloc(result, length)) == 0) {
+ if ((result = typeRealloc(char, length, result)) == 0) {
length = 0;
break;
}
@@ -155,7 +155,7 @@ tgoto_internal(const char *string, int x, int y)
*value = 16 * (*value / 10) + (*value % 10);
break;
case 'D': /* Reverse coding (Delta Data) */
- *value -= 2 * (*value / 16);
+ *value -= 2 * (*value % 16);
break;
}
if (fmt != 0) {
@@ -172,11 +172,13 @@ tgoto_internal(const char *string, int x, int y)
}
string++;
}
- if (need_BC) {
- strcpy(result + used, BC);
- used += strlen(BC);
+ if (result != 0) {
+ if (need_BC) {
+ strcpy(result + used, BC);
+ used += strlen(BC);
+ }
+ result[used] = '\0';
}
- result[used] = '\0';
return result;
}
#endif
@@ -186,8 +188,7 @@ tgoto_internal(const char *string, int x, int y)
* the last two arguments when invoking tparm().
*/
NCURSES_EXPORT(char *)
-tgoto
-(const char *string, int x, int y)
+tgoto(const char *string, int x, int y)
{
char *result;
@@ -197,6 +198,6 @@ tgoto
result = tgoto_internal(string, x, y);
else
#endif
- result = tparm((NCURSES_CONST char *) string, y, x);
+ result = TPARM_2((NCURSES_CONST char *) string, y, x);
returnPtr(result);
}
diff --git a/contrib/ncurses/ncurses/tinfo/lib_ti.c b/contrib/ncurses/ncurses/tinfo/lib_ti.c
index 8ef866588197..df460f953ea7 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_ti.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_ti.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2000,2003 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -36,12 +36,12 @@
#include <term_entry.h>
#include <tic.h>
-MODULE_ID("$Id: lib_ti.c,v 1.22 2000/12/10 02:55:08 tom Exp $")
+MODULE_ID("$Id: lib_ti.c,v 1.23 2003/05/24 21:10:28 tom Exp $")
NCURSES_EXPORT(int)
tigetflag(NCURSES_CONST char *str)
{
- int i;
+ unsigned i;
T((T_CALLED("tigetflag(%s)"), str));
@@ -62,7 +62,7 @@ tigetflag(NCURSES_CONST char *str)
NCURSES_EXPORT(int)
tigetnum(NCURSES_CONST char *str)
{
- int i;
+ unsigned i;
T((T_CALLED("tigetnum(%s)"), str));
@@ -84,7 +84,7 @@ tigetnum(NCURSES_CONST char *str)
NCURSES_EXPORT(char *)
tigetstr(NCURSES_CONST char *str)
{
- int i;
+ unsigned i;
T((T_CALLED("tigetstr(%s)"), str));
diff --git a/contrib/ncurses/ncurses/tinfo/lib_tparm.c b/contrib/ncurses/ncurses/tinfo/lib_tparm.c
index 931669e933bd..cba31d9fd36b 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_tparm.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_tparm.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,6 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey, 1996 on *
****************************************************************************/
/*
@@ -42,7 +43,7 @@
#include <term.h>
#include <tic.h>
-MODULE_ID("$Id: lib_tparm.c,v 1.53 2001/06/02 22:53:59 tom Exp $")
+MODULE_ID("$Id: lib_tparm.c,v 1.71 2006/11/26 01:12:56 tom Exp $")
/*
* char *
@@ -108,7 +109,7 @@ MODULE_ID("$Id: lib_tparm.c,v 1.53 2001/06/02 22:53:59 tom Exp $")
typedef struct {
union {
- unsigned int num;
+ int num;
char *str;
} data;
bool num_type;
@@ -128,6 +129,9 @@ static char *out_buff;
static size_t out_size;
static size_t out_used;
+static char *fmt_buff;
+static size_t fmt_size;
+
#if NO_LEAKS
NCURSES_EXPORT(void)
_nc_free_tparm(void)
@@ -136,28 +140,25 @@ _nc_free_tparm(void)
FreeAndNull(out_buff);
out_size = 0;
out_used = 0;
+ FreeAndNull(fmt_buff);
+ fmt_size = 0;
}
}
#endif
-static void
-really_get_space(size_t need)
-{
- out_size = need * 2;
- out_buff = typeRealloc(char, out_size, out_buff);
- if (out_buff == 0)
- _nc_err_abort("Out of memory");
-}
-
-static inline void
+static NCURSES_INLINE void
get_space(size_t need)
{
need += out_used;
- if (need > out_size)
- really_get_space(need);
+ if (need > out_size) {
+ out_size = need * 2;
+ out_buff = typeRealloc(char, out_size, out_buff);
+ if (out_buff == 0)
+ _nc_err_abort(MSG_NO_MEMORY);
+ }
}
-static inline void
+static NCURSES_INLINE void
save_text(const char *fmt, const char *s, int len)
{
size_t s_len = strlen(s);
@@ -170,19 +171,19 @@ save_text(const char *fmt, const char *s, int len)
out_used += strlen(out_buff + out_used);
}
-static inline void
+static NCURSES_INLINE void
save_number(const char *fmt, int number, int len)
{
if (len < 30)
len = 30; /* actually log10(MAX_INT)+1 */
- get_space(len + 1);
+ get_space((unsigned) len + 1);
(void) sprintf(out_buff + out_used, fmt, number);
out_used += strlen(out_buff + out_used);
}
-static inline void
+static NCURSES_INLINE void
save_char(int c)
{
if (c == 0)
@@ -191,7 +192,7 @@ save_char(int c)
out_buff[out_used++] = c;
}
-static inline void
+static NCURSES_INLINE void
npush(int x)
{
if (stack_ptr < STACKSIZE) {
@@ -204,7 +205,7 @@ npush(int x)
}
}
-static inline int
+static NCURSES_INLINE int
npop(void)
{
int result = 0;
@@ -219,7 +220,7 @@ npop(void)
return result;
}
-static inline void
+static NCURSES_INLINE void
spush(char *x)
{
if (stack_ptr < STACKSIZE) {
@@ -232,7 +233,7 @@ spush(char *x)
}
}
-static inline char *
+static NCURSES_INLINE char *
spop(void)
{
static char dummy[] = ""; /* avoid const-cast */
@@ -248,152 +249,139 @@ spop(void)
return result;
}
-static inline const char *
+static NCURSES_INLINE const char *
parse_format(const char *s, char *format, int *len)
{
- bool done = FALSE;
- bool allowminus = FALSE;
- bool dot = FALSE;
- bool err = FALSE;
- char *fmt = format;
- int prec = 0;
- int width = 0;
- int value = 0;
-
*len = 0;
- *format++ = '%';
- while (*s != '\0' && !done) {
- switch (*s) {
- case 'c': /* FALLTHRU */
- case 'd': /* FALLTHRU */
- case 'o': /* FALLTHRU */
- case 'x': /* FALLTHRU */
- case 'X': /* FALLTHRU */
- case 's':
- *format++ = *s;
- done = TRUE;
- break;
- case '.':
- *format++ = *s++;
- if (dot) {
- err = TRUE;
- } else {
- dot = TRUE;
- prec = value;
- }
- value = 0;
- break;
- case '#':
- *format++ = *s++;
- break;
- case ' ':
- *format++ = *s++;
- break;
- case ':':
- s++;
- allowminus = TRUE;
- break;
- case '-':
- if (allowminus) {
- *format++ = *s++;
- } else {
+ if (format != 0) {
+ bool done = FALSE;
+ bool allowminus = FALSE;
+ bool dot = FALSE;
+ bool err = FALSE;
+ char *fmt = format;
+ int my_width = 0;
+ int my_prec = 0;
+ int value = 0;
+
+ *len = 0;
+ *format++ = '%';
+ while (*s != '\0' && !done) {
+ switch (*s) {
+ case 'c': /* FALLTHRU */
+ case 'd': /* FALLTHRU */
+ case 'o': /* FALLTHRU */
+ case 'x': /* FALLTHRU */
+ case 'X': /* FALLTHRU */
+ case 's':
+ *format++ = *s;
done = TRUE;
- }
- break;
- default:
- if (isdigit(UChar(*s))) {
- value = (value * 10) + (*s - '0');
- if (value > 10000)
+ break;
+ case '.':
+ *format++ = *s++;
+ if (dot) {
err = TRUE;
+ } else { /* value before '.' is the width */
+ dot = TRUE;
+ my_width = value;
+ }
+ value = 0;
+ break;
+ case '#':
*format++ = *s++;
- } else {
- done = TRUE;
+ break;
+ case ' ':
+ *format++ = *s++;
+ break;
+ case ':':
+ s++;
+ allowminus = TRUE;
+ break;
+ case '-':
+ if (allowminus) {
+ *format++ = *s++;
+ } else {
+ done = TRUE;
+ }
+ break;
+ default:
+ if (isdigit(UChar(*s))) {
+ value = (value * 10) + (*s - '0');
+ if (value > 10000)
+ err = TRUE;
+ *format++ = *s++;
+ } else {
+ done = TRUE;
+ }
}
}
- }
-
- /*
- * If we found an error, ignore (and remove) the flags.
- */
- if (err) {
- prec = width = value = 0;
- format = fmt;
- *format++ = '%';
- *format++ = *s;
- }
- if (dot)
- width = value;
- else
- prec = value;
+ /*
+ * If we found an error, ignore (and remove) the flags.
+ */
+ if (err) {
+ my_width = my_prec = value = 0;
+ format = fmt;
+ *format++ = '%';
+ *format++ = *s;
+ }
- *format = '\0';
- /* return maximum string length in print */
- *len = (prec > width) ? prec : width;
+ /*
+ * Any value after '.' is the precision. If we did not see '.', then
+ * the value is the width.
+ */
+ if (dot)
+ my_prec = value;
+ else
+ my_width = value;
+
+ *format = '\0';
+ /* return maximum string length in print */
+ *len = (my_width > my_prec) ? my_width : my_prec;
+ }
return s;
}
#define isUPPER(c) ((c) >= 'A' && (c) <= 'Z')
#define isLOWER(c) ((c) >= 'a' && (c) <= 'z')
-static inline char *
-tparam_internal(const char *string, va_list ap)
+/*
+ * Analyze the string to see how many parameters we need from the varargs list,
+ * and what their types are. We will only accept string parameters if they
+ * appear as a %l or %s format following an explicit parameter reference (e.g.,
+ * %p2%s). All other parameters are numbers.
+ *
+ * 'number' counts coarsely the number of pop's we see in the string, and
+ * 'popcount' shows the highest parameter number in the string. We would like
+ * to simply use the latter count, but if we are reading termcap strings, there
+ * may be cases that we cannot see the explicit parameter numbers.
+ */
+NCURSES_EXPORT(int)
+_nc_tparm_analyze(const char *string, char *p_is_s[NUM_PARM], int *popcount)
{
-#define NUM_VARS 26
- char *p_is_s[9];
- int param[9];
- int lastpop;
- int popcount;
- int number;
- int len;
- int level;
- int x, y;
- int i;
size_t len2;
- register const char *cp;
- static size_t len_fmt;
+ int i;
+ int lastpop = -1;
+ int len;
+ int number = 0;
+ const char *cp = string;
static char dummy[] = "";
- static char *format;
- static int dynamic_var[NUM_VARS];
- static int static_vars[NUM_VARS];
- out_used = 0;
- if (string == NULL)
- return NULL;
+ if (cp == 0)
+ return 0;
- if ((len2 = strlen(string)) > len_fmt) {
- len_fmt = len2 + len_fmt + 2;
- if ((format = typeRealloc(char, len_fmt, format)) == 0)
+ if ((len2 = strlen(cp)) > fmt_size) {
+ fmt_size = len2 + fmt_size + 2;
+ if ((fmt_buff = typeRealloc(char, fmt_size, fmt_buff)) == 0)
return 0;
}
- /*
- * Find the highest parameter-number referred to in the format string.
- * Use this value to limit the number of arguments copied from the
- * variable-length argument list.
- */
-
- number = 0;
- lastpop = -1;
- popcount = 0;
- memset(p_is_s, 0, sizeof(p_is_s));
+ memset(p_is_s, 0, sizeof(p_is_s[0]) * NUM_PARM);
+ *popcount = 0;
- /*
- * Analyze the string to see how many parameters we need from the varargs
- * list, and what their types are. We will only accept string parameters
- * if they appear as a %l or %s format following an explicit parameter
- * reference (e.g., %p2%s). All other parameters are numbers.
- *
- * 'number' counts coarsely the number of pop's we see in the string, and
- * 'popcount' shows the highest parameter number in the string. We would
- * like to simply use the latter count, but if we are reading termcap
- * strings, there may be cases that we cannot see the explicit parameter
- * numbers.
- */
- for (cp = string; (cp - string) < (int) len2;) {
+ while ((cp - string) < (int) len2) {
if (*cp == '%') {
cp++;
- cp = parse_format(cp, format, &len);
+ cp = parse_format(cp, fmt_buff, &len);
switch (*cp) {
default:
break;
@@ -403,7 +391,8 @@ tparam_internal(const char *string, va_list ap)
case 'x': /* FALLTHRU */
case 'X': /* FALLTHRU */
case 'c': /* FALLTHRU */
- number++;
+ if (lastpop <= 0)
+ number++;
lastpop = -1;
break;
@@ -416,15 +405,19 @@ tparam_internal(const char *string, va_list ap)
case 'p':
cp++;
- i = (*cp - '0');
- if (i >= 0 && i <= 9) {
+ i = (UChar(*cp) - '0');
+ if (i >= 0 && i <= NUM_PARM) {
lastpop = i;
- if (lastpop > popcount)
- popcount = lastpop;
+ if (lastpop > *popcount)
+ *popcount = lastpop;
}
break;
case 'P':
+ ++number;
+ ++cp;
+ break;
+
case 'g':
cp++;
break;
@@ -436,7 +429,7 @@ tparam_internal(const char *string, va_list ap)
case L_BRACE:
cp++;
- while (*cp >= '0' && *cp <= '9') {
+ while (isdigit(UChar(*cp))) {
cp++;
}
break;
@@ -454,16 +447,18 @@ tparam_internal(const char *string, va_list ap)
case '=':
case '<':
case '>':
+ lastpop = -1;
+ number += 2;
+ break;
+
case '!':
case '~':
lastpop = -1;
- number += 2;
+ ++number;
break;
case 'i':
- lastpop = -1;
- if (popcount < 2)
- popcount = 2;
+ /* will add 1 to first (usually two) parameters */
break;
}
}
@@ -471,18 +466,55 @@ tparam_internal(const char *string, va_list ap)
cp++;
}
- if (number > 9)
- number = 9;
+ if (number > NUM_PARM)
+ number = NUM_PARM;
+ return number;
+}
+
+static NCURSES_INLINE char *
+tparam_internal(const char *string, va_list ap)
+{
+#define NUM_VARS 26
+ char *p_is_s[NUM_PARM];
+ TPARM_ARG param[NUM_PARM];
+ int popcount;
+ int number;
+ int len;
+ int level;
+ int x, y;
+ int i;
+ const char *cp = string;
+ size_t len2;
+ static int dynamic_var[NUM_VARS];
+ static int static_vars[NUM_VARS];
+
+ if (cp == NULL)
+ return NULL;
+
+ out_used = 0;
+ len2 = strlen(cp);
+
+ /*
+ * Find the highest parameter-number referred to in the format string.
+ * Use this value to limit the number of arguments copied from the
+ * variable-length argument list.
+ */
+ number = _nc_tparm_analyze(cp, p_is_s, &popcount);
+ if (fmt_buff == 0)
+ return NULL;
+
for (i = 0; i < max(popcount, number); i++) {
/*
* A few caps (such as plab_norm) have string-valued parms.
* We'll have to assume that the caller knows the difference, since
- * a char* and an int may not be the same size on the stack.
+ * a char* and an int may not be the same size on the stack. The
+ * normal prototype for this uses 9 long's, which is consistent with
+ * our va_arg() usage.
*/
if (p_is_s[i] != 0) {
p_is_s[i] = va_arg(ap, char *);
} else {
- param[i] = va_arg(ap, int);
+ param[i] = va_arg(ap, TPARM_ARG);
}
}
@@ -507,18 +539,18 @@ tparam_internal(const char *string, va_list ap)
else
save_number(", %d", param[i], 0);
}
- _tracef(T_CALLED("%s(%s%s)"), tname, _nc_visbuf(string), out_buff);
+ _tracef(T_CALLED("%s(%s%s)"), tname, _nc_visbuf(cp), out_buff);
out_used = 0;
}
#endif /* TRACE */
- while (*string) {
- if (*string != '%') {
- save_char(*string);
+ while ((cp - string) < (int) len2) {
+ if (*cp != '%') {
+ save_char(UChar(*cp));
} else {
- tparam_base = string++;
- string = parse_format(string, format, &len);
- switch (*string) {
+ tparam_base = cp++;
+ cp = parse_format(cp, fmt_buff, &len);
+ switch (*cp) {
default:
break;
case '%':
@@ -529,22 +561,25 @@ tparam_internal(const char *string, va_list ap)
case 'o': /* FALLTHRU */
case 'x': /* FALLTHRU */
case 'X': /* FALLTHRU */
+ save_number(fmt_buff, npop(), len);
+ break;
+
case 'c': /* FALLTHRU */
- save_number(format, npop(), len);
+ save_char(npop());
break;
case 'l':
- save_number("%d", strlen(spop()), 0);
+ save_number("%d", (int) strlen(spop()), 0);
break;
case 's':
- save_text(format, spop(), len);
+ save_text(fmt_buff, spop(), len);
break;
case 'p':
- string++;
- i = (*string - '1');
- if (i >= 0 && i < 9) {
+ cp++;
+ i = (UChar(*cp) - '1');
+ if (i >= 0 && i < NUM_PARM) {
if (p_is_s[i])
spush(p_is_s[i]);
else
@@ -553,39 +588,39 @@ tparam_internal(const char *string, va_list ap)
break;
case 'P':
- string++;
- if (isUPPER(*string)) {
- i = (*string - 'A');
+ cp++;
+ if (isUPPER(*cp)) {
+ i = (UChar(*cp) - 'A');
static_vars[i] = npop();
- } else if (isLOWER(*string)) {
- i = (*string - 'a');
+ } else if (isLOWER(*cp)) {
+ i = (UChar(*cp) - 'a');
dynamic_var[i] = npop();
}
break;
case 'g':
- string++;
- if (isUPPER(*string)) {
- i = (*string - 'A');
+ cp++;
+ if (isUPPER(*cp)) {
+ i = (UChar(*cp) - 'A');
npush(static_vars[i]);
- } else if (isLOWER(*string)) {
- i = (*string - 'a');
+ } else if (isLOWER(*cp)) {
+ i = (UChar(*cp) - 'a');
npush(dynamic_var[i]);
}
break;
case S_QUOTE:
- string++;
- npush(*string);
- string++;
+ cp++;
+ npush(UChar(*cp));
+ cp++;
break;
case L_BRACE:
number = 0;
- string++;
- while (*string >= '0' && *string <= '9') {
- number = number * 10 + *string - '0';
- string++;
+ cp++;
+ while (isdigit(UChar(*cp))) {
+ number = (number * 10) + (UChar(*cp) - '0');
+ cp++;
}
npush(number);
break;
@@ -676,38 +711,38 @@ tparam_internal(const char *string, va_list ap)
x = npop();
if (!x) {
/* scan forward for %e or %; at level zero */
- string++;
+ cp++;
level = 0;
- while (*string) {
- if (*string == '%') {
- string++;
- if (*string == '?')
+ while (*cp) {
+ if (*cp == '%') {
+ cp++;
+ if (*cp == '?')
level++;
- else if (*string == ';') {
+ else if (*cp == ';') {
if (level > 0)
level--;
else
break;
- } else if (*string == 'e' && level == 0)
+ } else if (*cp == 'e' && level == 0)
break;
}
- if (*string)
- string++;
+ if (*cp)
+ cp++;
}
}
break;
case 'e':
/* scan forward for a %; at level zero */
- string++;
+ cp++;
level = 0;
- while (*string) {
- if (*string == '%') {
- string++;
- if (*string == '?')
+ while (*cp) {
+ if (*cp == '%') {
+ cp++;
+ if (*cp == '?')
level++;
- else if (*string == ';') {
+ else if (*cp == ';') {
if (level > 0)
level--;
else
@@ -715,22 +750,22 @@ tparam_internal(const char *string, va_list ap)
}
}
- if (*string)
- string++;
+ if (*cp)
+ cp++;
}
break;
case ';':
break;
- } /* endswitch (*string) */
- } /* endelse (*string == '%') */
+ } /* endswitch (*cp) */
+ } /* endelse (*cp == '%') */
- if (*string == '\0')
+ if (*cp == '\0')
break;
- string++;
- } /* endwhile (*string) */
+ cp++;
+ } /* endwhile (*cp) */
get_space(1);
out_buff[out_used] = '\0';
@@ -739,9 +774,14 @@ tparam_internal(const char *string, va_list ap)
return (out_buff);
}
+#if NCURSES_TPARM_VARARGS
+#define tparm_varargs tparm
+#else
+#define tparm_proto tparm
+#endif
+
NCURSES_EXPORT(char *)
-tparm
-(NCURSES_CONST char *string,...)
+tparm_varargs(NCURSES_CONST char *string,...)
{
va_list ap;
char *result;
@@ -755,3 +795,20 @@ tparm
va_end(ap);
return result;
}
+
+#if !NCURSES_TPARM_VARARGS
+NCURSES_EXPORT(char *)
+tparm_proto(NCURSES_CONST char *string,
+ TPARM_ARG a1,
+ TPARM_ARG a2,
+ TPARM_ARG a3,
+ TPARM_ARG a4,
+ TPARM_ARG a5,
+ TPARM_ARG a6,
+ TPARM_ARG a7,
+ TPARM_ARG a8,
+ TPARM_ARG a9)
+{
+ return tparm_varargs(string, a1, a2, a3, a4, a5, a6, a7, a8, a9);
+}
+#endif /* NCURSES_TPARM_VARARGS */
diff --git a/contrib/ncurses/ncurses/tinfo/lib_tputs.c b/contrib/ncurses/ncurses/tinfo/lib_tputs.c
index 26d805ba4025..3a18ffd7404f 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_tputs.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_tputs.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2002,2003 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -45,16 +45,14 @@
#include <termcap.h> /* ospeed */
#include <tic.h>
-MODULE_ID("$Id: lib_tputs.c,v 1.59 2001/09/22 18:35:23 tom Exp $")
+MODULE_ID("$Id: lib_tputs.c,v 1.62 2003/08/23 21:39:20 tom Exp $")
-NCURSES_EXPORT_VAR(char)
-PC = 0; /* used by termcap library */
+NCURSES_EXPORT_VAR(char) PC = 0; /* used by termcap library */
NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed = 0; /* used by termcap library */
-NCURSES_EXPORT_VAR(int)
-_nc_nulls_sent = 0; /* used by 'tack' program */
+NCURSES_EXPORT_VAR(int) _nc_nulls_sent = 0; /* used by 'tack' program */
- static int (*my_outch) (int c) = _nc_outch;
+static int (*my_outch) (int c) = _nc_outch;
NCURSES_EXPORT(int)
delay_output(int ms)
@@ -67,7 +65,7 @@ delay_output(int ms)
} else {
register int nullcount;
- nullcount = (ms * _nc_baudrate(ospeed)) / 10000;
+ nullcount = (ms * _nc_baudrate(ospeed)) / (BAUDBYTE * 1000);
for (_nc_nulls_sent += nullcount; nullcount > 0; nullcount--)
my_outch(PC);
if (my_outch == _nc_outch)
@@ -86,9 +84,7 @@ _nc_flush(void)
NCURSES_EXPORT(int)
_nc_outch(int ch)
{
-#ifdef TRACE
- _nc_outchars++;
-#endif /* TRACE */
+ TRACE_OUTCHARS(1);
if (SP != 0
&& SP->_cleanup) {
@@ -111,8 +107,7 @@ putp(const char *string)
}
NCURSES_EXPORT(int)
-tputs
-(const char *string, int affcnt, int (*outc) (int))
+tputs(const char *string, int affcnt, int (*outc) (int))
{
bool always_delay;
bool normal_delay;
diff --git a/contrib/ncurses/ncurses/tinfo/lib_ttyflags.c b/contrib/ncurses/ncurses/tinfo/lib_ttyflags.c
index 385166e94fa7..77c35fa58426 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_ttyflags.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_ttyflags.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -38,42 +38,56 @@
#include <curses.priv.h>
#include <term.h> /* cur_term */
-MODULE_ID("$Id: lib_ttyflags.c,v 1.7 2002/05/25 14:50:00 tom Exp $")
-
-#undef tabs
-
-#ifdef TAB3
-# define tabs TAB3
-#else
-# ifdef XTABS
-# define tabs XTABS
-# else
-# ifdef OXTABS
-# define tabs OXTABS
-# else
-# define tabs 0
-# endif
-# endif
-#endif
+MODULE_ID("$Id: lib_ttyflags.c,v 1.13 2006/12/10 01:31:54 tom Exp $")
NCURSES_EXPORT(int)
_nc_get_tty_mode(TTY * buf)
{
- if (cur_term == 0
- || GET_TTY(cur_term->Filedes, buf) != 0)
- return (ERR);
- TR(TRACE_BITS, ("_nc_get_tty_mode: %s", _nc_trace_ttymode(buf)));
- return (OK);
+ int result = OK;
+
+ if (cur_term == 0) {
+ result = ERR;
+ } else {
+ for (;;) {
+ if (GET_TTY(cur_term->Filedes, buf) != 0) {
+ if (errno == EINTR)
+ continue;
+ result = ERR;
+ }
+ break;
+ }
+ }
+
+ if (result == ERR)
+ memset(buf, 0, sizeof(*buf));
+
+ TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s",
+ cur_term->Filedes, _nc_trace_ttymode(buf)));
+ return (result);
}
NCURSES_EXPORT(int)
_nc_set_tty_mode(TTY * buf)
{
- if (cur_term == 0
- || SET_TTY(cur_term->Filedes, buf) != 0)
- return (ERR);
- TR(TRACE_BITS, ("_nc_set_tty_mode: %s", _nc_trace_ttymode(buf)));
- return (OK);
+ int result = OK;
+
+ if (cur_term == 0) {
+ result = ERR;
+ } else {
+ for (;;) {
+ if (SET_TTY(cur_term->Filedes, buf) != 0) {
+ if (errno == EINTR)
+ continue;
+ if ((errno == ENOTTY) && (SP != 0))
+ SP->_notty = TRUE;
+ result = ERR;
+ }
+ break;
+ }
+ }
+ TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s",
+ cur_term->Filedes, _nc_trace_ttymode(buf)));
+ return (result);
}
NCURSES_EXPORT(int)
@@ -82,14 +96,13 @@ def_shell_mode(void)
T((T_CALLED("def_shell_mode()")));
/*
- * Turn off the XTABS bit in the tty structure if it was on. If XTABS
- * was on, remove the tab and backtab capabilities.
+ * If XTABS was on, remove the tab and backtab capabilities.
*/
if (_nc_get_tty_mode(&cur_term->Ottyb) != OK)
returnCode(ERR);
#ifdef TERMIOS
- if (cur_term->Ottyb.c_oflag & tabs)
+ if (cur_term->Ottyb.c_oflag & OFLAGS_TABS)
tab = back_tab = NULL;
#else
if (cur_term->Ottyb.sg_flags & XTABS)
@@ -103,10 +116,14 @@ def_prog_mode(void)
{
T((T_CALLED("def_prog_mode()")));
+ /*
+ * Turn off the XTABS bit in the tty structure if it was on.
+ */
+
if (_nc_get_tty_mode(&cur_term->Nttyb) != OK)
returnCode(ERR);
#ifdef TERMIOS
- cur_term->Nttyb.c_oflag &= ~tabs;
+ cur_term->Nttyb.c_oflag &= ~OFLAGS_TABS;
#else
cur_term->Nttyb.sg_flags &= ~XTABS;
#endif
@@ -119,13 +136,14 @@ reset_prog_mode(void)
T((T_CALLED("reset_prog_mode()")));
if (cur_term != 0) {
- _nc_set_tty_mode(&cur_term->Nttyb);
- if (SP) {
- if (SP->_keypad_on)
- _nc_keypad(TRUE);
- NC_BUFFERED(TRUE);
+ if (_nc_set_tty_mode(&cur_term->Nttyb) == OK) {
+ if (SP) {
+ if (SP->_keypad_on)
+ _nc_keypad(TRUE);
+ NC_BUFFERED(TRUE);
+ }
+ returnCode(OK);
}
- returnCode(OK);
}
returnCode(ERR);
}
diff --git a/contrib/ncurses/ncurses/tinfo/make_keys.c b/contrib/ncurses/ncurses/tinfo/make_keys.c
index 3c98da23e019..8f6243c93c75 100644
--- a/contrib/ncurses/ncurses/tinfo/make_keys.c
+++ b/contrib/ncurses/ncurses/tinfo/make_keys.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -35,9 +35,11 @@
* making the output show the indices into the TERMTYPE Strings array. Doing
* it that way lets us cut down on the size of the init_keytry() function.
*/
+
+#define USE_TERMLIB 1
#include <curses.priv.h>
-MODULE_ID("$Id: make_keys.c,v 1.10 2000/12/10 02:55:08 tom Exp $")
+MODULE_ID("$Id: make_keys.c,v 1.12 2005/08/20 19:58:18 tom Exp $")
#include <names.c>
@@ -66,7 +68,7 @@ lookup(const char *name)
}
static void
-make_keys(FILE * ifp, FILE * ofp)
+make_keys(FILE *ifp, FILE *ofp)
{
char buffer[BUFSIZ];
char from[BUFSIZ];
@@ -92,7 +94,7 @@ make_keys(FILE * ifp, FILE * ofp)
}
static void
-write_list(FILE * ofp, const char **list)
+write_list(FILE *ofp, const char **list)
{
while (*list != 0)
fprintf(ofp, "%s\n", *list++);
diff --git a/contrib/ncurses/ncurses/tinfo/name_match.c b/contrib/ncurses/ncurses/tinfo/name_match.c
index e7205d5ec8ab..fee3ba3bc711 100644
--- a/contrib/ncurses/ncurses/tinfo/name_match.c
+++ b/contrib/ncurses/ncurses/tinfo/name_match.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1999,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1999-2004,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -34,7 +34,7 @@
#include <term.h>
#include <tic.h>
-MODULE_ID("$Id: name_match.c,v 1.11 2001/09/22 21:11:34 tom Exp $")
+MODULE_ID("$Id: name_match.c,v 1.15 2005/01/22 21:47:25 tom Exp $")
/*
* _nc_first_name(char *names)
@@ -49,8 +49,16 @@ _nc_first_name(const char *const sp)
static char *buf;
register unsigned n;
+#if NO_LEAKS
+ if (sp == 0) {
+ if (buf != 0)
+ FreeAndNull(buf); /* for leak-testing */
+ return 0;
+ }
+#endif
+
if (buf == 0)
- buf = _nc_doalloc(buf, MAX_NAME_SIZE + 1);
+ buf = typeMalloc(char, MAX_NAME_SIZE + 1);
for (n = 0; n < MAX_NAME_SIZE; n++) {
if ((buf[n] = sp[n]) == '\0'
|| (buf[n] == '|'))
@@ -67,8 +75,7 @@ _nc_first_name(const char *const sp)
*/
NCURSES_EXPORT(int)
-_nc_name_match
-(const char *const namelst, const char *const name, const char *const delim)
+_nc_name_match(const char *const namelst, const char *const name, const char *const delim)
{
const char *s, *d, *t;
int code, found;
diff --git a/contrib/ncurses/ncurses/tinfo/parse_entry.c b/contrib/ncurses/ncurses/tinfo/parse_entry.c
index 1c0ce850e42d..510b232c8b5c 100644
--- a/contrib/ncurses/ncurses/tinfo/parse_entry.c
+++ b/contrib/ncurses/ncurses/tinfo/parse_entry.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,6 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
****************************************************************************/
/*
@@ -47,7 +48,7 @@
#include <tic.h>
#include <term_entry.h>
-MODULE_ID("$Id: parse_entry.c,v 1.56 2002/05/25 12:23:51 tom Exp $")
+MODULE_ID("$Id: parse_entry.c,v 1.63 2006/06/17 17:57:50 tom Exp $")
#ifdef LINT
static short const parametrized[] =
@@ -141,7 +142,7 @@ _nc_extend_names(ENTRY * entryp, char *name, int token_type)
case BOOLEAN:
tp->ext_Booleans += 1;
tp->num_Booleans += 1;
- tp->Booleans = typeRealloc(char, tp->num_Booleans, tp->Booleans);
+ tp->Booleans = typeRealloc(NCURSES_SBOOL, tp->num_Booleans, tp->Booleans);
for (last = tp->num_Booleans - 1; last > tindex; last--)
tp->Booleans[last] = tp->Booleans[last - 1];
break;
@@ -188,20 +189,24 @@ _nc_extend_names(ENTRY * entryp, char *name, int token_type)
* if the token was not a name in column 1, complain and die
* save names in entry's string table
* while (get_token() is not EOF and not NAMES)
- * check for existance and type-correctness
+ * check for existence and type-correctness
* enter cap into structure
* if STRING
* save string in entry's string table
* push back token
*/
+#define BAD_TC_USAGE if (!bad_tc_usage) \
+ { bad_tc_usage = TRUE; \
+ _nc_warning("Legacy termcap allows only a trailing tc= clause"); }
+
NCURSES_EXPORT(int)
-_nc_parse_entry
-(struct entry *entryp, int literal, bool silent)
+_nc_parse_entry(struct entry *entryp, int literal, bool silent)
{
int token_type;
struct name_table_entry const *entry_ptr;
char *ptr, *base;
+ bool bad_tc_usage = FALSE;
token_type = _nc_get_token(silent);
@@ -217,11 +222,25 @@ _nc_parse_entry
entryp->startline = _nc_start_line;
DEBUG(2, ("Comment range is %ld to %ld", entryp->cstart, entryp->cend));
- /* junk the 2-character termcap name, if present */
+ /*
+ * Strip off the 2-character termcap name, if present. Originally termcap
+ * used that as an indexing aid. We can retain 2-character terminfo names,
+ * but note that they would be lost if we translate to/from termcap. This
+ * feature is supposedly obsolete since "newer" BSD implementations do not
+ * use it; however our reference for this feature is SunOS 4.x, which
+ * implemented it. Note that the resulting terminal type was never the
+ * 2-character name, but was instead the first alias after that.
+ */
ptr = _nc_curr_token.tk_name;
- if (ptr[2] == '|') {
- ptr = _nc_curr_token.tk_name + 3;
- _nc_curr_token.tk_name[2] = '\0';
+ if (_nc_syntax == SYN_TERMCAP
+#if NCURSES_XNAMES
+ && !_nc_user_definable
+#endif
+ ) {
+ if (ptr[2] == '|') {
+ ptr += 3;
+ _nc_curr_token.tk_name[2] = '\0';
+ }
}
entryp->tterm.str_table = entryp->tterm.term_names = _nc_save_str(ptr);
@@ -252,11 +271,15 @@ _nc_parse_entry
for (token_type = _nc_get_token(silent);
token_type != EOF && token_type != NAMES;
token_type = _nc_get_token(silent)) {
- if (strcmp(_nc_curr_token.tk_name, "use") == 0
- || strcmp(_nc_curr_token.tk_name, "tc") == 0) {
+ bool is_use = (strcmp(_nc_curr_token.tk_name, "use") == 0);
+ bool is_tc = !is_use && (strcmp(_nc_curr_token.tk_name, "tc") == 0);
+ if (is_use || is_tc) {
entryp->uses[entryp->nuses].name = _nc_save_str(_nc_curr_token.tk_valstring);
entryp->uses[entryp->nuses].line = _nc_curr_line;
entryp->nuses++;
+ if (entryp->nuses > 1 && is_tc) {
+ BAD_TC_USAGE
+ }
} else {
/* normal token lookup */
entry_ptr = _nc_find_entry(_nc_curr_token.tk_name,
@@ -274,6 +297,9 @@ _nc_parse_entry
const struct alias *ap;
if (_nc_syntax == SYN_TERMCAP) {
+ if (entryp->nuses != 0) {
+ BAD_TC_USAGE
+ }
for (ap = _nc_capalias_table; ap->from; ap++)
if (strcmp(ap->from, _nc_curr_token.tk_name) == 0) {
if (ap->to == (char *) 0) {
@@ -345,22 +371,25 @@ _nc_parse_entry
*/
/* tell max_attributes from arrow_key_map */
- if (token_type == NUMBER && !strcmp("ma", _nc_curr_token.tk_name))
+ if (token_type == NUMBER
+ && !strcmp("ma", _nc_curr_token.tk_name)) {
entry_ptr = _nc_find_type_entry("ma", NUMBER,
_nc_get_table(_nc_syntax
!= 0));
- /* map terminfo's string MT to MT */
- else if (token_type == STRING && !strcmp("MT", _nc_curr_token.tk_name))
+ /* map terminfo's string MT to MT */
+ } else if (token_type == STRING
+ && !strcmp("MT", _nc_curr_token.tk_name)) {
entry_ptr = _nc_find_type_entry("MT", STRING,
_nc_get_table(_nc_syntax
!= 0));
- /* treat strings without following "=" as empty strings */
- else if (token_type == BOOLEAN && entry_ptr->nte_type == STRING)
+ /* treat strings without following "=" as empty strings */
+ } else if (token_type == BOOLEAN
+ && entry_ptr->nte_type == STRING) {
token_type = STRING;
- /* we couldn't recover; skip this token */
- else {
+ /* we couldn't recover; skip this token */
+ } else {
if (!silent) {
const char *type_name;
switch (entry_ptr->nte_type) {
@@ -594,7 +623,7 @@ static const char C_HT[] = "\t";
#define CUR tp->
static void
-postprocess_termcap(TERMTYPE * tp, bool has_base)
+postprocess_termcap(TERMTYPE *tp, bool has_base)
{
char buf[MAX_LINE * 2 + 2];
string_desc result;
@@ -869,13 +898,12 @@ postprocess_termcap(TERMTYPE * tp, bool has_base)
} else if (acs_chars == 0
&& enter_alt_charset_mode != 0
&& exit_alt_charset_mode != 0) {
- acs_chars =
- _nc_save_str("``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~");
+ acs_chars = _nc_save_str(VT_ACSC);
}
}
static void
-postprocess_terminfo(TERMTYPE * tp)
+postprocess_terminfo(TERMTYPE *tp)
{
/*
* TERMINFO-TO-TERMINFO MAPPINGS FOR SOURCE TRANSLATION
diff --git a/contrib/ncurses/ncurses/tinfo/read_entry.c b/contrib/ncurses/ncurses/tinfo/read_entry.c
index 006e56c3ddb1..c6c327514d57 100644
--- a/contrib/ncurses/ncurses/tinfo/read_entry.c
+++ b/contrib/ncurses/ncurses/tinfo/read_entry.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,77 +29,24 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
****************************************************************************/
/*
* read_entry.c -- Routine for reading in a compiled terminfo file
- *
*/
#include <curses.priv.h>
+#include <hashed_db.h>
#include <tic.h>
#include <term_entry.h>
-MODULE_ID("$Id: read_entry.c,v 1.72 2000/12/10 02:55:08 tom Exp $")
-
-#if !HAVE_TELL
-#define tell(fd) 0 /* lseek() is POSIX, but not tell() - odd... */
-#endif
-
-/*
- * int
- * _nc_read_file_entry(filename, ptr)
- *
- * Read the compiled terminfo entry in the given file into the
- * structure pointed to by ptr, allocating space for the string
- * table.
- */
-
-#undef BYTE
-#define BYTE(p,n) (unsigned char)((p)[n])
-
-#define IS_NEG1(p) ((BYTE(p,0) == 0377) && (BYTE(p,1) == 0377))
-#define IS_NEG2(p) ((BYTE(p,0) == 0376) && (BYTE(p,1) == 0377))
-#define LOW_MSB(p) (BYTE(p,0) + 256*BYTE(p,1))
-
-static bool have_tic_directory = FALSE;
-static bool keep_tic_directory = FALSE;
-
-/*
- * Record the "official" location of the terminfo directory, according to
- * the place where we're writing to, or the normal default, if not.
- */
-NCURSES_EXPORT(const char *)
-_nc_tic_dir(const char *path)
-{
- static const char *result = TERMINFO;
-
- if (!keep_tic_directory) {
- if (path != 0) {
- result = path;
- have_tic_directory = TRUE;
- } else if (!have_tic_directory && use_terminfo_vars()) {
- char *envp;
- if ((envp = getenv("TERMINFO")) != 0)
- return _nc_tic_dir(envp);
- }
- }
- return result;
-}
+MODULE_ID("$Id: read_entry.c,v 1.99 2006/08/19 15:58:50 tom Exp $")
-/*
- * Special fix to prevent the terminfo directory from being moved after tic
- * has chdir'd to it. If we let it be changed, then if $TERMINFO has a
- * relative path, we'll lose track of the actual directory.
- */
-NCURSES_EXPORT(void)
-_nc_keep_tic_dir(const char *path)
-{
- _nc_tic_dir(path);
- keep_tic_directory = TRUE;
-}
+#define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts))
+#if USE_DATABASE
static void
convert_shorts(char *buf, short *Numbers, int count)
{
@@ -145,30 +92,51 @@ convert_strings(char *buf, char **Strings, int count, int size, char *table)
}
}
-#define read_shorts(fd, buf, count) (read(fd, buf, (count)*2) == (count)*2)
+static int
+fake_read(char *src, int *offset, int limit, char *dst, unsigned want)
+{
+ int have = (limit - *offset);
+
+ if (have > 0) {
+ if ((int) want > have)
+ want = have;
+ memcpy(dst, src + *offset, want);
+ *offset += want;
+ } else {
+ want = 0;
+ }
+ return (int) want;
+}
+
+#define Read(buf, count) fake_read(buffer, &offset, limit, buf, count)
+
+#define read_shorts(buf, count) \
+ (Read(buf, (unsigned) (count)*2) == (int) (count)*2)
#define even_boundary(value) \
- if ((value) % 2 != 0) read(fd, buf, 1)
+ if ((value) % 2 != 0) Read(buf, 1)
-static int
-read_termtype(int fd, TERMTYPE * ptr)
+NCURSES_EXPORT(int)
+_nc_read_termtype(TERMTYPE *ptr, char *buffer, int limit)
/* return 1 if read, 0 if not found or garbled */
{
+ int offset = 0;
int name_size, bool_count, num_count, str_count, str_size;
int i;
- char buf[MAX_ENTRY_SIZE];
+ char buf[MAX_ENTRY_SIZE + 1];
+ char *string_table;
+ unsigned want, have;
- TR(TRACE_DATABASE, ("READ termtype header @%d", tell(fd)));
+ TR(TRACE_DATABASE, ("READ termtype header @%d", offset));
memset(ptr, 0, sizeof(*ptr));
/* grab the header */
- if (!read_shorts(fd, buf, 6)
- || LOW_MSB(buf) != MAGIC) {
- return (0);
+ if (!read_shorts(buf, 6)
+ || !IS_TIC_MAGIC(buf)) {
+ return (TGETENT_NO);
}
- _nc_free_termtype(ptr);
name_size = LOW_MSB(buf + 2);
bool_count = LOW_MSB(buf + 4);
num_count = LOW_MSB(buf + 6);
@@ -184,34 +152,41 @@ read_termtype(int fd, TERMTYPE * ptr)
|| num_count < 0
|| str_count < 0
|| str_size < 0) {
- return (0);
+ return (TGETENT_NO);
}
+ want = str_size + name_size + 1;
if (str_size) {
/* try to allocate space for the string table */
if (str_count * 2 >= (int) sizeof(buf)
- || (ptr->str_table = typeMalloc(char, (unsigned) str_size)) == 0) {
- return (0);
+ || (string_table = typeMalloc(char, want)) == 0) {
+ return (TGETENT_NO);
}
} else {
str_count = 0;
+ if ((string_table = typeMalloc(char, want)) == 0) {
+ return (TGETENT_NO);
+ }
}
- /* grab the name (a null-terminate string) */
- read(fd, buf, min(MAX_NAME_SIZE, (unsigned) name_size));
- buf[MAX_NAME_SIZE] = '\0';
- ptr->term_names = typeCalloc(char, strlen(buf) + 1);
- if (ptr->term_names == NULL) {
- return (0);
+ /* grab the name (a null-terminated string) */
+ want = min(MAX_NAME_SIZE, (unsigned) name_size);
+ ptr->str_table = string_table;
+ ptr->term_names = string_table;
+ if ((have = Read(ptr->term_names, want)) != want) {
+ memset(ptr->term_names + have, 0, want - have);
}
- (void) strcpy(ptr->term_names, buf);
- if (name_size > MAX_NAME_SIZE)
- lseek(fd, (off_t) (name_size - MAX_NAME_SIZE), 1);
+ ptr->term_names[want] = '\0';
+ string_table += (want + 1);
+
+ if (have > MAX_NAME_SIZE)
+ offset = (have - MAX_NAME_SIZE);
/* grab the booleans */
- if ((ptr->Booleans = typeCalloc(char, max(BOOLCOUNT, bool_count))) == 0
- || read(fd, ptr->Booleans, (unsigned) bool_count) < bool_count) {
- return (0);
+ if ((ptr->Booleans = TYPE_CALLOC(NCURSES_SBOOL,
+ max(BOOLCOUNT, bool_count))) == 0
+ || Read(ptr->Booleans, (unsigned) bool_count) < bool_count) {
+ return (TGETENT_NO);
}
/*
@@ -223,24 +198,24 @@ read_termtype(int fd, TERMTYPE * ptr)
even_boundary(name_size + bool_count);
/* grab the numbers */
- if ((ptr->Numbers = typeCalloc(short, max(NUMCOUNT, num_count))) == 0
- || !read_shorts(fd, buf, num_count)) {
- return (0);
+ if ((ptr->Numbers = TYPE_CALLOC(short, max(NUMCOUNT, num_count))) == 0
+ || !read_shorts(buf, num_count)) {
+ return (TGETENT_NO);
}
convert_shorts(buf, ptr->Numbers, num_count);
- if ((ptr->Strings = typeCalloc(char *, max(STRCOUNT, str_count))) == 0)
- return (0);
+ if ((ptr->Strings = TYPE_CALLOC(char *, max(STRCOUNT, str_count))) == 0)
+ return (TGETENT_NO);
if (str_count) {
/* grab the string offsets */
- if (!read_shorts(fd, buf, str_count)) {
- return (0);
+ if (!read_shorts(buf, str_count)) {
+ return (TGETENT_NO);
}
/* finally, grab the string table itself */
- if (read(fd, ptr->str_table, (unsigned) str_size) != str_size)
- return (0);
- convert_strings(buf, ptr->Strings, str_count, str_size, ptr->str_table);
+ if (Read(string_table, (unsigned) str_size) != str_size)
+ return (TGETENT_NO);
+ convert_strings(buf, ptr->Strings, str_count, str_size, string_table);
}
#if NCURSES_XNAMES
@@ -252,17 +227,17 @@ read_termtype(int fd, TERMTYPE * ptr)
* Read extended entries, if any, after the normal end of terminfo data.
*/
even_boundary(str_size);
- TR(TRACE_DATABASE, ("READ extended_header @%d", tell(fd)));
- if (_nc_user_definable && read_shorts(fd, buf, 5)) {
+ TR(TRACE_DATABASE, ("READ extended_header @%d", offset));
+ if (_nc_user_definable && read_shorts(buf, 5)) {
int ext_bool_count = LOW_MSB(buf + 0);
int ext_num_count = LOW_MSB(buf + 2);
int ext_str_count = LOW_MSB(buf + 4);
int ext_str_size = LOW_MSB(buf + 6);
int ext_str_limit = LOW_MSB(buf + 8);
- int need = (ext_bool_count + ext_num_count + ext_str_count);
+ unsigned need = (ext_bool_count + ext_num_count + ext_str_count);
int base = 0;
- if (need >= (int) sizeof(buf)
+ if (need >= sizeof(buf)
|| ext_str_size >= (int) sizeof(buf)
|| ext_str_limit >= (int) sizeof(buf)
|| ext_bool_count < 0
@@ -270,13 +245,13 @@ read_termtype(int fd, TERMTYPE * ptr)
|| ext_str_count < 0
|| ext_str_size < 0
|| ext_str_limit < 0)
- return (0);
+ return (TGETENT_NO);
ptr->num_Booleans = BOOLCOUNT + ext_bool_count;
ptr->num_Numbers = NUMCOUNT + ext_num_count;
ptr->num_Strings = STRCOUNT + ext_str_count;
- ptr->Booleans = typeRealloc(char, ptr->num_Booleans, ptr->Booleans);
+ ptr->Booleans = typeRealloc(NCURSES_SBOOL, ptr->num_Booleans, ptr->Booleans);
ptr->Numbers = typeRealloc(short, ptr->num_Numbers, ptr->Numbers);
ptr->Strings = typeRealloc(char *, ptr->num_Strings, ptr->Strings);
@@ -285,36 +260,36 @@ read_termtype(int fd, TERMTYPE * ptr)
ext_str_size, ext_str_limit));
TR(TRACE_DATABASE, ("READ %d extended-booleans @%d",
- ext_bool_count, tell(fd)));
+ ext_bool_count, offset));
if ((ptr->ext_Booleans = ext_bool_count) != 0) {
- if (read(fd, ptr->Booleans + BOOLCOUNT, (unsigned)
+ if (Read(ptr->Booleans + BOOLCOUNT, (unsigned)
ext_bool_count) != ext_bool_count)
- return (0);
+ return (TGETENT_NO);
}
even_boundary(ext_bool_count);
TR(TRACE_DATABASE, ("READ %d extended-numbers @%d",
- ext_num_count, tell(fd)));
+ ext_num_count, offset));
if ((ptr->ext_Numbers = ext_num_count) != 0) {
- if (!read_shorts(fd, buf, ext_num_count))
- return (0);
+ if (!read_shorts(buf, ext_num_count))
+ return (TGETENT_NO);
TR(TRACE_DATABASE, ("Before converting extended-numbers"));
convert_shorts(buf, ptr->Numbers + NUMCOUNT, ext_num_count);
}
- TR(TRACE_DATABASE, ("READ extended-offsets @%d", tell(fd)));
+ TR(TRACE_DATABASE, ("READ extended-offsets @%d", offset));
if ((ext_str_count || need)
- && !read_shorts(fd, buf, ext_str_count + need))
- return (0);
+ && !read_shorts(buf, ext_str_count + need))
+ return (TGETENT_NO);
TR(TRACE_DATABASE, ("READ %d bytes of extended-strings @%d",
- ext_str_limit, tell(fd)));
+ ext_str_limit, offset));
if (ext_str_limit) {
if ((ptr->ext_str_table = typeMalloc(char, ext_str_limit)) == 0)
- return (0);
- if (read(fd, ptr->ext_str_table, ext_str_limit) != ext_str_limit)
- return (0);
+ return (TGETENT_NO);
+ if (Read(ptr->ext_str_table, (unsigned) ext_str_limit) != ext_str_limit)
+ return (TGETENT_NO);
TR(TRACE_DATABASE, ("first extended-string is %s", _nc_visbuf(ptr->ext_str_table)));
}
@@ -338,12 +313,14 @@ read_termtype(int fd, TERMTYPE * ptr)
}
if (need) {
- if ((ptr->ext_Names = typeCalloc(char *, need)) == 0)
- return (0);
+ if ((ptr->ext_Names = TYPE_CALLOC(char *, need)) == 0)
+ return (TGETENT_NO);
TR(TRACE_DATABASE,
("ext_NAMES starting @%d in extended_strings, first = %s",
base, _nc_visbuf(ptr->ext_str_table + base)));
- convert_strings(buf + (2 * ext_str_count), ptr->ext_Names, need,
+ convert_strings(buf + (2 * ext_str_count),
+ ptr->ext_Names,
+ (int) need,
ext_str_limit, ptr->ext_str_table + base);
}
@@ -370,86 +347,160 @@ read_termtype(int fd, TERMTYPE * ptr)
for (i = str_count; i < STRCOUNT; i++)
ptr->Strings[i] = ABSENT_STRING;
- return (1);
+ return (TGETENT_YES);
}
+/*
+ * int
+ * _nc_read_file_entry(filename, ptr)
+ *
+ * Read the compiled terminfo entry in the given file into the
+ * structure pointed to by ptr, allocating space for the string
+ * table.
+ */
NCURSES_EXPORT(int)
-_nc_read_file_entry
-(const char *const filename, TERMTYPE * ptr)
+_nc_read_file_entry(const char *const filename, TERMTYPE *ptr)
/* return 1 if read, 0 if not found or garbled */
{
int code, fd = -1;
+ int limit;
+ char buffer[MAX_ENTRY_SIZE + 1];
if (_nc_access(filename, R_OK) < 0
|| (fd = open(filename, O_RDONLY | O_BINARY)) < 0) {
T(("cannot open terminfo %s (errno=%d)", filename, errno));
- return (0);
- }
+ code = TGETENT_NO;
+ } else {
+ if ((limit = read(fd, buffer, sizeof(buffer))) > 0) {
- T(("read terminfo %s", filename));
- if ((code = read_termtype(fd, ptr)) == 0)
- _nc_free_termtype(ptr);
- close(fd);
+ T(("read terminfo %s", filename));
+ if ((code = _nc_read_termtype(ptr, buffer, limit)) == TGETENT_NO) {
+ _nc_free_termtype(ptr);
+ }
+ } else {
+ code = TGETENT_NO;
+ }
+ close(fd);
+ }
return (code);
}
/*
- * Build a terminfo pathname and try to read the data. Returns 1 on success,
- * 0 on failure.
+ * Build a terminfo pathname and try to read the data. Returns TGETENT_YES on
+ * success, TGETENT_NO on failure.
*/
static int
-_nc_read_tic_entry(char *const filename,
- const char *const dir, const char *ttn, TERMTYPE * const tp)
+_nc_read_tic_entry(char *filename,
+ unsigned limit,
+ const char *const path,
+ const char *name,
+ TERMTYPE *const tp)
{
-/* maximum safe length of terminfo root directory name */
-#define MAX_TPATH (PATH_MAX - MAX_ALIAS - 6)
+ int result = TGETENT_NO;
- if (strlen(dir) > MAX_TPATH)
- return 0;
- (void) sprintf(filename, "%s/%s", dir, ttn);
- return _nc_read_file_entry(filename, tp);
-}
+ /*
+ * If we are looking in a directory, assume the entry is a file under that,
+ * according to the normal rules.
+ *
+ * FIXME - add caseless-filename fixup.
+ */
+ if (_nc_is_dir_path(path)) {
+ unsigned need = 4 + strlen(path) + strlen(name);
-/*
- * Process the list of :-separated directories, looking for the terminal type.
- * We don't use strtok because it does not show us empty tokens.
- */
-static int
-_nc_read_terminfo_dirs(const char *dirs, char *const filename, const char *const
- ttn, TERMTYPE * const tp)
-{
- char *list, *a;
- const char *b;
- int code = 0;
-
- /* we'll modify the argument, so we must copy */
- if ((b = a = list = strdup(dirs)) == NULL)
- return (0);
-
- for (;;) {
- int c = *a;
- if (c == 0 || c == NCURSES_PATHSEP) {
- *a = 0;
- if ((b + 1) >= a)
- b = TERMINFO;
- if (_nc_read_tic_entry(filename, b, ttn, tp) == 1) {
- code = 1;
- break;
+ if (need <= limit) {
+ (void) sprintf(filename, "%s/%c/%s", path, *name, name);
+ result = _nc_read_file_entry(filename, tp);
+ }
+ }
+#if USE_HASHED_DB
+ else {
+ static const char suffix[] = DBM_SUFFIX;
+ DB *capdbp;
+ unsigned lens = sizeof(suffix) - 1;
+ unsigned size = strlen(path);
+ unsigned need = lens + size;
+
+ if (need <= limit) {
+ if (size >= lens
+ && !strcmp(path + size - lens, suffix))
+ (void) strcpy(filename, path);
+ else
+ (void) sprintf(filename, "%s%s", path, suffix);
+
+ /*
+ * It would be nice to optimize the dbopen/close activity, as
+ * done in the cgetent implementation for tc= clauses. However,
+ * since we support multiple database locations, we cannot do
+ * that.
+ */
+ if ((capdbp = _nc_db_open(filename, FALSE)) != 0) {
+ DBT key, data;
+ int reccnt = 0;
+ char *save = strdup(name);
+
+ memset(&key, 0, sizeof(key));
+ key.data = save;
+ key.size = strlen(save);
+
+ /*
+ * This lookup could return termcap data, which we do not want.
+ * We are looking for compiled (binary) terminfo data.
+ *
+ * cgetent uses a two-level lookup. On the first it uses the
+ * given name to return a record containing only the aliases
+ * for an entry. On the second (using that list of aliases as
+ * a key), it returns the content of the terminal description.
+ * We expect second lookup to return data beginning with the
+ * same set of aliases.
+ *
+ * For compiled terminfo, the list of aliases in the second
+ * case will be null-terminated. A termcap entry will not be,
+ * and will run on into the description. So we can easily
+ * distinguish between the two (source/binary) by checking the
+ * lengths.
+ */
+ while (_nc_db_get(capdbp, &key, &data) == 0) {
+ int used = data.size - 1;
+ char *have = (char *) data.data;
+
+ if (*have++ == 0) {
+ if (data.size > key.size
+ && IS_TIC_MAGIC(have)) {
+ result = _nc_read_termtype(tp, have, used);
+ if (result == TGETENT_NO) {
+ _nc_free_termtype(tp);
+ }
+ }
+ break;
+ }
+
+ /*
+ * Just in case we have a corrupt database, do not waste
+ * time with it.
+ */
+ if (++reccnt >= 3)
+ break;
+
+ /*
+ * Prepare for the second level.
+ */
+ key.data = have;
+ key.size = used;
+ }
+
+ _nc_db_close(capdbp);
+ free(save);
}
- b = a + 1;
- if (c == 0)
- break;
}
- a++;
}
-
- free(list);
- return (code);
+#endif
+ return result;
}
+#endif /* USE_DATABASE */
/*
- * _nc_read_entry(char *tn, char *filename, TERMTYPE *tp)
+ * _nc_read_entry(char *name, char *filename, TERMTYPE *tp)
*
* Find and read the compiled entry for a given terminal type,
* if it exists. We take pains here to make sure no combination
@@ -458,46 +509,36 @@ _nc_read_terminfo_dirs(const char *dirs, char *const filename, const char *const
*/
NCURSES_EXPORT(int)
-_nc_read_entry
-(const char *const tn, char *const filename, TERMTYPE * const tp)
+_nc_read_entry(const char *const name, char *const filename, TERMTYPE *const tp)
{
- char *envp;
- char ttn[MAX_ALIAS + 3];
-
- /* truncate the terminal name to prevent dangerous buffer airline */
- (void) sprintf(ttn, "%c/%.*s", *tn, MAX_ALIAS, tn);
-
- /* This is System V behavior, in conjunction with our requirements for
- * writing terminfo entries.
- */
- if (have_tic_directory
- && _nc_read_tic_entry(filename, _nc_tic_dir(0), ttn, tp) == 1)
- return 1;
-
- if (use_terminfo_vars()) {
- if ((envp = getenv("TERMINFO")) != 0
- && _nc_read_tic_entry(filename, _nc_tic_dir(envp), ttn, tp) == 1)
- return 1;
-
- /* this is an ncurses extension */
- if ((envp = _nc_home_terminfo()) != 0) {
- if (_nc_read_tic_entry(filename, envp, ttn, tp) == 1) {
- return (1);
+ int code = TGETENT_NO;
+
+ if (strlen(name) == 0
+ || strcmp(name, ".") == 0
+ || strcmp(name, "..") == 0
+ || _nc_pathlast(name) != 0
+ || strchr(name, NCURSES_PATHSEP) != 0) {
+ T(("illegal or missing entry name '%s'", name));
+ } else {
+#if USE_DATABASE
+ DBDIRS state = dbdTIC;
+ int offset = 0;
+ const char *path;
+
+ while ((path = _nc_next_db(&state, &offset)) != 0) {
+ code = _nc_read_tic_entry(filename, PATH_MAX, path, name, tp);
+ if (code == TGETENT_YES) {
+ _nc_last_db();
+ break;
}
}
-
- /* this is an ncurses extension */
- if ((envp = getenv("TERMINFO_DIRS")) != 0)
- return _nc_read_terminfo_dirs(envp, filename, ttn, tp);
- }
-
- /* Try the system directory. Note that the TERMINFO_DIRS value, if
- * defined by the configure script, begins with a ":", which will be
- * interpreted as TERMINFO.
- */
-#ifdef TERMINFO_DIRS
- return _nc_read_terminfo_dirs(TERMINFO_DIRS, filename, ttn, tp);
-#else
- return _nc_read_tic_entry(filename, TERMINFO, ttn, tp);
#endif
+#if USE_TERMCAP
+ if (code != TGETENT_YES) {
+ code = _nc_read_termcap_entry(name, tp);
+ sprintf(filename, "%.*s", PATH_MAX - 1, _nc_get_source());
+ }
+#endif
+ }
+ return code;
}
diff --git a/contrib/ncurses/ncurses/tinfo/read_termcap.c b/contrib/ncurses/ncurses/tinfo/read_termcap.c
index c6e7e358ad91..d94d1a42466d 100644
--- a/contrib/ncurses/ncurses/tinfo/read_termcap.c
+++ b/contrib/ncurses/ncurses/tinfo/read_termcap.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,6 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
****************************************************************************/
/*
@@ -57,27 +58,20 @@
#include <tic.h>
#include <term_entry.h>
-MODULE_ID("$Id: read_termcap.c,v 1.58 2001/10/28 01:11:34 tom Exp $")
+MODULE_ID("$Id: read_termcap.c,v 1.71 2006/07/29 12:06:51 tom Exp $")
#if !PURE_TERMINFO
-#ifdef __EMX__
-#define is_pathname(s) ((((s) != 0) && ((s)[0] == '/')) \
- || (((s)[0] != 0) && ((s)[1] == ':')))
-#else
-#define is_pathname(s) ((s) != 0 && (s)[0] == '/')
-#endif
-
#define TC_SUCCESS 0
-#define TC_UNRESOLVED -1
-#define TC_NOT_FOUND -2
-#define TC_SYS_ERR -3
-#define TC_REF_LOOP -4
+#define TC_NOT_FOUND -1
+#define TC_SYS_ERR -2
+#define TC_REF_LOOP -3
+#define TC_UNRESOLVED -4 /* this is not returned by BSD cgetent */
-static char *
+static NCURSES_CONST char *
get_termpath(void)
{
- char *result;
+ NCURSES_CONST char *result;
if (!use_terminfo_vars() || (result = getenv("TERMPATH")) == 0)
result = TERMPATH;
@@ -231,10 +225,10 @@ _nc_cgetcap(char *buf, const char *cap, int type)
* Returns:
*
* positive # on success (i.e., the index in db_array)
- * TC_UNRESOLVED if we had too many recurrences to resolve
* TC_NOT_FOUND if the requested record couldn't be found
* TC_SYS_ERR if a system error was encountered (e.g.,couldn't open a file)
* TC_REF_LOOP if a potential reference loop is detected
+ * TC_UNRESOLVED if we had too many recurrences to resolve
*/
static int
_nc_cgetent(char **buf, int *oline, char **db_array, const char *name)
@@ -720,7 +714,7 @@ get_tc_token(char **srcp, int *endp)
if (*s == '\0') {
break;
} else if (*s++ == '\n') {
- while (isspace(*s))
+ while (isspace(UChar(*s)))
s++;
} else {
found = TRUE;
@@ -734,7 +728,7 @@ get_tc_token(char **srcp, int *endp)
break;
}
base = s;
- } else if (isgraph(ch)) {
+ } else if (isgraph(UChar(ch))) {
found = TRUE;
}
}
@@ -754,7 +748,7 @@ copy_tc_token(char *dst, const char *src, size_t len)
while ((ch = *src++) != '\0') {
if (ch == '\\' && *src == '\n') {
- while (isspace(*src))
+ while (isspace(UChar(*src)))
src++;
continue;
}
@@ -784,7 +778,7 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name)
char pathbuf[PBUFSIZ]; /* holds raw path of filenames */
char *pathvec[PVECSIZ]; /* to point to names in pathbuf */
char **pvec; /* holds usable tail of path vector */
- char *termpath;
+ NCURSES_CONST char *termpath;
string_desc desc;
fname = pathvec;
@@ -805,7 +799,7 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name)
_nc_str_init(&desc, pathbuf, sizeof(pathbuf));
if (cp == NULL) {
_nc_safe_strcpy(&desc, get_termpath());
- } else if (!is_pathname(cp)) { /* TERMCAP holds an entry */
+ } else if (!_nc_is_abs_path(cp)) { /* TERMCAP holds an entry */
if ((termpath = get_termpath()) != 0) {
_nc_safe_strcat(&desc, termpath);
} else {
@@ -843,7 +837,7 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name)
}
}
*fname = 0; /* mark end of vector */
- if (is_pathname(cp)) {
+ if (_nc_is_abs_path(cp)) {
if (_nc_cgetset(cp) < 0) {
return (TC_SYS_ERR);
}
@@ -896,8 +890,21 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name)
* cgetent, then it is the actual filename).
*/
if (i >= 0) {
+#if HAVE_BSD_CGETENT
+ char temp[PATH_MAX];
+
+ _nc_str_init(&desc, temp, sizeof(temp));
+ _nc_safe_strcpy(&desc, pathvec[i]);
+ _nc_safe_strcat(&desc, ".db");
+ if (_nc_access(temp, R_OK) == 0) {
+ _nc_safe_strcpy(&desc, pathvec[i]);
+ }
+ if ((the_source = strdup(temp)) != 0)
+ *sourcename = the_source;
+#else
if ((the_source = strdup(pathvec[i])) != 0)
*sourcename = the_source;
+#endif
}
return (i);
@@ -932,29 +939,39 @@ add_tc(char *termpaths[], char *path, int count)
#endif /* !USE_GETCAP */
NCURSES_EXPORT(int)
-_nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp)
+_nc_read_termcap_entry(const char *const tn, TERMTYPE *const tp)
{
- int found = FALSE;
+ int found = TGETENT_NO;
ENTRY *ep;
#if USE_GETCAP_CACHE
char cwd_buf[PATH_MAX];
#endif
#if USE_GETCAP
char *p, tc[TBUFSIZ];
+ int status;
static char *source;
static int lineno;
T(("read termcap entry for %s", tn));
+
+ if (strlen(tn) == 0
+ || strcmp(tn, ".") == 0
+ || strcmp(tn, "..") == 0
+ || _nc_pathlast(tn) != 0) {
+ T(("illegal or missing entry name '%s'", tn));
+ return TGETENT_NO;
+ }
+
if (use_terminfo_vars() && (p = getenv("TERMCAP")) != 0
- && !is_pathname(p) && _nc_name_match(p, tn, "|:")) {
+ && !_nc_is_abs_path(p) && _nc_name_match(p, tn, "|:")) {
/* TERMCAP holds a termcap entry */
strncpy(tc, p, sizeof(tc) - 1);
tc[sizeof(tc) - 1] = '\0';
_nc_set_source("TERMCAP");
} else {
/* we're using getcap(3) */
- if (_nc_tgetent(tc, &source, &lineno, tn) < 0)
- return (ERR);
+ if ((status = _nc_tgetent(tc, &source, &lineno, tn)) < 0)
+ return (status == TC_NOT_FOUND ? TGETENT_NO : TGETENT_ERR);
_nc_curr_line = lineno;
_nc_set_source(source);
@@ -1001,7 +1018,7 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp)
termpaths[filecount] = 0;
if (use_terminfo_vars() && (tc = getenv("TERMCAP")) != 0) {
- if (is_pathname(tc)) { /* interpret as a filename */
+ if (_nc_is_abs_path(tc)) { /* interpret as a filename */
ADD_TC(tc, 0);
normal = FALSE;
} else if (_nc_name_match(tc, tn, "|:")) { /* treat as a capability file */
@@ -1038,7 +1055,7 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp)
* Probably /etc/termcap is a symlink to /usr/share/misc/termcap.
* Avoid reading the same file twice.
*/
-#ifdef HAVE_LINK
+#if HAVE_LINK
for (j = 0; j < filecount; j++) {
bool omit = FALSE;
if (stat(termpaths[j], &test_stat[j]) != 0
@@ -1100,10 +1117,10 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp)
#endif /* USE_GETCAP */
if (_nc_head == 0)
- return (ERR);
+ return (TGETENT_ERR);
/* resolve all use references */
- _nc_resolve_uses(TRUE);
+ _nc_resolve_uses2(TRUE, FALSE);
/* find a terminal matching tn, if we can */
#if USE_GETCAP_CACHE
@@ -1113,13 +1130,12 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp)
for_entry_list(ep) {
if (_nc_name_match(ep->tterm.term_names, tn, "|:")) {
/*
- * Make a local copy of the terminal capabilities. Free all
- * entry storage except the string table for the loaded type
- * (which we disconnected from the list by NULLing out
- * ep->tterm.str_table above).
+ * Make a local copy of the terminal capabilities, delinked
+ * from the list.
*/
*tp = ep->tterm;
- ep->tterm.str_table = (char *) 0;
+ _nc_delink_entry(_nc_head, &(ep->tterm));
+ free(ep);
/*
* OK, now try to write the type to user's terminfo directory.
@@ -1136,7 +1152,7 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp)
#if USE_GETCAP_CACHE
(void) _nc_write_entry(tp);
#endif
- found = TRUE;
+ found = TGETENT_YES;
break;
}
}
@@ -1145,7 +1161,6 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp)
}
#endif
- _nc_free_entries(_nc_head);
return (found);
}
#else
diff --git a/contrib/ncurses/ncurses/tinfo/setbuf.c b/contrib/ncurses/ncurses/tinfo/setbuf.c
index 6d0201bfb2aa..94bb6d3463c5 100644
--- a/contrib/ncurses/ncurses/tinfo/setbuf.c
+++ b/contrib/ncurses/ncurses/tinfo/setbuf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2000,2003 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -40,7 +40,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: setbuf.c,v 1.7 2000/12/10 02:55:08 tom Exp $")
+MODULE_ID("$Id: setbuf.c,v 1.12 2003/11/15 23:55:34 tom Exp $")
/*
* If the output file descriptor is connected to a tty (the typical case) it
@@ -98,47 +98,53 @@ MODULE_ID("$Id: setbuf.c,v 1.7 2000/12/10 02:55:08 tom Exp $")
* buffer. So we disable this by default (there may yet be a workaround).
*/
NCURSES_EXPORT(void)
-_nc_set_buffer(FILE * ofp, bool buffered)
+_nc_set_buffer(FILE *ofp, bool buffered)
{
/* optional optimization hack -- do before any output to ofp */
#if HAVE_SETVBUF || HAVE_SETBUFFER
- unsigned buf_len;
- char *buf_ptr;
+ if (SP->_buffered != (int)buffered) {
+ unsigned buf_len;
+ char *buf_ptr;
- if (getenv("NCURSES_NO_SETBUF") != 0)
- return;
+ if (getenv("NCURSES_NO_SETBUF") != 0)
+ return;
- fflush(ofp);
- if ((SP->_buffered = buffered) != 0) {
- buf_len = min(LINES * (COLS + 6), 2800);
- if ((buf_ptr = SP->_setbuf) == 0) {
- if ((buf_ptr = typeMalloc(char, buf_len)) == NULL)
- return;
- SP->_setbuf = buf_ptr;
- /* Don't try to free this! */
- }
+ fflush(ofp);
+#ifdef __DJGPP__
+ setmode(ofp, O_BINARY);
+#endif
+ if (buffered != 0) {
+ buf_len = min(LINES * (COLS + 6), 2800);
+ if ((buf_ptr = SP->_setbuf) == 0) {
+ if ((buf_ptr = typeMalloc(char, buf_len)) == NULL)
+ return;
+ SP->_setbuf = buf_ptr;
+ /* Don't try to free this! */
+ }
#if !USE_SETBUF_0
- else
- return;
+ else
+ return;
#endif
- } else {
+ } else {
#if !USE_SETBUF_0
- return;
+ return;
#else
- buf_len = 0;
- buf_ptr = 0;
+ buf_len = 0;
+ buf_ptr = 0;
#endif
- }
+ }
#if HAVE_SETVBUF
#ifdef SETVBUF_REVERSED /* pre-svr3? */
- (void) setvbuf(ofp, buf_ptr, buf_len, buf_len ? _IOFBF : _IOLBF);
+ (void) setvbuf(ofp, buf_ptr, buf_len, buf_len ? _IOFBF : _IOLBF);
#else
- (void) setvbuf(ofp, buf_ptr, buf_len ? _IOFBF : _IOLBF, buf_len);
+ (void) setvbuf(ofp, buf_ptr, buf_len ? _IOFBF : _IOLBF, buf_len);
#endif
#elif HAVE_SETBUFFER
- (void) setbuffer(ofp, buf_ptr, (int) buf_len);
+ (void) setbuffer(ofp, buf_ptr, (int) buf_len);
#endif
+ SP->_buffered = buffered;
+ }
#endif /* HAVE_SETVBUF || HAVE_SETBUFFER */
}
diff --git a/contrib/ncurses/ncurses/tinfo/strings.c b/contrib/ncurses/ncurses/tinfo/strings.c
index 5fa68caf7534..d5377fe07a51 100644
--- a/contrib/ncurses/ncurses/tinfo/strings.c
+++ b/contrib/ncurses/ncurses/tinfo/strings.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2000 Free Software Foundation, Inc. *
+ * Copyright (c) 2000,2003 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -36,7 +36,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: strings.c,v 1.3 2000/12/10 02:55:08 tom Exp $")
+MODULE_ID("$Id: strings.c,v 1.5 2003/08/16 23:46:00 tom Exp $")
/****************************************************************************
* Useful string functions (especially for mvcur)
@@ -44,8 +44,7 @@ MODULE_ID("$Id: strings.c,v 1.3 2000/12/10 02:55:08 tom Exp $")
#if !HAVE_STRSTR
NCURSES_EXPORT(char *)
-_nc_strstr
-(const char *haystack, const char *needle)
+_nc_strstr(const char *haystack, const char *needle)
{
size_t len1 = strlen(haystack);
size_t len2 = strlen(needle);
@@ -63,16 +62,18 @@ _nc_strstr
#endif
/*
- * Initialize the descriptor so we can append to it.
+ * Initialize the descriptor so we can append to it. Note that 'src' may
+ * be a null pointer (see _nc_str_null), so the corresponding strcat and
+ * strcpy calls have to allow for this.
*/
NCURSES_EXPORT(string_desc *)
-_nc_str_init
-(string_desc * dst, char *src, size_t len)
+_nc_str_init(string_desc * dst, char *src, size_t len)
{
if (dst != 0) {
dst->s_head = src;
dst->s_tail = src;
dst->s_size = len - 1;
+ dst->s_init = dst->s_size;
if (src != 0)
*src = 0;
}
@@ -83,8 +84,7 @@ _nc_str_init
* Initialize the descriptor for only tracking the amount of memory used.
*/
NCURSES_EXPORT(string_desc *)
-_nc_str_null
-(string_desc * dst, size_t len)
+_nc_str_null(string_desc * dst, size_t len)
{
return _nc_str_init(dst, 0, len);
}
@@ -93,8 +93,7 @@ _nc_str_null
* Copy a descriptor
*/
NCURSES_EXPORT(string_desc *)
-_nc_str_copy
-(string_desc * dst, string_desc * src)
+_nc_str_copy(string_desc * dst, string_desc * src)
{
*dst = *src;
return dst;
@@ -135,7 +134,7 @@ _nc_safe_strcpy(string_desc * dst, const char *src)
strcpy(dst->s_head, src);
dst->s_tail = dst->s_head + len;
}
- dst->s_size -= len;
+ dst->s_size = dst->s_init - len;
return TRUE;
}
}
diff --git a/contrib/ncurses/ncurses/tinfo/trim_sgr0.c b/contrib/ncurses/ncurses/tinfo/trim_sgr0.c
new file mode 100644
index 000000000000..3ce18e070b06
--- /dev/null
+++ b/contrib/ncurses/ncurses/tinfo/trim_sgr0.c
@@ -0,0 +1,328 @@
+/****************************************************************************
+ * Copyright (c) 2005 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas Dickey *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+#include <ctype.h>
+
+#include <tic.h>
+#include <term_entry.h>
+
+MODULE_ID("$Id: trim_sgr0.c,v 1.7 2006/12/02 19:37:57 tom Exp $")
+
+#undef CUR
+#define CUR tp->
+
+#define CSI 233
+#define ESC 033 /* ^[ */
+#define L_BRACK '['
+
+static char *
+set_attribute_9(TERMTYPE *tp, int flag)
+{
+ const char *result;
+
+ if ((result = tparm(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, flag)) == 0)
+ result = "";
+ return strdup(result);
+}
+
+static int
+is_csi(const char *s)
+{
+ if (UChar(s[0]) == CSI)
+ return 1;
+ else if (s[0] == ESC && s[1] == L_BRACK)
+ return 2;
+ return 0;
+}
+
+static char *
+skip_zero(char *s)
+{
+ if (s[0] == '0') {
+ if (s[1] == ';')
+ s += 2;
+ else if (isalpha(UChar(s[1])))
+ s += 1;
+ }
+ return s;
+}
+
+static const char *
+skip_delay(const char *s)
+{
+ if (s[0] == '$' && s[1] == '<') {
+ s += 2;
+ while (isdigit(UChar(*s)) || *s == '/')
+ ++s;
+ if (*s == '>')
+ ++s;
+ }
+ return s;
+}
+
+/*
+ * Improve similar_sgr a little by moving the attr-string from the beginning
+ * to the end of the s-string.
+ */
+static bool
+rewrite_sgr(char *s, char *attr)
+{
+ if (PRESENT(s)) {
+ if (PRESENT(attr)) {
+ unsigned len_s = strlen(s);
+ unsigned len_a = strlen(attr);
+
+ if (len_s > len_a && !strncmp(attr, s, len_a)) {
+ unsigned n;
+ TR(TRACE_DATABASE, ("rewrite:\n\t%s", s));
+ for (n = 0; n < len_s - len_a; ++n) {
+ s[n] = s[n + len_a];
+ }
+ strcpy(s + n, attr);
+ TR(TRACE_DATABASE, ("to:\n\t%s", s));
+ }
+ }
+ return TRUE;
+ }
+ return FALSE; /* oops */
+}
+
+static bool
+similar_sgr(char *a, char *b)
+{
+ bool result = FALSE;
+ int csi_a = is_csi(a);
+ int csi_b = is_csi(b);
+ unsigned len_a;
+ unsigned len_b;
+
+ TR(TRACE_DATABASE, ("similar_sgr:\n\t%s\n\t%s",
+ _nc_visbuf2(1, a),
+ _nc_visbuf2(2, b)));
+ if (csi_a != 0 && csi_b != 0 && csi_a == csi_b) {
+ a += csi_a;
+ b += csi_b;
+ if (*a != *b) {
+ a = skip_zero(a);
+ b = skip_zero(b);
+ }
+ }
+ len_a = strlen(a);
+ len_b = strlen(b);
+ if (len_a && len_b) {
+ if (len_a > len_b)
+ result = (strncmp(a, b, len_b) == 0);
+ else
+ result = (strncmp(a, b, len_a) == 0);
+ }
+ TR(TRACE_DATABASE, ("...similar_sgr: %d\n\t%s\n\t%s", result,
+ _nc_visbuf2(1, a),
+ _nc_visbuf2(2, b)));
+ return result;
+}
+
+static unsigned
+chop_out(char *string, unsigned i, unsigned j)
+{
+ TR(TRACE_DATABASE, ("chop_out %d..%d from %s", i, j, _nc_visbuf(string)));
+ while (string[j] != '\0') {
+ string[i++] = string[j++];
+ }
+ string[i] = '\0';
+ return i;
+}
+
+/*
+ * Compare, ignoring delays. Some of the delay values are inconsistent, and
+ * we do not want to be stopped by that.
+ *
+ * Returns the number of chars from 'full' that we matched. If any mismatch
+ * occurs, return zero.
+ */
+static int
+compare_part(const char *part, const char *full)
+{
+ const char *next_part;
+ const char *next_full;
+ int used_full = 0;
+ int used_delay = 0;
+
+ while (*part != 0) {
+ if (*part != *full) {
+ used_full = 0;
+ break;
+ }
+
+ /*
+ * Adjust the return-value to allow the rare case of
+ * string<delay>string
+ * to remove the whole piece. The most common case is a delay at the
+ * end of the string. The adjusted string will retain the delay, which
+ * is conservative.
+ */
+ if (used_delay != 0) {
+ used_full += used_delay;
+ used_delay = 0;
+ }
+ if (*part == '$' && *full == '$') {
+ next_part = skip_delay(part);
+ next_full = skip_delay(full);
+ if (next_part != part && next_full != full) {
+ used_delay += (next_full - full);
+ full = next_full;
+ part = next_part;
+ continue;
+ }
+ }
+ ++used_full;
+ ++part;
+ ++full;
+ }
+ return used_full;
+}
+
+/*
+ * While 'sgr0' is the "same" as termcap 'me', there is a compatibility issue.
+ * The sgr/sgr0 capabilities include setting/clearing alternate character set
+ * mode. A termcap application cannot use sgr, so sgr0 strings that reset
+ * alternate character set mode will be misinterpreted. Here, we remove those
+ * from the more common ISO/ANSI/VT100 entries, which have sgr0 agreeing with
+ * sgr.
+ *
+ * This function returns the modified sgr0 if it can be modified, a null if
+ * an error occurs, or the original sgr0 if no change is needed.
+ */
+NCURSES_EXPORT(char *)
+_nc_trim_sgr0(TERMTYPE *tp)
+{
+ char *result = exit_attribute_mode;
+
+ T((T_CALLED("_nc_trim_sgr0()")));
+
+ if (PRESENT(exit_attribute_mode)
+ && PRESENT(set_attributes)) {
+ bool found = FALSE;
+ char *on = set_attribute_9(tp, 1);
+ char *off = set_attribute_9(tp, 0);
+ char *end = strdup(exit_attribute_mode);
+ char *tmp;
+ size_t i, j, k;
+
+ TR(TRACE_DATABASE, ("checking if we can trim sgr0 based on sgr"));
+ TR(TRACE_DATABASE, ("sgr0 %s", _nc_visbuf(end)));
+ TR(TRACE_DATABASE, ("sgr(9:off) %s", _nc_visbuf(off)));
+ TR(TRACE_DATABASE, ("sgr(9:on) %s", _nc_visbuf(on)));
+
+ if (!rewrite_sgr(on, enter_alt_charset_mode)
+ || !rewrite_sgr(off, exit_alt_charset_mode)
+ || !rewrite_sgr(end, exit_alt_charset_mode)) {
+ FreeIfNeeded(on);
+ FreeIfNeeded(off);
+ FreeIfNeeded(end);
+ } else if (similar_sgr(off, end)
+ && !similar_sgr(off, on)) {
+ TR(TRACE_DATABASE, ("adjusting sgr(9:off) : %s", _nc_visbuf(off)));
+ result = off;
+ /*
+ * If rmacs is a substring of sgr(0), remove that chunk.
+ */
+ if (exit_alt_charset_mode != 0) {
+ TR(TRACE_DATABASE, ("scan for rmacs %s", _nc_visbuf(exit_alt_charset_mode)));
+ j = strlen(off);
+ k = strlen(exit_alt_charset_mode);
+ if (j > k) {
+ for (i = 0; i <= (j - k); ++i) {
+ int k2 = compare_part(exit_alt_charset_mode, off + i);
+ if (k2 != 0) {
+ found = TRUE;
+ chop_out(off, i, i + k2);
+ break;
+ }
+ }
+ }
+ }
+ /*
+ * SGR 10 would reset to normal font.
+ */
+ if (!found) {
+ if ((i = is_csi(off)) != 0
+ && off[strlen(off) - 1] == 'm') {
+ TR(TRACE_DATABASE, ("looking for SGR 10 in %s",
+ _nc_visbuf(off)));
+ tmp = skip_zero(off + i);
+ if (tmp[0] == '1'
+ && skip_zero(tmp + 1) != tmp + 1) {
+ i = tmp - off;
+ if (off[i - 1] == ';')
+ i--;
+ j = skip_zero(tmp + 1) - off;
+ i = chop_out(off, i, j);
+ found = TRUE;
+ }
+ }
+ }
+ if (!found
+ && (tmp = strstr(end, off)) != 0
+ && strcmp(end, off) != 0) {
+ i = tmp - end;
+ j = strlen(off);
+ tmp = strdup(end);
+ chop_out(tmp, i, j);
+ free(off);
+ result = tmp;
+ }
+ TR(TRACE_DATABASE, ("...adjusted sgr0 : %s", _nc_visbuf(result)));
+ if (!strcmp(result, exit_attribute_mode)) {
+ TR(TRACE_DATABASE, ("...same result, discard"));
+ free(result);
+ result = exit_attribute_mode;
+ }
+ } else {
+ /*
+ * Either the sgr does not reference alternate character set,
+ * or it is incorrect. That's too hard to decide right now.
+ */
+ free(off);
+ }
+ free(end);
+ free(on);
+ } else {
+ /*
+ * Possibly some applications are confused if sgr0 contains rmacs,
+ * but that would be a different bug report -TD
+ */
+ }
+
+ returnPtr(result);
+}
diff --git a/contrib/ncurses/ncurses/tinfo/write_entry.c b/contrib/ncurses/ncurses/tinfo/write_entry.c
index 9750dffd5ffe..5426f1fc40d0 100644
--- a/contrib/ncurses/ncurses/tinfo/write_entry.c
+++ b/contrib/ncurses/ncurses/tinfo/write_entry.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2000,2002 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2002,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -29,6 +29,7 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
****************************************************************************/
/*
@@ -36,6 +37,7 @@
*/
#include <curses.priv.h>
+#include <hashed_db.h>
#include <sys/stat.h>
@@ -46,21 +48,27 @@
#define S_ISDIR(mode) ((mode & S_IFMT) == S_IFDIR)
#endif
-#if 0
+#if 1
#define TRACE_OUT(p) DEBUG(2, p)
#else
#define TRACE_OUT(p) /*nothing */
#endif
-MODULE_ID("$Id: write_entry.c,v 1.58 2002/04/21 20:35:08 tom Exp $")
+MODULE_ID("$Id: write_entry.c,v 1.68 2006/10/14 20:45:16 tom Exp $")
static int total_written;
-static int write_object(FILE *, TERMTYPE *);
+static int make_db_root(const char *);
+static int write_object(TERMTYPE *, char *, unsigned *, unsigned);
+#if !USE_HASHED_DB
static void
-write_file(char *filename, TERMTYPE * tp)
+write_file(char *filename, TERMTYPE *tp)
{
+ char buffer[MAX_ENTRY_SIZE];
+ unsigned limit = sizeof(buffer);
+ unsigned offset = 0;
+
FILE *fp = (_nc_access(filename, W_OK) == 0) ? fopen(filename, "wb") : 0;
if (fp == 0) {
perror(filename);
@@ -68,50 +76,118 @@ write_file(char *filename, TERMTYPE * tp)
}
DEBUG(1, ("Created %s", filename));
- if (write_object(fp, tp) == ERR) {
+ if (write_object(tp, buffer, &offset, limit) == ERR
+ || fwrite(buffer, sizeof(char), offset, fp) != offset) {
_nc_syserr_abort("error writing %s/%s", _nc_tic_dir(0), filename);
}
+
fclose(fp);
}
/*
- * make_directory(char *path)
+ * Check for access rights to destination directories
+ * Create any directories which don't exist.
*
- * Make a directory if it doesn't exist.
+ * Note: there's no reason to return the result of make_db_root(), since
+ * this function is called only in instances where that has to succeed.
*/
+static void
+check_writeable(int code)
+{
+ static const char dirnames[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ static bool verified[sizeof(dirnames)];
+
+ char dir[2];
+ char *s = 0;
+
+ if (code == 0 || (s = strchr(dirnames, code)) == 0)
+ _nc_err_abort("Illegal terminfo subdirectory \"%c\"", code);
+
+ if (verified[s - dirnames])
+ return;
+
+ dir[0] = code;
+ dir[1] = '\0';
+ if (make_db_root(dir) < 0) {
+ _nc_err_abort("%s/%s: permission denied", _nc_tic_dir(0), dir);
+ }
+
+ verified[s - dirnames] = TRUE;
+}
+#endif /* !USE_HASHED_DB */
+
static int
-make_directory(const char *path)
+make_db_path(char *dst, const char *src, unsigned limit)
{
- int rc;
- struct stat statbuf;
- char fullpath[PATH_MAX];
- const char *destination = _nc_tic_dir(0);
+ int rc = -1;
+ const char *top = _nc_tic_dir(0);
- if (path == destination || *path == '/') {
- if (strlen(path) + 1 > sizeof(fullpath))
- return (-1);
- (void) strcpy(fullpath, path);
+ if (src == top || _nc_is_abs_path(src)) {
+ if (strlen(src) + 1 <= limit) {
+ (void) strcpy(dst, src);
+ rc = 0;
+ }
} else {
- if (strlen(destination) + strlen(path) + 2 > sizeof(fullpath))
- return (-1);
- (void) sprintf(fullpath, "%s/%s", destination, path);
+ if (strlen(top) + strlen(src) + 2 <= limit) {
+ (void) sprintf(dst, "%s/%s", top, src);
+ rc = 0;
+ }
}
+#if USE_HASHED_DB
+ if (rc == 0) {
+ if (_nc_is_dir_path(dst)) {
+ rc = -1;
+ } else {
+ unsigned have = strlen(dst);
+ if (have > 3 && strcmp(dst + have - 3, DBM_SUFFIX)) {
+ if (have + 3 <= limit)
+ strcat(dst, DBM_SUFFIX);
+ else
+ rc = -1;
+ }
+ }
+ }
+#endif
+ return rc;
+}
- if ((rc = stat(path, &statbuf)) < 0) {
- rc = mkdir(path, 0777);
- } else {
- if (_nc_access(path, R_OK | W_OK | X_OK) < 0) {
+/*
+ * Make a database-root if it doesn't exist.
+ */
+static int
+make_db_root(const char *path)
+{
+ int rc;
+ char fullpath[PATH_MAX];
+
+ if ((rc = make_db_path(fullpath, path, sizeof(fullpath))) == 0) {
+#if USE_HASHED_DB
+ DB *capdbp;
+
+ if ((capdbp = _nc_db_open(fullpath, TRUE)) == NULL)
+ rc = -1;
+ else if (_nc_db_close(capdbp) < 0)
+ rc = -1;
+#else
+ struct stat statbuf;
+
+ if ((rc = stat(path, &statbuf)) < 0) {
+ rc = mkdir(path, 0777);
+ } else if (_nc_access(path, R_OK | W_OK | X_OK) < 0) {
rc = -1; /* permission denied */
} else if (!(S_ISDIR(statbuf.st_mode))) {
rc = -1; /* not a directory */
}
+#endif
}
return rc;
}
+/*
+ * Set the write directory for compiled entries.
+ */
NCURSES_EXPORT(void)
_nc_set_writedir(char *dir)
-/* set the write directory for compiled entries */
{
const char *destination;
char actual[PATH_MAX];
@@ -124,12 +200,12 @@ _nc_set_writedir(char *dir)
(void) _nc_tic_dir(dir);
destination = _nc_tic_dir(0);
- if (make_directory(destination) < 0) {
+ if (make_db_root(destination) < 0) {
char *home = _nc_home_terminfo();
if (home != 0) {
destination = home;
- if (make_directory(destination) < 0)
+ if (make_db_root(destination) < 0)
_nc_err_abort("%s: permission denied (errno %d)",
destination, errno);
}
@@ -139,51 +215,17 @@ _nc_set_writedir(char *dir)
* Note: because of this code, this logic should be exercised
* *once only* per run.
*/
+#if USE_HASHED_DB
+ make_db_path(actual, destination, sizeof(actual));
+#else
if (chdir(_nc_tic_dir(destination)) < 0
|| getcwd(actual, sizeof(actual)) == 0)
_nc_err_abort("%s: not a directory", destination);
+#endif
_nc_keep_tic_dir(strdup(actual));
}
/*
- * check_writeable(char code)
- *
- * Miscellaneous initialisations
- *
- * Check for access rights to destination directories
- * Create any directories which don't exist.
- * Note: there's no reason to return the result of make_directory(), since
- * this function is called only in instances where that has to succeed.
- *
- */
-
-static void
-check_writeable(int code)
-{
- static const char dirnames[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- static bool verified[sizeof(dirnames)];
-
- char dir[2];
- char *s = 0;
-
- if (code == 0 || (s = strchr(dirnames, code)) == 0)
- _nc_err_abort("Illegal terminfo subdirectory \"%c\"", code);
-
- if (verified[s - dirnames])
- return;
-
- dir[0] = code;
- dir[1] = '\0';
- if (make_directory(dir) < 0) {
- _nc_err_abort("%s/%s: permission denied", _nc_tic_dir(0), dir);
- }
-
- verified[s - dirnames] = TRUE;
-}
-
-/*
- * _nc_write_entry()
- *
* Save the compiled version of a description in the filesystem.
*
* make a copy of the name-list
@@ -203,13 +245,18 @@ check_writeable(int code)
* _nc_curr_line is properly set before the write_entry() call.
*/
-void
-_nc_write_entry(TERMTYPE * const tp)
+NCURSES_EXPORT(void)
+_nc_write_entry(TERMTYPE *const tp)
{
+#if USE_HASHED_DB
+
+ char buffer[MAX_ENTRY_SIZE + 1];
+ unsigned limit = sizeof(buffer);
+ unsigned offset = 0;
+
+#else /* !USE_HASHED_DB */
+
struct stat statbuf;
- char name_list[MAX_TERMINFO_LENGTH];
- char *first_name, *other_names;
- char *ptr;
char filename[PATH_MAX];
char linkname[PATH_MAX];
#if USE_SYMLINKS
@@ -219,12 +266,15 @@ _nc_write_entry(TERMTYPE * const tp)
#define HAVE_LINK 1
#endif
#endif /* USE_SYMLINKS */
+
static int call_count;
static time_t start_time; /* time at start of writes */
- if (call_count++ == 0) {
- start_time = 0;
- }
+#endif /* USE_HASHED_DB */
+
+ char name_list[MAX_TERMINFO_LENGTH];
+ char *first_name, *other_names;
+ char *ptr;
(void) strcpy(name_list, tp->term_names);
DEBUG(7, ("Name list = '%s'", name_list));
@@ -256,6 +306,55 @@ _nc_write_entry(TERMTYPE * const tp)
_nc_set_type(first_name);
+#if USE_HASHED_DB
+ if (write_object(tp, buffer + 1, &offset, limit - 1) != ERR) {
+ DB *capdb = _nc_db_open(_nc_tic_dir(0), TRUE);
+ DBT key, data;
+
+ if (capdb != 0) {
+ buffer[0] = 0;
+
+ memset(&key, 0, sizeof(key));
+ key.data = tp->term_names;
+ key.size = strlen(tp->term_names);
+
+ memset(&data, 0, sizeof(data));
+ data.data = buffer;
+ data.size = offset + 1;
+
+ _nc_db_put(capdb, &key, &data);
+
+ buffer[0] = 2;
+
+ key.data = name_list;
+ key.size = strlen(name_list);
+
+ strcpy(buffer + 1, tp->term_names);
+ data.size = strlen(tp->term_names) + 1;
+
+ _nc_db_put(capdb, &key, &data);
+
+ while (*other_names != '\0') {
+ ptr = other_names++;
+ while (*other_names != '|' && *other_names != '\0')
+ other_names++;
+
+ if (*other_names != '\0')
+ *(other_names++) = '\0';
+
+ key.data = ptr;
+ key.size = strlen(ptr);
+
+ _nc_db_put(capdb, &key, &data);
+ }
+ _nc_db_close(capdb);
+ }
+ }
+#else /* !USE_HASHED_DB */
+ if (call_count++ == 0) {
+ start_time = 0;
+ }
+
if (strlen(first_name) > sizeof(filename) - 3)
_nc_warning("terminal name too long.");
@@ -355,14 +454,39 @@ _nc_write_entry(TERMTYPE * const tp)
write_file(linkname, tp);
#endif /* HAVE_LINK */
}
+#endif /* USE_HASHED_DB */
}
+static unsigned
+fake_write(char *dst,
+ unsigned *offset,
+ unsigned limit,
+ char *src,
+ unsigned want,
+ unsigned size)
+{
+ int have = (limit - *offset);
+
+ want *= size;
+ if (have > 0) {
+ if ((int) want > have)
+ want = have;
+ memcpy(dst + *offset, src, want);
+ *offset += want;
+ } else {
+ want = 0;
+ }
+ return (int) (want / size);
+}
+
+#define Write(buf, size, count) fake_write(buffer, offset, limit, (char *) buf, count, size)
+
#undef LITTLE_ENDIAN /* BSD/OS defines this as a feature macro */
#define HI(x) ((x) / 256)
#define LO(x) ((x) % 256)
#define LITTLE_ENDIAN(p, x) (p)[0] = LO(x), (p)[1] = HI(x)
-#define WRITE_STRING(str) (fwrite(str, sizeof(char), strlen(str) + 1, fp) == strlen(str) + 1)
+#define WRITE_STRING(str) (Write(str, sizeof(char), strlen(str) + 1) == strlen(str) + 1)
static int
compute_offsets(char **Strings, unsigned strmax, short *offsets)
@@ -402,10 +526,68 @@ convert_shorts(unsigned char *buf, short *Numbers, unsigned count)
}
#define even_boundary(value) \
- ((value) % 2 != 0 && fwrite(&zero, sizeof(char), 1, fp) != 1)
+ ((value) % 2 != 0 && Write(&zero, sizeof(char), 1) != 1)
+
+#if NCURSES_XNAMES
+static unsigned
+extended_Booleans(TERMTYPE *tp)
+{
+ unsigned short result = 0;
+ unsigned short i;
+
+ for (i = 0; i < tp->ext_Booleans; ++i) {
+ if (tp->Booleans[BOOLCOUNT + i] == TRUE)
+ result = (i + 1);
+ }
+ return result;
+}
+
+static unsigned
+extended_Numbers(TERMTYPE *tp)
+{
+ unsigned short result = 0;
+ unsigned short i;
+
+ for (i = 0; i < tp->ext_Numbers; ++i) {
+ if (tp->Numbers[NUMCOUNT + i] != ABSENT_NUMERIC)
+ result = (i + 1);
+ }
+ return result;
+}
+
+static unsigned
+extended_Strings(TERMTYPE *tp)
+{
+ unsigned short result = 0;
+ unsigned short i;
+
+ for (i = 0; i < tp->ext_Strings; ++i) {
+ if (tp->Strings[STRCOUNT + i] != ABSENT_STRING)
+ result = (i + 1);
+ }
+ return result;
+}
+
+/*
+ * _nc_align_termtype() will extend entries that are referenced in a use=
+ * clause - discard the unneeded data.
+ */
+static bool
+extended_object(TERMTYPE *tp)
+{
+ bool result = FALSE;
+
+ if (_nc_user_definable) {
+ result = ((extended_Booleans(tp)
+ + extended_Numbers(tp)
+ + extended_Strings(tp)) != 0);
+ }
+ return result;
+}
+#endif
static int
-write_object(FILE * fp, TERMTYPE * tp)
+write_object(TERMTYPE *tp, char *buffer, unsigned *offset, unsigned limit)
{
char *namelist;
size_t namelen, boolmax, nummax, strmax;
@@ -464,9 +646,9 @@ write_object(FILE * fp, TERMTYPE * tp)
LITTLE_ENDIAN(buf + 10, nextfree);
/* write out the header */
- TRACE_OUT(("Header of %s @%ld", namelist, ftell(fp)));
- if (fwrite(buf, 12, 1, fp) != 1
- || fwrite(namelist, sizeof(char), namelen, fp) != namelen)
+ TRACE_OUT(("Header of %s @%d", namelist, *offset));
+ if (Write(buf, 12, 1) != 1
+ || Write(namelist, sizeof(char), namelen) != namelen)
return (ERR);
for (i = 0; i < boolmax; i++)
@@ -474,27 +656,27 @@ write_object(FILE * fp, TERMTYPE * tp)
buf[i] = TRUE;
else
buf[i] = FALSE;
- if (fwrite(buf, sizeof(char), boolmax, fp) != boolmax)
+ if (Write(buf, sizeof(char), boolmax) != boolmax)
return (ERR);
if (even_boundary(namelen + boolmax))
return (ERR);
- TRACE_OUT(("Numerics begin at %04lx", ftell(fp)));
+ TRACE_OUT(("Numerics begin at %04x", *offset));
/* the numerics */
convert_shorts(buf, tp->Numbers, nummax);
- if (fwrite(buf, 2, nummax, fp) != nummax)
+ if (Write(buf, 2, nummax) != nummax)
return (ERR);
- TRACE_OUT(("String offsets begin at %04lx", ftell(fp)));
+ TRACE_OUT(("String offsets begin at %04x", *offset));
/* the string offsets */
convert_shorts(buf, offsets, strmax);
- if (fwrite(buf, 2, strmax, fp) != strmax)
+ if (Write(buf, 2, strmax) != strmax)
return (ERR);
- TRACE_OUT(("String table begins at %04lx", ftell(fp)));
+ TRACE_OUT(("String table begins at %04x", *offset));
/* the strings */
for (i = 0; i < strmax; i++)
@@ -503,7 +685,7 @@ write_object(FILE * fp, TERMTYPE * tp)
return (ERR);
#if NCURSES_XNAMES
- if (NUM_EXT_NAMES(tp)) {
+ if (extended_object(tp)) {
unsigned extcnt = NUM_EXT_NAMES(tp);
if (even_boundary(nextfree))
@@ -523,23 +705,23 @@ write_object(FILE * fp, TERMTYPE * tp)
LITTLE_ENDIAN(buf + 4, tp->ext_Strings);
LITTLE_ENDIAN(buf + 6, strmax);
LITTLE_ENDIAN(buf + 8, nextfree);
- TRACE_OUT(("WRITE extended-header @%ld", ftell(fp)));
- if (fwrite(buf, 10, 1, fp) != 1)
+ TRACE_OUT(("WRITE extended-header @%d", *offset));
+ if (Write(buf, 10, 1) != 1)
return (ERR);
- TRACE_OUT(("WRITE %d booleans @%ld", tp->ext_Booleans, ftell(fp)));
+ TRACE_OUT(("WRITE %d booleans @%d", tp->ext_Booleans, *offset));
if (tp->ext_Booleans
- && fwrite(tp->Booleans + BOOLCOUNT, sizeof(char),
- tp->ext_Booleans, fp) != tp->ext_Booleans)
+ && Write(tp->Booleans + BOOLCOUNT, sizeof(char),
+ tp->ext_Booleans) != tp->ext_Booleans)
return (ERR);
if (even_boundary(tp->ext_Booleans))
return (ERR);
- TRACE_OUT(("WRITE %d numbers @%ld", tp->ext_Numbers, ftell(fp)));
+ TRACE_OUT(("WRITE %d numbers @%d", tp->ext_Numbers, *offset));
if (tp->ext_Numbers) {
convert_shorts(buf, tp->Numbers + NUMCOUNT, tp->ext_Numbers);
- if (fwrite(buf, 2, tp->ext_Numbers, fp) != tp->ext_Numbers)
+ if (Write(buf, 2, tp->ext_Numbers) != tp->ext_Numbers)
return (ERR);
}
@@ -548,8 +730,8 @@ write_object(FILE * fp, TERMTYPE * tp)
* in that order.
*/
convert_shorts(buf, offsets, strmax);
- TRACE_OUT(("WRITE offsets @%ld", ftell(fp)));
- if (fwrite(buf, 2, strmax, fp) != strmax)
+ TRACE_OUT(("WRITE offsets @%d", *offset));
+ if (Write(buf, 2, strmax) != strmax)
return (ERR);
/*