diff options
author | rafan <rafan@FreeBSD.org> | 2007-01-20 07:32:02 +0000 |
---|---|---|
committer | rafan <rafan@FreeBSD.org> | 2007-01-20 07:32:02 +0000 |
commit | de9cbef68d4c3ea6cd003ce086e2d3487600ace7 (patch) | |
tree | 1c6c3b549401156e1dbd96b9a6b18521f63ffb58 /contrib/ncurses/progs | |
parent | 377d0def80a85cb3dcd2eb1f80cd65a577eef9de (diff) | |
download | FreeBSD-src-de9cbef68d4c3ea6cd003ce086e2d3487600ace7.zip FreeBSD-src-de9cbef68d4c3ea6cd003ce086e2d3487600ace7.tar.gz |
Import ncurses 5.6-20061217 onto the vender branch
Approved by: delphij
Diffstat (limited to 'contrib/ncurses/progs')
-rwxr-xr-x | contrib/ncurses/progs/MKtermsort.sh | 42 | ||||
-rw-r--r-- | contrib/ncurses/progs/Makefile.in | 118 | ||||
-rwxr-xr-x | contrib/ncurses/progs/capconvert | 29 | ||||
-rw-r--r-- | contrib/ncurses/progs/clear.c | 24 | ||||
-rwxr-xr-x | contrib/ncurses/progs/clear.sh | 28 | ||||
-rw-r--r-- | contrib/ncurses/progs/dump_entry.c | 424 | ||||
-rw-r--r-- | contrib/ncurses/progs/dump_entry.h | 23 | ||||
-rw-r--r-- | contrib/ncurses/progs/infocmp.c | 537 | ||||
-rw-r--r-- | contrib/ncurses/progs/modules | 18 | ||||
-rw-r--r-- | contrib/ncurses/progs/progs.priv.h | 22 | ||||
-rw-r--r-- | contrib/ncurses/progs/tic.c | 597 | ||||
-rw-r--r-- | contrib/ncurses/progs/toe.c | 488 | ||||
-rw-r--r-- | contrib/ncurses/progs/tput.c | 99 | ||||
-rw-r--r-- | contrib/ncurses/progs/tset.c | 223 |
14 files changed, 1892 insertions, 780 deletions
diff --git a/contrib/ncurses/progs/MKtermsort.sh b/contrib/ncurses/progs/MKtermsort.sh index c3495c4..18b90ac 100755 --- a/contrib/ncurses/progs/MKtermsort.sh +++ b/contrib/ncurses/progs/MKtermsort.sh @@ -1,23 +1,53 @@ #!/bin/sh -# $Id: MKtermsort.sh,v 1.7 2001/05/26 23:37:57 tom Exp $ +# $Id: MKtermsort.sh,v 1.9 2003/01/11 22:23:50 tom Exp $ # # MKtermsort.sh -- generate indirection vectors for the various sort methods # +############################################################################## +# Copyright (c) 1998-2002,2003 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +# # The output of this script is C source for nine arrays that list three sort # orders for each of the three different classes of terminfo capabilities. # # keep the order independent of locale: -LANGUAGE=C -LC_ALL=C -export LANGUAGE -export LC_ALL +if test "${LANGUAGE+set}" = set; then LANGUAGE=C; export LANGUAGE; fi +if test "${LANG+set}" = set; then LANG=C; export LANG; fi +if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi +if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi +if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi +if test "${LC_COLLATE+set}" = set; then LC_COLLATE=C; export LC_COLLATE; fi # AWK=${1-awk} DATA=${2-../include/Caps} data=data$$ trap 'rm -f $data' 1 2 5 15 -sed -e 's/[ ]\+/ /g' < $DATA >$data +sed -e 's/[ ][ ]*/ /g' < $DATA >$data DATA=$data echo "/*"; diff --git a/contrib/ncurses/progs/Makefile.in b/contrib/ncurses/progs/Makefile.in index 43b85c4..820e0b4 100644 --- a/contrib/ncurses/progs/Makefile.in +++ b/contrib/ncurses/progs/Makefile.in @@ -1,6 +1,6 @@ -# $Id: Makefile.in,v 1.56 2001/12/08 18:48:01 tom Exp $ +# $Id: Makefile.in,v 1.70 2006/12/17 15:55:48 tom Exp $ ############################################################################## -# 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 "Software"), # @@ -27,7 +27,7 @@ # authorization. # ############################################################################## # -# Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 +# Author: Thomas E. Dickey 1996-on # # Makefile for ncurses source code. # @@ -47,10 +47,13 @@ THIS = Makefile CF_MFLAGS = @cf_cv_makeflags@ @SET_MAKE@ -x = @PROG_EXT@ + +x = @EXEEXT@ +o = .@OBJEXT@ MODEL = ../@DFT_OBJ_SUBDIR@ DESTDIR = @DESTDIR@ +top_srcdir = @top_srcdir@ srcdir = @srcdir@ prefix = @prefix@ exec_prefix = @exec_prefix@ @@ -60,9 +63,14 @@ includedir = @includedir@ datadir = @datadir@ LIBTOOL = @LIBTOOL@ +LIBTOOL_CLEAN = @LIB_CLEAN@ +LIBTOOL_COMPILE = @LIB_COMPILE@ +LIBTOOL_LINK = @LIB_LINK@ +LIBTOOL_INSTALL = @LIB_INSTALL@ +LIBTOOL_UNINSTALL = @LIB_UNINSTALL@ INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_PROG = @INSTALL_PROGRAM@ transform = @program_transform_name@ AWK = @AWK@ @@ -72,9 +80,8 @@ CC = @CC@ CPP = @CPP@ CFLAGS = @CFLAGS@ -INCDIR = $(srcdir)/../include -CPPFLAGS = -I../progs -I$(srcdir) @CPPFLAGS@ \ - -DHAVE_CONFIG_H +INCDIR = $(top_srcdir)/include +CPPFLAGS = -I../progs -I$(srcdir) -DHAVE_CONFIG_H @CPPFLAGS@ CCFLAGS = $(CPPFLAGS) $(CFLAGS) @@ -86,16 +93,20 @@ CFLAGS_SHARED = $(CCFLAGS) @CC_SHARED_OPTS@ CFLAGS_DEFAULT = $(CFLAGS_@DFT_UPR_MODEL@) +REL_VERSION = @cf_cv_rel_version@ +ABI_VERSION = @cf_cv_abi_version@ +LOCAL_LIBDIR = @top_builddir@/lib + LD = @LD@ -LINK = @LINK_PROGS@ $(LIBTOOL) $(CC) +LINK = @LINK_PROGS@ $(LIBTOOL_LINK) $(CC) LDFLAGS = @EXTRA_LDFLAGS@ \ - @PROG_ARGS@ @LDFLAGS@ @LD_MODEL@ @LIBS@ @EXTRA_LIBS@ + @TINFO_ARGS@ @LDFLAGS@ @LD_MODEL@ @LIBS@ -LDFLAGS_LIBTOOL = $(LDFLAGS) -LDFLAGS_NORMAL = $(LDFLAGS) -LDFLAGS_DEBUG = $(LDFLAGS) @CC_G_OPT@ -LDFLAGS_PROFILE = $(LDFLAGS) -pg -LDFLAGS_SHARED = $(LDFLAGS) @LD_SHARED_OPTS@ +LDFLAGS_LIBTOOL = $(LDFLAGS) $(CFLAGS_LIBTOOL) +LDFLAGS_NORMAL = $(LDFLAGS) $(CFLAGS_NORMAL) +LDFLAGS_DEBUG = $(LDFLAGS) $(CFLAGS_DEBUG) +LDFLAGS_PROFILE = $(LDFLAGS) $(CFLAGS_PROFILE) +LDFLAGS_SHARED = $(LDFLAGS) $(CFLAGS_SHARED) @LD_SHARED_OPTS@ LDFLAGS_DEFAULT = $(LDFLAGS_@DFT_UPR_MODEL@) @@ -107,16 +118,20 @@ AUTO_SRC = \ termsort.c \ transform.h -# tic and toe rely on direct access to the terminfo database -GET_PROGS = infocmp$x clear$x tput$x tset$x -PUT_PROGS = @MAKE_TERMINFO@ tic$x toe$x +# tic relies on direct access to the terminfo database +GET_PROGS = infocmp$x clear$x tput$x tset$x toe$x +PUT_PROGS = @MAKE_TERMINFO@ tic$x PROGS = $(PUT_PROGS) $(GET_PROGS) -TESTPROGS = mvcur$x tctest$x hardscroll$x hashmap$x - # Default library, for linking applications DEPS_CURSES = ../lib/@LIB_PREFIX@ncurses@DFT_DEP_SUFFIX@ +HEADER_DEPS = \ + ../include/curses.h \ + $(INCDIR)/term_entry.h \ + $(INCDIR)/tic.h \ + $(INCDIR)/nc_alloc.h + ################################################################################ all: $(AUTO_SRC) $(PROGS) @@ -132,6 +147,7 @@ uninstall.libs: TRANSFORM = sed 's/$x$$//'|sed '$(transform)'|sed 's/$$/$x/' +# transformed names for installing files actual_captoinfo = `echo captoinfo$x| $(TRANSFORM)` actual_clear = `echo clear$x| $(TRANSFORM)` actual_infocmp = `echo infocmp$x| $(TRANSFORM)` @@ -143,38 +159,44 @@ actual_toe = `echo toe$x| $(TRANSFORM)` actual_tput = `echo tput$x| $(TRANSFORM)` actual_tset = `echo tset$x| $(TRANSFORM)` +# transformed names for comparing at runtime +define_captoinfo = `echo captoinfo| $(TRANSFORM)` +define_infotocap = `echo infotocap| $(TRANSFORM)` +define_init = `echo init| $(TRANSFORM)` +define_reset = `echo reset| $(TRANSFORM)` + transform.h : - echo "#define PROG_CAPTOINFO \"$(actual_captoinfo)\"" >$@ - echo "#define PROG_INFOTOCAP \"$(actual_infotocap)\"" >>$@ - echo "#define PROG_RESET \"$(actual_reset)\"" >>$@ - echo "#define PROG_INIT \"$(actual_init)\"" >>$@ + echo "#define PROG_CAPTOINFO \"$(define_captoinfo)\"" >$@ + echo "#define PROG_INFOTOCAP \"$(define_infotocap)\"" >>$@ + echo "#define PROG_RESET \"$(define_reset)\"" >>$@ + echo "#define PROG_INIT \"$(define_init)\"" >>$@ install.progs: $(AUTO_SRC) $(PROGS) $(DESTDIR)$(bindir) -@MAKE_TERMINFO@ $(LIBTOOL) $(INSTALL_PROGRAM) tic$x $(DESTDIR)$(bindir)/$(actual_tic) -@MAKE_TERMINFO@ $(LIBTOOL) $(INSTALL_PROGRAM) toe$x $(DESTDIR)$(bindir)/$(actual_toe) +@MAKE_TERMINFO@ $(LIBTOOL_INSTALL) $(INSTALL_PROG) tic$x $(DESTDIR)$(bindir)/$(actual_tic) +@MAKE_TERMINFO@ $(LIBTOOL_INSTALL) $(INSTALL_PROG) toe$x $(DESTDIR)$(bindir)/$(actual_toe) @MAKE_TERMINFO@ @echo "linking $(actual_infotocap) to $(actual_tic)" @MAKE_TERMINFO@ -@rm -f $(DESTDIR)$(bindir)/$(actual_infotocap) @MAKE_TERMINFO@ (cd $(DESTDIR)$(bindir) && $(LN_S) $(actual_tic) $(actual_infotocap)) @MAKE_TERMINFO@ @echo "linking $(actual_captoinfo) to $(actual_tic)" @MAKE_TERMINFO@ -@rm -f $(DESTDIR)$(bindir)/$(actual_captoinfo) @MAKE_TERMINFO@ (cd $(DESTDIR)$(bindir) && $(LN_S) $(actual_tic) $(actual_captoinfo)) - $(LIBTOOL) $(INSTALL_PROGRAM) infocmp$x $(DESTDIR)$(bindir)/$(actual_infocmp) - $(LIBTOOL) $(INSTALL_PROGRAM) clear$x $(DESTDIR)$(bindir)/$(actual_clear) - $(LIBTOOL) $(INSTALL_PROGRAM) tput$x $(DESTDIR)$(bindir)/$(actual_tput) - $(LIBTOOL) $(INSTALL_PROGRAM) tset$x $(DESTDIR)$(bindir)/$(actual_tset) + $(LIBTOOL_INSTALL) $(INSTALL_PROG) infocmp$x $(DESTDIR)$(bindir)/$(actual_infocmp) + $(LIBTOOL_INSTALL) $(INSTALL_PROG) clear$x $(DESTDIR)$(bindir)/$(actual_clear) + $(LIBTOOL_INSTALL) $(INSTALL_PROG) tput$x $(DESTDIR)$(bindir)/$(actual_tput) + $(LIBTOOL_INSTALL) $(INSTALL_PROG) tset$x $(DESTDIR)$(bindir)/$(actual_tset) @echo "linking $(actual_reset) to $(actual_tset)" -@rm -f $(DESTDIR)$(bindir)/$(actual_reset) (cd $(DESTDIR)$(bindir) && $(LN_S) $(actual_tset) $(actual_reset)) uninstall.progs: -@MAKE_TERMINFO@ -@$(LIBTOOL) rm -f $(DESTDIR)$(bindir)/$(actual_tic) -@MAKE_TERMINFO@ -@$(LIBTOOL) rm -f $(DESTDIR)$(bindir)/$(actual_toe) +@MAKE_TERMINFO@ -@$(LIBTOOL_CLEAN) rm -f $(DESTDIR)$(bindir)/$(actual_tic) +@MAKE_TERMINFO@ -@$(LIBTOOL_CLEAN) rm -f $(DESTDIR)$(bindir)/$(actual_toe) @MAKE_TERMINFO@ -@rm -f $(DESTDIR)$(bindir)/$(actual_captoinfo) @MAKE_TERMINFO@ -@rm -f $(DESTDIR)$(bindir)/$(actual_infotocap) - -@$(LIBTOOL) rm -f $(DESTDIR)$(bindir)/$(actual_infocmp) - -@$(LIBTOOL) rm -f $(DESTDIR)$(bindir)/$(actual_clear) - -@$(LIBTOOL) rm -f $(DESTDIR)$(bindir)/$(actual_tput) - -@$(LIBTOOL) rm -f $(DESTDIR)$(bindir)/$(actual_tset) + -@$(LIBTOOL_CLEAN) rm -f $(DESTDIR)$(bindir)/$(actual_infocmp) + -@$(LIBTOOL_CLEAN) rm -f $(DESTDIR)$(bindir)/$(actual_clear) + -@$(LIBTOOL_CLEAN) rm -f $(DESTDIR)$(bindir)/$(actual_tput) + -@$(LIBTOOL_CLEAN) rm -f $(DESTDIR)$(bindir)/$(actual_tset) -@rm -f $(DESTDIR)$(bindir)/$(actual_reset) $(DESTDIR)$(bindir) : @@ -185,47 +207,47 @@ $(DESTDIR)$(bindir) : # DEPS_TIC = \ - $(MODEL)/tic.o \ - $(MODEL)/dump_entry.o + $(MODEL)/tic$o \ + $(MODEL)/dump_entry$o tic$x: $(DEPS_TIC) $(DEPS_CURSES) transform.h @ECHO_LINK@ $(LINK) $(DEPS_TIC) $(LDFLAGS_DEFAULT) -o $@ DEPS_TOE = \ - $(MODEL)/toe.o \ - $(MODEL)/dump_entry.o + $(MODEL)/toe$o \ + $(MODEL)/dump_entry$o toe$x: $(DEPS_TOE) $(DEPS_CURSES) @ECHO_LINK@ $(LINK) $(DEPS_TOE) $(LDFLAGS_DEFAULT) -o $@ DEPS_CLEAR = \ - $(MODEL)/clear.o + $(MODEL)/clear$o clear$x: $(DEPS_CLEAR) $(DEPS_CURSES) @ECHO_LINK@ $(LINK) $(DEPS_CLEAR) $(LDFLAGS_DEFAULT) -o $@ DEPS_TPUT = \ - $(MODEL)/tput.o + $(MODEL)/tput$o tput$x: $(DEPS_TPUT) $(DEPS_CURSES) transform.h @ECHO_LINK@ $(LINK) $(DEPS_TPUT) $(LDFLAGS_DEFAULT) -o $@ DEPS_INFOCMP = \ - $(MODEL)/infocmp.o \ - $(MODEL)/dump_entry.o + $(MODEL)/infocmp$o \ + $(MODEL)/dump_entry$o infocmp$x: $(DEPS_INFOCMP) $(DEPS_CURSES) @ECHO_LINK@ $(LINK) $(DEPS_INFOCMP) $(LDFLAGS_DEFAULT) -o $@ DEPS_TSET = \ - $(MODEL)/tset.o \ - $(MODEL)/dump_entry.o + $(MODEL)/tset$o \ + $(MODEL)/dump_entry$o tset$x: $(DEPS_TSET) $(DEPS_CURSES) transform.h @ECHO_LINK@ $(LINK) $(DEPS_TSET) $(LDFLAGS_DEFAULT) -o $@ termsort.c: $(srcdir)/MKtermsort.sh - sh -c "$(srcdir)/MKtermsort.sh $(AWK) $(srcdir)/../include/@TERMINFO_CAPS@" >$@ + sh $(srcdir)/MKtermsort.sh $(AWK) $(srcdir)/../include/@TERMINFO_CAPS@ >$@ # # Utility productions start here @@ -239,9 +261,9 @@ tags: mostlyclean :: -rm -f core tags TAGS *~ *.bak *.i *.ln *.atac trace - -rm -f $(TESTPROGS) clean :: mostlyclean + -sh -c "if test -n '$x' ; then $(MAKE) clean x=''; fi" -rm -f $(AUTO_SRC) -rm -f $(PROGS) -rm -rf .libs diff --git a/contrib/ncurses/progs/capconvert b/contrib/ncurses/progs/capconvert index 2125a0d..8199bbf 100755 --- a/contrib/ncurses/progs/capconvert +++ b/contrib/ncurses/progs/capconvert @@ -1,5 +1,32 @@ #!/bin/sh -# $Id: capconvert,v 1.3 1997/08/02 21:52:06 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: capconvert,v 1.4 2006/04/22 21:46:17 tom Exp $ # # capconvert -- automated conversion from termcap to terminfo # diff --git a/contrib/ncurses/progs/clear.c b/contrib/ncurses/progs/clear.c index d27b625..4e4aaa9 100644 --- a/contrib/ncurses/progs/clear.c +++ b/contrib/ncurses/progs/clear.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998 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,30 +29,30 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ - /* * clear.c -- clears the terminal's screen */ #include <progs.priv.h> -#include <curses.h> - -MODULE_ID("$Id: clear.c,v 1.8 1998/09/26 11:42:50 tom Exp $") +MODULE_ID("$Id: clear.c,v 1.10 2006/05/20 17:47:47 tom Exp $") -static int putch(int c) +static int +putch(int c) { - return putchar(c); + return putchar(c); } -int main( +int +main( int argc GCC_UNUSED, - char *argv[] GCC_UNUSED) + char *argv[]GCC_UNUSED) { - setupterm((char *) 0, STDOUT_FILENO, (int *) 0); - return (tputs(clear_screen, lines > 0 ? lines : 1, putch) == ERR) + setupterm((char *) 0, STDOUT_FILENO, (int *) 0); + ExitProgram((tputs(clear_screen, lines > 0 ? lines : 1, putch) == ERR) ? EXIT_FAILURE - : EXIT_SUCCESS; + : EXIT_SUCCESS); } diff --git a/contrib/ncurses/progs/clear.sh b/contrib/ncurses/progs/clear.sh index 1b6b0bb..f26112b 100755 --- a/contrib/ncurses/progs/clear.sh +++ b/contrib/ncurses/progs/clear.sh @@ -1 +1,29 @@ +#!/bin/sh +############################################################################## +# 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. # +############################################################################## exec tput clear diff --git a/contrib/ncurses/progs/dump_entry.c b/contrib/ncurses/progs/dump_entry.c index f54ecf8..0a3cb38 100644 --- a/contrib/ncurses/progs/dump_entry.c +++ b/contrib/ncurses/progs/dump_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 * @@ -39,7 +39,7 @@ #include "termsort.c" /* this C file is generated */ #include <parametrized.h> /* so is this */ -MODULE_ID("$Id: dump_entry.c,v 1.58 2002/06/01 22:58:11 tom Exp $") +MODULE_ID("$Id: dump_entry.c,v 1.79 2006/09/30 20:18:15 tom Exp $") #define INDENT 8 #define DISCARD(string) string = ABSENT_STRING @@ -59,11 +59,13 @@ static int column; /* current column, limited by 'width' */ static int oldcol; /* last value of column before wrap */ static bool pretty; /* true if we format if-then-else strings */ +static char *save_sgr; + static DYNBUF outbuf; static DYNBUF tmpbuf; /* indirection pointers for implementing sort and display modes */ -static const int *bool_indirect, *num_indirect, *str_indirect; +static const PredIdx *bool_indirect, *num_indirect, *str_indirect; static NCURSES_CONST char *const *bool_names; static NCURSES_CONST char *const *num_names; static NCURSES_CONST char *const *str_names; @@ -262,7 +264,7 @@ dump_init(const char *version, int mode, int sort, int twidth, int traceval, static TERMTYPE *cur_type; static int -dump_predicate(int type, int idx) +dump_predicate(PredType type, PredIdx idx) /* predicate function to use for ordinary decompilation */ { switch (type) { @@ -282,13 +284,21 @@ dump_predicate(int type, int idx) return (FALSE); /* pacify compiler */ } -static void set_obsolete_termcaps(TERMTYPE * tp); +static void set_obsolete_termcaps(TERMTYPE *tp); /* is this the index of a function key string? */ #define FNKEY(i) (((i)<= 65 && (i)>= 75) || ((i)<= 216 && (i)>= 268)) +/* + * If we configure with a different Caps file, the offsets into the arrays + * will change. So we use an address expression. + */ +#define BOOL_IDX(name) (&(name) - &(CUR Booleans[0])) +#define NUM_IDX(name) (&(name) - &(CUR Numbers[0])) +#define STR_IDX(name) (&(name) - &(CUR Strings[0])) + static bool -version_filter(int type, int idx) +version_filter(PredType type, PredIdx idx) /* filter out capabilities we may want to suppress */ { switch (tversion) { @@ -298,31 +308,28 @@ version_filter(int type, int idx) case V_SVR1: /* System V Release 1, Ultrix */ switch (type) { case BOOLEAN: - /* below and including xon_xoff */ - return ((idx <= 20) ? TRUE : FALSE); + return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE); case NUMBER: - /* below and including width_status_line */ - return ((idx <= 7) ? TRUE : FALSE); + return ((idx <= NUM_IDX(width_status_line)) ? TRUE : FALSE); case STRING: - /* below and including prtr_non */ - return ((idx <= 144) ? TRUE : FALSE); + return ((idx <= STR_IDX(prtr_non)) ? TRUE : FALSE); } break; case V_HPUX: /* Hewlett-Packard */ switch (type) { case BOOLEAN: - /* below and including xon_xoff */ - return ((idx <= 20) ? TRUE : FALSE); + return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE); case NUMBER: - /* below and including label_width */ - return ((idx <= 10) ? TRUE : FALSE); + return ((idx <= NUM_IDX(label_width)) ? TRUE : FALSE); case STRING: - if (idx <= 144) /* below and including prtr_non */ + if (idx <= STR_IDX(prtr_non)) return (TRUE); else if (FNKEY(idx)) /* function keys */ return (TRUE); - else if (idx == 147 || idx == 156 || idx == 157) /* plab_norm,label_on,label_off */ + else if (idx == STR_IDX(plab_norm) + || idx == STR_IDX(label_on) + || idx == STR_IDX(label_off)) return (TRUE); else return (FALSE); @@ -332,13 +339,11 @@ version_filter(int type, int idx) case V_AIX: /* AIX */ switch (type) { case BOOLEAN: - /* below and including xon_xoff */ - return ((idx <= 20) ? TRUE : FALSE); + return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE); case NUMBER: - /* below and including width_status_line */ - return ((idx <= 7) ? TRUE : FALSE); + return ((idx <= NUM_IDX(width_status_line)) ? TRUE : FALSE); case STRING: - if (idx <= 144) /* below and including prtr_non */ + if (idx <= STR_IDX(prtr_non)) return (TRUE); else if (FNKEY(idx)) /* function keys */ return (TRUE); @@ -363,9 +368,17 @@ version_filter(int type, int idx) } static void +trim_trailing(void) +{ + while (outbuf.used > 0 && outbuf.text[outbuf.used - 1] == ' ') + outbuf.text[--outbuf.used] = '\0'; +} + +static void force_wrap(void) { oldcol = column; + trim_trailing(); strcpy_DYN(&outbuf, trailer); column = INDENT; } @@ -419,43 +432,81 @@ termcap_length(const char *src) #define termcap_length(src) strlen(src) #endif +static void +indent_DYN(DYNBUF * buffer, int level) +{ + int n; + + for (n = 0; n < level; n++) + strncpy_DYN(buffer, "\t", 1); +} + +static bool +has_params(const char *src) +{ + bool result = FALSE; + int len = strlen(src); + int n; + bool ifthen = FALSE; + bool params = FALSE; + + for (n = 0; n < len - 1; ++n) { + if (!strncmp(src + n, "%p", 2)) { + params = TRUE; + } else if (!strncmp(src + n, "%;", 2)) { + ifthen = TRUE; + result = params; + break; + } + } + if (!ifthen) { + result = ((len > 50) && params); + } + return result; +} + static char * fmt_complex(char *src, int level) { - int percent = 0; - int n; - bool if_then = strstr(src, "%?") != 0; - bool params = !if_then && (strlen(src) > 50) && (strstr(src, "%p") != 0); + bool percent = FALSE; + bool params = has_params(src); while (*src != '\0') { switch (*src) { case '\\': - percent = 0; + percent = FALSE; strncpy_DYN(&tmpbuf, src++, 1); break; case '%': - percent = 1; + percent = TRUE; break; case '?': /* "if" */ case 't': /* "then" */ case 'e': /* "else" */ if (percent) { - percent = 0; + percent = FALSE; tmpbuf.text[tmpbuf.used - 1] = '\n'; - /* treat a "%e%?" as else-if, on the same level */ - if (!strncmp(src, "e%?", 3)) { - for (n = 0; n < level; n++) - strncpy_DYN(&tmpbuf, "\t", 1); + /* treat a "%e" as else-if, on the same level */ + if (*src == 'e') { + indent_DYN(&tmpbuf, level); strncpy_DYN(&tmpbuf, "%", 1); - strncpy_DYN(&tmpbuf, src, 3); - src += 3; + strncpy_DYN(&tmpbuf, src, 1); + src++; + params = has_params(src); + if (!params && *src != '\0' && *src != '%') { + strncpy_DYN(&tmpbuf, "\n", 1); + indent_DYN(&tmpbuf, level + 1); + } } else { - for (n = 0; n <= level; n++) - strncpy_DYN(&tmpbuf, "\t", 1); + indent_DYN(&tmpbuf, level + 1); strncpy_DYN(&tmpbuf, "%", 1); strncpy_DYN(&tmpbuf, src, 1); if (*src++ == '?') { src = fmt_complex(src, level + 1); + if (*src != '\0' && *src != '%') { + strncpy_DYN(&tmpbuf, "\n", 1); + indent_DYN(&tmpbuf, level + 1); + } } else if (level == 1) { _nc_warning("%%%c without %%?", *src); } @@ -465,11 +516,10 @@ fmt_complex(char *src, int level) break; case ';': /* "endif" */ if (percent) { - percent = 0; + percent = FALSE; if (level > 1) { tmpbuf.text[tmpbuf.used - 1] = '\n'; - for (n = 0; n < level; n++) - strncpy_DYN(&tmpbuf, "\t", 1); + indent_DYN(&tmpbuf, level); strncpy_DYN(&tmpbuf, "%", 1); strncpy_DYN(&tmpbuf, src++, 1); return src; @@ -480,14 +530,14 @@ fmt_complex(char *src, int level) case 'p': if (percent && params) { tmpbuf.text[tmpbuf.used - 1] = '\n'; - for (n = 0; n <= level; n++) - strncpy_DYN(&tmpbuf, "\t", 1); + indent_DYN(&tmpbuf, level + 1); strncpy_DYN(&tmpbuf, "%", 1); } - percent = 0; + params = FALSE; + percent = FALSE; break; default: - percent = 0; + percent = FALSE; break; } strncpy_DYN(&tmpbuf, src++, 1); @@ -495,20 +545,24 @@ fmt_complex(char *src, int level) return src; } +#define SAME_CAP(n,cap) (&tterm->Strings[n] == &cap) + int -fmt_entry(TERMTYPE * tterm, - int (*pred) (int type, int idx), +fmt_entry(TERMTYPE *tterm, + PredFunc pred, + bool content_only, bool suppress_untranslatable, bool infodump, int numbers) { - int i, j; + PredIdx i, j; char buffer[MAX_TERMINFO_LENGTH]; + char *capability; NCURSES_CONST char *name; int predval, len; - int num_bools = 0; - int num_values = 0; - int num_strings = 0; + PredIdx num_bools = 0; + PredIdx num_values = 0; + PredIdx num_strings = 0; bool outcount = 0; #define WRAP_CONCAT \ @@ -523,10 +577,14 @@ fmt_entry(TERMTYPE * tterm, } strcpy_DYN(&outbuf, 0); - strcpy_DYN(&outbuf, tterm->term_names); - strcpy_DYN(&outbuf, separator); - column = outbuf.used; - force_wrap(); + if (content_only) { + column = INDENT; /* FIXME: workaround to prevent empty lines */ + } else { + strcpy_DYN(&outbuf, tterm->term_names); + strcpy_DYN(&outbuf, separator); + column = outbuf.used; + force_wrap(); + } for_each_boolean(j, tterm) { i = BoolIndirect(j); @@ -599,51 +657,79 @@ fmt_entry(TERMTYPE * tterm, for_each_string(j, tterm) { i = StrIndirect(j); name = ExtStrname(tterm, i, str_names); + capability = tterm->Strings[i]; if (!version_filter(STRING, i)) continue; else if (isObsolete(outform, name)) continue; +#if NCURSES_XNAMES /* - * Some older versions of vi want rmir/smir to be defined - * for ich/ich1 to work. If they're not defined, force - * them to be output as defined and empty. + * Extended names can be longer than 2 characters, but termcap programs + * cannot read those (filter them out). */ + if (outform == F_TERMCAP && (strlen(name) > 2)) + continue; +#endif + if (outform == F_TERMCAP) { - if (insert_character || parm_ich) { - if (&tterm->Strings[i] == &enter_insert_mode + /* + * Some older versions of vi want rmir/smir to be defined + * for ich/ich1 to work. If they're not defined, force + * them to be output as defined and empty. + */ + if (PRESENT(insert_character) || PRESENT(parm_ich)) { + if (SAME_CAP(i, enter_insert_mode) && enter_insert_mode == ABSENT_STRING) { (void) strcpy(buffer, "im="); WRAP_CONCAT; continue; } - if (&tterm->Strings[i] == &exit_insert_mode + if (SAME_CAP(i, exit_insert_mode) && exit_insert_mode == ABSENT_STRING) { (void) strcpy(buffer, "ei="); WRAP_CONCAT; continue; } } + /* + * termcap applications such as screen will be confused if sgr0 + * is translated to a string containing rmacs. Filter that out. + */ + if (PRESENT(exit_attribute_mode)) { + if (SAME_CAP(i, exit_attribute_mode)) { + char *trimmed_sgr0; + char *my_sgr = set_attributes; + + set_attributes = save_sgr; + + trimmed_sgr0 = _nc_trim_sgr0(tterm); + if (strcmp(capability, trimmed_sgr0)) + capability = trimmed_sgr0; + + set_attributes = my_sgr; + } + } } predval = pred(STRING, i); buffer[0] = '\0'; if (predval != FAIL) { - if (tterm->Strings[i] != ABSENT_STRING + if (capability != ABSENT_STRING && i + 1 > num_strings) num_strings = i + 1; - if (!VALID_STRING(tterm->Strings[i])) { + if (!VALID_STRING(capability)) { sprintf(buffer, "%s@", name); WRAP_CONCAT; } else if (outform == F_TERMCAP || outform == F_TCONVERR) { int params = ((i < (int) SIZEOF(parametrized)) ? parametrized[i] : 0); - char *srccap = _nc_tic_expand(tterm->Strings[i], TRUE, numbers); + char *srccap = _nc_tic_expand(capability, TRUE, numbers); char *cv = _nc_infotocap(name, srccap, params); if (cv == 0) { @@ -669,10 +755,10 @@ fmt_entry(TERMTYPE * tterm, } else { sprintf(buffer, "%s=%s", name, cv); } - len += strlen(tterm->Strings[i]) + 1; + len += strlen(capability) + 1; WRAP_CONCAT; } else { - char *src = _nc_tic_expand(tterm->Strings[i], + char *src = _nc_tic_expand(capability, outform == F_TERMINFO, numbers); strcpy_DYN(&tmpbuf, 0); @@ -685,17 +771,20 @@ fmt_entry(TERMTYPE * tterm, } else { strcpy_DYN(&tmpbuf, src); } - len += strlen(tterm->Strings[i]) + 1; + len += strlen(capability) + 1; wrap_concat(tmpbuf.text); outcount = TRUE; } } + /* e.g., trimmed_sgr0 */ + if (capability != tterm->Strings[i]) + free(capability); } len += num_strings * 2; /* * This piece of code should be an effective inverse of the functions - * postprocess_terminfo and postprocess_terminfo in parse_entry.c. + * postprocess_terminfo() and postprocess_terminfo() in parse_entry.c. * Much more work should be done on this to support dumping termcaps. */ if (tversion == V_HPUX) { @@ -758,6 +847,7 @@ fmt_entry(TERMTYPE * tterm, if (trimmed) { outbuf.text[outbuf.used] = '\0'; column = oldcol; + strcpy_DYN(&outbuf, " "); } } #if 0 @@ -778,10 +868,10 @@ fmt_entry(TERMTYPE * tterm, } static bool -kill_string(TERMTYPE * tterm, char *cap) +kill_string(TERMTYPE *tterm, char *cap) { int n; - for (n = 0; n < tterm->num_Strings; ++n) { + for (n = 0; n < NUM_STRINGS(tterm); ++n) { if (cap == tterm->Strings[n]) { tterm->Strings[n] = ABSENT_STRING; return TRUE; @@ -791,10 +881,10 @@ kill_string(TERMTYPE * tterm, char *cap) } static char * -find_string(TERMTYPE * tterm, char *name) +find_string(TERMTYPE *tterm, char *name) { - int n; - for (n = 0; n < tterm->num_Strings; ++n) { + PredIdx n; + for (n = 0; n < NUM_STRINGS(tterm); ++n) { if (version_filter(STRING, n) && !strcmp(name, strnames[n])) { char *cap = tterm->Strings[n]; @@ -812,7 +902,7 @@ find_string(TERMTYPE * tterm, char *name) * make it smaller. */ static int -kill_labels(TERMTYPE * tterm, int target) +kill_labels(TERMTYPE *tterm, int target) { int n; int result = 0; @@ -837,7 +927,7 @@ kill_labels(TERMTYPE * tterm, int target) * make it smaller. */ static int -kill_fkeys(TERMTYPE * tterm, int target) +kill_fkeys(TERMTYPE *tterm, int target) { int n; int result = 0; @@ -857,13 +947,66 @@ kill_fkeys(TERMTYPE * tterm, int target) return result; } -int -dump_entry(TERMTYPE * tterm, +/* + * Check if the given acsc string is a 1-1 mapping, i.e., just-like-vt100. + * Also, since this is for termcap, we only care about the line-drawing map. + */ +#define isLine(c) (strchr("lmkjtuvwqxn", c) != 0) + +static bool +one_one_mapping(const char *mapping) +{ + bool result = TRUE; + + if (mapping != ABSENT_STRING) { + int n = 0; + while (mapping[n] != '\0') { + if (isLine(mapping[n]) && + mapping[n] != mapping[n + 1]) { + result = FALSE; + break; + } + n += 2; + } + } + return result; +} + +#define FMT_ENTRY() \ + fmt_entry(tterm, pred, \ + 0, \ + suppress_untranslatable, \ + infodump, numbers) + +#define SHOW_WHY PRINTF + +static bool +purged_acs(TERMTYPE *tterm) +{ + bool result = FALSE; + + if (VALID_STRING(acs_chars)) { + if (!one_one_mapping(acs_chars)) { + enter_alt_charset_mode = ABSENT_STRING; + exit_alt_charset_mode = ABSENT_STRING; + SHOW_WHY("# (rmacs/smacs removed for consistency)\n"); + } + result = TRUE; + } + return result; +} + +/* + * Dump a single entry. + */ +void +dump_entry(TERMTYPE *tterm, + bool suppress_untranslatable, bool limited, int numbers, - int (*pred) (int type, int idx)) -/* dump a single entry */ + PredFunc pred) { + TERMTYPE save_tterm; int len, critlen; const char *legend; bool infodump; @@ -879,85 +1022,132 @@ dump_entry(TERMTYPE * tterm, infodump = TRUE; } - if (((len = fmt_entry(tterm, pred, FALSE, infodump, numbers)) > critlen) + save_sgr = set_attributes; + + if (((len = FMT_ENTRY()) > critlen) && limited) { - PRINTF("# (untranslatable capabilities removed to fit entry within %d bytes)\n", - critlen); - if ((len = fmt_entry(tterm, pred, TRUE, infodump, numbers)) > critlen) { + + save_tterm = *tterm; + if (!suppress_untranslatable) { + SHOW_WHY("# (untranslatable capabilities removed to fit entry within %d bytes)\n", + critlen); + suppress_untranslatable = TRUE; + } + if ((len = FMT_ENTRY()) > critlen) { /* * We pick on sgr because it's a nice long string capability that * is really just an optimization hack. Another good candidate is * acsc since it is both long and unused by BSD termcap. */ - char *oldsgr = set_attributes; - char *oldacsc = acs_chars; - set_attributes = ABSENT_STRING; - PRINTF("# (sgr removed to fit entry within %d bytes)\n", - critlen); - if ((len = fmt_entry(tterm, pred, TRUE, infodump, numbers)) > critlen) { - acs_chars = ABSENT_STRING; - PRINTF("# (acsc removed to fit entry within %d bytes)\n", - critlen); + bool changed = FALSE; + +#if NCURSES_XNAMES + /* + * Extended names are most likely function-key definitions. Drop + * those first. + */ + int n; + for (n = STRCOUNT; n < NUM_STRINGS(tterm); n++) { + const char *name = ExtStrname(tterm, n, strnames); + + if (VALID_STRING(tterm->Strings[n])) { + set_attributes = ABSENT_STRING; + /* we remove long names anyway - only report the short */ + if (strlen(name) <= 2) { + SHOW_WHY("# (%s removed to fit entry within %d bytes)\n", + name, + critlen); + } + changed = TRUE; + if ((len = FMT_ENTRY()) <= critlen) + break; + } + } +#endif + if (VALID_STRING(set_attributes)) { + set_attributes = ABSENT_STRING; + SHOW_WHY("# (sgr removed to fit entry within %d bytes)\n", + critlen); + changed = TRUE; + } + if (!changed || ((len = FMT_ENTRY()) > critlen)) { + if (purged_acs(tterm)) { + acs_chars = ABSENT_STRING; + SHOW_WHY("# (acsc removed to fit entry within %d bytes)\n", + critlen); + changed = TRUE; + } } - if ((len = fmt_entry(tterm, pred, TRUE, infodump, numbers)) > critlen) { + if (!changed || ((len = FMT_ENTRY()) > critlen)) { int oldversion = tversion; tversion = V_BSD; - PRINTF("# (terminfo-only capabilities suppressed to fit entry within %d bytes)\n", - critlen); + SHOW_WHY("# (terminfo-only capabilities suppressed to fit entry within %d bytes)\n", + critlen); - len = fmt_entry(tterm, pred, TRUE, infodump, numbers); + len = FMT_ENTRY(); if (len > critlen && kill_labels(tterm, len - critlen)) { - PRINTF("# (some labels capabilities suppressed to fit entry within %d bytes)\n", - critlen); - len = fmt_entry(tterm, pred, TRUE, infodump, numbers); + SHOW_WHY("# (some labels capabilities suppressed to fit entry within %d bytes)\n", + critlen); + len = FMT_ENTRY(); } if (len > critlen && kill_fkeys(tterm, len - critlen)) { - PRINTF("# (some function-key capabilities suppressed to fit entry within %d bytes)\n", - critlen); - len = fmt_entry(tterm, pred, TRUE, infodump, numbers); + SHOW_WHY("# (some function-key capabilities suppressed to fit entry within %d bytes)\n", + critlen); + len = FMT_ENTRY(); } if (len > critlen) { (void) fprintf(stderr, "warning: %s entry is %d bytes long\n", _nc_first_name(tterm->term_names), len); - PRINTF( - "# WARNING: this entry, %d bytes long, may core-dump %s libraries!\n", - len, legend); + SHOW_WHY("# WARNING: this entry, %d bytes long, may core-dump %s libraries!\n", + len, legend); } tversion = oldversion; } - set_attributes = oldsgr; - acs_chars = oldacsc; + set_attributes = save_sgr; + *tterm = save_tterm; + } + } else if (!version_filter(STRING, STR_IDX(acs_chars))) { + save_tterm = *tterm; + if (purged_acs(tterm)) { + len = FMT_ENTRY(); } + *tterm = save_tterm; } - - (void) fputs(outbuf.text, stdout); - return len; } -int +void dump_uses(const char *name, bool infodump) /* dump "use=" clauses in the appropriate format */ { char buffer[MAX_TERMINFO_LENGTH]; - strcpy_DYN(&outbuf, 0); + if (outform == F_TERMCAP || outform == F_TCONVERR) + trim_trailing(); (void) sprintf(buffer, "%s%s", infodump ? "use=" : "tc=", name); wrap_concat(buffer); +} + +int +show_entry(void) +{ + trim_trailing(); (void) fputs(outbuf.text, stdout); + putchar('\n'); return outbuf.used; } void -compare_entry(void (*hook) (int t, int i, const char *name), TERMTYPE * tp - GCC_UNUSED, bool quiet) +compare_entry(void (*hook) (PredType t, PredIdx i, const char *name), + TERMTYPE *tp GCC_UNUSED, + bool quiet) /* compare two entries */ { - int i, j; + PredIdx i, j; NCURSES_CONST char *name; if (!quiet) @@ -1012,7 +1202,7 @@ compare_entry(void (*hook) (int t, int i, const char *name), TERMTYPE * tp #define CUR tp-> static void -set_obsolete_termcaps(TERMTYPE * tp) +set_obsolete_termcaps(TERMTYPE *tp) { #include "capdefaults.c" } @@ -1022,7 +1212,7 @@ set_obsolete_termcaps(TERMTYPE * tp) * unique. */ void -repair_acsc(TERMTYPE * tp) +repair_acsc(TERMTYPE *tp) { if (VALID_STRING(acs_chars)) { size_t n, m; diff --git a/contrib/ncurses/progs/dump_entry.h b/contrib/ncurses/progs/dump_entry.h index 5735470..f802ecb 100644 --- a/contrib/ncurses/progs/dump_entry.h +++ b/contrib/ncurses/progs/dump_entry.h @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999 Free Software Foundation, Inc. * + * Copyright (c) 1998-2002,2004 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,13 +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 * ****************************************************************************/ /* + * $Id: dump_entry.h,v 1.29 2006/08/19 21:11:14 tom Exp $ + * * Dump control definitions and variables */ +#ifndef DUMP_ENTRY_H +#define DUMP_ENTRY_H 1 + /* capability output formats */ #define F_TERMINFO 0 /* use terminfo names */ #define F_VARIABLE 1 /* use C variable names */ @@ -56,12 +62,19 @@ #define CMP_STRING 2 /* comparison on strings */ #define CMP_USE 3 /* comparison on use capabilities */ +typedef unsigned PredType; +typedef int PredIdx; +typedef int (*PredFunc)(PredType, PredIdx); + extern NCURSES_CONST char *nametrans(const char *); +extern int fmt_entry(TERMTYPE *, PredFunc, bool, bool, bool, int); +extern int show_entry(void); +extern void compare_entry(void (*)(PredType, PredIdx, const char *), TERMTYPE *, bool); +extern void dump_entry(TERMTYPE *, bool, bool, int, PredFunc); extern void dump_init(const char *, int, int, int, int, bool); -extern int fmt_entry(TERMTYPE *, int (*)(int, int), bool, bool, int); -extern int dump_entry(TERMTYPE *, bool, int, int (*)(int, int)); -extern int dump_uses(const char *, bool); -extern void compare_entry(void (*)(int, int, const char *), TERMTYPE *, bool); +extern void dump_uses(const char *, bool); extern void repair_acsc(TERMTYPE * tp); #define FAIL -1 + +#endif /* DUMP_ENTRY_H */ diff --git a/contrib/ncurses/progs/infocmp.c b/contrib/ncurses/progs/infocmp.c index 69f00ae..d3353f2 100644 --- a/contrib/ncurses/progs/infocmp.c +++ b/contrib/ncurses/progs/infocmp.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 * ****************************************************************************/ /* @@ -38,10 +39,9 @@ #include <progs.priv.h> -#include <term_entry.h> #include <dump_entry.h> -MODULE_ID("$Id: infocmp.c,v 1.63 2001/09/22 19:57:40 tom Exp $") +MODULE_ID("$Id: infocmp.c,v 1.85 2006/08/19 21:20:37 tom Exp $") #define L_CURL "{" #define R_CURL "}" @@ -66,6 +66,7 @@ static int termcount; /* count of terminal entries */ static bool limited = TRUE; /* "-r" option is not set */ static bool quiet = FALSE; +static bool literal = FALSE; static const char *bool_sep = ":"; static const char *s_absent = "NULL"; static const char *s_cancel = "NULL"; @@ -87,11 +88,10 @@ static bool ignorepads; /* ignore pad prefixes when diffing */ #if NO_LEAKS #undef ExitProgram -static void -ExitProgram(int code) GCC_NORETURN; +static void ExitProgram(int code) GCC_NORETURN; /* prototype is to get gcc to accept the noreturn attribute */ - static void - ExitProgram(int code) +static void +ExitProgram(int code) { while (termcount-- > 0) _nc_free_termtype(&entries[termcount].tterm); @@ -120,7 +120,7 @@ canonical_name(char *ptr, char *buf) ***************************************************************************/ static int -capcmp(int idx, const char *s, const char *t) +capcmp(PredIdx idx, const char *s, const char *t) /* capability comparison function */ { if (!VALID_STRING(s) && !VALID_STRING(t)) @@ -135,7 +135,7 @@ capcmp(int idx, const char *s, const char *t) } static int -use_predicate(int type, int idx) +use_predicate(unsigned type, PredIdx idx) /* predicate function to use for use decompilation */ { ENTRY *ep; @@ -245,10 +245,10 @@ useeq(ENTRY * e1, ENTRY * e2) } static bool -entryeq(TERMTYPE * t1, TERMTYPE * t2) +entryeq(TERMTYPE *t1, TERMTYPE *t2) /* are two entries equivalent? */ { - int i; + unsigned i; for (i = 0; i < NUM_BOOLEANS(t1); i++) if (t1->Booleans[i] != t2->Booleans[i]) @@ -259,7 +259,7 @@ entryeq(TERMTYPE * t1, TERMTYPE * t2) return (FALSE); for (i = 0; i < NUM_STRINGS(t1); i++) - if (capcmp(i, t1->Strings[i], t2->Strings[i])) + if (capcmp((PredIdx) i, t1->Strings[i], t2->Strings[i])) return (FALSE); return (TRUE); @@ -268,7 +268,7 @@ entryeq(TERMTYPE * t1, TERMTYPE * t2) #define TIC_EXPAND(result) _nc_tic_expand(result, outform==F_TERMINFO, numbers) static void -print_uses(ENTRY * ep, FILE * fp) +print_uses(ENTRY * ep, FILE *fp) /* print an entry's use references */ { int i; @@ -332,7 +332,7 @@ dump_string(char *val, char *buf) } static void -compare_predicate(int type, int idx, const char *name) +compare_predicate(PredType type, PredIdx idx, const char *name) /* predicate function to use for entry difference reports */ { register ENTRY *e1 = &entries[0]; @@ -474,14 +474,26 @@ static const assoc std_caps[] = {"\033)A", "ISO UK G1"}, /* enable UK chars for G1 */ {"\033)B", "ISO US G1"}, /* enable US chars for G1 */ - /* these are DEC private modes widely supported by emulators */ + /* these are DEC private controls widely supported by emulators */ {"\033=", "DECPAM"}, /* application keypad mode */ {"\033>", "DECPNM"}, /* normal keypad mode */ {"\033<", "DECANSI"}, /* enter ANSI mode */ + {"\033[!p", "DECSTR"}, /* soft reset */ + {"\033 F", "S7C1T"}, /* 7-bit controls */ {(char *) 0, (char *) 0} }; +static const assoc std_modes[] = +/* ECMA \E[ ... [hl] modes recognized by many emulators */ +{ + {"2", "AM"}, /* keyboard action mode */ + {"4", "IRM"}, /* insert/replace mode */ + {"12", "SRM"}, /* send/receive mode */ + {"20", "LNM"}, /* linefeed mode */ + {(char *) 0, (char *) 0} +}; + static const assoc private_modes[] = /* DEC \E[ ... [hl] modes recognized by many emulators */ { @@ -532,13 +544,65 @@ static const assoc ecma_highlights[] = {(char *) 0, (char *) 0} }; +static int +skip_csi(const char *cap) +{ + int result = 0; + if (cap[0] == '\033' && cap[1] == '[') + result = 2; + else if (UChar(cap[0]) == 0233) + result = 1; + return result; +} + +static bool +same_param(const char *table, const char *param, unsigned length) +{ + bool result = FALSE; + if (strncmp(table, param, length) == 0) { + result = !isdigit(UChar(param[length])); + } + return result; +} + +static char * +lookup_params(const assoc * table, char *dst, char *src) +{ + const char *ep = strtok(src, ";"); + const assoc *ap; + + do { + bool found = FALSE; + + for (ap = table; ap->from; ap++) { + size_t tlen = strlen(ap->from); + + if (same_param(ap->from, ep, tlen)) { + (void) strcat(dst, ap->to); + found = TRUE; + break; + } + } + + if (!found) + (void) strcat(dst, ep); + (void) strcat(dst, ";"); + } while + ((ep = strtok((char *) 0, ";"))); + + dst[strlen(dst) - 1] = '\0'; + + return dst; +} + static void -analyze_string(const char *name, const char *cap, TERMTYPE * tp) +analyze_string(const char *name, const char *cap, TERMTYPE *tp) { char buf[MAX_TERMINFO_LENGTH]; char buf2[MAX_TERMINFO_LENGTH]; - const char *sp, *ep; + const char *sp; const assoc *ap; + int tp_lines = tp->Numbers[2]; if (cap == ABSENT_STRING || cap == CANCELLED_STRING) return; @@ -547,8 +611,11 @@ analyze_string(const char *name, const char *cap, TERMTYPE * tp) buf[0] = '\0'; for (sp = cap; *sp; sp++) { int i; + int csi; size_t len = 0; + size_t next; const char *expansion = 0; + char buf3[MAX_TERMINFO_LENGTH]; /* first, check other capabilities in this entry */ for (i = 0; i < STRCOUNT; i++) { @@ -586,100 +653,109 @@ analyze_string(const char *name, const char *cap, TERMTYPE * tp) } /* now check the standard capabilities */ - if (!expansion) + if (!expansion) { + csi = skip_csi(sp); for (ap = std_caps; ap->from; ap++) { - len = strlen(ap->from); + size_t adj = csi ? 2 : 0; - if (strncmp(ap->from, sp, len) == 0) { + len = strlen(ap->from); + if (csi && skip_csi(ap->from) != csi) + continue; + if (len > adj + && strncmp(ap->from + adj, sp + csi, len - adj) == 0) { expansion = ap->to; + len -= adj; + len += csi; break; } } + } - /* now check for private-mode sequences */ + /* now check for standard-mode sequences */ if (!expansion - && sp[0] == '\033' && sp[1] == '[' && sp[2] == '?' - && (len = strspn(sp + 3, "0123456789;")) - && ((sp[3 + len] == 'h') || (sp[3 + len] == 'l'))) { - char buf3[MAX_TERMINFO_LENGTH]; - - (void) strcpy(buf2, (sp[3 + len] == 'h') ? "DEC+" : "DEC-"); - (void) strncpy(buf3, sp + 3, len); - len += 4; - buf3[len] = '\0'; + && (csi = skip_csi(sp)) != 0 + && (len = strspn(sp + csi, "0123456789;")) + && (next = csi + len) + && ((sp[next] == 'h') || (sp[next] == 'l'))) { - ep = strtok(buf3, ";"); - do { - bool found = FALSE; + (void) strcpy(buf2, (sp[next] == 'h') ? "ECMA+" : "ECMA-"); + (void) strncpy(buf3, sp + csi, len); + buf3[len] = '\0'; + len += csi + 1; - for (ap = private_modes; ap->from; ap++) { - size_t tlen = strlen(ap->from); + expansion = lookup_params(std_modes, buf2, buf3); + } - if (strncmp(ap->from, ep, tlen) == 0) { - (void) strcat(buf2, ap->to); - found = TRUE; - break; - } - } + /* now check for private-mode sequences */ + if (!expansion + && (csi = skip_csi(sp)) != 0 + && sp[csi] == '?' + && (len = strspn(sp + csi + 1, "0123456789;")) + && (next = csi + 1 + len) + && ((sp[next] == 'h') || (sp[next] == 'l'))) { + + (void) strcpy(buf2, (sp[next] == 'h') ? "DEC+" : "DEC-"); + (void) strncpy(buf3, sp + csi + 1, len); + buf3[len] = '\0'; + len += csi + 2; - if (!found) - (void) strcat(buf2, ep); - (void) strcat(buf2, ";"); - } while - ((ep = strtok((char *) 0, ";"))); - buf2[strlen(buf2) - 1] = '\0'; - expansion = buf2; + expansion = lookup_params(private_modes, buf2, buf3); } /* now check for ECMA highlight sequences */ if (!expansion - && sp[0] == '\033' && sp[1] == '[' - && (len = strspn(sp + 2, "0123456789;")) - && sp[2 + len] == 'm') { - char buf3[MAX_TERMINFO_LENGTH]; + && (csi = skip_csi(sp)) != 0 + && (len = strspn(sp + csi, "0123456789;")) != 0 + && (next = csi + len) + && sp[next] == 'm') { (void) strcpy(buf2, "SGR:"); - (void) strncpy(buf3, sp + 2, len); - len += 3; + (void) strncpy(buf3, sp + csi, len); buf3[len] = '\0'; + len += csi + 1; - ep = strtok(buf3, ";"); - do { - bool found = FALSE; - - for (ap = ecma_highlights; ap->from; ap++) { - size_t tlen = strlen(ap->from); - - if (strncmp(ap->from, ep, tlen) == 0) { - (void) strcat(buf2, ap->to); - found = TRUE; - break; - } - } - - if (!found) - (void) strcat(buf2, ep); - (void) strcat(buf2, ";"); - } while - ((ep = strtok((char *) 0, ";"))); + expansion = lookup_params(ecma_highlights, buf2, buf3); + } - buf2[strlen(buf2) - 1] = '\0'; + if (!expansion + && (csi = skip_csi(sp)) != 0 + && sp[csi] == 'm') { + len = csi + 1; + (void) strcpy(buf2, "SGR:"); + strcat(buf2, ecma_highlights[0].to); expansion = buf2; } + /* now check for scroll region reset */ - if (!expansion) { - (void) sprintf(buf2, "\033[1;%dr", tp->Numbers[2]); - len = strlen(buf2); - if (strncmp(buf2, sp, len) == 0) + if (!expansion + && (csi = skip_csi(sp)) != 0) { + if (sp[csi] == 'r') { expansion = "RSR"; + len = 1; + } else { + (void) sprintf(buf2, "1;%dr", tp_lines); + len = strlen(buf2); + if (strncmp(buf2, sp + csi, len) == 0) + expansion = "RSR"; + } + len += csi; } /* now check for home-down */ - if (!expansion) { - (void) sprintf(buf2, "\033[%d;1H", tp->Numbers[2]); + if (!expansion + && (csi = skip_csi(sp)) != 0) { + (void) sprintf(buf2, "%d;1H", tp_lines); len = strlen(buf2); - if (strncmp(buf2, sp, len) == 0) + if (strncmp(buf2, sp + csi, len) == 0) { expansion = "LL"; + } else { + (void) sprintf(buf2, "%dH", tp_lines); + len = strlen(buf2); + if (strncmp(buf2, sp + csi, len) == 0) { + expansion = "LL"; + } + } + len += csi; } /* now look at the expansion we got, if any */ @@ -723,13 +799,13 @@ file_comparison(int argc, char *argv[]) /* parse entries out of the source file */ _nc_set_source(argv[n]); - _nc_read_entry_source(stdin, NULL, TRUE, FALSE, NULLHOOK); + _nc_read_entry_source(stdin, NULL, TRUE, literal, NULLHOOK); if (itrace) (void) fprintf(stderr, "Resolving file %d...\n", n - 0); /* maybe do use resolution */ - if (!_nc_resolve_uses(!limited)) { + if (!_nc_resolve_uses2(!limited, literal)) { (void) fprintf(stderr, "There are unresolved use entries in %s:\n", argv[n]); @@ -739,7 +815,7 @@ file_comparison(int argc, char *argv[]) (void) fputc('\n', stderr); } } - exit(EXIT_FAILURE); + ExitProgram(EXIT_FAILURE); } heads[filecount] = _nc_head; @@ -898,6 +974,7 @@ usage(void) ," -L use long names" ," -R subset (see manpage)" ," -T eliminate size limits (test)" + ," -U eliminate post-processing of entries" ," -V print version" #if NCURSES_XNAMES ," -a with -F, list commented-out caps" @@ -917,9 +994,15 @@ usage(void) ," -r with -C, output in termcap form" ," -r with -F, resolve use-references" ," -s [d|i|l|c] sort fields" +#if NCURSES_XNAMES + ," -t suppress commented-out capabilities" +#endif ," -u produce source with 'use='" ," -v number (verbose)" ," -w number (width)" +#if NCURSES_XNAMES + ," -x treat unknown capabilities as user-defined" +#endif }; const size_t first = 3; const size_t last = SIZEOF(tbl); @@ -933,7 +1016,7 @@ usage(void) else fprintf(stderr, "%s\n", tbl[n]); } - exit(EXIT_FAILURE); + ExitProgram(EXIT_FAILURE); } static char * @@ -970,9 +1053,9 @@ string_variable(const char *type) /* dump C initializers for the terminal type */ static void -dump_initializers(TERMTYPE * term) +dump_initializers(TERMTYPE *term) { - int n; + unsigned n; int size; const char *str = 0; @@ -1027,7 +1110,7 @@ dump_initializers(TERMTYPE * term) str = "CANCELLED_BOOLEAN"; break; } - (void) printf("\t/* %3d: %-8s */\t%s,\n", + (void) printf("\t/* %3u: %-8s */\t%s,\n", n, ExtBoolname(term, n, boolnames), str); } (void) printf("%s;\n", R_CURL); @@ -1048,14 +1131,14 @@ dump_initializers(TERMTYPE * term) str = buf; break; } - (void) printf("\t/* %3d: %-8s */\t%s,\n", n, + (void) printf("\t/* %3u: %-8s */\t%s,\n", n, ExtNumname(term, n, numnames), str); } (void) printf("%s;\n", R_CURL); - size = sizeof(TERMTYPE) - + (NUM_BOOLEANS(term) * sizeof(term->Booleans[0])) - + (NUM_NUMBERS(term) * sizeof(term->Numbers[0])); + size = (sizeof(TERMTYPE) + + (NUM_BOOLEANS(term) * sizeof(term->Booleans[0])) + + (NUM_NUMBERS(term) * sizeof(term->Numbers[0]))); (void) printf("static char * %s[] = %s\n", name_initializer("string"), L_CURL); @@ -1068,7 +1151,7 @@ dump_initializers(TERMTYPE * term) else { str = string_variable(ExtStrname(term, n, strnames)); } - (void) printf("\t/* %3d: %-8s */\t%s,\n", n, + (void) printf("\t/* %3u: %-8s */\t%s,\n", n, ExtStrname(term, n, strnames), str); } (void) printf("%s;\n", R_CURL); @@ -1080,15 +1163,15 @@ dump_initializers(TERMTYPE * term) (void) printf("static char * %s[] = %s\n", name_initializer("string_ext"), L_CURL); for (n = BOOLCOUNT; n < NUM_BOOLEANS(term); ++n) { - (void) printf("\t/* %3d: bool */\t\"%s\",\n", + (void) printf("\t/* %3u: bool */\t\"%s\",\n", n, ExtBoolname(term, n, boolnames)); } for (n = NUMCOUNT; n < NUM_NUMBERS(term); ++n) { - (void) printf("\t/* %3d: num */\t\"%s\",\n", + (void) printf("\t/* %3u: num */\t\"%s\",\n", n, ExtNumname(term, n, numnames)); } for (n = STRCOUNT; n < NUM_STRINGS(term); ++n) { - (void) printf("\t/* %3d: str */\t\"%s\",\n", + (void) printf("\t/* %3u: str */\t\"%s\",\n", n, ExtStrname(term, n, strnames)); } (void) printf("%s;\n", R_CURL); @@ -1098,7 +1181,7 @@ dump_initializers(TERMTYPE * term) /* dump C initializers for the terminal type */ static void -dump_termtype(TERMTYPE * term) +dump_termtype(TERMTYPE *term) { (void) printf("\t%s\n\t\t%s,\n", L_CURL, name_initializer("alias")); (void) printf("\t\t(char *)0,\t/* pointer to string table */\n"); @@ -1142,11 +1225,24 @@ optarg_to_number(void) if (temp == 0 || temp == optarg || *temp != 0) { fprintf(stderr, "Expected a number, not \"%s\"\n", optarg); - exit(EXIT_FAILURE); + ExitProgram(EXIT_FAILURE); } return (int) value; } +static char * +terminal_env(void) +{ + char *terminal; + + if ((terminal = getenv("TERM")) == 0) { + (void) fprintf(stderr, + "infocmp: environment variable TERM not set\n"); + exit(EXIT_FAILURE); + } + return terminal; +} + /*************************************************************************** * * Main sequence @@ -1156,7 +1252,7 @@ optarg_to_number(void) int main(int argc, char *argv[]) { - char *terminal, *firstdir, *restdir; + char *firstdir, *restdir; /* Avoid "local data >32k" error with mwcc */ /* Also avoid overflowing smaller stacks on systems like AmigaOS */ path *tfile = (path *) malloc(sizeof(path) * MAXTERMS); @@ -1165,45 +1261,62 @@ main(int argc, char *argv[]) bool filecompare = FALSE; int initdump = 0; bool init_analyze = FALSE; - - if ((terminal = getenv("TERM")) == 0) { - (void) fprintf(stderr, - "infocmp: environment variable TERM not set\n"); - return EXIT_FAILURE; - } + bool suppress_untranslatable = FALSE; /* where is the terminfo database location going to default to? */ restdir = firstdir = 0; - while ((c = getopt(argc, argv, "adeEcCfFGgIinlLpqrR:s:uv:Vw:A:B:1T")) != EOF) +#if NCURSES_XNAMES + use_extended_names(FALSE); +#endif + + while ((c = getopt(argc, + argv, + "1A:aB:CcdEeFfGgIiLlnpqR:rs:TtUuVv:w:x")) != EOF) { switch (c) { + case '1': + mwidth = 0; + break; + + case 'A': + firstdir = optarg; + break; + #if NCURSES_XNAMES case 'a': _nc_disable_period = TRUE; use_extended_names(TRUE); break; #endif - case 'd': - compare = C_DIFFERENCE; + case 'B': + restdir = optarg; break; - case 'e': - initdump |= 1; + case 'C': + outform = F_TERMCAP; + tversion = "BSD"; + if (sortmode == S_DEFAULT) + sortmode = S_TERMCAP; + break; + + case 'c': + compare = C_COMMON; + break; + + case 'd': + compare = C_DIFFERENCE; break; case 'E': initdump |= 2; break; - case 'c': - compare = C_COMMON; + case 'e': + initdump |= 1; break; - case 'C': - outform = F_TERMCAP; - tversion = "BSD"; - if (sortmode == S_DEFAULT) - sortmode = S_TERMCAP; + case 'F': + filecompare = TRUE; break; case 'f': @@ -1218,10 +1331,6 @@ main(int argc, char *argv[]) numbers = -1; break; - case 'F': - filecompare = TRUE; - break; - case 'I': outform = F_TERMINFO; if (sortmode == S_DEFAULT) @@ -1233,16 +1342,16 @@ main(int argc, char *argv[]) init_analyze = TRUE; break; - case 'l': - outform = F_TERMINFO; - break; - case 'L': outform = F_VARIABLE; if (sortmode == S_DEFAULT) sortmode = S_VARIABLE; break; + case 'l': + outform = F_TERMINFO; + break; + case 'n': compare = C_NAND; break; @@ -1258,15 +1367,15 @@ main(int argc, char *argv[]) bool_sep = ", "; break; + case 'R': + tversion = optarg; + break; + case 'r': tversion = 0; limited = FALSE; break; - case 'R': - tversion = optarg; - break; - case 's': if (*optarg == 'd') sortmode = S_NOSORT; @@ -1279,45 +1388,52 @@ main(int argc, char *argv[]) else { (void) fprintf(stderr, "infocmp: unknown sort mode\n"); - return EXIT_FAILURE; + ExitProgram(EXIT_FAILURE); } break; + case 'T': + limited = FALSE; + break; + +#if NCURSES_XNAMES + case 't': + _nc_disable_period = FALSE; + suppress_untranslatable = TRUE; + break; +#endif + + case 'U': + literal = TRUE; + break; + case 'u': compare = C_USEALL; break; + case 'V': + puts(curses_version()); + ExitProgram(EXIT_SUCCESS); + case 'v': itrace = optarg_to_number(); set_trace_level(itrace); break; - case 'V': - puts(curses_version()); - ExitProgram(EXIT_SUCCESS); - case 'w': mwidth = optarg_to_number(); break; - case 'A': - firstdir = optarg; - break; - - case 'B': - restdir = optarg; - break; - - case '1': - mwidth = 0; +#if NCURSES_XNAMES + case 'x': + use_extended_names(TRUE); break; +#endif - case 'T': - limited = FALSE; - break; default: usage(); } + } /* by default, sort by terminfo name */ if (sortmode == S_DEFAULT) @@ -1328,11 +1444,11 @@ main(int argc, char *argv[]) /* make sure we have at least one terminal name to work with */ if (optind >= argc) - argv[argc++] = terminal; + argv[argc++] = terminal_env(); /* if user is after a comparison, make sure we have two entries */ if (compare != C_DEFAULT && optind >= argc - 1) - argv[argc++] = terminal; + argv[argc++] = terminal_env(); /* exactly two terminal names with no options means do -d */ if (argc - optind == 2 && compare == C_DEFAULT) @@ -1345,7 +1461,7 @@ main(int argc, char *argv[]) if (termcount >= MAXTERMS) { (void) fprintf(stderr, "infocmp: too many terminal type arguments\n"); - return EXIT_FAILURE; + ExitProgram(EXIT_FAILURE); } else { const char *directory = termcount ? restdir : firstdir; int status; @@ -1353,6 +1469,7 @@ main(int argc, char *argv[]) tname[termcount] = argv[optind]; if (directory) { +#if USE_DATABASE (void) sprintf(tfile[termcount], "%s/%c/%s", directory, *argv[optind], argv[optind]); @@ -1363,11 +1480,15 @@ main(int argc, char *argv[]) status = _nc_read_file_entry(tfile[termcount], &entries[termcount].tterm); +#else + (void) fprintf(stderr, "terminfo files not supported\n"); + ExitProgram(EXIT_FAILURE); +#endif } else { if (itrace) (void) fprintf(stderr, - "infocmp: reading entry %s from system directories %s\n", - argv[optind], tname[termcount]); + "infocmp: reading entry %s from database\n", + tname[termcount]); status = _nc_read_entry(tname[termcount], tfile[termcount], @@ -1379,7 +1500,7 @@ main(int argc, char *argv[]) (void) fprintf(stderr, "infocmp: couldn't open terminfo file %s.\n", tfile[termcount]); - return EXIT_FAILURE; + ExitProgram(EXIT_FAILURE); } repair_acsc(&entries[termcount].tterm); termcount++; @@ -1397,11 +1518,10 @@ main(int argc, char *argv[]) dump_termtype(&entries[0].tterm); if (initdump & 2) dump_initializers(&entries[0].tterm); - ExitProgram(EXIT_SUCCESS); } /* analyze the init strings */ - if (init_analyze) { + else if (init_analyze) { #undef CUR #define CUR entries[0].tterm. analyze_string("is1", init_1string, &entries[0].tterm); @@ -1413,60 +1533,68 @@ main(int argc, char *argv[]) analyze_string("smcup", enter_ca_mode, &entries[0].tterm); analyze_string("rmcup", exit_ca_mode, &entries[0].tterm); #undef CUR - ExitProgram(EXIT_SUCCESS); - } + } else { - /* - * Here's where the real work gets done - */ - switch (compare) { - case C_DEFAULT: - if (itrace) - (void) fprintf(stderr, - "infocmp: about to dump %s\n", - tname[0]); - (void) printf("#\tReconstructed via infocmp from file: %s\n", - tfile[0]); - len = dump_entry(&entries[0].tterm, limited, numbers, NULL); - putchar('\n'); - if (itrace) - (void) fprintf(stderr, "infocmp: length %d\n", len); - break; + /* + * Here's where the real work gets done + */ + switch (compare) { + case C_DEFAULT: + if (itrace) + (void) fprintf(stderr, + "infocmp: about to dump %s\n", + tname[0]); + (void) printf("#\tReconstructed via infocmp from file: %s\n", + tfile[0]); + dump_entry(&entries[0].tterm, + suppress_untranslatable, + limited, + numbers, + NULL); + len = show_entry(); + if (itrace) + (void) fprintf(stderr, "infocmp: length %d\n", len); + break; - case C_DIFFERENCE: - if (itrace) - (void) fprintf(stderr, "infocmp: dumping differences\n"); - (void) printf("comparing %s to %s.\n", tname[0], tname[1]); - compare_entry(compare_predicate, &entries->tterm, quiet); - break; + case C_DIFFERENCE: + if (itrace) + (void) fprintf(stderr, "infocmp: dumping differences\n"); + (void) printf("comparing %s to %s.\n", tname[0], tname[1]); + compare_entry(compare_predicate, &entries->tterm, quiet); + break; - case C_COMMON: - if (itrace) - (void) fprintf(stderr, - "infocmp: dumping common capabilities\n"); - (void) printf("comparing %s to %s.\n", tname[0], tname[1]); - compare_entry(compare_predicate, &entries->tterm, quiet); - break; + case C_COMMON: + if (itrace) + (void) fprintf(stderr, + "infocmp: dumping common capabilities\n"); + (void) printf("comparing %s to %s.\n", tname[0], tname[1]); + compare_entry(compare_predicate, &entries->tterm, quiet); + break; - case C_NAND: - if (itrace) - (void) fprintf(stderr, - "infocmp: dumping differences\n"); - (void) printf("comparing %s to %s.\n", tname[0], tname[1]); - compare_entry(compare_predicate, &entries->tterm, quiet); - break; + case C_NAND: + if (itrace) + (void) fprintf(stderr, + "infocmp: dumping differences\n"); + (void) printf("comparing %s to %s.\n", tname[0], tname[1]); + compare_entry(compare_predicate, &entries->tterm, quiet); + break; - case C_USEALL: - if (itrace) - (void) fprintf(stderr, "infocmp: dumping use entry\n"); - len = dump_entry(&entries[0].tterm, limited, numbers, use_predicate); - for (i = 1; i < termcount; i++) - len += dump_uses(tname[i], !(outform == F_TERMCAP || outform - == F_TCONVERR)); - putchar('\n'); - if (itrace) - (void) fprintf(stderr, "infocmp: length %d\n", len); - break; + case C_USEALL: + if (itrace) + (void) fprintf(stderr, "infocmp: dumping use entry\n"); + dump_entry(&entries[0].tterm, + suppress_untranslatable, + limited, + numbers, + use_predicate); + for (i = 1; i < termcount; i++) + dump_uses(tname[i], !(outform == F_TERMCAP + || outform == F_TCONVERR)); + len = show_entry(); + if (itrace) + (void) fprintf(stderr, "infocmp: length %d\n", len); + break; + } } } else if (compare == C_USEALL) (void) fprintf(stderr, "Sorry, -u doesn't work with -F\n"); @@ -1478,6 +1606,7 @@ main(int argc, char *argv[]) else file_comparison(argc - optind, argv + optind); + free(tfile); ExitProgram(EXIT_SUCCESS); } diff --git a/contrib/ncurses/progs/modules b/contrib/ncurses/progs/modules index 3d065a9..f822464 100644 --- a/contrib/ncurses/progs/modules +++ b/contrib/ncurses/progs/modules @@ -1,7 +1,7 @@ -# $Id: modules,v 1.10 2000/01/02 01:30:45 tom Exp $ +# $Id: modules,v 1.12 2005/09/25 00:54:22 tom Exp $ # Program modules (some are in ncurses lib!) ############################################################################## -# Copyright (c) 1998-2000 Free Software Foundation, Inc. # +# Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. # # # # Permission is hereby granted, free of charge, to any person obtaining a # # copy of this software and associated documentation files (the "Software"), # @@ -32,10 +32,10 @@ # @ base -clear progs $(srcdir) ../include/term.h -tic progs $(srcdir) ../include/term.h $(INCDIR)/tic.h $(srcdir)/dump_entry.h -toe progs $(srcdir) ../include/term.h $(INCDIR)/tic.h $(srcdir)/dump_entry.h -dump_entry progs $(srcdir) ../include/term.h $(INCDIR)/tic.h $(srcdir)/dump_entry.h ../include/parametrized.h $(INCDIR)/capdefaults.c termsort.c -infocmp progs $(srcdir) ../include/term.h $(INCDIR)/tic.h $(srcdir)/dump_entry.h -tput progs $(srcdir) ../include/term.h -tset progs $(srcdir) ../include/term.h +clear progs $(srcdir) $(HEADER_DEPS) +tic progs $(srcdir) $(HEADER_DEPS) transform.h $(srcdir)/dump_entry.h +toe progs $(srcdir) $(HEADER_DEPS) $(srcdir)/dump_entry.h +dump_entry progs $(srcdir) $(HEADER_DEPS) $(srcdir)/dump_entry.h ../include/parametrized.h $(INCDIR)/capdefaults.c termsort.c +infocmp progs $(srcdir) $(HEADER_DEPS) $(srcdir)/dump_entry.h +tput progs $(srcdir) $(HEADER_DEPS) transform.h termsort.c +tset progs $(srcdir) $(HEADER_DEPS) transform.h $(srcdir)/dump_entry.h ../include/termcap.h diff --git a/contrib/ncurses/progs/progs.priv.h b/contrib/ncurses/progs/progs.priv.h index 9d13b3c..eaa4c80 100644 --- a/contrib/ncurses/progs/progs.priv.h +++ b/contrib/ncurses/progs/progs.priv.h @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -27,10 +27,10 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1997,1998 * + * Author: Thomas E. Dickey 1997-on * ****************************************************************************/ /* - * $Id: progs.priv.h,v 1.27 2001/06/18 18:43:52 tom Exp $ + * $Id: progs.priv.h,v 1.30 2006/11/26 00:28:01 tom Exp $ * * progs.priv.h * @@ -52,10 +52,6 @@ #if HAVE_UNISTD_H #include <unistd.h> -#else -# if HAVE_LIBC_H -# include <libc.h> -# endif #endif #if HAVE_SYS_BSDTYPES_H @@ -71,8 +67,17 @@ #if HAVE_DIRENT_H # include <dirent.h> # define NAMLEN(dirent) strlen((dirent)->d_name) +# if defined(_FILE_OFFSET_BITS) && defined(HAVE_STRUCT_DIRENT64) +# if !defined(_LP64) && (_FILE_OFFSET_BITS == 64) +# define DIRENT struct dirent64 +# else +# define DIRENT struct dirent +# endif +# else +# define DIRENT struct dirent +# endif #else -# define dirent direct +# define DIRENT struct direct # define NAMLEN(dirent) (dirent)->d_namlen # if HAVE_SYS_NDIR_H # include <sys/ndir.h> @@ -104,6 +109,7 @@ extern int optind; #include <curses.h> #include <term_entry.h> #include <tic.h> +#include <nc_tparm.h> #include <nc_alloc.h> /* usually in <unistd.h> */ diff --git a/contrib/ncurses/progs/tic.c b/contrib/ncurses/progs/tic.c index 2fb34df..1b03f38 100644 --- a/contrib/ncurses/progs/tic.c +++ b/contrib/ncurses/progs/tic.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 * @@ -42,23 +42,48 @@ #include <sys/stat.h> #include <dump_entry.h> -#include <term_entry.h> #include <transform.h> -MODULE_ID("$Id: tic.c,v 1.96 2002/06/01 20:42:53 tom Exp $") +MODULE_ID("$Id: tic.c,v 1.131 2006/12/02 22:13:17 tom Exp $") const char *_nc_progname = "tic"; static FILE *log_fp; static FILE *tmp_fp; +static bool capdump = FALSE; /* running as infotocap? */ +static bool infodump = FALSE; /* running as captoinfo? */ static bool showsummary = FALSE; static const char *to_remove; -static int tparm_errs; -static void (*save_check_termtype) (TERMTYPE *); -static void check_termtype(TERMTYPE * tt); - -static const char usage_string[] = "[-V] [-v[n]] [-e names] [-CILNRTcfrswx1] source-file\n"; +static void (*save_check_termtype) (TERMTYPE *, bool); +static void check_termtype(TERMTYPE *tt, bool); + +static const char usage_string[] = "\ +[-e names] \ +[-o dir] \ +[-R name] \ +[-v[n]] \ +[-V] \ +[-w[n]] \ +[-\ +1\ +a\ +C\ +c\ +f\ +G\ +g\ +I\ +L\ +N\ +r\ +s\ +T\ +t\ +U\ +x\ +] \ +source-file\n"; static void cleanup(void) @@ -79,7 +104,7 @@ failed(const char *msg) { perror(msg); cleanup(); - exit(EXIT_FAILURE); + ExitProgram(EXIT_FAILURE); } static void @@ -89,24 +114,28 @@ usage(void) { "Options:", " -1 format translation output one capability per line", - " -C translate entries to termcap source form", - " -I translate entries to terminfo source form", - " -L translate entries to full terminfo source form", - " -N disable smart defaults for source translation", - " -R restrict translation to given terminfo/termcap version", - " -T remove size-restrictions on compiled description", - " -V print version", #if NCURSES_XNAMES " -a retain commented-out capabilities (sets -x also)", #endif + " -C translate entries to termcap source form", " -c check only, validate input without compiling or translating", + " -e<names> translate/compile only entries named by comma-separated list", " -f format complex strings for readability", " -G format %{number} to %'char'", " -g format %'char' to %{number}", - " -e<names> translate/compile only entries named by comma-separated list", + " -I translate entries to terminfo source form", + " -L translate entries to full terminfo source form", + " -N disable smart defaults for source translation", " -o<dir> set output directory for compiled entry writes", + " -R<name> restrict translation to given terminfo/termcap version", " -r force resolution of all use entries in source translation", " -s print summary statistics", + " -T remove size-restrictions on compiled description", +#if NCURSES_XNAMES + " -t suppress commented-out capabilities", +#endif + " -U suppress post-processing of entries", + " -V print version", " -v[n] set verbosity level", " -w[n] set format width for translation output", #if NCURSES_XNAMES @@ -123,7 +152,7 @@ usage(void) fputs(tbl[j], stderr); putc('\n', stderr); } - exit(EXIT_FAILURE); + ExitProgram(EXIT_FAILURE); } #define L_BRACE '{' @@ -297,7 +326,7 @@ stripped(char *src) while (isspace(UChar(*src))) src++; if (*src != '\0') { - char *dst = strcpy(malloc(strlen(src) + 1), src); + char *dst = strcpy((char *) malloc(strlen(src) + 1), src); size_t len = strlen(dst); while (--len != 0 && isspace(UChar(dst[len]))) dst[len] = '\0'; @@ -314,12 +343,12 @@ open_input(const char *filename) if (fp == 0) { fprintf(stderr, "%s: Can't open %s\n", _nc_progname, filename); - exit(EXIT_FAILURE); + ExitProgram(EXIT_FAILURE); } if (fstat(fileno(fp), &sb) < 0 || (sb.st_mode & S_IFMT) != S_IFREG) { fprintf(stderr, "%s: %s is not a file\n", _nc_progname, filename); - exit(EXIT_FAILURE); + ExitProgram(EXIT_FAILURE); } return fp; } @@ -378,7 +407,7 @@ make_namelist(char *src) if (showsummary) { fprintf(log_fp, "Entries that will be compiled:\n"); for (n = 0; dst[n] != 0; n++) - fprintf(log_fp, "%d:%s\n", n + 1, dst[n]); + fprintf(log_fp, "%u:%s\n", n + 1, dst[n]); } return dst; } @@ -433,9 +462,8 @@ main(int argc, char *argv[]) int width = 60; bool formatted = FALSE; /* reformat complex strings? */ + bool literal = FALSE; /* suppress post-processing? */ int numbers = 0; /* format "%'char'" to/from "%{number}" */ - bool infodump = FALSE; /* running as captoinfo? */ - bool capdump = FALSE; /* running as infotocap? */ bool forceresolve = FALSE; /* force resolution */ bool limited = TRUE; char *tversion = (char *) NULL; @@ -443,6 +471,7 @@ main(int argc, char *argv[]) const char **namelst = 0; char *outdir = (char *) NULL; bool check_only = FALSE; + bool suppress_untranslatable = FALSE; log_fp = stderr; @@ -466,7 +495,7 @@ main(int argc, char *argv[]) * be optional. */ while ((this_opt = getopt(argc, argv, - "0123456789CILNR:TVace:fGgo:rsvwx")) != EOF) { + "0123456789CILNR:TUVace:fGgo:rstvwx")) != EOF) { if (isdigit(this_opt)) { switch (last_opt) { case 'v': @@ -501,6 +530,7 @@ main(int argc, char *argv[]) break; case 'N': smart_defaults = FALSE; + literal = TRUE; break; case 'R': tversion = optarg; @@ -508,6 +538,9 @@ main(int argc, char *argv[]) case 'T': limited = FALSE; break; + case 'U': + literal = TRUE; + break; case 'V': puts(curses_version()); return EXIT_SUCCESS; @@ -542,6 +575,10 @@ main(int argc, char *argv[]) width = 0; break; #if NCURSES_XNAMES + case 't': + _nc_disable_period = FALSE; + suppress_untranslatable = TRUE; + break; case 'a': _nc_disable_period = TRUE; /* FALLTHRU */ @@ -559,8 +596,8 @@ main(int argc, char *argv[]) set_trace_level(debug_level); if (_nc_tracing) { - save_check_termtype = _nc_check_termtype; - _nc_check_termtype = check_termtype; + save_check_termtype = _nc_check_termtype2; + _nc_check_termtype2 = check_termtype; } #if !HAVE_BIG_CORE /* @@ -577,7 +614,7 @@ main(int argc, char *argv[]) (void) fprintf(stderr, "Sorry, -e can't be used without -I or -C\n"); cleanup(); - return EXIT_FAILURE; + ExitProgram(EXIT_FAILURE); } #endif /* HAVE_BIG_CORE */ @@ -589,7 +626,7 @@ main(int argc, char *argv[]) _nc_progname, _nc_progname, usage_string); - return EXIT_FAILURE; + ExitProgram(EXIT_FAILURE); } } else { if (infodump == TRUE) { @@ -620,7 +657,7 @@ main(int argc, char *argv[]) _nc_progname, usage_string); cleanup(); - return EXIT_FAILURE; + ExitProgram(EXIT_FAILURE); } } @@ -645,14 +682,16 @@ main(int argc, char *argv[]) _nc_set_writedir(outdir); #endif /* HAVE_BIG_CORE */ _nc_read_entry_source(tmp_fp, (char *) NULL, - !smart_defaults, FALSE, - (check_only || infodump || capdump) ? NULLHOOK : immedhook); + !smart_defaults || literal, FALSE, + ((check_only || infodump || capdump) + ? NULLHOOK + : immedhook)); /* do use resolution */ if (check_only || (!infodump && !capdump) || forceresolve) { - if (!_nc_resolve_uses(TRUE) && !check_only) { + if (!_nc_resolve_uses2(TRUE, literal) && !check_only) { cleanup(); - return EXIT_FAILURE; + ExitProgram(EXIT_FAILURE); } } @@ -660,7 +699,7 @@ main(int argc, char *argv[]) if (check_only && (capdump || infodump)) { for_entry_list(qp) { if (matches(namelst, qp->tterm.term_names)) { - int len = fmt_entry(&qp->tterm, NULL, TRUE, infodump, numbers); + int len = fmt_entry(&qp->tterm, NULL, FALSE, TRUE, infodump, numbers); if (len > (infodump ? MAX_TERMINFO_LENGTH : MAX_TERMCAP_LENGTH)) (void) fprintf(stderr, @@ -692,17 +731,18 @@ main(int argc, char *argv[]) _nc_set_type(_nc_first_name(qp->tterm.term_names)); (void) fseek(tmp_fp, qp->cstart, SEEK_SET); - while (j--) { + while (j-- > 0) { if (infodump) (void) putchar(fgetc(tmp_fp)); else put_translate(fgetc(tmp_fp)); } - len = dump_entry(&qp->tterm, limited, numbers, NULL); + dump_entry(&qp->tterm, suppress_untranslatable, + limited, numbers, NULL); for (j = 0; j < qp->nuses; j++) - len += dump_uses(qp->uses[j].name, !capdump); - (void) putchar('\n'); + dump_uses(qp->uses[j].name, !capdump); + len = show_entry(); if (debug_level != 0 && !limited) printf("# length=%d\n", len); } @@ -745,7 +785,7 @@ main(int argc, char *argv[]) fprintf(log_fp, "No entries written\n"); } cleanup(); - return (EXIT_SUCCESS); + ExitProgram(EXIT_SUCCESS); } /* @@ -753,13 +793,220 @@ main(int argc, char *argv[]) * references to locations in the arrays Booleans, Numbers, and Strings --- * precisely what's needed (see comp_parse.c). */ - -TERMINAL *cur_term; /* tweak to avoid linking lib_cur_term.c */ - #undef CUR #define CUR tp-> /* + * Check if the alternate character-set capabilities are consistent. + */ +static void +check_acs(TERMTYPE *tp) +{ + if (VALID_STRING(acs_chars)) { + const char *boxes = "lmkjtuvwqxn"; + char mapped[256]; + char missing[256]; + const char *p; + char *q; + + memset(mapped, 0, sizeof(mapped)); + for (p = acs_chars; *p != '\0'; p += 2) { + if (p[1] == '\0') { + _nc_warning("acsc has odd number of characters"); + break; + } + mapped[UChar(p[0])] = p[1]; + } + if (mapped[UChar('I')] && !mapped[UChar('i')]) { + _nc_warning("acsc refers to 'I', which is probably an error"); + } + for (p = boxes, q = missing; *p != '\0'; ++p) { + if (!mapped[UChar(p[0])]) { + *q++ = p[0]; + } + *q = '\0'; + } + if (*missing != '\0' && strcmp(missing, boxes)) { + _nc_warning("acsc is missing some line-drawing mapping: %s", missing); + } + } +} + +/* + * Check if the color capabilities are consistent + */ +static void +check_colors(TERMTYPE *tp) +{ + if ((max_colors > 0) != (max_pairs > 0) + || ((max_colors > max_pairs) && (initialize_pair == 0))) + _nc_warning("inconsistent values for max_colors (%d) and max_pairs (%d)", + max_colors, max_pairs); + + PAIRED(set_foreground, set_background); + PAIRED(set_a_foreground, set_a_background); + PAIRED(set_color_pair, initialize_pair); + + if (VALID_STRING(set_foreground) + && VALID_STRING(set_a_foreground) + && !_nc_capcmp(set_foreground, set_a_foreground)) + _nc_warning("expected setf/setaf to be different"); + + if (VALID_STRING(set_background) + && VALID_STRING(set_a_background) + && !_nc_capcmp(set_background, set_a_background)) + _nc_warning("expected setb/setab to be different"); + + /* see: has_colors() */ + if (VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs) + && (((set_foreground != NULL) + && (set_background != NULL)) + || ((set_a_foreground != NULL) + && (set_a_background != NULL)) + || set_color_pair)) { + if (!VALID_STRING(orig_pair) && !VALID_STRING(orig_colors)) + _nc_warning("expected either op/oc string for resetting colors"); + } +} + +static int +keypad_final(const char *string) +{ + int result = '\0'; + + if (VALID_STRING(string) + && *string++ == '\033' + && *string++ == 'O' + && strlen(string) == 1) { + result = *string; + } + + return result; +} + +static int +keypad_index(const char *string) +{ + char *test; + const char *list = "PQRSwxymtuvlqrsPpn"; /* app-keypad except "Enter" */ + int ch; + int result = -1; + + if ((ch = keypad_final(string)) != '\0') { + test = strchr(list, ch); + if (test != 0) + result = (test - list); + } + return result; +} + +/* + * Do a quick sanity-check for vt100-style keypads to see if the 5-key keypad + * is mapped inconsistently. + */ +static void +check_keypad(TERMTYPE *tp) +{ + char show[80]; + + if (VALID_STRING(key_a1) && + VALID_STRING(key_a3) && + VALID_STRING(key_b2) && + VALID_STRING(key_c1) && + VALID_STRING(key_c3)) { + char final[6]; + int list[5]; + int increase = 0; + int j, k, kk; + int last; + int test; + + final[0] = keypad_final(key_a1); + final[1] = keypad_final(key_a3); + final[2] = keypad_final(key_b2); + final[3] = keypad_final(key_c1); + final[4] = keypad_final(key_c3); + final[5] = '\0'; + + /* special case: legacy coding using 1,2,3,0,. on the bottom */ + if (!strcmp(final, "qsrpn")) + return; + + list[0] = keypad_index(key_a1); + list[1] = keypad_index(key_a3); + list[2] = keypad_index(key_b2); + list[3] = keypad_index(key_c1); + list[4] = keypad_index(key_c3); + + /* check that they're all vt100 keys */ + for (j = 0; j < 5; ++j) { + if (list[j] < 0) { + return; + } + } + + /* check if they're all in increasing order */ + for (j = 1; j < 5; ++j) { + if (list[j] > list[j - 1]) { + ++increase; + } + } + if (increase != 4) { + show[0] = '\0'; + + for (j = 0, last = -1; j < 5; ++j) { + for (k = 0, kk = -1, test = 100; k < 5; ++k) { + if (list[k] > last && + list[k] < test) { + test = list[k]; + kk = k; + } + } + last = test; + switch (kk) { + case 0: + strcat(show, " ka1"); + break; + case 1: + strcat(show, " ka3"); + break; + case 2: + strcat(show, " kb2"); + break; + case 3: + strcat(show, " kc1"); + break; + case 4: + strcat(show, " kc3"); + break; + } + } + + _nc_warning("vt100 keypad order inconsistent: %s", show); + } + + } else if (VALID_STRING(key_a1) || + VALID_STRING(key_a3) || + VALID_STRING(key_b2) || + VALID_STRING(key_c1) || + VALID_STRING(key_c3)) { + show[0] = '\0'; + if (keypad_index(key_a1) >= 0) + strcat(show, " ka1"); + if (keypad_index(key_a3) >= 0) + strcat(show, " ka3"); + if (keypad_index(key_b2) >= 0) + strcat(show, " kb2"); + if (keypad_index(key_c1) >= 0) + strcat(show, " kc1"); + if (keypad_index(key_c3) >= 0) + strcat(show, " kc3"); + if (*show != '\0') + _nc_warning("vt100 keypad map incomplete:%s", show); + } +} + +/* * Returns the expected number of parameters for the given capability. */ static int @@ -856,7 +1103,7 @@ expected_params(const char *name) * markers. */ static void -check_params(TERMTYPE * tp, const char *name, char *value) +check_params(TERMTYPE *tp, const char *name, char *value) { int expected = expected_params(name); int actual = 0; @@ -864,9 +1111,11 @@ check_params(TERMTYPE * tp, const char *name, char *value) bool params[10]; char *s = value; +#ifdef set_top_margin_parm if (!strcmp(name, "smgbp") && set_top_margin_parm == 0) expected = 2; +#endif for (n = 0; n < 10; n++) params[n] = FALSE; @@ -915,6 +1164,43 @@ skip_delay(char *s) } /* + * Skip a delay altogether, e.g., when comparing a simple string to sgr, + * the latter may have a worst-case delay on the end. + */ +static char * +ignore_delays(char *s) +{ + int delaying = 0; + + do { + switch (*s) { + case '$': + if (delaying == 0) + delaying = 1; + break; + case '<': + if (delaying == 1) + delaying = 2; + break; + case '\0': + delaying = 0; + break; + default: + if (delaying) { + s = skip_delay(s); + if (*s == '>') + ++s; + delaying = 0; + } + break; + } + if (delaying) + ++s; + } while (delaying); + return s; +} + +/* * An sgr string may contain several settings other than the one we're * interested in, essentially sgr0 + rmacs + whatever. As long as the * "whatever" is contained in the sgr string, that is close enough for our @@ -976,23 +1262,27 @@ similar_sgr(int num, char *a, char *b) a++; b++; } - return TRUE; + /* ignore delays on the end of the string */ + a = ignore_delays(a); + return ((num != 0) || (*a == 0)); } -static void -check_sgr(TERMTYPE * tp, char *zero, int num, char *cap, const char *name) +static char * +check_sgr(TERMTYPE *tp, char *zero, int num, char *cap, const char *name) { - char *test = tparm(set_attributes, - num == 1, - num == 2, - num == 3, - num == 4, - num == 5, - num == 6, - num == 7, - num == 8, - num == 9); - tparm_errs += _nc_tparm_err; + char *test; + + _nc_tparm_err = 0; + test = TPARM_9(set_attributes, + num == 1, + num == 2, + num == 3, + num == 4, + num == 5, + num == 6, + num == 7, + num == 8, + num == 9); if (test != 0) { if (PRESENT(cap)) { if (!similar_sgr(num, test, cap)) { @@ -1001,21 +1291,47 @@ check_sgr(TERMTYPE * tp, char *zero, int num, char *cap, const char *name) name, _nc_visbuf2(1, cap), num, _nc_visbuf2(2, test)); } - } else if (strcmp(test, zero)) { + } else if (_nc_capcmp(test, zero)) { _nc_warning("sgr(%d) present, but not %s", num, name); } } else if (PRESENT(cap)) { _nc_warning("sgr(%d) missing, but %s present", num, name); } + if (_nc_tparm_err) + _nc_warning("stack error in sgr(%d) string", num); + return test; } #define CHECK_SGR(num,name) check_sgr(tp, zero, num, name, #name) +#ifdef TRACE +/* + * If tic is compiled with TRACE, we'll be able to see the output from the + * DEBUG() macro. But since it doesn't use traceon(), it always goes to + * the standard error. Use this function to make it simpler to follow the + * resulting debug traces. + */ +static void +show_where(unsigned level) +{ + if (_nc_tracing >= DEBUG_LEVEL(level)) { + char my_name[256]; + _nc_get_type(my_name); + fprintf(stderr, "\"%s\", line %d, '%s' ", + _nc_get_source(), + _nc_curr_line, my_name); + } +} + +#else +#define show_where(level) /* nothing */ +#endif + /* other sanity-checks (things that we don't want in the normal * logic that reads a terminfo entry) */ static void -check_termtype(TERMTYPE * tp) +check_termtype(TERMTYPE *tp, bool literal) { bool conflict = FALSE; unsigned j, k; @@ -1026,37 +1342,39 @@ check_termtype(TERMTYPE * tp) * a given string (e.g., KEY_END and KEY_LL). But curses will only * return one (the last one assigned). */ - memset(fkeys, 0, sizeof(fkeys)); - for (j = 0; _nc_tinfo_fkeys[j].code; j++) { - char *a = tp->Strings[_nc_tinfo_fkeys[j].offset]; - bool first = TRUE; - if (!VALID_STRING(a)) - continue; - for (k = j + 1; _nc_tinfo_fkeys[k].code; k++) { - char *b = tp->Strings[_nc_tinfo_fkeys[k].offset]; - if (!VALID_STRING(b) - || fkeys[k]) + if (!(_nc_syntax == SYN_TERMCAP && capdump)) { + memset(fkeys, 0, sizeof(fkeys)); + for (j = 0; _nc_tinfo_fkeys[j].code; j++) { + char *a = tp->Strings[_nc_tinfo_fkeys[j].offset]; + bool first = TRUE; + if (!VALID_STRING(a)) continue; - if (!strcmp(a, b)) { - fkeys[j] = 1; - fkeys[k] = 1; - if (first) { - if (!conflict) { - _nc_warning("Conflicting key definitions (using the last)"); - conflict = TRUE; + for (k = j + 1; _nc_tinfo_fkeys[k].code; k++) { + char *b = tp->Strings[_nc_tinfo_fkeys[k].offset]; + if (!VALID_STRING(b) + || fkeys[k]) + continue; + if (!_nc_capcmp(a, b)) { + fkeys[j] = 1; + fkeys[k] = 1; + if (first) { + if (!conflict) { + _nc_warning("Conflicting key definitions (using the last)"); + conflict = TRUE; + } + fprintf(stderr, "... %s is the same as %s", + keyname((int) _nc_tinfo_fkeys[j].code), + keyname((int) _nc_tinfo_fkeys[k].code)); + first = FALSE; + } else { + fprintf(stderr, ", %s", + keyname((int) _nc_tinfo_fkeys[k].code)); } - fprintf(stderr, "... %s is the same as %s", - keyname(_nc_tinfo_fkeys[j].code), - keyname(_nc_tinfo_fkeys[k].code)); - first = FALSE; - } else { - fprintf(stderr, ", %s", - keyname(_nc_tinfo_fkeys[k].code)); } } + if (!first) + fprintf(stderr, "\n"); } - if (!first) - fprintf(stderr, "\n"); } for (j = 0; j < NUM_STRINGS(tp); j++) { @@ -1065,17 +1383,9 @@ check_termtype(TERMTYPE * tp) check_params(tp, ExtStrname(tp, j, strnames), a); } - /* - * Quick check for color. We could also check if the ANSI versus - * non-ANSI strings are misused. - */ - if ((max_colors > 0) != (max_pairs > 0) - || ((max_colors > max_pairs) && (initialize_pair == 0))) - _nc_warning("inconsistent values for max_colors (%d) and max_pairs (%d)", - max_colors, max_pairs); - - PAIRED(set_foreground, set_background); - PAIRED(set_a_foreground, set_a_background); + check_acs(tp); + check_colors(tp); + check_keypad(tp); /* * These may be mismatched because the terminal description relies on @@ -1085,7 +1395,7 @@ check_termtype(TERMTYPE * tp) ANDMISSING(cursor_visible, cursor_normal); if (PRESENT(cursor_visible) && PRESENT(cursor_normal) - && !strcmp(cursor_visible, cursor_normal)) + && !_nc_capcmp(cursor_visible, cursor_normal)) _nc_warning("cursor_visible is same as cursor_normal"); /* @@ -1096,39 +1406,90 @@ check_termtype(TERMTYPE * tp) ANDMISSING(change_scroll_region, save_cursor); ANDMISSING(change_scroll_region, restore_cursor); - tparm_errs = 0; if (PRESENT(set_attributes)) { - char *zero = tparm(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, 0); - - zero = strdup(zero); - CHECK_SGR(1, enter_standout_mode); - CHECK_SGR(2, enter_underline_mode); - CHECK_SGR(3, enter_reverse_mode); - CHECK_SGR(4, enter_blink_mode); - CHECK_SGR(5, enter_dim_mode); - CHECK_SGR(6, enter_bold_mode); - CHECK_SGR(7, enter_secure_mode); - CHECK_SGR(8, enter_protected_mode); - CHECK_SGR(9, enter_alt_charset_mode); - free(zero); - if (tparm_errs) - _nc_warning("stack error in sgr string"); + char *zero = 0; + + _nc_tparm_err = 0; + if (PRESENT(exit_attribute_mode)) { + zero = strdup(CHECK_SGR(0, exit_attribute_mode)); + } else { + zero = strdup(TPARM_9(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + } + if (_nc_tparm_err) + _nc_warning("stack error in sgr(0) string"); + + if (zero != 0) { + CHECK_SGR(1, enter_standout_mode); + CHECK_SGR(2, enter_underline_mode); + CHECK_SGR(3, enter_reverse_mode); + CHECK_SGR(4, enter_blink_mode); + CHECK_SGR(5, enter_dim_mode); + CHECK_SGR(6, enter_bold_mode); + CHECK_SGR(7, enter_secure_mode); + CHECK_SGR(8, enter_protected_mode); + CHECK_SGR(9, enter_alt_charset_mode); + free(zero); + } else { + _nc_warning("sgr(0) did not return a value"); + } + } else if (PRESENT(exit_attribute_mode) && + set_attributes != CANCELLED_STRING) { + if (_nc_syntax == SYN_TERMINFO) + _nc_warning("missing sgr string"); } + if (PRESENT(exit_attribute_mode)) { + char *check_sgr0 = _nc_trim_sgr0(tp); + + if (check_sgr0 == 0 || *check_sgr0 == '\0') { + _nc_warning("trimmed sgr0 is empty"); + } else { + show_where(2); + if (check_sgr0 != exit_attribute_mode) { + DEBUG(2, + ("will trim sgr0\n\toriginal sgr0=%s\n\ttrimmed sgr0=%s", + _nc_visbuf2(1, exit_attribute_mode), + _nc_visbuf2(2, check_sgr0))); + free(check_sgr0); + } else { + DEBUG(2, + ("will not trim sgr0\n\toriginal sgr0=%s", + _nc_visbuf(exit_attribute_mode))); + } + } + } +#ifdef TRACE + show_where(2); + if (!auto_right_margin) { + DEBUG(2, + ("can write to lower-right directly")); + } else if (PRESENT(enter_am_mode) && PRESENT(exit_am_mode)) { + DEBUG(2, + ("can write to lower-right by suppressing automargin")); + } else if ((PRESENT(enter_insert_mode) && PRESENT(exit_insert_mode)) + || PRESENT(insert_character) || PRESENT(parm_ich)) { + DEBUG(2, + ("can write to lower-right by using inserts")); + } else { + DEBUG(2, + ("cannot write to lower-right")); + } +#endif + /* * Some standard applications (e.g., vi) and some non-curses - * applications (e.g., jove) get confused if we have both ich/ich1 and + * applications (e.g., jove) get confused if we have both ich1 and * smir/rmir. Let's be nice and warn about that, too, even though * ncurses handles it. */ if ((PRESENT(enter_insert_mode) || PRESENT(exit_insert_mode)) - && (PRESENT(insert_character) || PRESENT(parm_ich))) { - _nc_warning("non-curses applications may be confused by ich/ich1 with smir/rmir"); + && PRESENT(parm_ich)) { + _nc_warning("non-curses applications may be confused by ich1 with smir/rmir"); } /* * Finally, do the non-verbose checks */ if (save_check_termtype != 0) - save_check_termtype(tp); + save_check_termtype(tp, literal); } diff --git a/contrib/ncurses/progs/toe.c b/contrib/ncurses/progs/toe.c index 7a75785..9c0de79 100644 --- a/contrib/ncurses/progs/toe.c +++ b/contrib/ncurses/progs/toe.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,11 +29,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 * ****************************************************************************/ /* * toe.c --- table of entries report generator - * */ #include <progs.priv.h> @@ -41,23 +41,22 @@ #include <sys/stat.h> #include <dump_entry.h> -#include <term_entry.h> -MODULE_ID("$Id: toe.c,v 1.26 2001/06/16 11:00:41 tom Exp $") +#if USE_HASHED_DB +#include <hashed_db.h> +#endif + +MODULE_ID("$Id: toe.c,v 1.41 2006/08/19 18:18:09 tom Exp $") #define isDotname(name) (!strcmp(name, ".") || !strcmp(name, "..")) const char *_nc_progname; -static int typelist(int eargc, char *eargv[], bool, - void (*)(const char *, TERMTYPE *)); -static void deschook(const char *, TERMTYPE *); - #if NO_LEAKS #undef ExitProgram +static void ExitProgram(int code) GCC_NORETURN; static void -ExitProgram(int code) GCC_NORETURN; - static void ExitProgram(int code) +ExitProgram(int code) { _nc_free_entries(_nc_head); _nc_leaks_dump_entry(); @@ -65,46 +64,289 @@ ExitProgram(int code) GCC_NORETURN; } #endif +#if USE_HASHED_DB static bool -is_a_file(char *path) +make_db_name(char *dst, const char *src, unsigned limit) { - struct stat sb; - return (stat(path, &sb) == 0 - && (sb.st_mode & S_IFMT) == S_IFREG); + static const char suffix[] = DBM_SUFFIX; + + bool result = FALSE; + unsigned lens = sizeof(suffix) - 1; + unsigned size = strlen(src); + unsigned need = lens + size; + + if (need <= limit) { + if (size >= lens + && !strcmp(src + size - lens, suffix)) + (void) strcpy(dst, src); + else + (void) sprintf(dst, "%s%s", src, suffix); + result = TRUE; + } + return result; } +#endif static bool -is_a_directory(char *path) +is_database(const char *path) { - struct stat sb; - return (stat(path, &sb) == 0 - && (sb.st_mode & S_IFMT) == S_IFDIR); + bool result = FALSE; +#if USE_DATABASE + if (_nc_is_dir_path(path) && access(path, R_OK | X_OK) == 0) { + result = TRUE; + } +#endif +#if USE_TERMCAP + if (_nc_is_file_path(path) && access(path, R_OK) == 0) { + result = TRUE; + } +#endif +#if USE_HASHED_DB + if (!result) { + char filename[PATH_MAX]; + if (_nc_is_file_path(path) && access(path, R_OK) == 0) { + result = TRUE; + } else if (make_db_name(filename, path, sizeof(filename))) { + if (_nc_is_file_path(filename) && access(filename, R_OK) == 0) { + result = TRUE; + } + } + } +#endif + return result; } -static char * -get_directory(char *path) +static void +deschook(const char *cn, TERMTYPE *tp) +/* display a description for the type */ { - if (path != 0) { - if (!is_a_directory(path) - || access(path, R_OK | X_OK) != 0) - path = 0; + const char *desc; + + if ((desc = strrchr(tp->term_names, '|')) == 0 || *++desc == '\0') + desc = "(No description)"; + + (void) printf("%-10s\t%s\n", cn, desc); +} + +#if USE_TERMCAP +static void +show_termcap(char *buffer, + void (*hook) (const char *, TERMTYPE *tp)) +{ + TERMTYPE data; + char *next = strchr(buffer, ':'); + char *last; + char *list = buffer; + + if (next) + *next = '\0'; + + last = strrchr(buffer, '|'); + if (last) + ++last; + + data.term_names = strdup(buffer); + while ((next = strtok(list, "|")) != 0) { + if (next != last) + hook(next, &data); + list = 0; + } + free(data.term_names); +} +#endif + +static int +typelist(int eargc, char *eargv[], + bool verbosity, + void (*hook) (const char *, TERMTYPE *tp)) +/* apply a function to each entry in given terminfo directories */ +{ + int i; + + for (i = 0; i < eargc; i++) { +#if USE_DATABASE + if (_nc_is_dir_path(eargv[i])) { + DIR *termdir; + DIRENT *subdir; + + if ((termdir = opendir(eargv[i])) == 0) { + (void) fflush(stdout); + (void) fprintf(stderr, + "%s: can't open terminfo directory %s\n", + _nc_progname, eargv[i]); + return (EXIT_FAILURE); + } else if (verbosity) + (void) printf("#\n#%s:\n#\n", eargv[i]); + + while ((subdir = readdir(termdir)) != 0) { + size_t len = NAMLEN(subdir); + char buf[PATH_MAX]; + char name_1[PATH_MAX]; + DIR *entrydir; + DIRENT *entry; + + strncpy(name_1, subdir->d_name, len)[len] = '\0'; + if (isDotname(name_1)) + continue; + + (void) sprintf(buf, "%s/%s/", eargv[i], name_1); + if (chdir(buf) != 0) + continue; + + entrydir = opendir("."); + while ((entry = readdir(entrydir)) != 0) { + char name_2[PATH_MAX]; + TERMTYPE lterm; + char *cn; + int status; + + len = NAMLEN(entry); + strncpy(name_2, entry->d_name, len)[len] = '\0'; + if (isDotname(name_2) || !_nc_is_file_path(name_2)) + continue; + + status = _nc_read_file_entry(name_2, <erm); + if (status <= 0) { + (void) fflush(stdout); + (void) fprintf(stderr, + "%s: couldn't open terminfo file %s.\n", + _nc_progname, name_2); + return (EXIT_FAILURE); + } + + /* only visit things once, by primary name */ + cn = _nc_first_name(lterm.term_names); + if (!strcmp(cn, name_2)) { + /* apply the selected hook function */ + (*hook) (cn, <erm); + } + _nc_free_termtype(<erm); + } + closedir(entrydir); + } + closedir(termdir); + } +#if USE_HASHED_DB + else { + DB *capdbp; + char filename[PATH_MAX]; + + if (make_db_name(filename, eargv[i], sizeof(filename))) { + if ((capdbp = _nc_db_open(filename, FALSE)) != 0) { + DBT key, data; + int code; + + code = _nc_db_first(capdbp, &key, &data); + while (code == 0) { + TERMTYPE lterm; + int used; + char *have; + char *cn; + + if (_nc_db_have_data(&key, &data, &have, &used)) { + if (_nc_read_termtype(<erm, have, used) > 0) { + /* only visit things once, by primary name */ + cn = _nc_first_name(lterm.term_names); + /* apply the selected hook function */ + (*hook) (cn, <erm); + _nc_free_termtype(<erm); + } + } + code = _nc_db_next(capdbp, &key, &data); + } + + _nc_db_close(capdbp); + } + } + } +#endif +#endif +#if USE_TERMCAP +#if HAVE_BSD_CGETENT + char *db_array[2]; + char *buffer = 0; + + if (verbosity) + (void) printf("#\n#%s:\n#\n", eargv[i]); + + db_array[0] = eargv[i]; + db_array[1] = 0; + + if (cgetfirst(&buffer, db_array)) { + show_termcap(buffer, hook); + free(buffer); + while (cgetnext(&buffer, db_array)) { + show_termcap(buffer, hook); + free(buffer); + } + } + cgetclose(); +#else + /* scan termcap text-file only */ + if (_nc_is_file_path(eargv[i])) { + char buffer[2048]; + FILE *fp; + + if ((fp = fopen(eargv[i], "r")) != 0) { + while (fgets(buffer, sizeof(buffer), fp) != 0) { + if (*buffer == '#') + continue; + if (isspace(*buffer)) + continue; + show_termcap(buffer, hook); + } + fclose(fp); + } + } +#endif +#endif } - return path; + + return (EXIT_SUCCESS); +} + +static void +usage(void) +{ + (void) fprintf(stderr, "usage: %s [-ahuUV] [-v n] [file...]\n", _nc_progname); + ExitProgram(EXIT_FAILURE); } int main(int argc, char *argv[]) { + bool all_dirs = FALSE; bool direct_dependencies = FALSE; bool invert_dependencies = FALSE; bool header = FALSE; - int i, c; + int i; int code; + int this_opt, last_opt = '?'; + int v_opt = 0; _nc_progname = _nc_rootname(argv[0]); - while ((c = getopt(argc, argv, "huv:UV")) != EOF) - switch (c) { + while ((this_opt = getopt(argc, argv, "0123456789ahuvUV")) != EOF) { + /* handle optional parameter */ + if (isdigit(this_opt)) { + switch (last_opt) { + case 'v': + v_opt = (this_opt - '0'); + break; + default: + if (isdigit(last_opt)) + v_opt *= 10; + else + v_opt = 0; + v_opt += (this_opt - '0'); + last_opt = this_opt; + } + continue; + } + switch (this_opt) { + case 'a': + all_dirs = TRUE; + break; case 'h': header = TRUE; break; @@ -112,7 +354,7 @@ main(int argc, char *argv[]) direct_dependencies = TRUE; break; case 'v': - set_trace_level(atoi(optarg)); + v_opt = 1; break; case 'U': invert_dependencies = TRUE; @@ -121,9 +363,10 @@ main(int argc, char *argv[]) puts(curses_version()); ExitProgram(EXIT_SUCCESS); default: - (void) fprintf(stderr, "usage: toe [-huUV] [-v n] [file...]\n"); - ExitProgram(EXIT_FAILURE); + usage(); } + } + set_trace_level(v_opt); if (direct_dependencies || invert_dependencies) { if (freopen(argv[optind], "r", stdin) == 0) { @@ -141,14 +384,15 @@ main(int argc, char *argv[]) if (direct_dependencies) { ENTRY *qp; - for_entry_list(qp) + for_entry_list(qp) { if (qp->nuses) { - int j; + int j; - (void) printf("%s:", _nc_first_name(qp->tterm.term_names)); - for (j = 0; j < qp->nuses; j++) - (void) printf(" %s", qp->uses[j].name); - putchar('\n'); + (void) printf("%s:", _nc_first_name(qp->tterm.term_names)); + for (j = 0; j < qp->nuses; j++) + (void) printf(" %s", qp->uses[j].name); + putchar('\n'); + } } ExitProgram(EXIT_SUCCESS); @@ -187,121 +431,71 @@ main(int argc, char *argv[]) */ if (optind < argc) { code = typelist(argc - optind, argv + optind, header, deschook); + } else if (all_dirs) { + DBDIRS state; + int offset; + int pass; + const char *path; + char **eargv = 0; + + code = EXIT_FAILURE; + for (pass = 0; pass < 2; ++pass) { + unsigned count = 0; + + _nc_first_db(&state, &offset); + while ((path = _nc_next_db(&state, &offset)) != 0) { + if (!is_database(path)) { + ; + } else if (eargv != 0) { + unsigned n; + int found = FALSE; + + /* eliminate duplicates */ + for (n = 0; n < count; ++n) { + if (!strcmp(path, eargv[n])) { + found = TRUE; + break; + } + } + if (!found) { + eargv[count] = strdup(path); + ++count; + } + } else { + ++count; + } + } + if (!pass) { + eargv = typeCalloc(char *, count + 1); + } else { + code = typelist((int) count, eargv, header, deschook); + while (count-- > 0) + free(eargv[count]); + free(eargv); + } + } } else { - char *home, *eargv[3]; - char personal[PATH_MAX]; - int j; - - j = 0; - if ((eargv[j] = get_directory(getenv("TERMINFO"))) != 0) { - j++; - } else { - if ((home = getenv("HOME")) != 0) { - (void) sprintf(personal, PRIVATE_INFO, home); - if ((eargv[j] = get_directory(personal)) != 0) - j++; + DBDIRS state; + int offset; + const char *path; + char *eargv[3]; + int count = 0; + + _nc_first_db(&state, &offset); + while ((path = _nc_next_db(&state, &offset)) != 0) { + if (is_database(path)) { + eargv[count++] = strdup(path); + break; } - if ((eargv[j] = get_directory(strcpy(personal, TERMINFO))) != 0) - j++; } - eargv[j] = 0; + eargv[count] = 0; - code = typelist(j, eargv, header, deschook); - } - - ExitProgram(code); -} + code = typelist(count, eargv, header, deschook); -static void -deschook(const char *cn, TERMTYPE * tp) -/* display a description for the type */ -{ - const char *desc; - - if ((desc = strrchr(tp->term_names, '|')) == 0) - desc = "(No description)"; - else - ++desc; - - (void) printf("%-10s\t%s\n", cn, desc); -} - -static int -typelist(int eargc, char *eargv[], - bool verbosity, - void (*hook) (const char *, TERMTYPE * tp)) -/* apply a function to each entry in given terminfo directories */ -{ - int i; - - for (i = 0; i < eargc; i++) { - DIR *termdir; - struct dirent *subdir; - - if ((termdir = opendir(eargv[i])) == 0) { - (void) fflush(stdout); - (void) fprintf(stderr, - "%s: can't open terminfo directory %s\n", - _nc_progname, eargv[i]); - return (EXIT_FAILURE); - } else if (verbosity) - (void) printf("#\n#%s:\n#\n", eargv[i]); - - while ((subdir = readdir(termdir)) != 0) { - size_t len = NAMLEN(subdir); - char buf[PATH_MAX]; - char name_1[PATH_MAX]; - DIR *entrydir; - struct dirent *entry; - - strncpy(name_1, subdir->d_name, len)[len] = '\0'; - if (isDotname(name_1)) - continue; - - (void) sprintf(buf, "%s/%s/", eargv[i], name_1); - if (chdir(buf) != 0) - continue; - - entrydir = opendir("."); - while ((entry = readdir(entrydir)) != 0) { - char name_2[PATH_MAX]; - TERMTYPE lterm; - char *cn; - int status; - - len = NAMLEN(entry); - strncpy(name_2, entry->d_name, len)[len] = '\0'; - if (isDotname(name_2) || !is_a_file(name_2)) - continue; - - status = _nc_read_file_entry(name_2, <erm); - if (status <= 0) { - (void) fflush(stdout); - (void) fprintf(stderr, - "toe: couldn't open terminfo file %s.\n", - name_2); - return (EXIT_FAILURE); - } - - /* only visit things once, by primary name */ - cn = _nc_first_name(lterm.term_names); - if (!strcmp(cn, name_2)) { - /* apply the selected hook function */ - (*hook) (cn, <erm); - } - if (lterm.term_names) { - free(lterm.term_names); - lterm.term_names = 0; - } - if (lterm.str_table) { - free(lterm.str_table); - lterm.str_table = 0; - } - } - closedir(entrydir); - } - closedir(termdir); + while (count-- > 0) + free(eargv[count]); } + _nc_last_db(); - return (EXIT_SUCCESS); + ExitProgram(code); } diff --git a/contrib/ncurses/progs/tput.c b/contrib/ncurses/progs/tput.c index 3b65d15..47e4c20 100644 --- a/contrib/ncurses/progs/tput.c +++ b/contrib/ncurses/progs/tput.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 * @@ -45,7 +45,7 @@ #endif #include <transform.h> -MODULE_ID("$Id: tput.c,v 1.30 2001/07/22 00:16:33 tom Exp $") +MODULE_ID("$Id: tput.c,v 1.38 2006/11/26 00:27:47 tom Exp $") #define PUTS(s) fputs(s, stdout) #define PUTCHAR(c) putchar(c) @@ -67,17 +67,18 @@ quit(int status, const char *fmt,...) va_list argp; va_start(argp, fmt); + fprintf(stderr, "%s: ", prg_name); vfprintf(stderr, fmt, argp); fprintf(stderr, "\n"); va_end(argp); - exit(status); + ExitProgram(status); } static void usage(void) { fprintf(stderr, "usage: %s [-V] [-S] [-T term] capname\n", prg_name); - exit(EXIT_FAILURE); + ExitProgram(EXIT_FAILURE); } static void @@ -124,6 +125,25 @@ tparm_type(const char *name) } static int +exit_code(int token, int value) +{ + int result = 99; + + switch (token) { + case BOOLEAN: + result = !value; /* TRUE=0, FALSE=1 */ + break; + case NUMBER: + result = 0; /* always zero */ + break; + case STRING: + result = value; /* 0=normal, 1=missing */ + break; + } + return result; +} + +static int tput(int argc, char *argv[]) { NCURSES_CONST char *name; @@ -157,14 +177,14 @@ tput(int argc, char *argv[]) #ifdef set_lr_margin if (set_lr_margin != 0) { - PUTS(tparm(set_lr_margin, 0, columns - 1)); + PUTS(TPARM_2(set_lr_margin, 0, columns - 1)); } else #endif #ifdef set_left_margin_parm if (set_left_margin_parm != 0 && set_right_margin_parm != 0) { - PUTS(tparm(set_left_margin_parm, 0)); - PUTS(tparm(set_right_margin_parm, columns - 1)); + PUTS(TPARM_1(set_left_margin_parm, 0)); + PUTS(TPARM_1(set_right_margin_parm, columns - 1)); } else #endif if (clear_margins != 0 @@ -178,7 +198,7 @@ tput(int argc, char *argv[]) } PUTS(set_left_margin); if (parm_right_cursor) { - PUTS(tparm(parm_right_cursor, columns - 1)); + PUTS(TPARM_1(parm_right_cursor, columns - 1)); } else { for (i = 0; i < columns - 1; i++) { PUTCHAR(' '); @@ -197,7 +217,7 @@ tput(int argc, char *argv[]) if (clear_all_tabs != 0 && set_tab != 0) { for (i = 0; i < columns - 1; i += 8) { if (parm_right_cursor) { - PUTS(tparm(parm_right_cursor, 8)); + PUTS(TPARM_1(parm_right_cursor, 8)); } else { for (j = 0; j < 8; j++) PUTCHAR(' '); @@ -211,7 +231,7 @@ tput(int argc, char *argv[]) if (is_reset && reset_file != 0) { f = fopen(reset_file, "r"); if (f == 0) { - quit(errno, "Can't open reset_file: '%s'", reset_file); + quit(4 + errno, "Can't open reset_file: '%s'", reset_file); } while ((c = fgetc(f)) != EOF) { PUTCHAR(c); @@ -220,7 +240,7 @@ tput(int argc, char *argv[]) } else if (init_file != 0) { f = fopen(init_file, "r"); if (f == 0) { - quit(errno, "Can't open init_file: '%s'", init_file); + quit(4 + errno, "Can't open init_file: '%s'", init_file); } while ((c = fgetc(f)) != EOF) { PUTCHAR(c); @@ -231,8 +251,8 @@ tput(int argc, char *argv[]) if (is_reset && reset_3string != 0) { PUTS(reset_3string); - } else if (init_2string != 0) { - PUTS(init_2string); + } else if (init_3string != 0) { + PUTS(init_3string); } FLUSH; return 0; @@ -267,17 +287,19 @@ tput(int argc, char *argv[]) #endif if ((status = tigetflag(name)) != -1) { - return (status != 0); + return exit_code(BOOLEAN, status); } else if ((status = tigetnum(name)) != CANCELLED_NUMERIC) { (void) printf("%d\n", status); - return (0); + return exit_code(NUMBER, 0); } else if ((s = tigetstr(name)) == CANCELLED_STRING) { - quit(4, "%s: unknown terminfo capability '%s'", prg_name, name); + quit(4, "unknown terminfo capability '%s'", name); } else if (s != ABSENT_STRING) { if (argc > 1) { int k; - int numbers[10]; - char *strings[10]; + int popcount; + long numbers[1 + NUM_PARM]; + char *strings[1 + NUM_PARM]; + char *p_is_s[NUM_PARM]; /* Nasty hack time. The tparm function needs to see numeric * parameters as numbers, not as pointers to their string @@ -291,32 +313,40 @@ tput(int argc, char *argv[]) if (tmp == 0 || *tmp != 0) numbers[k] = 0; } - for (k = argc; k <= 9; k++) { + for (k = argc; k <= NUM_PARM; k++) { numbers[k] = 0; strings[k] = 0; } switch (tparm_type(name)) { case Num_Str: - s = tparm(s, numbers[1], strings[2]); + s = TPARM_2(s, numbers[1], strings[2]); break; case Num_Str_Str: - s = tparm(s, numbers[1], strings[2], strings[3]); + s = TPARM_3(s, numbers[1], strings[2], strings[3]); break; default: - s = tparm(s, - numbers[1], numbers[2], numbers[3], - numbers[4], numbers[5], numbers[6], - numbers[7], numbers[8], numbers[9]); + (void) _nc_tparm_analyze(s, p_is_s, &popcount); +#define myParam(n) (p_is_s[n - 1] != 0 ? ((long) strings[n]) : numbers[n]) + s = TPARM_9(s, + myParam(1), + myParam(2), + myParam(3), + myParam(4), + myParam(5), + myParam(6), + myParam(7), + myParam(8), + myParam(9)); break; } } /* use putp() in order to perform padding */ putp(s); - return (0); + return exit_code(STRING, 0); } - return (0); + return exit_code(STRING, 1); } int @@ -327,7 +357,7 @@ main(int argc, char **argv) bool cmdline = TRUE; int c; char buf[BUFSIZ]; - int errors = 0; + int result = 0; check_aliases(prg_name = _nc_rootname(argv[0])); @@ -344,7 +374,7 @@ main(int argc, char **argv) break; case 'V': puts(curses_version()); - return EXIT_SUCCESS; + ExitProgram(EXIT_SUCCESS); default: usage(); /* NOTREACHED */ @@ -374,7 +404,7 @@ main(int argc, char **argv) if (cmdline) { if ((argc <= 0) && !is_reset && !is_init) usage(); - return tput(argc, argv); + ExitProgram(tput(argc, argv)); } while (fgets(buf, sizeof(buf), stdin) != 0) { @@ -395,9 +425,12 @@ main(int argc, char **argv) argvec[argnum] = 0; if (argnum != 0 - && tput(argnum, argvec) != 0) - errors++; + && tput(argnum, argvec) != 0) { + if (result == 0) + result = 4; /* will return value >4 */ + ++result; + } } - return errors > 0; + ExitProgram(result); } diff --git a/contrib/ncurses/progs/tset.c b/contrib/ncurses/progs/tset.c index 0276c4b..6ce3f50 100644 --- a/contrib/ncurses/progs/tset.c +++ b/contrib/ncurses/progs/tset.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 * ****************************************************************************/ /* @@ -99,11 +100,10 @@ char *ttyname(int fd); #include <sys/ptem.h> #endif -#include <curses.h> /* for bool typedef */ #include <dump_entry.h> #include <transform.h> -MODULE_ID("$Id: tset.c,v 0.52 2001/09/29 21:13:56 tom Exp $") +MODULE_ID("$Id: tset.c,v 1.67 2006/09/16 17:51:10 tom Exp $") extern char **environ; @@ -114,6 +114,9 @@ const char *_nc_progname = "tset"; static TTY mode, oldmode, original; +static bool opt_c; /* set control-chars */ +static bool opt_w; /* set window-size */ + static bool can_restore = FALSE; static bool isreset = FALSE; /* invoked as reset */ static int terasechar = -1; /* new erase character */ @@ -142,7 +145,7 @@ exit_error(void) SET_TTY(STDERR_FILENO, &original); (void) fprintf(stderr, "\n"); fflush(stderr); - exit(EXIT_FAILURE); + ExitProgram(EXIT_FAILURE); /* NOTREACHED */ } @@ -151,7 +154,7 @@ err(const char *fmt,...) { va_list ap; va_start(ap, fmt); - (void) fprintf(stderr, "tset: "); + (void) fprintf(stderr, "%s: ", _nc_progname); (void) vfprintf(stderr, fmt, ap); va_end(ap); exit_error(); @@ -162,7 +165,15 @@ static void failed(const char *msg) { char temp[BUFSIZ]; - perror(strncat(strcpy(temp, "tset: "), msg, sizeof(temp) - 10)); + unsigned len = strlen(_nc_progname) + 2; + + if (len < sizeof(temp) - 12) { + strcpy(temp, _nc_progname); + strcat(temp, ": "); + } else { + strcpy(temp, "tset: "); + } + perror(strncat(temp, msg, sizeof(temp) - strlen(temp) - 2)); exit_error(); /* NOTREACHED */ } @@ -197,6 +208,7 @@ askuser(const char *dflt) char *p; /* We can get recalled; if so, don't continue uselessly. */ + clearerr(stdin); if (feof(stdin) || ferror(stdin)) { (void) fprintf(stderr, "\n"); exit_error(); @@ -349,7 +361,7 @@ add_mapping(const char *port, char *arg) char *base = 0; copy = strdup(arg); - mapp = malloc(sizeof(MAP)); + mapp = (MAP *) malloc(sizeof(MAP)); if (copy == 0 || mapp == 0) failed("malloc"); mapp->next = 0; @@ -573,7 +585,7 @@ get_termcap_entry(char *userarg) * real entry from /etc/termcap. This prevents us from being fooled * by out of date stuff in the environment. */ - found:if ((p = getenv("TERMCAP")) != 0 && *p != '/') { + found:if ((p = getenv("TERMCAP")) != 0 && !_nc_is_abs_path(p)) { /* 'unsetenv("TERMCAP")' is not portable. * The 'environ' array is better. */ @@ -602,13 +614,13 @@ get_termcap_entry(char *userarg) while (setupterm((NCURSES_CONST char *) ttype, STDOUT_FILENO, &errret) != OK) { if (errret == 0) { - (void) fprintf(stderr, "tset: unknown terminal type %s\n", - ttype); + (void) fprintf(stderr, "%s: unknown terminal type %s\n", + _nc_progname, ttype); ttype = 0; } else { (void) fprintf(stderr, - "tset: can't initialize terminal type %s (error %d)\n", - ttype, errret); + "%s: can't initialize terminal type %s (error %d)\n", + _nc_progname, ttype, errret); ttype = 0; } ttype = askuser(ttype); @@ -626,8 +638,10 @@ get_termcap_entry(char *userarg) **************************************************************************/ /* some BSD systems have these built in, some systems are missing - * one or more definitions. The safest solution is to override. + * one or more definitions. The safest solution is to override unless the + * commonly-altered ones are defined. */ +#if !(defined(CERASE) && defined(CINTR) && defined(CKILL) && defined(CQUIT)) #undef CEOF #undef CERASE #undef CINTR @@ -638,20 +652,49 @@ get_termcap_entry(char *userarg) #undef CSTART #undef CSTOP #undef CSUSP +#endif /* control-character defaults */ +#ifndef CEOF #define CEOF CTRL('D') +#endif +#ifndef CERASE #define CERASE CTRL('H') +#endif +#ifndef CINTR #define CINTR 127 /* ^? */ +#endif +#ifndef CKILL #define CKILL CTRL('U') +#endif +#ifndef CLNEXT #define CLNEXT CTRL('v') +#endif +#ifndef CRPRNT #define CRPRNT CTRL('r') +#endif +#ifndef CQUIT #define CQUIT CTRL('\\') +#endif +#ifndef CSTART #define CSTART CTRL('Q') +#endif +#ifndef CSTOP #define CSTOP CTRL('S') +#endif +#ifndef CSUSP #define CSUSP CTRL('Z') +#endif + +#if defined(_POSIX_VDISABLE) +#define DISABLED(val) (((_POSIX_VDISABLE != -1) \ + && ((val) == _POSIX_VDISABLE)) \ + || ((val) <= 0)) +#else +#define DISABLED(val) ((int)(val) <= 0) +#endif -#define CHK(val, dft) ((int)val <= 0 ? dft : val) +#define CHK(val, dft) (DISABLED(val) ? dft : val) static bool set_tabs(void); @@ -803,13 +846,13 @@ static void set_control_chars(void) { #ifdef TERMIOS - if (mode.c_cc[VERASE] == 0 || terasechar >= 0) + if (DISABLED(mode.c_cc[VERASE]) || terasechar >= 0) mode.c_cc[VERASE] = terasechar >= 0 ? terasechar : default_erase(); - if (mode.c_cc[VINTR] == 0 || intrchar >= 0) + if (DISABLED(mode.c_cc[VINTR]) || intrchar >= 0) mode.c_cc[VINTR] = intrchar >= 0 ? intrchar : CINTR; - if (mode.c_cc[VKILL] == 0 || tkillchar >= 0) + if (DISABLED(mode.c_cc[VKILL]) || tkillchar >= 0) mode.c_cc[VKILL] = tkillchar >= 0 ? tkillchar : CKILL; #endif } @@ -935,7 +978,7 @@ set_init(void) * Return TRUE if we set any tab stops, FALSE if not. */ static bool -set_tabs() +set_tabs(void) { if (set_tab && clear_all_tabs) { int c; @@ -948,10 +991,10 @@ set_tabs() * used to try a bunch of half-clever things * with cup and hpa, for an average saving of * somewhat less than two character times per - * tab stop, less that .01 sec at 2400cps. We + * tab stop, less than .01 sec at 2400cps. We * lost all this cruft because it seemed to be * introducing some odd bugs. - * ----------12345678----------- */ + * -----------12345678----------- */ (void) fputs(" ", stderr); tputs(set_tab, 0, outc); } @@ -985,11 +1028,13 @@ report(const char *name, int which, unsigned def) (void) fprintf(stderr, "%s %s ", name, older == newer ? "is" : "set to"); + if (DISABLED(newer)) + (void) fprintf(stderr, "undef.\n"); /* * Check 'delete' before 'backspace', since the key_backspace value * is ambiguous. */ - if (newer == 0177) + else if (newer == 0177) (void) fprintf(stderr, "delete.\n"); else if ((p = key_backspace) != 0 && newer == (unsigned char) p[0] @@ -997,9 +1042,9 @@ report(const char *name, int which, unsigned def) (void) fprintf(stderr, "backspace.\n"); else if (newer < 040) { newer ^= 0100; - (void) fprintf(stderr, "control-%c (^%c).\n", newer, newer); + (void) fprintf(stderr, "control-%c (^%c).\n", UChar(newer), UChar(newer)); } else - (void) fprintf(stderr, "%c.\n", newer); + (void) fprintf(stderr, "%c.\n", UChar(newer)); } #endif @@ -1038,10 +1083,28 @@ obsolete(char **argv) } static void -usage(const char *pname) +usage(void) { - (void) fprintf(stderr, - "usage: %s [-IQVrs] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]", pname); + static const char *tbl[] = + { + "" + ,"Options:" + ," -c set control characters" + ," -e ch erase character" + ," -I no initialization strings" + ," -i ch interrupt character" + ," -k ch kill character" + ," -m mapping map identifier to type" + ," -Q do not output control key settings" + ," -r display term on stderr" + ," -s output TERM set command" + ," -V print curses-version" + ," -w set window-size" + }; + unsigned n; + (void) fprintf(stderr, "Usage: %s [options] [terminal]\n", _nc_progname); + for (n = 0; n < sizeof(tbl) / sizeof(tbl[0]); ++n) + fprintf(stderr, "%s\n", tbl[n]); exit_error(); /* NOTREACHED */ } @@ -1064,28 +1127,12 @@ main(int argc, char **argv) const char *p; const char *ttype; - if (GET_TTY(STDERR_FILENO, &mode) < 0) - failed("standard error"); - can_restore = TRUE; - original = oldmode = mode; -#ifdef TERMIOS - ospeed = cfgetospeed(&mode); -#else - ospeed = mode.sg_ospeed; -#endif - - p = _nc_rootname(*argv); - if (!strcmp(p, PROG_RESET)) { - isreset = TRUE; - reset_mode(); - } - obsolete(argv); noinit = noset = quiet = Sflag = sflag = showterm = 0; - while ((ch = getopt(argc, argv, "a:d:e:Ii:k:m:np:qQSrsV")) != EOF) { + while ((ch = getopt(argc, argv, "a:cd:e:Ii:k:m:np:qQSrsVw")) != EOF) { switch (ch) { - case 'q': /* display term only */ - noset = 1; + case 'c': /* set control-chars */ + opt_c = TRUE; break; case 'a': /* OBSOLETE: map identifier to type */ add_mapping("arpanet", optarg); @@ -1116,28 +1163,54 @@ main(int argc, char **argv) case 'Q': /* don't output control key settings */ quiet = 1; break; - case 'S': /* OBSOLETE: output TERM & TERMCAP */ - Sflag = 1; + case 'q': /* display term only */ + noset = 1; break; case 'r': /* display term on stderr */ showterm = 1; break; + case 'S': /* OBSOLETE: output TERM & TERMCAP */ + Sflag = 1; + break; case 's': /* output TERM set command */ sflag = 1; break; - case 'V': + case 'V': /* print curses-version */ puts(curses_version()); - return EXIT_SUCCESS; + ExitProgram(EXIT_SUCCESS); + case 'w': /* set window-size */ + opt_w = TRUE; + break; case '?': default: - usage(*argv); + usage(); } } + + _nc_progname = _nc_rootname(*argv); argc -= optind; argv += optind; if (argc > 1) - usage(*argv); + usage(); + + if (!opt_c && !opt_w) + opt_c = opt_w = TRUE; + + if (GET_TTY(STDERR_FILENO, &mode) < 0) + failed("standard error"); + can_restore = TRUE; + original = oldmode = mode; +#ifdef TERMIOS + ospeed = cfgetospeed(&mode); +#else + ospeed = mode.sg_ospeed; +#endif + + if (!strcmp(_nc_progname, PROG_RESET)) { + isreset = TRUE; + reset_mode(); + } ttype = get_termcap_entry(*argv); @@ -1146,24 +1219,28 @@ main(int argc, char **argv) tlines = lines; #if defined(TIOCGWINSZ) && defined(TIOCSWINSZ) - /* Set window size */ - (void) ioctl(STDERR_FILENO, TIOCGWINSZ, &win); - if (win.ws_row == 0 && win.ws_col == 0 && - tlines > 0 && tcolumns > 0) { - win.ws_row = tlines; - win.ws_col = tcolumns; - (void) ioctl(STDERR_FILENO, TIOCSWINSZ, &win); + if (opt_w) { + /* Set window size */ + (void) ioctl(STDERR_FILENO, TIOCGWINSZ, &win); + if (win.ws_row == 0 && win.ws_col == 0 && + tlines > 0 && tcolumns > 0) { + win.ws_row = tlines; + win.ws_col = tcolumns; + (void) ioctl(STDERR_FILENO, TIOCSWINSZ, &win); + } } #endif - set_control_chars(); - set_conversions(); + if (opt_c) { + set_control_chars(); + set_conversions(); - if (!noinit) - set_init(); + if (!noinit) + set_init(); - /* Set the modes if they've changed. */ - if (memcmp(&mode, &oldmode, sizeof(mode))) { - SET_TTY(STDERR_FILENO, &mode); + /* Set the modes if they've changed. */ + if (memcmp(&mode, &oldmode, sizeof(mode))) { + SET_TTY(STDERR_FILENO, &mode); + } } } @@ -1182,8 +1259,8 @@ main(int argc, char **argv) #ifdef TERMIOS if (!quiet) { report("Erase", VERASE, CERASE); - report("Kill", VKILL, CINTR); - report("Interrupt", VINTR, CKILL); + report("Kill", VKILL, CKILL); + report("Interrupt", VINTR, CINTR); } #endif } @@ -1192,19 +1269,21 @@ main(int argc, char **argv) err("The -S option is not supported under terminfo."); if (sflag) { + int len; + char *var; + char *leaf; /* * Figure out what shell we're using. A hack, we look for an * environmental variable SHELL ending in "csh". */ - if ((p = getenv("SHELL")) != 0 - && !strcmp(p + strlen(p) - 3, "csh")) + if ((var = getenv("SHELL")) != 0 + && ((len = strlen(leaf = _nc_basename(var))) >= 3) + && !strcmp(leaf + len - 3, "csh")) p = "set noglob;\nsetenv TERM %s;\nunset noglob;\n"; else p = "TERM=%s;\n"; (void) printf(p, ttype); } - return EXIT_SUCCESS; + ExitProgram(EXIT_SUCCESS); } - -/* tset.c ends here */ |