Update to ncurses-6.0
Change-Id: I98ab2ea8a5e13cca9f8b7cf6277b9b14a4da4299
diff --git a/progs/MKtermsort.sh b/progs/MKtermsort.sh
index 2247f14..9f5db27 100755
--- a/progs/MKtermsort.sh
+++ b/progs/MKtermsort.sh
@@ -1,10 +1,10 @@
#!/bin/sh
-# $Id: MKtermsort.sh,v 1.10 2008/07/12 20:22:54 tom Exp $
+# $Id: MKtermsort.sh,v 1.11 2015/07/04 23:59:54 tom Exp $
#
# MKtermsort.sh -- generate indirection vectors for the various sort methods
#
##############################################################################
-# Copyright (c) 1998-2003,2008 Free Software Foundation, Inc. #
+# Copyright (c) 1998-2008,2015 Free 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"), #
@@ -139,24 +139,30 @@
echo "static const bool bool_from_termcap[] = {";
$AWK <$DATA '
-$3 == "bool" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */";}
-$3 == "bool" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */";}
+BEGIN { count = 0; valid = 0; }
+$3 == "bool" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */"; count++; }
+$3 == "bool" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */"; valid = count++; }
+END { printf "#define OK_bool_from_termcap %d\n", valid; }
'
echo "};";
echo "";
echo "static const bool num_from_termcap[] = {";
$AWK <$DATA '
-$3 == "num" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */";}
-$3 == "num" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */";}
+BEGIN { count = 0; valid = 0; }
+$3 == "num" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */"; count++; }
+$3 == "num" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */"; valid = count++; }
+END { printf "#define OK_num_from_termcap %d\n", valid; }
'
echo "};";
echo "";
echo "static const bool str_from_termcap[] = {";
$AWK <$DATA '
-$3 == "str" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */";}
-$3 == "str" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */";}
+BEGIN { count = 0; valid = 0; }
+$3 == "str" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */"; count++; }
+$3 == "str" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */"; valid = count++; }
+END { printf "#define OK_str_from_termcap %d\n", valid; }
'
echo "};";
echo "";
diff --git a/progs/Makefile.in b/progs/Makefile.in
index 886fd5b..663a5a0 100644
--- a/progs/Makefile.in
+++ b/progs/Makefile.in
@@ -1,6 +1,6 @@
-# $Id: Makefile.in,v 1.79 2008/09/07 13:58:55 tom Exp $
+# $Id: Makefile.in,v 1.95 2015/08/05 09:24:06 tom Exp $
##############################################################################
-# Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. #
+# Copyright (c) 1998-2014,2015 Free 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"), #
@@ -42,7 +42,8 @@
# turn off _all_ suffix rules; we'll generate our own
.SUFFIXES:
-SHELL = /bin/sh
+SHELL = @SHELL@
+VPATH = @srcdir@
THIS = Makefile
CF_MFLAGS = @cf_cv_makeflags@
@@ -60,9 +61,16 @@
bindir = @bindir@
libdir = @libdir@
includedir = @includedir@
+datarootdir = @datarootdir@
datadir = @datadir@
+includesubdir = @includesubdir@
+
+INCLUDEDIR = $(DESTDIR)$(includedir)$(includesubdir)
+
+PACKAGE = @PACKAGE@
LIBTOOL = @LIBTOOL@
+LIBTOOL_OPTS = @LIBTOOL_OPTS@
LIBTOOL_CLEAN = @LIB_CLEAN@
LIBTOOL_COMPILE = @LIB_COMPILE@
LIBTOOL_LINK = @LIB_LINK@
@@ -76,12 +84,15 @@
AWK = @AWK@
LN_S = @LN_S@
+CTAGS = @CTAGS@
+ETAGS = @ETAGS@
+
CC = @CC@
CPP = @CPP@
CFLAGS = @CFLAGS@
INCDIR = $(top_srcdir)/include
-CPPFLAGS = -I../progs -I$(srcdir) -DHAVE_CONFIG_H @CPPFLAGS@
+CPPFLAGS = -DHAVE_CONFIG_H @CPPFLAGS@
CCFLAGS = $(CPPFLAGS) $(CFLAGS)
@@ -100,20 +111,21 @@
LD = @LD@
LINK = @LINK_PROGS@ $(LIBTOOL_LINK)
LDFLAGS = @EXTRA_LDFLAGS@ @LDFLAGS@
+RPATH_LIST = @RPATH_LIST@
LDFLAGS_LIBTOOL = $(LDFLAGS) $(CFLAGS_LIBTOOL)
LDFLAGS_NORMAL = $(LDFLAGS) $(CFLAGS_NORMAL)
LDFLAGS_DEBUG = $(LDFLAGS) $(CFLAGS_DEBUG)
-LDFLAGS_PROFILE = $(LDFLAGS) $(CFLAGS_PROFILE)
+LDFLAGS_PROFILE = $(LDFLAGS) $(CFLAGS_PROFILE)
LDFLAGS_SHARED = $(LDFLAGS) $(CFLAGS_SHARED) @LD_SHARED_OPTS@
LDFLAGS_DEFAULT = $(LDFLAGS_@DFT_UPR_MODEL@)
-LIBS_TIC = @LDFLAGS_STATIC@ @TICS_ARGS@ @TINFO_ARGS@ @LDFLAGS_SHARED@ @LD_MODEL@ @LIBS@
-LDFLAGS_TIC = $(LDFLAGS_@DFT_UPR_MODEL@) $(LIBS_TIC)
+LIBS_TIC = @TINFO_LDFLAGS@ @LDFLAGS_STATIC@ @TICS_LIBS@ @TINFO_LIBS@ @LDFLAGS_SHARED@ @LD_MODEL@ @LIBS@
+LDFLAGS_TIC = @TICS_LDFLAGS@ $(LDFLAGS_@DFT_UPR_MODEL@) $(LIBS_TIC)
-LIBS_TINFO = @LDFLAGS_STATIC@ @TINFO_ARGS@ @LDFLAGS_SHARED@ @LD_MODEL@ @LIBS@
-LDFLAGS_TINFO = $(LDFLAGS_@DFT_UPR_MODEL@) $(LIBS_TINFO)
+LIBS_TINFO = @LDFLAGS_STATIC@ @TINFO_LIBS@ @LDFLAGS_SHARED@ @LD_MODEL@ @LIBS@
+LDFLAGS_TINFO = @TINFO_LDFLAGS@ $(LDFLAGS_@DFT_UPR_MODEL@) $(LIBS_TINFO)
LINT = @LINT@
LINT_OPTS = @LINT_OPTS@
@@ -124,7 +136,7 @@
transform.h
# tic relies on direct access to the terminfo database
-GET_PROGS = infocmp$x clear$x tput$x tset$x toe$x
+GET_PROGS = infocmp$x clear$x tabs$x tput$x tset$x toe$x
PUT_PROGS = @MAKE_TERMINFO@ tic$x
PROGS = $(PUT_PROGS) $(GET_PROGS)
@@ -159,6 +171,7 @@
actual_infotocap = `echo infotocap$x| $(TRANSFORM)`
actual_init = `echo init$x| $(TRANSFORM)`
actual_reset = `echo reset$x| $(TRANSFORM)`
+actual_tabs = `echo tabs$x| $(TRANSFORM)`
actual_tic = `echo tic$x| $(TRANSFORM)`
actual_toe = `echo toe$x| $(TRANSFORM)`
actual_tput = `echo tput$x| $(TRANSFORM)`
@@ -171,10 +184,16 @@
define_reset = `echo reset| $(TRANSFORM)`
transform.h :
- echo "#define PROG_CAPTOINFO \"$(define_captoinfo)\"" >$@
- echo "#define PROG_INFOTOCAP \"$(define_infotocap)\"" >>$@
- echo "#define PROG_RESET \"$(define_reset)\"" >>$@
- echo "#define PROG_INIT \"$(define_init)\"" >>$@
+ echo "#ifndef __TRANSFORM_H" >$@
+ echo "#define __TRANSFORM_H 1" >>$@
+ echo "#include <progs.priv.h>" >>$@
+ echo "extern bool same_program(const char *, const char *);" >>$@
+ -$(SHELL) -c 'if test -n "$x" ; then echo "#define SUFFIX_IGNORED \"$x\"">>$@; fi'
+ echo "#define PROG_CAPTOINFO \"$(define_captoinfo)\"" >>$@
+ echo "#define PROG_INFOTOCAP \"$(define_infotocap)\"" >>$@
+ echo "#define PROG_RESET \"$(define_reset)\"" >>$@
+ echo "#define PROG_INIT \"$(define_init)\"" >>$@
+ echo "#endif /* __TRANSFORM_H */" >>$@
install.progs: $(AUTO_SRC) $(PROGS) $(DESTDIR)$(bindir)
@MAKE_TERMINFO@ $(LIBTOOL_INSTALL) $(INSTALL_PROG) tic$x $(DESTDIR)$(bindir)/$(actual_tic)
@@ -187,6 +206,7 @@
@MAKE_TERMINFO@ (cd $(DESTDIR)$(bindir) && $(LN_S) $(actual_tic) $(actual_captoinfo))
$(LIBTOOL_INSTALL) $(INSTALL_PROG) infocmp$x $(DESTDIR)$(bindir)/$(actual_infocmp)
$(LIBTOOL_INSTALL) $(INSTALL_PROG) clear$x $(DESTDIR)$(bindir)/$(actual_clear)
+ $(LIBTOOL_INSTALL) $(INSTALL_PROG) tabs$x $(DESTDIR)$(bindir)/$(actual_tabs)
$(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)"
@@ -200,12 +220,13 @@
@MAKE_TERMINFO@ -@rm -f $(DESTDIR)$(bindir)/$(actual_infotocap)
-@$(LIBTOOL_CLEAN) rm -f $(DESTDIR)$(bindir)/$(actual_infocmp)
-@$(LIBTOOL_CLEAN) rm -f $(DESTDIR)$(bindir)/$(actual_clear)
+ -@$(LIBTOOL_CLEAN) rm -f $(DESTDIR)$(bindir)/$(actual_tabs)
-@$(LIBTOOL_CLEAN) rm -f $(DESTDIR)$(bindir)/$(actual_tput)
-@$(LIBTOOL_CLEAN) rm -f $(DESTDIR)$(bindir)/$(actual_tset)
-@rm -f $(DESTDIR)$(bindir)/$(actual_reset)
$(DESTDIR)$(bindir) :
- sh $(srcdir)/../mkdirs.sh $@
+ mkdir -p $@
#
# Utilities normally built by make all start here
@@ -213,63 +234,74 @@
DEPS_TIC = \
$(MODEL)/tic$o \
- $(MODEL)/dump_entry$o
+ $(MODEL)/dump_entry$o \
+ $(MODEL)/tparm_type$o \
+ $(MODEL)/transform$o
tic$x: $(DEPS_TIC) $(DEPS_CURSES) transform.h
- @ECHO_LINK@ $(LINK) $(DEPS_TIC) $(LDFLAGS_TIC) -o $@
+ @ECHO_LD@ $(LINK) $(DEPS_TIC) $(LDFLAGS_TIC) -o $@
DEPS_TOE = \
$(MODEL)/toe$o
toe$x: $(DEPS_TOE) $(DEPS_CURSES)
- @ECHO_LINK@ $(LINK) $(DEPS_TOE) $(LDFLAGS_TIC) -o $@
+ @ECHO_LD@ $(LINK) $(DEPS_TOE) $(LDFLAGS_TIC) -o $@
DEPS_CLEAR = \
$(MODEL)/clear$o
clear$x: $(DEPS_CLEAR) $(DEPS_CURSES)
- @ECHO_LINK@ $(LINK) $(DEPS_CLEAR) $(LDFLAGS_TINFO) -o $@
+ @ECHO_LD@ $(LINK) $(DEPS_CLEAR) $(LDFLAGS_TINFO) -o $@
+
+DEPS_TABS = \
+ $(MODEL)/tabs$o
+
+tabs$x: $(DEPS_TABS) $(DEPS_TABS)
+ @ECHO_LD@ $(LINK) $(DEPS_TABS) $(LDFLAGS_TINFO) -o $@
DEPS_TPUT = \
- $(MODEL)/tput$o
+ $(MODEL)/tput$o \
+ $(MODEL)/tparm_type$o \
+ $(MODEL)/transform$o
tput$x: $(DEPS_TPUT) $(DEPS_CURSES) transform.h
- @ECHO_LINK@ $(LINK) $(DEPS_TPUT) $(LDFLAGS_TINFO) -o $@
+ @ECHO_LD@ $(LINK) $(DEPS_TPUT) $(LDFLAGS_TINFO) -o $@
DEPS_INFOCMP = \
$(MODEL)/infocmp$o \
$(MODEL)/dump_entry$o
infocmp$x: $(DEPS_INFOCMP) $(DEPS_CURSES)
- @ECHO_LINK@ $(LINK) $(DEPS_INFOCMP) $(LDFLAGS_TIC) -o $@
+ @ECHO_LD@ $(LINK) $(DEPS_INFOCMP) $(LDFLAGS_TIC) -o $@
DEPS_TSET = \
- $(MODEL)/tset$o
+ $(MODEL)/tset$o \
+ $(MODEL)/transform$o
tset$x: $(DEPS_TSET) $(DEPS_CURSES) transform.h
- @ECHO_LINK@ $(LINK) $(DEPS_TSET) $(LDFLAGS_TINFO) -o $@
+ @ECHO_LD@ $(LINK) $(DEPS_TSET) $(LDFLAGS_TINFO) -o $@
termsort.c: $(srcdir)/MKtermsort.sh
- sh $(srcdir)/MKtermsort.sh $(AWK) $(srcdir)/../include/@TERMINFO_CAPS@ >$@
+ $(SHELL) $(srcdir)/MKtermsort.sh $(AWK) $(srcdir)/../include/@TERMINFO_CAPS@ >$@
#
# Utility productions start here
#
tags:
- ctags *.[ch]
+ $(CTAGS) *.[ch]
@MAKE_UPPER_TAGS@TAGS:
-@MAKE_UPPER_TAGS@ etags *.[ch]
+@MAKE_UPPER_TAGS@ $(ETAGS) *.[ch]
mostlyclean ::
-rm -f core tags TAGS *~ *.bak *.i *.ln *.atac trace
clean :: mostlyclean
- -sh -c "if test -n '$x' ; then $(MAKE) clean x=''; fi"
+ -$(SHELL) -c "if test -n '$x' ; then $(MAKE) clean x=''; fi"
-rm -f $(AUTO_SRC)
-rm -f $(PROGS)
- -rm -rf .libs
+ -rm -rf .libs *.dSYM
distclean :: clean
-rm -f Makefile
@@ -289,6 +321,7 @@
@MAKE_TERMINFO@ $(LINT) $(LINT_OPTS) $(CPPFLAGS) $(srcdir)/toe.c $(srcdir)/dump_entry.c $(LINT_LIBS)
$(LINT) $(LINT_OPTS) $(CPPFLAGS) $(srcdir)/clear.c $(LINT_LIBS)
$(LINT) $(LINT_OPTS) $(CPPFLAGS) $(srcdir)/infocmp.c $(srcdir)/dump_entry.c $(LINT_LIBS)
+ $(LINT) $(LINT_OPTS) $(CPPFLAGS) $(srcdir)/tabs.c $(LINT_LIBS)
$(LINT) $(LINT_OPTS) $(CPPFLAGS) $(srcdir)/tput.c $(LINT_LIBS)
$(LINT) $(LINT_OPTS) $(CPPFLAGS) $(srcdir)/tset.c $(srcdir)/dump_entry.c $(LINT_LIBS)
diff --git a/progs/capconvert b/progs/capconvert
index 8199bbf..eb382e0 100755
--- a/progs/capconvert
+++ b/progs/capconvert
@@ -1,6 +1,6 @@
#!/bin/sh
##############################################################################
-# Copyright (c) 1998,2006 Free Software Foundation, Inc. #
+# Copyright (c) 1998-2006,2011 Free 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"), #
@@ -26,7 +26,7 @@
# use or other dealings in this Software without prior written #
# authorization. #
##############################################################################
-# $Id: capconvert,v 1.4 2006/04/22 21:46:17 tom Exp $
+# $Id: capconvert,v 1.5 2011/11/12 23:28:07 Robert.Millan Exp $
#
# capconvert -- automated conversion from termcap to terminfo
#
@@ -77,16 +77,18 @@
# Assumes the terminfo master covers all canned terminal types
exit;
fi
- if test "$TERM" = "xterm"
- then
+ case $TERM in
+ xterm | xterm-*)
echo "You are running xterm, which usually sets TERMCAP itself."
echo "We can ignore this, because terminfo knows about xterm."
echo "So you will just use the system-wide terminfo tree."
- exit;
- else
+ exit
+ ;;
+ *)
echo "We will have to make a local one for you anyway, to capture the effect"
echo "of your TERMCAP variable."
- fi
+ ;;
+ esac
else
echo "No system-wide terminfo tree. We will make you a local one."
fi
@@ -109,7 +111,7 @@
for x in $PATH .
do
if test $OPT $x/tic
- then
+ then
TIC=$x/tic
break
fi
@@ -141,7 +143,7 @@
then
echo "It appears you already have a private terminfo directory"
echo "at $HOME/.terminfo; this seems odd, because TERMINFO"
- echo "is not defined. I am not going to second-guess this -- if you"
+ echo "is not defined. I am not going to second-guess this -- if you"
echo "really want me to try auto-configuring for you, remove or"
echo "rename $HOME/terminfo and run me again."
exit;
@@ -214,7 +216,7 @@
#
echo "You now have a private tree under $HOME/.terminfo;"
echo "the ncurses library will automatically read from it,"
-echo "and ncurses tic will automatically compile entries to it."
+echo "and ncurses tic will automatically compile entries to it."
# We're done unless user has a .termcap file or equivalent named by TERMCAP
if test -z "$TERMCAP"
@@ -235,7 +237,7 @@
echo "Done."
echo "Note that editing $HOME/.termcap will no longer change the data curses sees."
elif test -f "$TERMCAP"
-then
+then
echo "Your TERMCAP names the file $TERMCAP. I will compile that."
eval $TIC $TERMCAP
echo "Done."
diff --git a/progs/clear b/progs/clear
deleted file mode 100755
index 2e8d121..0000000
--- a/progs/clear
+++ /dev/null
Binary files differ
diff --git a/progs/clear.c b/progs/clear.c
index 9f5a543..4ac503e 100644
--- a/progs/clear.c
+++ b/progs/clear.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2007,2013 Free 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 @@
#define USE_LIBTINFO
#include <progs.priv.h>
-MODULE_ID("$Id: clear.c,v 1.11 2007/10/13 22:16:02 tom Exp $")
+MODULE_ID("$Id: clear.c,v 1.13 2013/06/22 22:20:54 tom Exp $")
static int
putch(int c)
@@ -52,7 +52,15 @@
int argc GCC_UNUSED,
char *argv[]GCC_UNUSED)
{
+ char *E3;
+
setupterm((char *) 0, STDOUT_FILENO, (int *) 0);
+
+ /* Clear the scrollback buffer if possible. */
+ E3 = tigetstr("E3");
+ if (E3)
+ (void) tputs(E3, lines > 0 ? lines : 1, putch);
+
ExitProgram((tputs(clear_screen, lines > 0 ? lines : 1, putch) == ERR)
? EXIT_FAILURE
: EXIT_SUCCESS);
diff --git a/progs/dump_entry.c b/progs/dump_entry.c
index bd24220..d59a925 100644
--- a/progs/dump_entry.c
+++ b/progs/dump_entry.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2014,2015 Free 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.88 2008/08/04 12:36:12 tom Exp $")
+MODULE_ID("$Id: dump_entry.c,v 1.118 2015/07/07 08:06:39 Werner.Fink Exp $")
#define INDENT 8
#define DISCARD(string) string = ABSENT_STRING
@@ -57,9 +57,11 @@
static int outform; /* output format to use */
static int sortmode; /* sort mode to use */
static int width = 60; /* max line width for listings */
+static int height = 65535; /* max number of lines for listings */
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 bool checking; /* true if we are checking for tic */
static char *save_sgr;
@@ -72,7 +74,7 @@
static NCURSES_CONST char *const *num_names;
static NCURSES_CONST char *const *str_names;
-static const char *separator, *trailer;
+static const char *separator = "", *trailer = "";
/* cover various ports and variants of terminfo */
#define V_ALLCAPS 0 /* all capabilities (SVr4, XSI, ncurses) */
@@ -99,6 +101,15 @@
#define StrIndirect(j) ((sortmode == S_NOSORT) ? (j) : str_indirect[j])
#endif
+static void failed(const char *) GCC_NORETURN;
+
+static void
+failed(const char *s)
+{
+ perror(s);
+ ExitProgram(EXIT_FAILURE);
+}
+
static void
strncpy_DYN(DYNBUF * dst, const char *src, size_t need)
{
@@ -106,6 +117,8 @@
if (want > dst->size) {
dst->size += (want + 1024); /* be generous */
dst->text = typeRealloc(char, dst->size, dst->text);
+ if (dst->text == 0)
+ failed("strncpy_DYN");
}
(void) strncpy(dst->text + dst->used, src, need);
dst->used += need;
@@ -143,17 +156,17 @@
#endif
#define NameTrans(check,result) \
- if (OkIndex(np->nte_index, check) \
+ if ((np->nte_index <= OK_ ## check) \
&& check[np->nte_index]) \
return (result[np->nte_index])
NCURSES_CONST char *
nametrans(const char *name)
-/* translate a capability name from termcap to terminfo */
+/* translate a capability name to termcap from terminfo */
{
const struct name_table_entry *np;
- if ((np = _nc_find_entry(name, _nc_get_hash_table(0))) != 0)
+ if ((np = _nc_find_entry(name, _nc_get_hash_table(0))) != 0) {
switch (np->nte_type) {
case BOOLEAN:
NameTrans(bool_from_termcap, boolcodes);
@@ -167,17 +180,26 @@
NameTrans(str_from_termcap, strcodes);
break;
}
+ }
return (0);
}
void
-dump_init(const char *version, int mode, int sort, int twidth, int traceval,
- bool formatted)
+dump_init(const char *version,
+ int mode,
+ int sort,
+ int twidth,
+ int theight,
+ unsigned traceval,
+ bool formatted,
+ bool check)
/* set up for entry display */
{
width = twidth;
+ height = theight;
pretty = formatted;
+ checking = check;
/* versions */
if (version == 0)
@@ -201,7 +223,7 @@
bool_names = boolnames;
num_names = numnames;
str_names = strnames;
- separator = twidth ? ", " : ",";
+ separator = (twidth > 0 && theight > 1) ? ", " : ",";
trailer = "\n\t";
break;
@@ -209,7 +231,7 @@
bool_names = boolfnames;
num_names = numfnames;
str_names = strfnames;
- separator = twidth ? ", " : ",";
+ separator = (twidth > 0 && theight > 1) ? ", " : ",";
trailer = "\n\t";
break;
@@ -291,7 +313,11 @@
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))
+#define FNKEY(i) \
+ (((i) >= STR_IDX(key_f0) && \
+ (i) <= STR_IDX(key_f9)) || \
+ ((i) >= STR_IDX(key_f11) && \
+ (i) <= STR_IDX(key_f63)))
/*
* If we configure with a different Caps file, the offsets into the arrays
@@ -393,8 +419,8 @@
static void
wrap_concat(const char *src)
{
- unsigned need = strlen(src);
- unsigned want = strlen(separator) + need;
+ size_t need = strlen(src);
+ size_t want = strlen(separator) + need;
if (column > INDENT
&& column + (int) want > width) {
@@ -445,10 +471,10 @@
int n;
for (n = 0; n < level; n++)
- strncpy_DYN(buffer, "\t", 1);
+ strncpy_DYN(buffer, "\t", (size_t) 1);
}
-static bool
+bool
has_params(const char *src)
{
bool result = FALSE;
@@ -458,9 +484,9 @@
bool params = FALSE;
for (n = 0; n < len - 1; ++n) {
- if (!strncmp(src + n, "%p", 2)) {
+ if (!strncmp(src + n, "%p", (size_t) 2)) {
params = TRUE;
- } else if (!strncmp(src + n, "%;", 2)) {
+ } else if (!strncmp(src + n, "%;", (size_t) 2)) {
ifthen = TRUE;
result = params;
break;
@@ -473,7 +499,7 @@
}
static char *
-fmt_complex(char *src, int level)
+fmt_complex(TERMTYPE *tterm, const char *capability, char *src, int level)
{
bool percent = FALSE;
bool params = has_params(src);
@@ -482,7 +508,7 @@
switch (*src) {
case '\\':
percent = FALSE;
- strncpy_DYN(&tmpbuf, src++, 1);
+ strncpy_DYN(&tmpbuf, src++, (size_t) 1);
break;
case '%':
percent = TRUE;
@@ -496,26 +522,29 @@
/* 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, 1);
+ strncpy_DYN(&tmpbuf, "%", (size_t) 1);
+ strncpy_DYN(&tmpbuf, src, (size_t) 1);
src++;
params = has_params(src);
if (!params && *src != '\0' && *src != '%') {
- strncpy_DYN(&tmpbuf, "\n", 1);
+ strncpy_DYN(&tmpbuf, "\n", (size_t) 1);
indent_DYN(&tmpbuf, level + 1);
}
} else {
indent_DYN(&tmpbuf, level + 1);
- strncpy_DYN(&tmpbuf, "%", 1);
- strncpy_DYN(&tmpbuf, src, 1);
+ strncpy_DYN(&tmpbuf, "%", (size_t) 1);
+ strncpy_DYN(&tmpbuf, src, (size_t) 1);
if (*src++ == '?') {
- src = fmt_complex(src, level + 1);
+ src = fmt_complex(tterm, capability, src, level + 1);
if (*src != '\0' && *src != '%') {
- strncpy_DYN(&tmpbuf, "\n", 1);
+ strncpy_DYN(&tmpbuf, "\n", (size_t) 1);
indent_DYN(&tmpbuf, level + 1);
}
} else if (level == 1) {
- _nc_warning("%%%c without %%?", *src);
+ if (checking)
+ _nc_warning("%s: %%%c without %%? in %s",
+ _nc_first_name(tterm->term_names),
+ *src, capability);
}
}
continue;
@@ -527,31 +556,40 @@
if (level > 1) {
tmpbuf.text[tmpbuf.used - 1] = '\n';
indent_DYN(&tmpbuf, level);
- strncpy_DYN(&tmpbuf, "%", 1);
- strncpy_DYN(&tmpbuf, src++, 1);
+ strncpy_DYN(&tmpbuf, "%", (size_t) 1);
+ strncpy_DYN(&tmpbuf, src++, (size_t) 1);
+ if (src[0] == '%'
+ && src[1] != '\0'
+ && (strchr("?e;", src[1])) == 0) {
+ tmpbuf.text[tmpbuf.used++] = '\n';
+ indent_DYN(&tmpbuf, level);
+ }
return src;
}
- _nc_warning("%%; without %%?");
+ if (checking)
+ _nc_warning("%s: %%; without %%? in %s",
+ _nc_first_name(tterm->term_names),
+ capability);
}
break;
case 'p':
if (percent && params) {
tmpbuf.text[tmpbuf.used - 1] = '\n';
indent_DYN(&tmpbuf, level + 1);
- strncpy_DYN(&tmpbuf, "%", 1);
+ strncpy_DYN(&tmpbuf, "%", (size_t) 1);
}
params = FALSE;
percent = FALSE;
break;
case ' ':
- strncpy_DYN(&tmpbuf, "\\s", 2);
+ strncpy_DYN(&tmpbuf, "\\s", (size_t) 2);
++src;
continue;
default:
percent = FALSE;
break;
}
- strncpy_DYN(&tmpbuf, src++, 1);
+ strncpy_DYN(&tmpbuf, src++, (size_t) 1);
}
return src;
}
@@ -562,9 +600,9 @@
int
fmt_entry(TERMTYPE *tterm,
PredFunc pred,
- bool content_only,
- bool suppress_untranslatable,
- bool infodump,
+ int content_only,
+ int suppress_untranslatable,
+ int infodump,
int numbers)
{
PredIdx i, j;
@@ -593,14 +631,28 @@
column = INDENT; /* FIXME: workaround to prevent empty lines */
} else {
strcpy_DYN(&outbuf, tterm->term_names);
+
+ /*
+ * Colon is legal in terminfo descriptions, but not in termcap.
+ */
+ if (!infodump) {
+ char *p = outbuf.text;
+ while (*p) {
+ if (*p == ':') {
+ *p = '=';
+ }
+ ++p;
+ }
+ }
strcpy_DYN(&outbuf, separator);
column = (int) outbuf.used;
- force_wrap();
+ if (height > 1)
+ force_wrap();
}
for_each_boolean(j, tterm) {
i = BoolIndirect(j);
- name = ExtBoolname(tterm, i, bool_names);
+ name = ExtBoolname(tterm, (int) i, bool_names);
assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
if (!version_filter(BOOLEAN, i))
@@ -610,21 +662,21 @@
predval = pred(BOOLEAN, i);
if (predval != FAIL) {
- (void) strcpy(buffer, name);
+ _nc_STRCPY(buffer, name, sizeof(buffer));
if (predval <= 0)
- (void) strcat(buffer, "@");
+ _nc_STRCAT(buffer, "@", sizeof(buffer));
else if (i + 1 > num_bools)
num_bools = i + 1;
WRAP_CONCAT;
}
}
- if (column != INDENT)
+ if (column != INDENT && height > 1)
force_wrap();
for_each_number(j, tterm) {
i = NumIndirect(j);
- name = ExtNumname(tterm, i, num_names);
+ name = ExtNumname(tterm, (int) i, num_names);
assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
if (!version_filter(NUMBER, i))
@@ -635,9 +687,11 @@
predval = pred(NUMBER, i);
if (predval != FAIL) {
if (tterm->Numbers[i] < 0) {
- sprintf(buffer, "%s@", name);
+ _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+ "%s@", name);
} else {
- sprintf(buffer, "%s#%d", name, tterm->Numbers[i]);
+ _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+ "%s#%d", name, tterm->Numbers[i]);
if (i + 1 > num_values)
num_values = i + 1;
}
@@ -645,7 +699,7 @@
}
}
- if (column != INDENT)
+ if (column != INDENT && height > 1)
force_wrap();
len += (int) (num_bools
@@ -670,7 +724,7 @@
for_each_string(j, tterm) {
i = StrIndirect(j);
- name = ExtStrname(tterm, i, str_names);
+ name = ExtStrname(tterm, (int) i, str_names);
assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
capability = tterm->Strings[i];
@@ -698,14 +752,14 @@
if (PRESENT(insert_character) || PRESENT(parm_ich)) {
if (SAME_CAP(i, enter_insert_mode)
&& enter_insert_mode == ABSENT_STRING) {
- (void) strcpy(buffer, "im=");
+ _nc_STRCPY(buffer, "im=", sizeof(buffer));
WRAP_CONCAT;
continue;
}
if (SAME_CAP(i, exit_insert_mode)
&& exit_insert_mode == ABSENT_STRING) {
- (void) strcpy(buffer, "ei=");
+ _nc_STRCPY(buffer, "ei=", sizeof(buffer));
WRAP_CONCAT;
continue;
}
@@ -724,6 +778,10 @@
trimmed_sgr0 = _nc_trim_sgr0(tterm);
if (strcmp(capability, trimmed_sgr0))
capability = trimmed_sgr0;
+ else {
+ if (trimmed_sgr0 != exit_attribute_mode)
+ free(trimmed_sgr0);
+ }
set_attributes = my_sgr;
}
@@ -739,24 +797,29 @@
num_strings = i + 1;
if (!VALID_STRING(capability)) {
- sprintf(buffer, "%s@", name);
+ _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(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(capability, TRUE, numbers);
+ int params = (((i < (int) SIZEOF(parametrized)) &&
+ (i < STRCOUNT))
+ ? parametrized[i]
+ : ((*srccap == 'k')
+ ? 0
+ : has_params(srccap)));
char *cv = _nc_infotocap(name, srccap, params);
if (cv == 0) {
if (outform == F_TCONVERR) {
- sprintf(buffer, "%s=!!! %s WILL NOT CONVERT !!!",
- name, srccap);
+ _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+ "%s=!!! %s WILL NOT CONVERT !!!",
+ name, srccap);
} else if (suppress_untranslatable) {
continue;
} else {
char *s = srccap, *d = buffer;
- sprintf(d, "..%s=", name);
+ _nc_SPRINTF(d, _nc_SLIMIT(sizeof(buffer)) "..%s=", name);
d += strlen(d);
while ((*d = *s++) != 0) {
if (*d == ':') {
@@ -769,7 +832,8 @@
}
}
} else {
- sprintf(buffer, "%s=%s", name, cv);
+ _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+ "%s=%s", name, cv);
}
len += (int) strlen(capability) + 1;
WRAP_CONCAT;
@@ -783,7 +847,7 @@
if (pretty
&& (outform == F_TERMINFO
|| outform == F_VARIABLE)) {
- fmt_complex(src, 1);
+ fmt_complex(tterm, name, src, 1);
} else {
strcpy_DYN(&tmpbuf, src);
}
@@ -793,7 +857,9 @@
}
}
/* e.g., trimmed_sgr0 */
- if (capability != tterm->Strings[i])
+ if (capability != ABSENT_STRING &&
+ capability != CANCELLED_STRING &&
+ capability != tterm->Strings[i])
free(capability);
}
len += (int) (num_strings * 2);
@@ -805,11 +871,13 @@
*/
if (tversion == V_HPUX) {
if (VALID_STRING(memory_lock)) {
- (void) sprintf(buffer, "meml=%s", memory_lock);
+ _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+ "meml=%s", memory_lock);
WRAP_CONCAT;
}
if (VALID_STRING(memory_unlock)) {
- (void) sprintf(buffer, "memu=%s", memory_unlock);
+ _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+ "memu=%s", memory_unlock);
WRAP_CONCAT;
}
} else if (tversion == V_AIX) {
@@ -821,7 +889,7 @@
tp = boxchars;
for (cp = acstrans; *cp; cp++) {
- sp = strchr(acs_chars, *cp);
+ sp = (strchr) (acs_chars, *cp);
if (sp)
*tp++ = sp[1];
else {
@@ -832,9 +900,41 @@
tp[0] = '\0';
if (box_ok) {
- (void) strcpy(buffer, "box1=");
- (void) strcat(buffer, _nc_tic_expand(boxchars,
- outform == F_TERMINFO, numbers));
+ char *tmp = _nc_tic_expand(boxchars,
+ (outform == F_TERMINFO),
+ numbers);
+ _nc_STRCPY(buffer, "box1=", sizeof(buffer));
+ while (*tmp != '\0') {
+ size_t have = strlen(buffer);
+ size_t next = strlen(tmp);
+ size_t want = have + next + 1;
+ size_t last = next;
+ char save = '\0';
+
+ /*
+ * If the expanded string is too long for the buffer,
+ * chop it off and save the location where we chopped it.
+ */
+ if (want >= sizeof(buffer)) {
+ save = tmp[last];
+ tmp[last] = '\0';
+ }
+ _nc_STRCAT(buffer, tmp, sizeof(buffer));
+
+ /*
+ * If we chopped the buffer, replace the missing piece and
+ * shift everything to append the remainder.
+ */
+ if (save != '\0') {
+ next = 0;
+ tmp[last] = save;
+ while ((tmp[next] = tmp[last + next]) != '\0') {
+ ++next;
+ }
+ } else {
+ break;
+ }
+ }
WRAP_CONCAT;
}
}
@@ -846,7 +946,7 @@
*/
if (outcount) {
bool trimmed = FALSE;
- j = outbuf.used;
+ j = (PredIdx) outbuf.used;
if (j >= 2
&& outbuf.text[j - 1] == '\t'
&& outbuf.text[j - 2] == '\n') {
@@ -926,7 +1026,7 @@
char name[10];
for (n = 0; n <= 10; ++n) {
- sprintf(name, "lf%d", n);
+ _nc_SPRINTF(name, _nc_SLIMIT(sizeof(name)) "lf%d", n);
if ((cap = find_string(tterm, name)) != ABSENT_STRING
&& kill_string(tterm, cap)) {
target -= (int) (strlen(cap) + 5);
@@ -951,7 +1051,7 @@
char name[10];
for (n = 60; n >= 0; --n) {
- sprintf(name, "kf%d", n);
+ _nc_SPRINTF(name, _nc_SLIMIT(sizeof(name)) "kf%d", n);
if ((cap = find_string(tterm, name)) != ABSENT_STRING
&& kill_string(tterm, cap)) {
target -= (int) (strlen(cap) + 5);
@@ -1017,8 +1117,8 @@
*/
void
dump_entry(TERMTYPE *tterm,
- bool suppress_untranslatable,
- bool limited,
+ int suppress_untranslatable,
+ int limited,
int numbers,
PredFunc pred)
{
@@ -1040,7 +1140,7 @@
save_sgr = set_attributes;
- if (((len = FMT_ENTRY()) > critlen)
+ if ((FMT_ENTRY() > critlen)
&& limited) {
save_tterm = *tterm;
@@ -1049,7 +1149,7 @@
critlen);
suppress_untranslatable = TRUE;
}
- if ((len = FMT_ENTRY()) > critlen) {
+ if (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
@@ -1064,7 +1164,7 @@
*/
unsigned n;
for (n = STRCOUNT; n < NUM_STRINGS(tterm); n++) {
- const char *name = ExtStrname(tterm, n, strnames);
+ const char *name = ExtStrname(tterm, (int) n, strnames);
if (VALID_STRING(tterm->Strings[n])) {
set_attributes = ABSENT_STRING;
@@ -1075,7 +1175,7 @@
critlen);
}
changed = TRUE;
- if ((len = FMT_ENTRY()) <= critlen)
+ if (FMT_ENTRY() <= critlen)
break;
}
}
@@ -1086,7 +1186,7 @@
critlen);
changed = TRUE;
}
- if (!changed || ((len = FMT_ENTRY()) > critlen)) {
+ if (!changed || (FMT_ENTRY() > critlen)) {
if (purged_acs(tterm)) {
acs_chars = ABSENT_STRING;
SHOW_WHY("# (acsc removed to fit entry within %d bytes)\n",
@@ -1094,7 +1194,7 @@
changed = TRUE;
}
}
- if (!changed || ((len = FMT_ENTRY()) > critlen)) {
+ if (!changed || (FMT_ENTRY() > critlen)) {
int oldversion = tversion;
tversion = V_BSD;
@@ -1130,7 +1230,7 @@
} else if (!version_filter(STRING, STR_IDX(acs_chars))) {
save_tterm = *tterm;
if (purged_acs(tterm)) {
- len = FMT_ENTRY();
+ (void) FMT_ENTRY();
}
*tterm = save_tterm;
}
@@ -1144,21 +1244,45 @@
if (outform == F_TERMCAP || outform == F_TCONVERR)
trim_trailing();
- (void) sprintf(buffer, "%s%s", infodump ? "use=" : "tc=", name);
+ _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+ "%s%s", infodump ? "use=" : "tc=", name);
wrap_concat(buffer);
}
int
show_entry(void)
{
- trim_trailing();
+ /*
+ * Trim any remaining whitespace.
+ */
+ if (outbuf.used != 0) {
+ bool infodump = (outform != F_TERMCAP && outform != F_TCONVERR);
+ char delim = (char) (infodump ? ',' : ':');
+ int j;
+
+ for (j = (int) outbuf.used - 1; j > 0; --j) {
+ char ch = outbuf.text[j];
+ if (ch == '\n') {
+ ;
+ } else if (isspace(UChar(ch))) {
+ outbuf.used = (size_t) j;
+ } else if (!infodump && ch == '\\') {
+ outbuf.used = (size_t) j;
+ } else if (ch == delim && (j == 0 || outbuf.text[j - 1] != '\\')) {
+ outbuf.used = (size_t) (j + 1);
+ } else {
+ break;
+ }
+ }
+ outbuf.text[outbuf.used] = '\0';
+ }
(void) fputs(outbuf.text, stdout);
putchar('\n');
return (int) outbuf.used;
}
void
-compare_entry(void (*hook) (PredType t, PredIdx i, const char *name),
+compare_entry(PredHook hook,
TERMTYPE *tp GCC_UNUSED,
bool quiet)
/* compare two entries */
@@ -1170,7 +1294,7 @@
fputs(" comparing booleans.\n", stdout);
for_each_boolean(j, tp) {
i = BoolIndirect(j);
- name = ExtBoolname(tp, i, bool_names);
+ name = ExtBoolname(tp, (int) i, bool_names);
if (isObsolete(outform, name))
continue;
@@ -1182,7 +1306,7 @@
fputs(" comparing numbers.\n", stdout);
for_each_number(j, tp) {
i = NumIndirect(j);
- name = ExtNumname(tp, i, num_names);
+ name = ExtNumname(tp, (int) i, num_names);
if (isObsolete(outform, name))
continue;
@@ -1194,7 +1318,7 @@
fputs(" comparing strings.\n", stdout);
for_each_string(j, tp) {
i = StrIndirect(j);
- name = ExtStrname(tp, i, str_names);
+ name = ExtStrname(tp, (int) i, str_names);
if (isObsolete(outform, name))
continue;
diff --git a/progs/dump_entry.h b/progs/dump_entry.h
index b99a37a..8b1ebd2 100644
--- a/progs/dump_entry.h
+++ b/progs/dump_entry.h
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -32,9 +32,8 @@
* and: Thomas E. Dickey 1996-on *
****************************************************************************/
-
/*
- * $Id: dump_entry.h,v 1.30 2008/07/12 20:23:03 tom Exp $
+ * $Id: dump_entry.h,v 1.35 2015/05/27 00:56:54 tom Exp $
*
* Dump control definitions and variables
*/
@@ -64,16 +63,18 @@
typedef unsigned PredType;
typedef unsigned PredIdx;
-typedef int (*PredFunc)(PredType, PredIdx);
+typedef int (*PredFunc) (PredType, PredIdx);
+typedef void (*PredHook) (PredType, PredIdx, const char *);
extern NCURSES_CONST char *nametrans(const char *);
-extern int fmt_entry(TERMTYPE *, PredFunc, bool, bool, bool, int);
+extern bool has_params(const char *src);
+extern int fmt_entry(TERMTYPE *, PredFunc, int, int, int, 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 void compare_entry(PredHook, TERMTYPE *, bool);
+extern void dump_entry(TERMTYPE *, int, int, int, PredFunc);
+extern void dump_init(const char *, int, int, int, int, unsigned, bool, bool);
extern void dump_uses(const char *, bool);
-extern void repair_acsc(TERMTYPE * tp);
+extern void repair_acsc(TERMTYPE *tp);
#define FAIL -1
diff --git a/progs/infocmp b/progs/infocmp
deleted file mode 100755
index 42060de..0000000
--- a/progs/infocmp
+++ /dev/null
Binary files differ
diff --git a/progs/infocmp.c b/progs/infocmp.c
index 84989ff..d3fdc52 100644
--- a/progs/infocmp.c
+++ b/progs/infocmp.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2014,2015 Free 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,7 +42,7 @@
#include <dump_entry.h>
-MODULE_ID("$Id: infocmp.c,v 1.103 2008/08/16 22:04:56 tom Exp $")
+MODULE_ID("$Id: infocmp.c,v 1.133 2015/05/27 00:57:41 tom Exp $")
#define L_CURL "{"
#define R_CURL "}"
@@ -70,8 +70,9 @@
static const char *s_absent = "NULL";
static const char *s_cancel = "NULL";
static const char *tversion; /* terminfo version selected */
-static int itrace; /* trace flag for debugging */
+static unsigned itrace; /* trace flag for debugging */
static int mwidth = 60;
+static int mheight = 65535;
static int numbers = 0; /* format "%'char'" to/from "%{number}" */
static int outform = F_TERMINFO; /* output format */
static int sortmode; /* sort_mode */
@@ -86,27 +87,52 @@
static bool ignorepads; /* ignore pad prefixes when diffing */
#if NO_LEAKS
+
+typedef struct {
+ ENTRY *head;
+ ENTRY *tail;
+} ENTERED;
+
+static ENTERED *entered;
+
#undef ExitProgram
static void ExitProgram(int code) GCC_NORETURN;
/* prototype is to get gcc to accept the noreturn attribute */
static void
ExitProgram(int code)
{
- while (termcount-- > 0)
- _nc_free_termtype(&entries[termcount].tterm);
+ int n;
+
+ for (n = 0; n < termcount; ++n) {
+ ENTRY *new_head = _nc_head;
+ ENTRY *new_tail = _nc_tail;
+ _nc_head = entered[n].head;
+ _nc_tail = entered[n].tail;
+ _nc_free_entries(entered[n].head);
+ _nc_head = new_head;
+ _nc_tail = new_tail;
+ }
_nc_leaks_dump_entry();
free(entries);
+ free(entered);
_nc_free_tic(code);
}
#endif
+static void
+failed(const char *s)
+{
+ perror(s);
+ ExitProgram(EXIT_FAILURE);
+}
+
static char *
canonical_name(char *ptr, char *buf)
/* extract the terminal type's primary name */
{
char *bp;
- (void) strcpy(buf, ptr);
+ _nc_STRCPY(buf, ptr, NAMESIZE);
if ((bp = strchr(buf, '|')) != 0)
*bp = '\0';
@@ -307,13 +333,13 @@
{
switch (val) {
case ABSENT_NUMERIC:
- strcpy(buf, s_absent);
+ _nc_STRCPY(buf, s_absent, MAX_STRING);
break;
case CANCELLED_NUMERIC:
- strcpy(buf, s_cancel);
+ _nc_STRCPY(buf, s_cancel, MAX_STRING);
break;
default:
- sprintf(buf, "%d", val);
+ _nc_SPRINTF(buf, _nc_SLIMIT(MAX_STRING) "%d", val);
break;
}
}
@@ -323,31 +349,94 @@
/* display the value of a string capability */
{
if (val == ABSENT_STRING)
- strcpy(buf, s_absent);
+ _nc_STRCPY(buf, s_absent, MAX_STRING);
else if (val == CANCELLED_STRING)
- strcpy(buf, s_cancel);
+ _nc_STRCPY(buf, s_cancel, MAX_STRING);
else {
- sprintf(buf, "'%.*s'", MAX_STRING - 3, TIC_EXPAND(val));
+ _nc_SPRINTF(buf, _nc_SLIMIT(MAX_STRING)
+ "'%.*s'", MAX_STRING - 3, TIC_EXPAND(val));
}
}
+/*
+ * Show "comparing..." message for the given terminal names.
+ */
+static void
+show_comparing(char **names)
+{
+ if (itrace) {
+ switch (compare) {
+ case C_DIFFERENCE:
+ (void) fprintf(stderr, "%s: dumping differences\n", _nc_progname);
+ break;
+
+ case C_COMMON:
+ (void) fprintf(stderr, "%s: dumping common capabilities\n", _nc_progname);
+ break;
+
+ case C_NAND:
+ (void) fprintf(stderr, "%s: dumping differences\n", _nc_progname);
+ break;
+ }
+ }
+ if (*names) {
+ printf("comparing %s", *names++);
+ if (*names) {
+ printf(" to %s", *names++);
+ while (*names) {
+ printf(", %s", *names++);
+ }
+ }
+ printf(".\n");
+ }
+}
+
+/*
+ * ncurses stores two types of non-standard capabilities:
+ * a) capabilities listed past the "STOP-HERE" comment in the Caps file.
+ * These are used in the terminfo source file to provide data for termcaps,
+ * e.g., when there is no equivalent capability in terminfo, as well as for
+ * widely-used non-standard capabilities.
+ * b) user-definable capabilities, via "tic -x".
+ *
+ * However, if "-x" is omitted from the tic command, both types of
+ * non-standard capability are not loaded into the terminfo database. This
+ * macro is used for limit-checks against the symbols that tic uses to omit
+ * the two types of non-standard entry.
+ */
+#if NCURSES_XNAMES
+#define check_user_definable(n,limit) if (!_nc_user_definable && (n) > (limit)) break
+#else
+#define check_user_definable(n,limit) if ((n) > (limit)) break
+#endif
+
+/*
+ * Use these macros to simplify loops on C_COMMON and C_NAND:
+ */
+#define for_each_entry() while (entries[extra].tterm.term_names)
+#define next_entry (&(entries[extra++].tterm))
+
static void
compare_predicate(PredType type, PredIdx idx, const char *name)
/* predicate function to use for entry difference reports */
{
- register ENTRY *e1 = &entries[0];
- register ENTRY *e2 = &entries[1];
- char buf1[MAX_STRING], buf2[MAX_STRING];
+ ENTRY *e1 = &entries[0];
+ ENTRY *e2 = &entries[1];
+ char buf1[MAX_STRING];
+ char buf2[MAX_STRING];
int b1, b2;
int n1, n2;
char *s1, *s2;
+ bool found;
+ int extra = 1;
switch (type) {
case CMP_BOOLEAN:
+ check_user_definable(idx, BOOLWRITE);
b1 = e1->tterm.Booleans[idx];
- b2 = e2->tterm.Booleans[idx];
switch (compare) {
case C_DIFFERENCE:
+ b2 = next_entry->Booleans[idx];
if (!(b1 == ABSENT_BOOLEAN && b2 == ABSENT_BOOLEAN) && b1 != b2)
(void) printf("\t%s: %s%s%s.\n",
name,
@@ -357,45 +446,93 @@
break;
case C_COMMON:
- if (b1 == b2 && b1 != ABSENT_BOOLEAN)
- (void) printf("\t%s= %s.\n", name, dump_boolean(b1));
+ if (b1 != ABSENT_BOOLEAN) {
+ found = TRUE;
+ for_each_entry() {
+ b2 = next_entry->Booleans[idx];
+ if (b1 != b2) {
+ found = FALSE;
+ break;
+ }
+ }
+ if (found) {
+ (void) printf("\t%s= %s.\n", name, dump_boolean(b1));
+ }
+ }
break;
case C_NAND:
- if (b1 == ABSENT_BOOLEAN && b2 == ABSENT_BOOLEAN)
- (void) printf("\t!%s.\n", name);
+ if (b1 == ABSENT_BOOLEAN) {
+ found = TRUE;
+ for_each_entry() {
+ b2 = next_entry->Booleans[idx];
+ if (b1 != b2) {
+ found = FALSE;
+ break;
+ }
+ }
+ if (found) {
+ (void) printf("\t!%s.\n", name);
+ }
+ }
break;
}
break;
case CMP_NUMBER:
+ check_user_definable(idx, NUMWRITE);
n1 = e1->tterm.Numbers[idx];
- n2 = e2->tterm.Numbers[idx];
- dump_numeric(n1, buf1);
- dump_numeric(n2, buf2);
switch (compare) {
case C_DIFFERENCE:
- if (!((n1 == ABSENT_NUMERIC && n2 == ABSENT_NUMERIC)) && n1 != n2)
+ n2 = next_entry->Numbers[idx];
+ if (!((n1 == ABSENT_NUMERIC && n2 == ABSENT_NUMERIC)) && n1 != n2) {
+ dump_numeric(n1, buf1);
+ dump_numeric(n2, buf2);
(void) printf("\t%s: %s, %s.\n", name, buf1, buf2);
+ }
break;
case C_COMMON:
- if (n1 != ABSENT_NUMERIC && n2 != ABSENT_NUMERIC && n1 == n2)
- (void) printf("\t%s= %s.\n", name, buf1);
+ if (n1 != ABSENT_NUMERIC) {
+ found = TRUE;
+ for_each_entry() {
+ n2 = next_entry->Numbers[idx];
+ if (n1 != n2) {
+ found = FALSE;
+ break;
+ }
+ }
+ if (found) {
+ dump_numeric(n1, buf1);
+ (void) printf("\t%s= %s.\n", name, buf1);
+ }
+ }
break;
case C_NAND:
- if (n1 == ABSENT_NUMERIC && n2 == ABSENT_NUMERIC)
- (void) printf("\t!%s.\n", name);
+ if (n1 == ABSENT_NUMERIC) {
+ found = TRUE;
+ for_each_entry() {
+ n2 = next_entry->Numbers[idx];
+ if (n1 != n2) {
+ found = FALSE;
+ break;
+ }
+ }
+ if (found) {
+ (void) printf("\t!%s.\n", name);
+ }
+ }
break;
}
break;
case CMP_STRING:
+ check_user_definable(idx, STRWRITE);
s1 = e1->tterm.Strings[idx];
- s2 = e2->tterm.Strings[idx];
switch (compare) {
case C_DIFFERENCE:
+ s2 = next_entry->Strings[idx];
if (capcmp(idx, s1, s2)) {
dump_string(s1, buf1);
dump_string(s2, buf2);
@@ -405,13 +542,35 @@
break;
case C_COMMON:
- if (s1 && s2 && !capcmp(idx, s1, s2))
- (void) printf("\t%s= '%s'.\n", name, TIC_EXPAND(s1));
+ if (s1 != ABSENT_STRING) {
+ found = TRUE;
+ for_each_entry() {
+ s2 = next_entry->Strings[idx];
+ if (capcmp(idx, s1, s2) != 0) {
+ found = FALSE;
+ break;
+ }
+ }
+ if (found) {
+ (void) printf("\t%s= '%s'.\n", name, TIC_EXPAND(s1));
+ }
+ }
break;
case C_NAND:
- if (!s1 && !s2)
- (void) printf("\t!%s.\n", name);
+ if (s1 == ABSENT_STRING) {
+ found = TRUE;
+ for_each_entry() {
+ s2 = next_entry->Strings[idx];
+ if (s2 != s1) {
+ found = FALSE;
+ break;
+ }
+ }
+ if (found) {
+ (void) printf("\t!%s.\n", name);
+ }
+ }
break;
}
break;
@@ -430,16 +589,37 @@
break;
case C_COMMON:
- if (e1->nuses && e2->nuses && useeq(e1, e2)) {
- (void) fputs("\tuse: ", stdout);
- print_uses(e1, stdout);
- fputs(".\n", stdout);
+ if (e1->nuses) {
+ found = TRUE;
+ for_each_entry() {
+ e2 = &entries[extra++];
+ if (e2->nuses != e1->nuses || !useeq(e1, e2)) {
+ found = FALSE;
+ break;
+ }
+ }
+ if (found) {
+ (void) fputs("\tuse: ", stdout);
+ print_uses(e1, stdout);
+ fputs(".\n", stdout);
+ }
}
break;
case C_NAND:
- if (!e1->nuses && !e2->nuses)
- (void) printf("\t!use.\n");
+ if (!e1->nuses) {
+ found = TRUE;
+ for_each_entry() {
+ e2 = &entries[extra++];
+ if (e2->nuses != e1->nuses) {
+ found = FALSE;
+ break;
+ }
+ }
+ if (found) {
+ (void) printf("\t!use.\n");
+ }
+ }
break;
}
}
@@ -451,99 +631,104 @@
*
***************************************************************************/
+#define DATA(from, to) { { from }, { to } }
+#define DATAX() DATA("", "")
+
typedef struct {
- const char *from;
- const char *to;
+ const char from[4];
+ const char to[12];
} assoc;
static const assoc std_caps[] =
{
/* these are specified by X.364 and iBCS2 */
- {"\033c", "RIS"}, /* full reset */
- {"\0337", "SC"}, /* save cursor */
- {"\0338", "RC"}, /* restore cursor */
- {"\033[r", "RSR"}, /* not an X.364 mnemonic */
- {"\033[m", "SGR0"}, /* not an X.364 mnemonic */
- {"\033[2J", "ED2"}, /* clear page */
+ DATA("\033c", "RIS"), /* full reset */
+ DATA("\0337", "SC"), /* save cursor */
+ DATA("\0338", "RC"), /* restore cursor */
+ DATA("\033[r", "RSR"), /* not an X.364 mnemonic */
+ DATA("\033[m", "SGR0"), /* not an X.364 mnemonic */
+ DATA("\033[2J", "ED2"), /* clear page */
/* this group is specified by ISO 2022 */
- {"\033(0", "ISO DEC G0"}, /* enable DEC graphics for G0 */
- {"\033(A", "ISO UK G0"}, /* enable UK chars for G0 */
- {"\033(B", "ISO US G0"}, /* enable US chars for G0 */
- {"\033)0", "ISO DEC G1"}, /* enable DEC graphics for G1 */
- {"\033)A", "ISO UK G1"}, /* enable UK chars for G1 */
- {"\033)B", "ISO US G1"}, /* enable US chars for G1 */
+ DATA("\033(0", "ISO DEC G0"), /* enable DEC graphics for G0 */
+ DATA("\033(A", "ISO UK G0"), /* enable UK chars for G0 */
+ DATA("\033(B", "ISO US G0"), /* enable US chars for G0 */
+ DATA("\033)0", "ISO DEC G1"), /* enable DEC graphics for G1 */
+ DATA("\033)A", "ISO UK G1"), /* enable UK chars for G1 */
+ DATA("\033)B", "ISO US G1"), /* enable US chars for G1 */
/* 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 */
+ DATA("\033=", "DECPAM"), /* application keypad mode */
+ DATA("\033>", "DECPNM"), /* normal keypad mode */
+ DATA("\033<", "DECANSI"), /* enter ANSI mode */
+ DATA("\033[!p", "DECSTR"), /* soft reset */
+ DATA("\033 F", "S7C1T"), /* 7-bit controls */
- {(char *) 0, (char *) 0}
+ DATAX()
};
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}
+ DATA("2", "AM"), /* keyboard action mode */
+ DATA("4", "IRM"), /* insert/replace mode */
+ DATA("12", "SRM"), /* send/receive mode */
+ DATA("20", "LNM"), /* linefeed mode */
+ DATAX()
};
static const assoc private_modes[] =
/* DEC \E[ ... [hl] modes recognized by many emulators */
{
- {"1", "CKM"}, /* application cursor keys */
- {"2", "ANM"}, /* set VT52 mode */
- {"3", "COLM"}, /* 132-column mode */
- {"4", "SCLM"}, /* smooth scroll */
- {"5", "SCNM"}, /* reverse video mode */
- {"6", "OM"}, /* origin mode */
- {"7", "AWM"}, /* wraparound mode */
- {"8", "ARM"}, /* auto-repeat mode */
- {(char *) 0, (char *) 0}
+ DATA("1", "CKM"), /* application cursor keys */
+ DATA("2", "ANM"), /* set VT52 mode */
+ DATA("3", "COLM"), /* 132-column mode */
+ DATA("4", "SCLM"), /* smooth scroll */
+ DATA("5", "SCNM"), /* reverse video mode */
+ DATA("6", "OM"), /* origin mode */
+ DATA("7", "AWM"), /* wraparound mode */
+ DATA("8", "ARM"), /* auto-repeat mode */
+ DATAX()
};
static const assoc ecma_highlights[] =
/* recognize ECMA attribute sequences */
{
- {"0", "NORMAL"}, /* normal */
- {"1", "+BOLD"}, /* bold on */
- {"2", "+DIM"}, /* dim on */
- {"3", "+ITALIC"}, /* italic on */
- {"4", "+UNDERLINE"}, /* underline on */
- {"5", "+BLINK"}, /* blink on */
- {"6", "+FASTBLINK"}, /* fastblink on */
- {"7", "+REVERSE"}, /* reverse on */
- {"8", "+INVISIBLE"}, /* invisible on */
- {"9", "+DELETED"}, /* deleted on */
- {"10", "MAIN-FONT"}, /* select primary font */
- {"11", "ALT-FONT-1"}, /* select alternate font 1 */
- {"12", "ALT-FONT-2"}, /* select alternate font 2 */
- {"13", "ALT-FONT-3"}, /* select alternate font 3 */
- {"14", "ALT-FONT-4"}, /* select alternate font 4 */
- {"15", "ALT-FONT-5"}, /* select alternate font 5 */
- {"16", "ALT-FONT-6"}, /* select alternate font 6 */
- {"17", "ALT-FONT-7"}, /* select alternate font 7 */
- {"18", "ALT-FONT-1"}, /* select alternate font 1 */
- {"19", "ALT-FONT-1"}, /* select alternate font 1 */
- {"20", "FRAKTUR"}, /* Fraktur font */
- {"21", "DOUBLEUNDER"}, /* double underline */
- {"22", "-DIM"}, /* dim off */
- {"23", "-ITALIC"}, /* italic off */
- {"24", "-UNDERLINE"}, /* underline off */
- {"25", "-BLINK"}, /* blink off */
- {"26", "-FASTBLINK"}, /* fastblink off */
- {"27", "-REVERSE"}, /* reverse off */
- {"28", "-INVISIBLE"}, /* invisible off */
- {"29", "-DELETED"}, /* deleted off */
- {(char *) 0, (char *) 0}
+ DATA("0", "NORMAL"), /* normal */
+ DATA("1", "+BOLD"), /* bold on */
+ DATA("2", "+DIM"), /* dim on */
+ DATA("3", "+ITALIC"), /* italic on */
+ DATA("4", "+UNDERLINE"), /* underline on */
+ DATA("5", "+BLINK"), /* blink on */
+ DATA("6", "+FASTBLINK"), /* fastblink on */
+ DATA("7", "+REVERSE"), /* reverse on */
+ DATA("8", "+INVISIBLE"), /* invisible on */
+ DATA("9", "+DELETED"), /* deleted on */
+ DATA("10", "MAIN-FONT"), /* select primary font */
+ DATA("11", "ALT-FONT-1"), /* select alternate font 1 */
+ DATA("12", "ALT-FONT-2"), /* select alternate font 2 */
+ DATA("13", "ALT-FONT-3"), /* select alternate font 3 */
+ DATA("14", "ALT-FONT-4"), /* select alternate font 4 */
+ DATA("15", "ALT-FONT-5"), /* select alternate font 5 */
+ DATA("16", "ALT-FONT-6"), /* select alternate font 6 */
+ DATA("17", "ALT-FONT-7"), /* select alternate font 7 */
+ DATA("18", "ALT-FONT-1"), /* select alternate font 1 */
+ DATA("19", "ALT-FONT-1"), /* select alternate font 1 */
+ DATA("20", "FRAKTUR"), /* Fraktur font */
+ DATA("21", "DOUBLEUNDER"), /* double underline */
+ DATA("22", "-DIM"), /* dim off */
+ DATA("23", "-ITALIC"), /* italic off */
+ DATA("24", "-UNDERLINE"), /* underline off */
+ DATA("25", "-BLINK"), /* blink off */
+ DATA("26", "-FASTBLINK"), /* fastblink off */
+ DATA("27", "-REVERSE"), /* reverse off */
+ DATA("28", "-INVISIBLE"), /* invisible off */
+ DATA("29", "-DELETED"), /* deleted off */
+ DATAX()
};
+#undef DATA
+
static int
skip_csi(const char *cap)
{
@@ -556,7 +741,7 @@
}
static bool
-same_param(const char *table, const char *param, unsigned length)
+same_param(const char *table, const char *param, size_t length)
{
bool result = FALSE;
if (strncmp(table, param, length) == 0) {
@@ -577,19 +762,19 @@
do {
bool found = FALSE;
- for (ap = table; ap->from; ap++) {
+ for (ap = table; ap->from[0]; ap++) {
size_t tlen = strlen(ap->from);
if (same_param(ap->from, ep, tlen)) {
- (void) strcat(dst, ap->to);
+ _nc_STRCAT(dst, ap->to, MAX_TERMINFO_LENGTH);
found = TRUE;
break;
}
}
if (!found)
- (void) strcat(dst, ep);
- (void) strcat(dst, ";");
+ _nc_STRCAT(dst, ep, MAX_TERMINFO_LENGTH);
+ _nc_STRCAT(dst, ";", MAX_TERMINFO_LENGTH);
} while
((ep = strtok((char *) 0, ";")));
@@ -608,7 +793,7 @@
const assoc *ap;
int tp_lines = tp->Numbers[2];
- if (cap == ABSENT_STRING || cap == CANCELLED_STRING)
+ if (!VALID_STRING(cap))
return;
(void) printf("%s: ", name);
@@ -624,12 +809,13 @@
for (i = 0; i < STRCOUNT; i++) {
char *cp = tp->Strings[i];
- /* don't use soft-key capabilities */
- if (strnames[i][0] == 'k' && strnames[i][0] == 'f')
+ /* don't use function-key capabilities */
+ if (strnames[i][0] == 'k' && strnames[i][1] == 'f')
continue;
- if (cp != ABSENT_STRING && cp != CANCELLED_STRING && cp[0] && cp
- != cap) {
+ if (VALID_STRING(cp) &&
+ cp[0] != '\0' &&
+ cp != cap) {
len = strlen(cp);
(void) strncpy(buf2, sp, len);
buf2[len] = '\0';
@@ -637,7 +823,7 @@
if (_nc_capcmp(cp, buf2))
continue;
-#define ISRS(s) (!strncmp((s), "is", 2) || !strncmp((s), "rs", 2))
+#define ISRS(s) (!strncmp((s), "is", (size_t) 2) || !strncmp((s), "rs", (size_t) 2))
/*
* Theoretically we just passed the test for translation
* (equality once the padding is stripped). However, there
@@ -658,7 +844,7 @@
/* now check the standard capabilities */
if (!expansion) {
csi = skip_csi(sp);
- for (ap = std_caps; ap->from; ap++) {
+ for (ap = std_caps; ap->from[0]; ap++) {
size_t adj = (size_t) (csi ? 2 : 0);
len = strlen(ap->from);
@@ -677,12 +863,16 @@
/* now check for standard-mode sequences */
if (!expansion
&& (csi = skip_csi(sp)) != 0
- && (len = strspn(sp + csi, "0123456789;"))
+ && (len = (strspn) (sp + csi, "0123456789;"))
&& (len < sizeof(buf3))
&& (next = (size_t) csi + len)
&& ((sp[next] == 'h') || (sp[next] == 'l'))) {
- (void) strcpy(buf2, (sp[next] == 'h') ? "ECMA+" : "ECMA-");
+ _nc_STRCPY(buf2,
+ ((sp[next] == 'h')
+ ? "ECMA+"
+ : "ECMA-"),
+ sizeof(buf2));
(void) strncpy(buf3, sp + csi, len);
buf3[len] = '\0';
len += (size_t) csi + 1;
@@ -694,12 +884,16 @@
if (!expansion
&& (csi = skip_csi(sp)) != 0
&& sp[csi] == '?'
- && (len = strspn(sp + csi + 1, "0123456789;"))
+ && (len = (strspn) (sp + csi + 1, "0123456789;"))
&& (len < sizeof(buf3))
&& (next = (size_t) csi + 1 + len)
&& ((sp[next] == 'h') || (sp[next] == 'l'))) {
- (void) strcpy(buf2, (sp[next] == 'h') ? "DEC+" : "DEC-");
+ _nc_STRCPY(buf2,
+ ((sp[next] == 'h')
+ ? "DEC+"
+ : "DEC-"),
+ sizeof(buf2));
(void) strncpy(buf3, sp + csi + 1, len);
buf3[len] = '\0';
len += (size_t) csi + 2;
@@ -710,12 +904,12 @@
/* now check for ECMA highlight sequences */
if (!expansion
&& (csi = skip_csi(sp)) != 0
- && (len = strspn(sp + csi, "0123456789;")) != 0
+ && (len = (strspn) (sp + csi, "0123456789;")) != 0
&& (len < sizeof(buf3))
&& (next = (size_t) csi + len)
&& sp[next] == 'm') {
- (void) strcpy(buf2, "SGR:");
+ _nc_STRCPY(buf2, "SGR:", sizeof(buf2));
(void) strncpy(buf3, sp + csi, len);
buf3[len] = '\0';
len += (size_t) csi + 1;
@@ -727,8 +921,8 @@
&& (csi = skip_csi(sp)) != 0
&& sp[csi] == 'm') {
len = (size_t) csi + 1;
- (void) strcpy(buf2, "SGR:");
- strcat(buf2, ecma_highlights[0].to);
+ _nc_STRCPY(buf2, "SGR:", sizeof(buf2));
+ _nc_STRCAT(buf2, ecma_highlights[0].to, sizeof(buf2));
expansion = buf2;
}
@@ -739,7 +933,7 @@
expansion = "RSR";
len = 1;
} else {
- (void) sprintf(buf2, "1;%dr", tp_lines);
+ _nc_SPRINTF(buf2, _nc_SLIMIT(sizeof(buf2)) "1;%dr", tp_lines);
len = strlen(buf2);
if (strncmp(buf2, sp + csi, len) == 0)
expansion = "RSR";
@@ -750,12 +944,12 @@
/* now check for home-down */
if (!expansion
&& (csi = skip_csi(sp)) != 0) {
- (void) sprintf(buf2, "%d;1H", tp_lines);
+ _nc_SPRINTF(buf2, _nc_SLIMIT(sizeof(buf2)) "%d;1H", tp_lines);
len = strlen(buf2);
if (strncmp(buf2, sp + csi, len) == 0) {
expansion = "LL";
} else {
- (void) sprintf(buf2, "%dH", tp_lines);
+ _nc_SPRINTF(buf2, _nc_SLIMIT(sizeof(buf2)) "%dH", tp_lines);
len = strlen(buf2);
if (strncmp(buf2, sp + csi, len) == 0) {
expansion = "LL";
@@ -795,12 +989,16 @@
int i, n;
memset(heads, 0, sizeof(heads));
- dump_init((char *) 0, F_LITERAL, S_TERMINFO, 0, itrace, FALSE);
+ dump_init((char *) 0, F_LITERAL, S_TERMINFO, 0, 65535, itrace, FALSE, FALSE);
for (n = 0; n < argc && n < MAXCOMPARE; n++) {
if (freopen(argv[n], "r", stdin) == 0)
_nc_err_abort("Can't open %s", argv[n]);
+#if NO_LEAKS
+ entered[n].head = _nc_head;
+ entered[n].tail = _nc_tail;
+#endif
_nc_head = _nc_tail = 0;
/* parse entries out of the source file */
@@ -894,8 +1092,6 @@
(void) printf("The following entries are equivalent:\n");
for (qp = heads[0]; qp; qp = qp->next) {
- rp = qp->crosslinks[0];
-
if (qp->ncrosslinks == 1) {
rp = qp->crosslinks[0];
@@ -927,6 +1123,11 @@
#endif
if (!(entryeq(&qp->tterm, &rp->tterm) && useeq(qp, rp))) {
char name1[NAMESIZE], name2[NAMESIZE];
+ char *names[3];
+
+ names[0] = name1;
+ names[1] = name2;
+ names[2] = 0;
entries[0] = *qp;
entries[1] = *rp;
@@ -936,29 +1137,17 @@
switch (compare) {
case C_DIFFERENCE:
- if (itrace)
- (void) fprintf(stderr,
- "%s: dumping differences\n",
- _nc_progname);
- (void) printf("comparing %s to %s.\n", name1, name2);
+ show_comparing(names);
compare_entry(compare_predicate, &entries->tterm, quiet);
break;
case C_COMMON:
- if (itrace)
- (void) fprintf(stderr,
- "%s: dumping common capabilities\n",
- _nc_progname);
- (void) printf("comparing %s to %s.\n", name1, name2);
+ show_comparing(names);
compare_entry(compare_predicate, &entries->tterm, quiet);
break;
case C_NAND:
- if (itrace)
- (void) fprintf(stderr,
- "%s: dumping differences\n",
- _nc_progname);
- (void) printf("comparing %s to %s.\n", name1, name2);
+ show_comparing(names);
compare_entry(compare_predicate, &entries->tterm, quiet);
break;
@@ -971,19 +1160,28 @@
static void
usage(void)
{
- static const char *tbl[] =
+#define DATA(s) s "\n"
+ static const char head[] =
{
- "Usage: infocmp [options] [-A directory] [-B directory] [termname...]"
- ,""
- ,"Options:"
+ DATA("Usage: infocmp [options] [-A directory] [-B directory] [termname...]")
+ DATA("")
+ DATA("Options:")
+ };
+#undef DATA
+#define DATA(s) s
+ static const char options[][45] =
+ {
+ " -0 print single-row"
," -1 print single-column"
+ ," -K use termcap-names and BSD syntax"
," -C use termcap-names"
," -F compare terminfo-files"
," -I use terminfo-names"
," -L use long names"
," -R subset (see manpage)"
," -T eliminate size limits (test)"
- ," -U eliminate post-processing of entries"
+ ," -U do not post-process entries"
+ ," -D print database locations"
," -V print version"
#if NCURSES_XNAMES
," -a with -F, list commented-out caps"
@@ -1010,20 +1208,21 @@
," -v number (verbose)"
," -w number (width)"
#if NCURSES_XNAMES
- ," -x treat unknown capabilities as user-defined"
+ ," -x unknown capabilities are user-defined"
#endif
};
- const size_t first = 3;
- const size_t last = SIZEOF(tbl);
- const size_t left = (last - first + 1) / 2 + first;
+#undef DATA
+ const size_t last = SIZEOF(options);
+ const size_t left = (last + 1) / 2;
size_t n;
+ fputs(head, stderr);
for (n = 0; n < left; n++) {
- size_t m = (n < first) ? last : n + left - first;
+ size_t m = n + left;
if (m < last)
- fprintf(stderr, "%-40.40s%s\n", tbl[n], tbl[m]);
+ fprintf(stderr, "%-40.40s%s\n", options[n], options[m]);
else
- fprintf(stderr, "%s\n", tbl[n]);
+ fprintf(stderr, "%s\n", options[n]);
}
ExitProgram(EXIT_FAILURE);
}
@@ -1032,19 +1231,25 @@
any_initializer(const char *fmt, const char *type)
{
static char *initializer;
+ static size_t need;
char *s;
- if (initializer == 0)
- initializer = (char *) malloc(strlen(entries->tterm.term_names) +
- strlen(type) + strlen(fmt));
+ if (initializer == 0) {
+ need = (strlen(entries->tterm.term_names)
+ + strlen(type)
+ + strlen(fmt));
+ initializer = (char *) malloc(need + 1);
+ if (initializer == 0)
+ failed("any_initializer");
+ }
- (void) strcpy(initializer, entries->tterm.term_names);
+ _nc_STRCPY(initializer, entries->tterm.term_names, need);
for (s = initializer; *s != 0 && *s != '|'; s++) {
if (!isalnum(UChar(*s)))
*s = '_';
}
*s = 0;
- (void) sprintf(s, fmt, type);
+ _nc_SPRINTF(s, _nc_SLIMIT(need) fmt, type);
return initializer;
}
@@ -1075,9 +1280,10 @@
if (VALID_STRING(term->Strings[n])) {
tp = buf;
+#define TP_LIMIT ((MAX_STRING - 5) - (size_t)(tp - buf))
*tp++ = '"';
for (sp = term->Strings[n];
- *sp != 0 && (tp - buf) < MAX_STRING - 6;
+ *sp != 0 && TP_LIMIT > 2;
sp++) {
if (isascii(UChar(*sp))
&& isprint(UChar(*sp))
@@ -1085,14 +1291,15 @@
&& *sp != '"')
*tp++ = *sp;
else {
- (void) sprintf(tp, "\\%03o", UChar(*sp));
+ _nc_SPRINTF(tp, _nc_SLIMIT(TP_LIMIT) "\\%03o", UChar(*sp));
tp += 4;
}
}
*tp++ = '"';
*tp = '\0';
(void) printf("static char %-20s[] = %s;\n",
- string_variable(ExtStrname(term, n, strnames)), buf);
+ string_variable(ExtStrname(term, (int) n, strnames)),
+ buf);
}
}
printf("\n");
@@ -1118,7 +1325,7 @@
break;
}
(void) printf("\t/* %3u: %-8s */\t%s,\n",
- n, ExtBoolname(term, n, boolnames), str);
+ n, ExtBoolname(term, (int) n, boolnames), str);
}
(void) printf("%s;\n", R_CURL);
@@ -1134,12 +1341,12 @@
str = "CANCELLED_NUMERIC";
break;
default:
- sprintf(buf, "%d", term->Numbers[n]);
+ _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf)) "%d", term->Numbers[n]);
str = buf;
break;
}
(void) printf("\t/* %3u: %-8s */\t%s,\n", n,
- ExtNumname(term, n, numnames), str);
+ ExtNumname(term, (int) n, numnames), str);
}
(void) printf("%s;\n", R_CURL);
@@ -1152,10 +1359,10 @@
else if (term->Strings[n] == CANCELLED_STRING)
str = "CANCELLED_STRING";
else {
- str = string_variable(ExtStrname(term, n, strnames));
+ str = string_variable(ExtStrname(term, (int) n, strnames));
}
(void) printf("\t/* %3u: %-8s */\t%s,\n", n,
- ExtStrname(term, n, strnames), str);
+ ExtStrname(term, (int) n, strnames), str);
}
(void) printf("%s;\n", R_CURL);
@@ -1167,15 +1374,15 @@
name_initializer("string_ext"), L_CURL);
for (n = BOOLCOUNT; n < NUM_BOOLEANS(term); ++n) {
(void) printf("\t/* %3u: bool */\t\"%s\",\n",
- n, ExtBoolname(term, n, boolnames));
+ n, ExtBoolname(term, (int) n, boolnames));
}
for (n = NUMCOUNT; n < NUM_NUMBERS(term); ++n) {
(void) printf("\t/* %3u: num */\t\"%s\",\n",
- n, ExtNumname(term, n, numnames));
+ n, ExtNumname(term, (int) n, numnames));
}
for (n = STRCOUNT; n < NUM_STRINGS(term); ++n) {
(void) printf("\t/* %3u: str */\t\"%s\",\n",
- n, ExtStrname(term, n, strnames));
+ n, ExtStrname(term, (int) n, strnames));
}
(void) printf("%s;\n", R_CURL);
}
@@ -1249,12 +1456,38 @@
return terminal;
}
+/*
+ * Show the databases that infocmp knows about. The location to which it writes is
+ */
+static void
+show_databases(void)
+{
+ DBDIRS state;
+ int offset;
+ const char *path2;
+
+ _nc_first_db(&state, &offset);
+ while ((path2 = _nc_next_db(&state, &offset)) != 0) {
+ printf("%s\n", path2);
+ }
+ _nc_last_db();
+}
+
/***************************************************************************
*
* Main sequence
*
***************************************************************************/
+#if NO_LEAKS
+#define MAIN_LEAKS() \
+ free(myargv); \
+ free(tfile); \
+ free(tname)
+#else
+#define MAIN_LEAKS() /* nothing */
+#endif
+
int
main(int argc, char *argv[])
{
@@ -1262,7 +1495,7 @@
/* Also avoid overflowing smaller stacks on systems like AmigaOS */
path *tfile = 0;
char **tname = 0;
- int maxterms;
+ size_t maxterms;
char **myargv;
@@ -1280,18 +1513,27 @@
#if NCURSES_XNAMES
use_extended_names(FALSE);
#endif
+ _nc_strict_bsd = 0;
_nc_progname = _nc_rootname(argv[0]);
/* make sure we have enough space to add two terminal entries */
myargv = typeCalloc(char *, (size_t) (argc + 3));
+ if (myargv == 0)
+ failed("myargv");
+
memcpy(myargv, argv, (sizeof(char *) * (size_t) argc));
argv = myargv;
while ((c = getopt(argc,
argv,
- "1A:aB:CcdEeFfGgIiLlnpqR:rs:TtUuVv:w:x")) != -1) {
+ "01A:aB:CcDdEeFfGgIiKLlnpqR:rs:TtUuVv:w:x")) != -1) {
switch (c) {
+ case '0':
+ mwidth = 65535;
+ mheight = 1;
+ break;
+
case '1':
mwidth = 0;
break;
@@ -1310,6 +1552,9 @@
restdir = optarg;
break;
+ case 'K':
+ _nc_strict_bsd = 1;
+ /* FALLTHRU */
case 'C':
outform = F_TERMCAP;
tversion = "BSD";
@@ -1317,6 +1562,11 @@
sortmode = S_TERMCAP;
break;
+ case 'D':
+ show_databases();
+ ExitProgram(EXIT_SUCCESS);
+ break;
+
case 'c':
compare = C_COMMON;
break;
@@ -1434,7 +1684,7 @@
ExitProgram(EXIT_SUCCESS);
case 'v':
- itrace = optarg_to_number();
+ itrace = (unsigned) optarg_to_number();
set_trace_level(itrace);
break;
@@ -1453,10 +1703,17 @@
}
}
- maxterms = (argc + 2 - optind);
- tfile = typeMalloc(path, maxterms);
- tname = typeCalloc(char *, maxterms);
- entries = typeCalloc(ENTRY, maxterms);
+ maxterms = (size_t) (argc + 2 - optind);
+ if ((tfile = typeMalloc(path, maxterms)) == 0)
+ failed("tfile");
+ if ((tname = typeCalloc(char *, maxterms)) == 0)
+ failed("tname");
+ if ((entries = typeCalloc(ENTRY, maxterms)) == 0)
+ failed("entries");
+#if NO_LEAKS
+ if ((entered = typeCalloc(ENTERED, maxterms)) == 0)
+ failed("entered");
+#endif
if (tfile == 0
|| tname == 0
@@ -1469,9 +1726,6 @@
if (sortmode == S_DEFAULT)
sortmode = S_TERMINFO;
- /* set up for display */
- dump_init(tversion, outform, sortmode, mwidth, itrace, formatted);
-
/* make sure we have at least one terminal name to work with */
if (optind >= argc)
argv[argc++] = terminal_env();
@@ -1480,9 +1734,24 @@
if (compare != C_DEFAULT && optind >= argc - 1)
argv[argc++] = terminal_env();
+ /* exactly one terminal name with no options means display it */
/* exactly two terminal names with no options means do -d */
- if (argc - optind == 2 && compare == C_DEFAULT)
- compare = C_DIFFERENCE;
+ if (compare == C_DEFAULT) {
+ switch (argc - optind) {
+ default:
+ fprintf(stderr, "%s: too many names to compare\n", _nc_progname);
+ ExitProgram(EXIT_FAILURE);
+ case 1:
+ break;
+ case 2:
+ compare = C_DIFFERENCE;
+ break;
+ }
+ }
+
+ /* set up for display */
+ dump_init(tversion, outform, sortmode, mwidth, mheight, itrace,
+ formatted, FALSE);
if (!filecompare) {
/* grab the entries */
@@ -1494,15 +1763,17 @@
tname[termcount] = argv[optind];
if (directory) {
-#if USE_DATABASE
+#if NCURSES_USE_DATABASE
#if MIXEDCASE_FILENAMES
#define LEAF_FMT "%c"
#else
#define LEAF_FMT "%02x"
#endif
- (void) sprintf(tfile[termcount], "%s/" LEAF_FMT "/%s",
- directory,
- UChar(*argv[optind]), argv[optind]);
+ _nc_SPRINTF(tfile[termcount],
+ _nc_SLIMIT(sizeof(path))
+ "%s/" LEAF_FMT "/%s",
+ directory,
+ UChar(*argv[optind]), argv[optind]);
if (itrace)
(void) fprintf(stderr,
"%s: reading entry %s from file %s\n",
@@ -1514,6 +1785,7 @@
#else
(void) fprintf(stderr, "%s: terminfo files not supported\n",
_nc_progname);
+ MAIN_LEAKS();
ExitProgram(EXIT_FAILURE);
#endif
} else {
@@ -1526,7 +1798,6 @@
status = _nc_read_entry(tname[termcount],
tfile[termcount],
&entries[termcount].tterm);
- directory = TERMINFO; /* for error message */
}
if (status <= 0) {
@@ -1534,6 +1805,7 @@
"%s: couldn't open terminfo file %s.\n",
_nc_progname,
tfile[termcount]);
+ MAIN_LEAKS();
ExitProgram(EXIT_FAILURE);
}
repair_acsc(&entries[termcount].tterm);
@@ -1565,6 +1837,8 @@
analyze_string("rs3", reset_3string, &entries[0].tterm);
analyze_string("smcup", enter_ca_mode, &entries[0].tterm);
analyze_string("rmcup", exit_ca_mode, &entries[0].tterm);
+ analyze_string("smkx", keypad_xmit, &entries[0].tterm);
+ analyze_string("rmkx", keypad_local, &entries[0].tterm);
#undef CUR
} else {
@@ -1591,27 +1865,17 @@
break;
case C_DIFFERENCE:
- if (itrace)
- (void) fprintf(stderr, "%s: dumping differences\n", _nc_progname);
- (void) printf("comparing %s to %s.\n", tname[0], tname[1]);
+ show_comparing(tname);
compare_entry(compare_predicate, &entries->tterm, quiet);
break;
case C_COMMON:
- if (itrace)
- (void) fprintf(stderr,
- "%s: dumping common capabilities\n",
- _nc_progname);
- (void) printf("comparing %s to %s.\n", tname[0], tname[1]);
+ show_comparing(tname);
compare_entry(compare_predicate, &entries->tterm, quiet);
break;
case C_NAND:
- if (itrace)
- (void) fprintf(stderr,
- "%s: dumping differences\n",
- _nc_progname);
- (void) printf("comparing %s to %s.\n", tname[0], tname[1]);
+ show_comparing(tname);
compare_entry(compare_predicate, &entries->tterm, quiet);
break;
@@ -1632,21 +1896,18 @@
break;
}
}
- } else if (compare == C_USEALL)
+ } else if (compare == C_USEALL) {
(void) fprintf(stderr, "Sorry, -u doesn't work with -F\n");
- else if (compare == C_DEFAULT)
+ } else if (compare == C_DEFAULT) {
(void) fprintf(stderr, "Use `tic -[CI] <file>' for this.\n");
- else if (argc - optind != 2)
+ } else if (argc - optind != 2) {
(void) fprintf(stderr,
"File comparison needs exactly two file arguments.\n");
- else
+ } else {
file_comparison(argc - optind, argv + optind);
+ }
-#if NO_LEAKS
- free(myargv);
- free(tfile);
- free(tname);
-#endif
+ MAIN_LEAKS();
ExitProgram(EXIT_SUCCESS);
}
diff --git a/progs/modules b/progs/modules
index 3b4f3b6..c09d2a6 100644
--- a/progs/modules
+++ b/progs/modules
@@ -1,7 +1,7 @@
-# $Id: modules,v 1.13 2006/12/24 00:53:21 tom Exp $
+# $Id: modules,v 1.18 2014/05/21 17:01:28 tom Exp $
# Program modules (some are in ncurses lib!)
##############################################################################
-# Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. #
+# Copyright (c) 1998-2010,2014 Free 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"), #
@@ -33,11 +33,14 @@
@ base
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
+tic progs $(srcdir) $(HEADER_DEPS) transform.h $(srcdir)/dump_entry.h $(srcdir)/tparm_type.h
+toe progs $(srcdir) $(HEADER_DEPS) $(INCDIR)/hashed_db.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
+tabs progs $(srcdir) $(HEADER_DEPS)
+tparm_type progs $(srcdir) $(HEADER_DEPS) $(srcdir)/tparm_type.h
+tput progs $(srcdir) $(HEADER_DEPS) transform.h $(srcdir)/dump_entry.h $(srcdir)/tparm_type.h termsort.c
tset progs $(srcdir) $(HEADER_DEPS) transform.h $(srcdir)/dump_entry.h ../include/termcap.h
+transform progs $(srcdir) $(HEADER_DEPS) transform.h
# vile:makemode
diff --git a/progs/progs.priv.h b/progs/progs.priv.h
index f0ea460..786fe55 100644
--- a/progs/progs.priv.h
+++ b/progs/progs.priv.h
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -30,19 +30,22 @@
* Author: Thomas E. Dickey 1997-on *
****************************************************************************/
/*
- * $Id: progs.priv.h,v 1.34 2008/08/03 17:43:05 tom Exp $
+ * $Id: progs.priv.h,v 1.41 2015/05/23 23:53:55 tom Exp $
*
* progs.priv.h
*
* Header file for curses utility programs
*/
+#ifndef PROGS_PRIV_H
+#define PROGS_PRIV_H 1
+
#include <ncurses_cfg.h>
#if USE_RCS_IDS
#define MODULE_ID(id) static const char Ident[] = id;
#else
-#define MODULE_ID(id) /*nothing*/
+#define MODULE_ID(id) /*nothing */
#endif
#include <stdlib.h>
@@ -90,6 +93,14 @@
# endif
#endif
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#else
+# if HAVE_STDINT_H
+# include <stdint.h>
+# endif
+#endif
+
#include <assert.h>
#include <errno.h>
@@ -99,7 +110,7 @@
#if HAVE_GETOPT_H
#include <getopt.h>
-#else
+#elif !defined(HAVE_GETOPT_HEADER)
/* 'getopt()' may be prototyped in <stdlib.h>, but declaring its
* variables doesn't hurt.
*/
@@ -109,9 +120,11 @@
#include <curses.h>
#include <term_entry.h>
+#include <nc_termios.h>
#include <tic.h>
#include <nc_tparm.h>
+#include <nc_string.h>
#include <nc_alloc.h>
#if HAVE_NC_FREEALL
#undef ExitProgram
@@ -122,6 +135,12 @@
#endif
#endif
+#if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
+#define IGNORE_RC(func) errno = (int) func
+#else
+#define IGNORE_RC(func) (void) func
+#endif /* gcc workarounds */
+
/* usually in <unistd.h> */
#ifndef STDOUT_FILENO
#define STDOUT_FILENO 1
@@ -171,7 +190,7 @@
# elif defined(MAXPATHLEN)
# define PATH_MAX MAXPATHLEN
# else
-# define PATH_MAX 255 /* the Posix minimum pathsize */
+# define PATH_MAX 255 /* the Posix minimum pathsize */
# endif
#endif
@@ -183,10 +202,12 @@
# if ('z'-'a' == 25) && ('z' < 127) && ('Z'-'A' == 25) && ('Z' < 127) && ('9' < 127)
# define isascii(c) (UChar(c) <= 127)
# else
-# define isascii(c) 1 /* not really ascii anyway */
+# define isascii(c) 1 /* not really ascii anyway */
# endif
#endif
#define UChar(c) ((unsigned char)(c))
#define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
+
+#endif /* PROGS_PRIV_H */
diff --git a/progs/tabs.c b/progs/tabs.c
new file mode 100644
index 0000000..9974c33
--- /dev/null
+++ b/progs/tabs.c
@@ -0,0 +1,546 @@
+/****************************************************************************
+ * Copyright (c) 2008-2013,2015 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey 2008 *
+ ****************************************************************************/
+
+/*
+ * tabs.c -- set terminal hard-tabstops
+ */
+
+#define USE_LIBTINFO
+#include <progs.priv.h>
+
+MODULE_ID("$Id: tabs.c,v 1.37 2015/07/04 21:14:42 tom Exp $")
+
+static void usage(void) GCC_NORETURN;
+
+static char *prg_name;
+static int max_cols;
+
+static void
+failed(const char *s)
+{
+ perror(s);
+ ExitProgram(EXIT_FAILURE);
+}
+
+static int
+putch(int c)
+{
+ return putchar(c);
+}
+
+static void
+do_tabs(int *tab_list)
+{
+ int last = 1;
+ int stop;
+
+ putchar('\r');
+ while ((stop = *tab_list++) > 0) {
+ if (last < stop) {
+ while (last++ < stop) {
+ if (last > max_cols)
+ break;
+ putchar(' ');
+ }
+ }
+ if (stop <= max_cols) {
+ tputs(tparm(set_tab, stop), 1, putch);
+ last = stop;
+ } else {
+ break;
+ }
+ }
+ putchar('\r');
+}
+
+static int *
+decode_tabs(const char *tab_list)
+{
+ int *result = typeCalloc(int, strlen(tab_list) + (unsigned) max_cols);
+ int n = 0;
+ int value = 0;
+ int prior = 0;
+ int ch;
+
+ if (result == 0)
+ failed("decode_tabs");
+
+ while ((ch = *tab_list++) != '\0') {
+ if (isdigit(UChar(ch))) {
+ value *= 10;
+ value += (ch - '0');
+ } else if (ch == ',') {
+ result[n] = value + prior;
+ if (n > 0 && result[n] <= result[n - 1]) {
+ fprintf(stderr,
+ "%s: tab-stops are not in increasing order: %d %d\n",
+ prg_name, value, result[n - 1]);
+ free(result);
+ result = 0;
+ break;
+ }
+ ++n;
+ value = 0;
+ prior = 0;
+ } else if (ch == '+') {
+ if (n)
+ prior = result[n - 1];
+ }
+ }
+
+ if (result != 0) {
+ /*
+ * If there is only one value, then it is an option such as "-8".
+ */
+ if ((n == 0) && (value > 0)) {
+ int step = value;
+ value = 1;
+ while (n < max_cols - 1) {
+ result[n++] = value;
+ value += step;
+ }
+ }
+
+ /*
+ * Add the last value, if any.
+ */
+ result[n++] = value + prior;
+ result[n] = 0;
+ }
+
+ return result;
+}
+
+static void
+print_ruler(int *tab_list)
+{
+ int last = 0;
+ int stop;
+ int n;
+
+ /* first print a readable ruler */
+ for (n = 0; n < max_cols; n += 10) {
+ int ch = 1 + (n / 10);
+ char buffer[20];
+ _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+ "----+----%c",
+ ((ch < 10)
+ ? (ch + '0')
+ : (ch + 'A' - 10)));
+ printf("%.*s", ((max_cols - n) > 10) ? 10 : (max_cols - n), buffer);
+ }
+ putchar('\n');
+
+ /* now, print '*' for each stop */
+ for (n = 0, last = 0; (tab_list[n] > 0) && (last < max_cols); ++n) {
+ stop = tab_list[n];
+ while (++last < stop) {
+ if (last <= max_cols) {
+ putchar('-');
+ } else {
+ break;
+ }
+ }
+ if (last <= max_cols) {
+ putchar('*');
+ last = stop;
+ } else {
+ break;
+ }
+ }
+ while (++last <= max_cols)
+ putchar('-');
+ putchar('\n');
+}
+
+/*
+ * Write an '*' on each tabstop, to demonstrate whether it lines up with the
+ * ruler.
+ */
+static void
+write_tabs(int *tab_list)
+{
+ int stop;
+
+ while ((stop = *tab_list++) > 0 && stop <= max_cols) {
+ fputs((stop == 1) ? "*" : "\t*", stdout);
+ };
+ /* also show a tab _past_ the stops */
+ if (stop < max_cols)
+ fputs("\t+", stdout);
+ putchar('\n');
+}
+
+/*
+ * Trim leading/trailing blanks, as well as blanks after a comma.
+ * Convert embedded blanks to commas.
+ */
+static char *
+trimmed_tab_list(const char *source)
+{
+ char *result = strdup(source);
+ int ch, j, k, last;
+
+ if (result != 0) {
+ for (j = k = last = 0; result[j] != 0; ++j) {
+ ch = UChar(result[j]);
+ if (isspace(ch)) {
+ if (last == '\0') {
+ continue;
+ } else if (isdigit(last) || last == ',') {
+ ch = ',';
+ }
+ } else if (ch == ',') {
+ ;
+ } else {
+ if (last == ',')
+ result[k++] = (char) last;
+ result[k++] = (char) ch;
+ }
+ last = ch;
+ }
+ result[k] = '\0';
+ }
+ return result;
+}
+
+static bool
+comma_is_needed(const char *source)
+{
+ bool result = FALSE;
+
+ if (source != 0) {
+ size_t len = strlen(source);
+ if (len != 0)
+ result = (source[len - 1] != ',');
+ } else {
+ result = FALSE;
+ }
+ return result;
+}
+
+/*
+ * Add a command-line parameter to the tab-list. It can be blank- or comma-
+ * separated (or a mixture). For simplicity, empty tabs are ignored, e.g.,
+ * tabs 1,,6,11
+ * tabs 1,6,11
+ * are treated the same.
+ */
+static const char *
+add_to_tab_list(char **append, const char *value)
+{
+ char *result = *append;
+ char *copied = trimmed_tab_list(value);
+
+ if (copied != 0 && *copied != '\0') {
+ const char *comma = ",";
+ size_t need = 1 + strlen(copied);
+
+ if (*copied == ',')
+ comma = "";
+ else if (!comma_is_needed(*append))
+ comma = "";
+
+ need += strlen(comma);
+ if (*append != 0)
+ need += strlen(*append);
+
+ result = malloc(need);
+ if (result == 0)
+ failed("add_to_tab_list");
+
+ *result = '\0';
+ if (*append != 0) {
+ _nc_STRCPY(result, *append, need);
+ free(*append);
+ }
+ _nc_STRCAT(result, comma, need);
+ _nc_STRCAT(result, copied, need);
+
+ *append = result;
+ }
+ free(copied);
+ return result;
+}
+
+/*
+ * Check for illegal characters in the tab-list.
+ */
+static bool
+legal_tab_list(const char *tab_list)
+{
+ bool result = TRUE;
+
+ if (tab_list != 0 && *tab_list != '\0') {
+ if (comma_is_needed(tab_list)) {
+ int n, ch;
+ for (n = 0; tab_list[n] != '\0'; ++n) {
+ ch = UChar(tab_list[n]);
+ if (!(isdigit(ch) || ch == ',' || ch == '+')) {
+ fprintf(stderr,
+ "%s: unexpected character found '%c'\n",
+ prg_name, ch);
+ result = FALSE;
+ break;
+ }
+ }
+ } else {
+ fprintf(stderr, "%s: trailing comma found '%s'\n", prg_name, tab_list);
+ result = FALSE;
+ }
+ } else {
+ fprintf(stderr, "%s: no tab-list given\n", prg_name);
+ result = FALSE;
+ }
+ return result;
+}
+
+static char *
+skip_list(char *value)
+{
+ while (*value != '\0' &&
+ (isdigit(UChar(*value)) ||
+ isspace(UChar(*value)) ||
+ strchr("+,", UChar(*value)) != 0)) {
+ ++value;
+ }
+ return value;
+}
+
+static void
+usage(void)
+{
+#define DATA(s) s "\n"
+ static const char msg[] =
+ {
+ DATA("Usage: tabs [options] [tabstop-list]")
+ DATA("")
+ DATA("Options:")
+ DATA(" -0 reset tabs")
+ DATA(" -8 set tabs to standard interval")
+ DATA(" -a Assembler, IBM S/370, first format")
+ DATA(" -a2 Assembler, IBM S/370, second format")
+ DATA(" -c COBOL, normal format")
+ DATA(" -c2 COBOL compact format")
+ DATA(" -c3 COBOL compact format extended")
+ DATA(" -d debug (show ruler with expected/actual tab positions)")
+ DATA(" -f FORTRAN")
+ DATA(" -n no-op (do not modify terminal settings)")
+ DATA(" -p PL/I")
+ DATA(" -s SNOBOL")
+ DATA(" -u UNIVAC 1100 Assembler")
+ DATA(" -T name use terminal type 'name'")
+ DATA(" -V print version")
+ DATA("")
+ DATA("A tabstop-list is an ordered list of column numbers, e.g., 1,11,21")
+ DATA("or 1,+10,+10 which is the same.")
+ };
+#undef DATA
+
+ fflush(stdout);
+ fputs(msg, stderr);
+ ExitProgram(EXIT_FAILURE);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int rc = EXIT_FAILURE;
+ bool debug = FALSE;
+ bool no_op = FALSE;
+ int n, ch;
+ NCURSES_CONST char *term_name = 0;
+ char *append = 0;
+ const char *tab_list = 0;
+
+ prg_name = _nc_rootname(argv[0]);
+
+ if ((term_name = getenv("TERM")) == 0)
+ term_name = "ansi+tabs";
+
+ /* cannot use getopt, since some options are two-character */
+ for (n = 1; n < argc; ++n) {
+ char *option = argv[n];
+ switch (option[0]) {
+ case '-':
+ while ((ch = *++option) != '\0') {
+ switch (ch) {
+ case 'a':
+ switch (*++option) {
+ default:
+ case '\0':
+ tab_list = "1,10,16,36,72";
+ option--;
+ /* Assembler, IBM S/370, first format */
+ break;
+ case '2':
+ tab_list = "1,10,16,40,72";
+ /* Assembler, IBM S/370, second format */
+ break;
+ }
+ break;
+ case 'c':
+ switch (*++option) {
+ default:
+ case '\0':
+ tab_list = "1,8,12,16,20,55";
+ option--;
+ /* COBOL, normal format */
+ break;
+ case '2':
+ tab_list = "1,6,10,14,49";
+ /* COBOL compact format */
+ break;
+ case '3':
+ tab_list = "1,6,10,14,18,22,26,30,34,38,42,46,50,54,58,62,67";
+ /* COBOL compact format extended */
+ break;
+ }
+ break;
+ case 'd': /* ncurses extension */
+ debug = TRUE;
+ break;
+ case 'f':
+ tab_list = "1,7,11,15,19,23";
+ /* FORTRAN */
+ break;
+ case 'n': /* ncurses extension */
+ no_op = TRUE;
+ break;
+ case 'p':
+ tab_list = "1,5,9,13,17,21,25,29,33,37,41,45,49,53,57,61";
+ /* PL/I */
+ break;
+ case 's':
+ tab_list = "1,10,55";
+ /* SNOBOL */
+ break;
+ case 'u':
+ tab_list = "1,12,20,44";
+ /* UNIVAC 1100 Assembler */
+ break;
+ case 'T':
+ ++n;
+ if (*++option != '\0') {
+ term_name = option;
+ } else {
+ term_name = argv[n++];
+ option--;
+ }
+ option += ((int) strlen(option)) - 1;
+ continue;
+ case 'V':
+ puts(curses_version());
+ ExitProgram(EXIT_SUCCESS);
+ default:
+ if (isdigit(UChar(*option))) {
+ char *copy = strdup(option);
+ *skip_list(copy) = '\0';
+ tab_list = copy;
+ option = skip_list(option) - 1;
+ } else {
+ usage();
+ }
+ break;
+ }
+ }
+ break;
+ case '+':
+ while ((ch = *++option) != '\0') {
+ switch (ch) {
+ case 'm':
+ /*
+ * The "+mXXX" option is unimplemented because only the long-obsolete
+ * att510d implements smgl, which is needed to support
+ * this option.
+ */
+ break;
+ default:
+ /* special case of relative stops separated by spaces? */
+ if (option == argv[n] + 1) {
+ tab_list = add_to_tab_list(&append, argv[n]);
+ }
+ break;
+ }
+ }
+ break;
+ default:
+ if (append != 0) {
+ if (tab_list != (const char *) append) {
+ /* one of the predefined options was used */
+ free(append);
+ append = 0;
+ }
+ }
+ tab_list = add_to_tab_list(&append, option);
+ break;
+ }
+ }
+
+ setupterm(term_name, STDOUT_FILENO, (int *) 0);
+
+ max_cols = (columns > 0) ? columns : 80;
+
+ if (!VALID_STRING(clear_all_tabs)) {
+ fprintf(stderr,
+ "%s: terminal type '%s' cannot reset tabs\n",
+ prg_name, term_name);
+ } else if (!VALID_STRING(set_tab)) {
+ fprintf(stderr,
+ "%s: terminal type '%s' cannot set tabs\n",
+ prg_name, term_name);
+ } else if (legal_tab_list(tab_list)) {
+ int *list = decode_tabs(tab_list);
+
+ if (!no_op)
+ tputs(clear_all_tabs, 1, putch);
+
+ if (list != 0) {
+ if (!no_op)
+ do_tabs(list);
+ if (debug) {
+ fflush(stderr);
+ printf("tabs %s\n", tab_list);
+ print_ruler(list);
+ write_tabs(list);
+ }
+ free(list);
+ } else if (debug) {
+ fflush(stderr);
+ printf("tabs %s\n", tab_list);
+ }
+ rc = EXIT_SUCCESS;
+ }
+ if (append != 0)
+ free(append);
+ ExitProgram(rc);
+}
diff --git a/progs/termsort.c b/progs/termsort.c
deleted file mode 100644
index 9cd80f8..0000000
--- a/progs/termsort.c
+++ /dev/null
@@ -1,2163 +0,0 @@
-/*
- * termsort.c --- sort order arrays for use by infocmp.
- *
- * Note: this file is generated using MKtermsort.sh, do not edit by hand.
- */
-static const PredIdx bool_terminfo_sort[] = {
- 40 , /* OTMT */
- 41 , /* OTNL */
- 37 , /* OTbs */
- 39 , /* OTnc */
- 38 , /* OTns */
- 42 , /* OTpt */
- 43 , /* OTxr */
- 1 , /* am */
- 28 , /* bce */
- 0 , /* bw */
- 27 , /* ccc */
- 23 , /* chts */
- 35 , /* cpix */
- 31 , /* crxm */
- 11 , /* da */
- 32 , /* daisy */
- 12 , /* db */
- 5 , /* eo */
- 16 , /* eslok */
- 6 , /* gn */
- 7 , /* hc */
- 29 , /* hls */
- 9 , /* hs */
- 18 , /* hz */
- 10 , /* in */
- 8 , /* km */
- 36 , /* lpix */
- 22 , /* mc5i */
- 13 , /* mir */
- 14 , /* msgr */
- 26 , /* ndscr */
- 25 , /* npc */
- 24 , /* nrrmc */
- 21 , /* nxon */
- 15 , /* os */
- 34 , /* sam */
- 19 , /* ul */
- 4 , /* xenl */
- 3 , /* xhp */
- 30 , /* xhpa */
- 20 , /* xon */
- 2 , /* xsb */
- 17 , /* xt */
- 33 , /* xvpa */
-};
-
-static const PredIdx num_terminfo_sort[] = {
- 36 , /* OTdB */
- 34 , /* OTdC */
- 35 , /* OTdN */
- 37 , /* OTdT */
- 38 , /* OTkn */
- 33 , /* OTug */
- 31 , /* bitwin */
- 32 , /* bitype */
- 30 , /* btns */
- 16 , /* bufsz */
- 13 , /* colors */
- 0 , /* cols */
- 28 , /* cps */
- 1 , /* it */
- 9 , /* lh */
- 2 , /* lines */
- 3 , /* lm */
- 10 , /* lw */
- 11 , /* ma */
- 19 , /* maddr */
- 21 , /* mcs */
- 20 , /* mjump */
- 22 , /* mls */
- 15 , /* ncv */
- 8 , /* nlab */
- 23 , /* npins */
- 24 , /* orc */
- 26 , /* orhi */
- 25 , /* orl */
- 27 , /* orvi */
- 14 , /* pairs */
- 5 , /* pb */
- 18 , /* spinh */
- 17 , /* spinv */
- 6 , /* vt */
- 29 , /* widcs */
- 12 , /* wnum */
- 7 , /* wsl */
- 4 , /* xmc */
-};
-
-static const PredIdx str_terminfo_sort[] = {
- 402 , /* OTG1 */
- 400 , /* OTG2 */
- 401 , /* OTG3 */
- 403 , /* OTG4 */
- 410 , /* OTGC */
- 407 , /* OTGD */
- 408 , /* OTGH */
- 405 , /* OTGL */
- 404 , /* OTGR */
- 406 , /* OTGU */
- 409 , /* OTGV */
- 397 , /* OTbc */
- 394 , /* OTi2 */
- 398 , /* OTko */
- 399 , /* OTma */
- 396 , /* OTnl */
- 395 , /* OTrs */
- 146 , /* acsc */
- 1 , /* bel */
- 372 , /* bicr */
- 371 , /* binel */
- 370 , /* birep */
- 26 , /* blink */
- 27 , /* bold */
- 413 , /* box1 */
- 0 , /* cbt */
- 306 , /* chr */
- 13 , /* civis */
- 5 , /* clear */
- 9 , /* cmdch */
- 16 , /* cnorm */
- 373 , /* colornm */
- 304 , /* cpi */
- 2 , /* cr */
- 363 , /* csin */
- 354 , /* csnm */
- 3 , /* csr */
- 111 , /* cub */
- 14 , /* cub1 */
- 107 , /* cud */
- 11 , /* cud1 */
- 112 , /* cuf */
- 17 , /* cuf1 */
- 10 , /* cup */
- 114 , /* cuu */
- 19 , /* cuu1 */
- 307 , /* cvr */
- 20 , /* cvvis */
- 277 , /* cwin */
- 105 , /* dch */
- 21 , /* dch1 */
- 275 , /* dclk */
- 374 , /* defbi */
- 308 , /* defc */
- 362 , /* devt */
- 280 , /* dial */
- 30 , /* dim */
- 378 , /* dispc */
- 106 , /* dl */
- 22 , /* dl1 */
- 352 , /* docr */
- 23 , /* dsl */
- 37 , /* ech */
- 7 , /* ed */
- 386 , /* ehhlm */
- 6 , /* el */
- 269 , /* el1 */
- 387 , /* elhlm */
- 388 , /* elohlm */
- 155 , /* enacs */
- 375 , /* endbi */
- 389 , /* erhlm */
- 390 , /* ethlm */
- 391 , /* evhlm */
- 46 , /* ff */
- 45 , /* flash */
- 273 , /* fln */
- 47 , /* fsl */
- 358 , /* getm */
- 24 , /* hd */
- 12 , /* home */
- 284 , /* hook */
- 8 , /* hpa */
- 134 , /* ht */
- 132 , /* hts */
- 137 , /* hu */
- 279 , /* hup */
- 108 , /* ich */
- 52 , /* ich1 */
- 51 , /* if */
- 110 , /* il */
- 53 , /* il1 */
- 129 , /* ind */
- 109 , /* indn */
- 299 , /* initc */
- 300 , /* initp */
- 32 , /* invis */
- 54 , /* ip */
- 138 , /* iprog */
- 48 , /* is1 */
- 49 , /* is2 */
- 50 , /* is3 */
- 186 , /* kBEG */
- 187 , /* kCAN */
- 188 , /* kCMD */
- 189 , /* kCPY */
- 190 , /* kCRT */
- 191 , /* kDC */
- 192 , /* kDL */
- 194 , /* kEND */
- 195 , /* kEOL */
- 196 , /* kEXT */
- 197 , /* kFND */
- 198 , /* kHLP */
- 199 , /* kHOM */
- 200 , /* kIC */
- 201 , /* kLFT */
- 203 , /* kMOV */
- 202 , /* kMSG */
- 204 , /* kNXT */
- 205 , /* kOPT */
- 207 , /* kPRT */
- 206 , /* kPRV */
- 208 , /* kRDO */
- 211 , /* kRES */
- 210 , /* kRIT */
- 209 , /* kRPL */
- 212 , /* kSAV */
- 213 , /* kSPD */
- 214 , /* kUND */
- 139 , /* ka1 */
- 140 , /* ka3 */
- 141 , /* kb2 */
- 158 , /* kbeg */
- 55 , /* kbs */
- 142 , /* kc1 */
- 143 , /* kc3 */
- 159 , /* kcan */
- 148 , /* kcbt */
- 160 , /* kclo */
- 57 , /* kclr */
- 161 , /* kcmd */
- 162 , /* kcpy */
- 163 , /* kcrt */
- 58 , /* kctab */
- 79 , /* kcub1 */
- 61 , /* kcud1 */
- 83 , /* kcuf1 */
- 87 , /* kcuu1 */
- 59 , /* kdch1 */
- 60 , /* kdl1 */
- 64 , /* ked */
- 63 , /* kel */
- 164 , /* kend */
- 165 , /* kent */
- 166 , /* kext */
- 65 , /* kf0 */
- 66 , /* kf1 */
- 67 , /* kf10 */
- 216 , /* kf11 */
- 217 , /* kf12 */
- 218 , /* kf13 */
- 219 , /* kf14 */
- 220 , /* kf15 */
- 221 , /* kf16 */
- 222 , /* kf17 */
- 223 , /* kf18 */
- 224 , /* kf19 */
- 68 , /* kf2 */
- 225 , /* kf20 */
- 226 , /* kf21 */
- 227 , /* kf22 */
- 228 , /* kf23 */
- 229 , /* kf24 */
- 230 , /* kf25 */
- 231 , /* kf26 */
- 232 , /* kf27 */
- 233 , /* kf28 */
- 234 , /* kf29 */
- 69 , /* kf3 */
- 235 , /* kf30 */
- 236 , /* kf31 */
- 237 , /* kf32 */
- 238 , /* kf33 */
- 239 , /* kf34 */
- 240 , /* kf35 */
- 241 , /* kf36 */
- 242 , /* kf37 */
- 243 , /* kf38 */
- 244 , /* kf39 */
- 70 , /* kf4 */
- 245 , /* kf40 */
- 246 , /* kf41 */
- 247 , /* kf42 */
- 248 , /* kf43 */
- 249 , /* kf44 */
- 250 , /* kf45 */
- 251 , /* kf46 */
- 252 , /* kf47 */
- 253 , /* kf48 */
- 254 , /* kf49 */
- 71 , /* kf5 */
- 255 , /* kf50 */
- 256 , /* kf51 */
- 257 , /* kf52 */
- 258 , /* kf53 */
- 259 , /* kf54 */
- 260 , /* kf55 */
- 261 , /* kf56 */
- 262 , /* kf57 */
- 263 , /* kf58 */
- 264 , /* kf59 */
- 72 , /* kf6 */
- 265 , /* kf60 */
- 266 , /* kf61 */
- 267 , /* kf62 */
- 268 , /* kf63 */
- 73 , /* kf7 */
- 74 , /* kf8 */
- 75 , /* kf9 */
- 167 , /* kfnd */
- 168 , /* khlp */
- 76 , /* khome */
- 86 , /* khts */
- 77 , /* kich1 */
- 78 , /* kil1 */
- 84 , /* kind */
- 80 , /* kll */
- 355 , /* kmous */
- 171 , /* kmov */
- 169 , /* kmrk */
- 170 , /* kmsg */
- 81 , /* knp */
- 172 , /* knxt */
- 173 , /* kopn */
- 174 , /* kopt */
- 82 , /* kpp */
- 176 , /* kprt */
- 175 , /* kprv */
- 177 , /* krdo */
- 178 , /* kref */
- 182 , /* kres */
- 179 , /* krfr */
- 85 , /* kri */
- 62 , /* krmir */
- 180 , /* krpl */
- 181 , /* krst */
- 183 , /* ksav */
- 193 , /* kslt */
- 184 , /* kspd */
- 56 , /* ktbc */
- 185 , /* kund */
- 90 , /* lf0 */
- 91 , /* lf1 */
- 92 , /* lf10 */
- 93 , /* lf2 */
- 94 , /* lf3 */
- 95 , /* lf4 */
- 96 , /* lf5 */
- 97 , /* lf6 */
- 98 , /* lf7 */
- 99 , /* lf8 */
- 100 , /* lf9 */
- 18 , /* ll */
- 305 , /* lpi */
- 118 , /* mc0 */
- 119 , /* mc4 */
- 120 , /* mc5 */
- 144 , /* mc5p */
- 336 , /* mcub */
- 330 , /* mcub1 */
- 335 , /* mcud */
- 329 , /* mcud1 */
- 337 , /* mcuf */
- 331 , /* mcuf1 */
- 338 , /* mcuu */
- 333 , /* mcuu1 */
- 411 , /* meml */
- 412 , /* memu */
- 270 , /* mgc */
- 328 , /* mhpa */
- 356 , /* minfo */
- 15 , /* mrcup */
- 332 , /* mvpa */
- 103 , /* nel */
- 298 , /* oc */
- 297 , /* op */
- 104 , /* pad */
- 285 , /* pause */
- 383 , /* pctrm */
- 115 , /* pfkey */
- 116 , /* pfloc */
- 117 , /* pfx */
- 361 , /* pfxl */
- 147 , /* pln */
- 334 , /* porder */
- 33 , /* prot */
- 283 , /* pulse */
- 281 , /* qdial */
- 348 , /* rbim */
- 126 , /* rc */
- 349 , /* rcsd */
- 121 , /* rep */
- 357 , /* reqmp */
- 34 , /* rev */
- 125 , /* rf */
- 215 , /* rfi */
- 130 , /* ri */
- 113 , /* rin */
- 321 , /* ritm */
- 322 , /* rlm */
- 38 , /* rmacs */
- 152 , /* rmam */
- 276 , /* rmclk */
- 40 , /* rmcup */
- 41 , /* rmdc */
- 323 , /* rmicm */
- 42 , /* rmir */
- 88 , /* rmkx */
- 157 , /* rmln */
- 101 , /* rmm */
- 145 , /* rmp */
- 380 , /* rmpch */
- 382 , /* rmsc */
- 43 , /* rmso */
- 44 , /* rmul */
- 150 , /* rmxon */
- 122 , /* rs1 */
- 123 , /* rs2 */
- 124 , /* rs3 */
- 324 , /* rshm */
- 325 , /* rsubm */
- 326 , /* rsupm */
- 327 , /* rum */
- 320 , /* rwidm */
- 364 , /* s0ds */
- 365 , /* s1ds */
- 366 , /* s2ds */
- 367 , /* s3ds */
- 346 , /* sbim */
- 128 , /* sc */
- 385 , /* scesa */
- 384 , /* scesc */
- 274 , /* sclk */
- 301 , /* scp */
- 339 , /* scs */
- 347 , /* scsd */
- 310 , /* sdrfq */
- 360 , /* setab */
- 359 , /* setaf */
- 303 , /* setb */
- 376 , /* setcolor */
- 302 , /* setf */
- 131 , /* sgr */
- 39 , /* sgr0 */
- 392 , /* sgr1 */
- 311 , /* sitm */
- 393 , /* slength */
- 377 , /* slines */
- 312 , /* slm */
- 25 , /* smacs */
- 151 , /* smam */
- 28 , /* smcup */
- 29 , /* smdc */
- 340 , /* smgb */
- 341 , /* smgbp */
- 271 , /* smgl */
- 342 , /* smglp */
- 368 , /* smglr */
- 272 , /* smgr */
- 343 , /* smgrp */
- 344 , /* smgt */
- 369 , /* smgtb */
- 345 , /* smgtp */
- 313 , /* smicm */
- 31 , /* smir */
- 89 , /* smkx */
- 156 , /* smln */
- 102 , /* smm */
- 379 , /* smpch */
- 381 , /* smsc */
- 35 , /* smso */
- 36 , /* smul */
- 149 , /* smxon */
- 314 , /* snlq */
- 315 , /* snrmq */
- 316 , /* sshm */
- 317 , /* ssubm */
- 318 , /* ssupm */
- 350 , /* subcs */
- 319 , /* sum */
- 351 , /* supcs */
- 309 , /* swidm */
- 4 , /* tbc */
- 282 , /* tone */
- 135 , /* tsl */
- 287 , /* u0 */
- 288 , /* u1 */
- 289 , /* u2 */
- 290 , /* u3 */
- 291 , /* u4 */
- 292 , /* u5 */
- 293 , /* u6 */
- 294 , /* u7 */
- 295 , /* u8 */
- 296 , /* u9 */
- 136 , /* uc */
- 127 , /* vpa */
- 286 , /* wait */
- 133 , /* wind */
- 278 , /* wingo */
- 154 , /* xoffc */
- 153 , /* xonc */
- 353 , /* zerom */
-};
-
-static const PredIdx bool_variable_sort[] = {
- 0 , /* auto_left_margin */
- 1 , /* auto_right_margin */
- 28 , /* back_color_erase */
- 37 , /* backspaces_with_bs */
- 27 , /* can_change */
- 3 , /* ceol_standout_glitch */
- 30 , /* col_addr_glitch */
- 35 , /* cpi_changes_res */
- 31 , /* cr_cancels_micro_mode */
- 38 , /* crt_no_scrolling */
- 17 , /* dest_tabs_magic_smso */
- 4 , /* eat_newline_glitch */
- 5 , /* erase_overstrike */
- 6 , /* generic_type */
- 40 , /* gnu_has_meta_key */
- 7 , /* hard_copy */
- 23 , /* hard_cursor */
- 42 , /* has_hardware_tabs */
- 8 , /* has_meta_key */
- 32 , /* has_print_wheel */
- 9 , /* has_status_line */
- 29 , /* hue_lightness_saturation */
- 10 , /* insert_null_glitch */
- 41 , /* linefeed_is_newline */
- 36 , /* lpi_changes_res */
- 11 , /* memory_above */
- 12 , /* memory_below */
- 13 , /* move_insert_mode */
- 14 , /* move_standout_mode */
- 21 , /* needs_xon_xoff */
- 39 , /* no_correctly_working_cr */
- 2 , /* no_esc_ctlc */
- 25 , /* no_pad_char */
- 26 , /* non_dest_scroll_region */
- 24 , /* non_rev_rmcup */
- 15 , /* over_strike */
- 22 , /* prtr_silent */
- 43 , /* return_does_clr_eol */
- 33 , /* row_addr_glitch */
- 34 , /* semi_auto_right_margin */
- 16 , /* status_line_esc_ok */
- 18 , /* tilde_glitch */
- 19 , /* transparent_underline */
- 20 , /* xon_xoff */
-};
-
-static const PredIdx num_variable_sort[] = {
- 36 , /* backspace_delay */
- 31 , /* bit_image_entwining */
- 32 , /* bit_image_type */
- 16 , /* buffer_capacity */
- 30 , /* buttons */
- 34 , /* carriage_return_delay */
- 0 , /* columns */
- 18 , /* dot_horz_spacing */
- 17 , /* dot_vert_spacing */
- 37 , /* horizontal_tab_delay */
- 1 , /* init_tabs */
- 9 , /* label_height */
- 10 , /* label_width */
- 2 , /* lines */
- 3 , /* lines_of_memory */
- 4 , /* magic_cookie_glitch */
- 33 , /* magic_cookie_glitch_ul */
- 11 , /* max_attributes */
- 13 , /* max_colors */
- 19 , /* max_micro_address */
- 20 , /* max_micro_jump */
- 14 , /* max_pairs */
- 12 , /* maximum_windows */
- 21 , /* micro_col_size */
- 22 , /* micro_line_size */
- 35 , /* new_line_delay */
- 15 , /* no_color_video */
- 8 , /* num_labels */
- 38 , /* number_of_function_keys */
- 23 , /* number_of_pins */
- 24 , /* output_res_char */
- 26 , /* output_res_horz_inch */
- 25 , /* output_res_line */
- 27 , /* output_res_vert_inch */
- 5 , /* padding_baud_rate */
- 28 , /* print_rate */
- 6 , /* virtual_terminal */
- 29 , /* wide_char_size */
- 7 , /* width_status_line */
-};
-
-static const PredIdx str_variable_sort[] = {
- 406 , /* acs_btee */
- 146 , /* acs_chars */
- 408 , /* acs_hline */
- 401 , /* acs_llcorner */
- 403 , /* acs_lrcorner */
- 404 , /* acs_ltee */
- 410 , /* acs_plus */
- 405 , /* acs_rtee */
- 407 , /* acs_ttee */
- 400 , /* acs_ulcorner */
- 402 , /* acs_urcorner */
- 409 , /* acs_vline */
- 385 , /* alt_scancode_esc */
- 399 , /* arrow_key_map */
- 0 , /* back_tab */
- 397 , /* backspace_if_not_bs */
- 1 , /* bell */
- 372 , /* bit_image_carriage_return */
- 371 , /* bit_image_newline */
- 370 , /* bit_image_repeat */
- 413 , /* box_chars_1 */
- 2 , /* carriage_return */
- 304 , /* change_char_pitch */
- 305 , /* change_line_pitch */
- 306 , /* change_res_horz */
- 307 , /* change_res_vert */
- 3 , /* change_scroll_region */
- 145 , /* char_padding */
- 354 , /* char_set_names */
- 4 , /* clear_all_tabs */
- 270 , /* clear_margins */
- 5 , /* clear_screen */
- 269 , /* clr_bol */
- 6 , /* clr_eol */
- 7 , /* clr_eos */
- 363 , /* code_set_init */
- 373 , /* color_names */
- 8 , /* column_address */
- 9 , /* command_character */
- 277 , /* create_window */
- 10 , /* cursor_address */
- 11 , /* cursor_down */
- 12 , /* cursor_home */
- 13 , /* cursor_invisible */
- 14 , /* cursor_left */
- 15 , /* cursor_mem_address */
- 16 , /* cursor_normal */
- 17 , /* cursor_right */
- 18 , /* cursor_to_ll */
- 19 , /* cursor_up */
- 20 , /* cursor_visible */
- 374 , /* define_bit_image_region */
- 308 , /* define_char */
- 21 , /* delete_character */
- 22 , /* delete_line */
- 362 , /* device_type */
- 280 , /* dial_phone */
- 23 , /* dis_status_line */
- 275 , /* display_clock */
- 378 , /* display_pc_char */
- 24 , /* down_half_line */
- 155 , /* ena_acs */
- 375 , /* end_bit_image_region */
- 25 , /* enter_alt_charset_mode */
- 151 , /* enter_am_mode */
- 26 , /* enter_blink_mode */
- 27 , /* enter_bold_mode */
- 28 , /* enter_ca_mode */
- 29 , /* enter_delete_mode */
- 30 , /* enter_dim_mode */
- 309 , /* enter_doublewide_mode */
- 310 , /* enter_draft_quality */
- 386 , /* enter_horizontal_hl_mode */
- 31 , /* enter_insert_mode */
- 311 , /* enter_italics_mode */
- 387 , /* enter_left_hl_mode */
- 312 , /* enter_leftward_mode */
- 388 , /* enter_low_hl_mode */
- 313 , /* enter_micro_mode */
- 314 , /* enter_near_letter_quality */
- 315 , /* enter_normal_quality */
- 379 , /* enter_pc_charset_mode */
- 33 , /* enter_protected_mode */
- 34 , /* enter_reverse_mode */
- 389 , /* enter_right_hl_mode */
- 381 , /* enter_scancode_mode */
- 32 , /* enter_secure_mode */
- 316 , /* enter_shadow_mode */
- 35 , /* enter_standout_mode */
- 317 , /* enter_subscript_mode */
- 318 , /* enter_superscript_mode */
- 390 , /* enter_top_hl_mode */
- 36 , /* enter_underline_mode */
- 319 , /* enter_upward_mode */
- 391 , /* enter_vertical_hl_mode */
- 149 , /* enter_xon_mode */
- 37 , /* erase_chars */
- 38 , /* exit_alt_charset_mode */
- 152 , /* exit_am_mode */
- 39 , /* exit_attribute_mode */
- 40 , /* exit_ca_mode */
- 41 , /* exit_delete_mode */
- 320 , /* exit_doublewide_mode */
- 42 , /* exit_insert_mode */
- 321 , /* exit_italics_mode */
- 322 , /* exit_leftward_mode */
- 323 , /* exit_micro_mode */
- 380 , /* exit_pc_charset_mode */
- 382 , /* exit_scancode_mode */
- 324 , /* exit_shadow_mode */
- 43 , /* exit_standout_mode */
- 325 , /* exit_subscript_mode */
- 326 , /* exit_superscript_mode */
- 44 , /* exit_underline_mode */
- 327 , /* exit_upward_mode */
- 150 , /* exit_xon_mode */
- 285 , /* fixed_pause */
- 284 , /* flash_hook */
- 45 , /* flash_screen */
- 46 , /* form_feed */
- 47 , /* from_status_line */
- 358 , /* get_mouse */
- 278 , /* goto_window */
- 279 , /* hangup */
- 48 , /* init_1string */
- 49 , /* init_2string */
- 50 , /* init_3string */
- 51 , /* init_file */
- 138 , /* init_prog */
- 299 , /* initialize_color */
- 300 , /* initialize_pair */
- 52 , /* insert_character */
- 53 , /* insert_line */
- 54 , /* insert_padding */
- 139 , /* key_a1 */
- 140 , /* key_a3 */
- 141 , /* key_b2 */
- 55 , /* key_backspace */
- 158 , /* key_beg */
- 148 , /* key_btab */
- 142 , /* key_c1 */
- 143 , /* key_c3 */
- 159 , /* key_cancel */
- 56 , /* key_catab */
- 57 , /* key_clear */
- 160 , /* key_close */
- 161 , /* key_command */
- 162 , /* key_copy */
- 163 , /* key_create */
- 58 , /* key_ctab */
- 59 , /* key_dc */
- 60 , /* key_dl */
- 61 , /* key_down */
- 62 , /* key_eic */
- 164 , /* key_end */
- 165 , /* key_enter */
- 63 , /* key_eol */
- 64 , /* key_eos */
- 166 , /* key_exit */
- 65 , /* key_f0 */
- 66 , /* key_f1 */
- 67 , /* key_f10 */
- 216 , /* key_f11 */
- 217 , /* key_f12 */
- 218 , /* key_f13 */
- 219 , /* key_f14 */
- 220 , /* key_f15 */
- 221 , /* key_f16 */
- 222 , /* key_f17 */
- 223 , /* key_f18 */
- 224 , /* key_f19 */
- 68 , /* key_f2 */
- 225 , /* key_f20 */
- 226 , /* key_f21 */
- 227 , /* key_f22 */
- 228 , /* key_f23 */
- 229 , /* key_f24 */
- 230 , /* key_f25 */
- 231 , /* key_f26 */
- 232 , /* key_f27 */
- 233 , /* key_f28 */
- 234 , /* key_f29 */
- 69 , /* key_f3 */
- 235 , /* key_f30 */
- 236 , /* key_f31 */
- 237 , /* key_f32 */
- 238 , /* key_f33 */
- 239 , /* key_f34 */
- 240 , /* key_f35 */
- 241 , /* key_f36 */
- 242 , /* key_f37 */
- 243 , /* key_f38 */
- 244 , /* key_f39 */
- 70 , /* key_f4 */
- 245 , /* key_f40 */
- 246 , /* key_f41 */
- 247 , /* key_f42 */
- 248 , /* key_f43 */
- 249 , /* key_f44 */
- 250 , /* key_f45 */
- 251 , /* key_f46 */
- 252 , /* key_f47 */
- 253 , /* key_f48 */
- 254 , /* key_f49 */
- 71 , /* key_f5 */
- 255 , /* key_f50 */
- 256 , /* key_f51 */
- 257 , /* key_f52 */
- 258 , /* key_f53 */
- 259 , /* key_f54 */
- 260 , /* key_f55 */
- 261 , /* key_f56 */
- 262 , /* key_f57 */
- 263 , /* key_f58 */
- 264 , /* key_f59 */
- 72 , /* key_f6 */
- 265 , /* key_f60 */
- 266 , /* key_f61 */
- 267 , /* key_f62 */
- 268 , /* key_f63 */
- 73 , /* key_f7 */
- 74 , /* key_f8 */
- 75 , /* key_f9 */
- 167 , /* key_find */
- 168 , /* key_help */
- 76 , /* key_home */
- 77 , /* key_ic */
- 78 , /* key_il */
- 79 , /* key_left */
- 80 , /* key_ll */
- 169 , /* key_mark */
- 170 , /* key_message */
- 355 , /* key_mouse */
- 171 , /* key_move */
- 172 , /* key_next */
- 81 , /* key_npage */
- 173 , /* key_open */
- 174 , /* key_options */
- 82 , /* key_ppage */
- 175 , /* key_previous */
- 176 , /* key_print */
- 177 , /* key_redo */
- 178 , /* key_reference */
- 179 , /* key_refresh */
- 180 , /* key_replace */
- 181 , /* key_restart */
- 182 , /* key_resume */
- 83 , /* key_right */
- 183 , /* key_save */
- 186 , /* key_sbeg */
- 187 , /* key_scancel */
- 188 , /* key_scommand */
- 189 , /* key_scopy */
- 190 , /* key_screate */
- 191 , /* key_sdc */
- 192 , /* key_sdl */
- 193 , /* key_select */
- 194 , /* key_send */
- 195 , /* key_seol */
- 196 , /* key_sexit */
- 84 , /* key_sf */
- 197 , /* key_sfind */
- 198 , /* key_shelp */
- 199 , /* key_shome */
- 200 , /* key_sic */
- 201 , /* key_sleft */
- 202 , /* key_smessage */
- 203 , /* key_smove */
- 204 , /* key_snext */
- 205 , /* key_soptions */
- 206 , /* key_sprevious */
- 207 , /* key_sprint */
- 85 , /* key_sr */
- 208 , /* key_sredo */
- 209 , /* key_sreplace */
- 210 , /* key_sright */
- 211 , /* key_srsume */
- 212 , /* key_ssave */
- 213 , /* key_ssuspend */
- 86 , /* key_stab */
- 214 , /* key_sundo */
- 184 , /* key_suspend */
- 185 , /* key_undo */
- 87 , /* key_up */
- 88 , /* keypad_local */
- 89 , /* keypad_xmit */
- 90 , /* lab_f0 */
- 91 , /* lab_f1 */
- 92 , /* lab_f10 */
- 93 , /* lab_f2 */
- 94 , /* lab_f3 */
- 95 , /* lab_f4 */
- 96 , /* lab_f5 */
- 97 , /* lab_f6 */
- 98 , /* lab_f7 */
- 99 , /* lab_f8 */
- 100 , /* lab_f9 */
- 273 , /* label_format */
- 157 , /* label_off */
- 156 , /* label_on */
- 396 , /* linefeed_if_not_lf */
- 411 , /* memory_lock */
- 412 , /* memory_unlock */
- 101 , /* meta_off */
- 102 , /* meta_on */
- 328 , /* micro_column_address */
- 329 , /* micro_down */
- 330 , /* micro_left */
- 331 , /* micro_right */
- 332 , /* micro_row_address */
- 333 , /* micro_up */
- 356 , /* mouse_info */
- 103 , /* newline */
- 334 , /* order_of_pins */
- 298 , /* orig_colors */
- 297 , /* orig_pair */
- 398 , /* other_non_function_keys */
- 104 , /* pad_char */
- 105 , /* parm_dch */
- 106 , /* parm_delete_line */
- 107 , /* parm_down_cursor */
- 335 , /* parm_down_micro */
- 108 , /* parm_ich */
- 109 , /* parm_index */
- 110 , /* parm_insert_line */
- 111 , /* parm_left_cursor */
- 336 , /* parm_left_micro */
- 112 , /* parm_right_cursor */
- 337 , /* parm_right_micro */
- 113 , /* parm_rindex */
- 114 , /* parm_up_cursor */
- 338 , /* parm_up_micro */
- 383 , /* pc_term_options */
- 115 , /* pkey_key */
- 116 , /* pkey_local */
- 361 , /* pkey_plab */
- 117 , /* pkey_xmit */
- 147 , /* plab_norm */
- 118 , /* print_screen */
- 144 , /* prtr_non */
- 119 , /* prtr_off */
- 120 , /* prtr_on */
- 283 , /* pulse */
- 281 , /* quick_dial */
- 276 , /* remove_clock */
- 121 , /* repeat_char */
- 215 , /* req_for_input */
- 357 , /* req_mouse_pos */
- 122 , /* reset_1string */
- 123 , /* reset_2string */
- 124 , /* reset_3string */
- 125 , /* reset_file */
- 126 , /* restore_cursor */
- 127 , /* row_address */
- 128 , /* save_cursor */
- 384 , /* scancode_escape */
- 129 , /* scroll_forward */
- 130 , /* scroll_reverse */
- 339 , /* select_char_set */
- 364 , /* set0_des_seq */
- 365 , /* set1_des_seq */
- 366 , /* set2_des_seq */
- 367 , /* set3_des_seq */
- 392 , /* set_a_attributes */
- 360 , /* set_a_background */
- 359 , /* set_a_foreground */
- 131 , /* set_attributes */
- 303 , /* set_background */
- 340 , /* set_bottom_margin */
- 341 , /* set_bottom_margin_parm */
- 274 , /* set_clock */
- 376 , /* set_color_band */
- 301 , /* set_color_pair */
- 302 , /* set_foreground */
- 271 , /* set_left_margin */
- 342 , /* set_left_margin_parm */
- 368 , /* set_lr_margin */
- 377 , /* set_page_length */
- 393 , /* set_pglen_inch */
- 272 , /* set_right_margin */
- 343 , /* set_right_margin_parm */
- 132 , /* set_tab */
- 369 , /* set_tb_margin */
- 344 , /* set_top_margin */
- 345 , /* set_top_margin_parm */
- 133 , /* set_window */
- 346 , /* start_bit_image */
- 347 , /* start_char_set_def */
- 348 , /* stop_bit_image */
- 349 , /* stop_char_set_def */
- 350 , /* subscript_characters */
- 351 , /* superscript_characters */
- 134 , /* tab */
- 394 , /* termcap_init2 */
- 395 , /* termcap_reset */
- 352 , /* these_cause_cr */
- 135 , /* to_status_line */
- 282 , /* tone */
- 136 , /* underline_char */
- 137 , /* up_half_line */
- 287 , /* user0 */
- 288 , /* user1 */
- 289 , /* user2 */
- 290 , /* user3 */
- 291 , /* user4 */
- 292 , /* user5 */
- 293 , /* user6 */
- 294 , /* user7 */
- 295 , /* user8 */
- 296 , /* user9 */
- 286 , /* wait_tone */
- 154 , /* xoff_character */
- 153 , /* xon_character */
- 353 , /* zero_motion */
-};
-
-static const PredIdx bool_termcap_sort[] = {
- 22 , /* 5i */
- 23 , /* HC */
- 40 , /* MT */
- 26 , /* ND */
- 41 , /* NL */
- 25 , /* NP */
- 24 , /* NR */
- 30 , /* YA */
- 31 , /* YB */
- 32 , /* YC */
- 33 , /* YD */
- 34 , /* YE */
- 35 , /* YF */
- 36 , /* YG */
- 1 , /* am */
- 37 , /* bs */
- 0 , /* bw */
- 27 , /* cc */
- 11 , /* da */
- 12 , /* db */
- 5 , /* eo */
- 16 , /* es */
- 6 , /* gn */
- 7 , /* hc */
- 29 , /* hl */
- 9 , /* hs */
- 18 , /* hz */
- 10 , /* in */
- 8 , /* km */
- 13 , /* mi */
- 14 , /* ms */
- 39 , /* nc */
- 38 , /* ns */
- 21 , /* nx */
- 15 , /* os */
- 42 , /* pt */
- 19 , /* ul */
- 28 , /* ut */
- 2 , /* xb */
- 4 , /* xn */
- 20 , /* xo */
- 43 , /* xr */
- 3 , /* xs */
- 17 , /* xt */
-};
-
-static const PredIdx num_termcap_sort[] = {
- 30 , /* BT */
- 13 , /* Co */
- 12 , /* MW */
- 15 , /* NC */
- 8 , /* Nl */
- 16 , /* Ya */
- 17 , /* Yb */
- 18 , /* Yc */
- 19 , /* Yd */
- 20 , /* Ye */
- 21 , /* Yf */
- 22 , /* Yg */
- 23 , /* Yh */
- 24 , /* Yi */
- 25 , /* Yj */
- 26 , /* Yk */
- 27 , /* Yl */
- 28 , /* Ym */
- 29 , /* Yn */
- 31 , /* Yo */
- 32 , /* Yp */
- 0 , /* co */
- 36 , /* dB */
- 34 , /* dC */
- 35 , /* dN */
- 37 , /* dT */
- 1 , /* it */
- 38 , /* kn */
- 9 , /* lh */
- 2 , /* li */
- 3 , /* lm */
- 10 , /* lw */
- 11 , /* ma */
- 14 , /* pa */
- 5 , /* pb */
- 4 , /* sg */
- 33 , /* ug */
- 6 , /* vt */
- 7 , /* ws */
-};
-
-static const PredIdx str_termcap_sort[] = {
- 212 , /* !1 */
- 213 , /* !2 */
- 214 , /* !3 */
- 198 , /* #1 */
- 199 , /* #2 */
- 200 , /* #3 */
- 201 , /* #4 */
- 177 , /* %0 */
- 168 , /* %1 */
- 169 , /* %2 */
- 170 , /* %3 */
- 171 , /* %4 */
- 172 , /* %5 */
- 173 , /* %6 */
- 174 , /* %7 */
- 175 , /* %8 */
- 176 , /* %9 */
- 202 , /* %a */
- 203 , /* %b */
- 204 , /* %c */
- 205 , /* %d */
- 206 , /* %e */
- 207 , /* %f */
- 208 , /* %g */
- 209 , /* %h */
- 210 , /* %i */
- 211 , /* %j */
- 187 , /* &0 */
- 178 , /* &1 */
- 179 , /* &2 */
- 180 , /* &3 */
- 181 , /* &4 */
- 182 , /* &5 */
- 183 , /* &6 */
- 184 , /* &7 */
- 185 , /* &8 */
- 186 , /* &9 */
- 197 , /* *0 */
- 188 , /* *1 */
- 189 , /* *2 */
- 190 , /* *3 */
- 191 , /* *4 */
- 192 , /* *5 */
- 193 , /* *6 */
- 194 , /* *7 */
- 195 , /* *8 */
- 196 , /* *9 */
- 167 , /* @0 */
- 158 , /* @1 */
- 159 , /* @2 */
- 160 , /* @3 */
- 161 , /* @4 */
- 162 , /* @5 */
- 163 , /* @6 */
- 164 , /* @7 */
- 165 , /* @8 */
- 166 , /* @9 */
- 360 , /* AB */
- 359 , /* AF */
- 110 , /* AL */
- 9 , /* CC */
- 15 , /* CM */
- 277 , /* CW */
- 105 , /* DC */
- 280 , /* DI */
- 275 , /* DK */
- 106 , /* DL */
- 107 , /* DO */
- 216 , /* F1 */
- 217 , /* F2 */
- 218 , /* F3 */
- 219 , /* F4 */
- 220 , /* F5 */
- 221 , /* F6 */
- 222 , /* F7 */
- 223 , /* F8 */
- 224 , /* F9 */
- 225 , /* FA */
- 226 , /* FB */
- 227 , /* FC */
- 228 , /* FD */
- 229 , /* FE */
- 230 , /* FF */
- 231 , /* FG */
- 232 , /* FH */
- 233 , /* FI */
- 234 , /* FJ */
- 235 , /* FK */
- 236 , /* FL */
- 237 , /* FM */
- 238 , /* FN */
- 239 , /* FO */
- 240 , /* FP */
- 241 , /* FQ */
- 242 , /* FR */
- 243 , /* FS */
- 244 , /* FT */
- 245 , /* FU */
- 246 , /* FV */
- 247 , /* FW */
- 248 , /* FX */
- 249 , /* FY */
- 250 , /* FZ */
- 251 , /* Fa */
- 252 , /* Fb */
- 253 , /* Fc */
- 254 , /* Fd */
- 255 , /* Fe */
- 256 , /* Ff */
- 257 , /* Fg */
- 258 , /* Fh */
- 259 , /* Fi */
- 260 , /* Fj */
- 261 , /* Fk */
- 262 , /* Fl */
- 263 , /* Fm */
- 264 , /* Fn */
- 265 , /* Fo */
- 266 , /* Fp */
- 267 , /* Fq */
- 268 , /* Fr */
- 402 , /* G1 */
- 400 , /* G2 */
- 401 , /* G3 */
- 403 , /* G4 */
- 410 , /* GC */
- 407 , /* GD */
- 408 , /* GH */
- 405 , /* GL */
- 404 , /* GR */
- 406 , /* GU */
- 409 , /* GV */
- 358 , /* Gm */
- 279 , /* HU */
- 108 , /* IC */
- 299 , /* Ic */
- 300 , /* Ip */
- 139 , /* K1 */
- 141 , /* K2 */
- 140 , /* K3 */
- 142 , /* K4 */
- 143 , /* K5 */
- 355 , /* Km */
- 111 , /* LE */
- 157 , /* LF */
- 156 , /* LO */
- 273 , /* Lf */
- 270 , /* MC */
- 271 , /* ML */
- 368 , /* ML */
- 272 , /* MR */
- 369 , /* MT */
- 356 , /* Mi */
- 285 , /* PA */
- 283 , /* PU */
- 281 , /* QD */
- 152 , /* RA */
- 276 , /* RC */
- 215 , /* RF */
- 112 , /* RI */
- 357 , /* RQ */
- 150 , /* RX */
- 378 , /* S1 */
- 379 , /* S2 */
- 380 , /* S3 */
- 381 , /* S4 */
- 382 , /* S5 */
- 383 , /* S6 */
- 384 , /* S7 */
- 385 , /* S8 */
- 151 , /* SA */
- 274 , /* SC */
- 109 , /* SF */
- 113 , /* SR */
- 149 , /* SX */
- 303 , /* Sb */
- 302 , /* Sf */
- 282 , /* TO */
- 114 , /* UP */
- 286 , /* WA */
- 278 , /* WG */
- 154 , /* XF */
- 153 , /* XN */
- 386 , /* Xh */
- 387 , /* Xl */
- 388 , /* Xo */
- 389 , /* Xr */
- 390 , /* Xt */
- 391 , /* Xv */
- 370 , /* Xy */
- 377 , /* YZ */
- 372 , /* Yv */
- 373 , /* Yw */
- 374 , /* Yx */
- 375 , /* Yy */
- 376 , /* Yz */
- 304 , /* ZA */
- 305 , /* ZB */
- 306 , /* ZC */
- 307 , /* ZD */
- 308 , /* ZE */
- 309 , /* ZF */
- 310 , /* ZG */
- 311 , /* ZH */
- 312 , /* ZI */
- 313 , /* ZJ */
- 314 , /* ZK */
- 315 , /* ZL */
- 316 , /* ZM */
- 317 , /* ZN */
- 318 , /* ZO */
- 319 , /* ZP */
- 320 , /* ZQ */
- 321 , /* ZR */
- 322 , /* ZS */
- 323 , /* ZT */
- 324 , /* ZU */
- 325 , /* ZV */
- 326 , /* ZW */
- 327 , /* ZX */
- 328 , /* ZY */
- 329 , /* ZZ */
- 330 , /* Za */
- 331 , /* Zb */
- 332 , /* Zc */
- 333 , /* Zd */
- 334 , /* Ze */
- 335 , /* Zf */
- 336 , /* Zg */
- 337 , /* Zh */
- 338 , /* Zi */
- 339 , /* Zj */
- 340 , /* Zk */
- 341 , /* Zl */
- 342 , /* Zm */
- 343 , /* Zn */
- 344 , /* Zo */
- 345 , /* Zp */
- 346 , /* Zq */
- 347 , /* Zr */
- 348 , /* Zs */
- 349 , /* Zt */
- 350 , /* Zu */
- 351 , /* Zv */
- 352 , /* Zw */
- 353 , /* Zx */
- 354 , /* Zy */
- 371 , /* Zz */
- 146 , /* ac */
- 38 , /* ae */
- 53 , /* al */
- 25 , /* as */
- 397 , /* bc */
- 1 , /* bl */
- 0 , /* bt */
- 413 , /* bx */
- 269 , /* cb */
- 7 , /* cd */
- 6 , /* ce */
- 8 , /* ch */
- 363 , /* ci */
- 5 , /* cl */
- 10 , /* cm */
- 2 , /* cr */
- 3 , /* cs */
- 4 , /* ct */
- 127 , /* cv */
- 21 , /* dc */
- 22 , /* dl */
- 29 , /* dm */
- 11 , /* do */
- 23 , /* ds */
- 362 , /* dv */
- 155 , /* eA */
- 37 , /* ec */
- 41 , /* ed */
- 42 , /* ei */
- 46 , /* ff */
- 284 , /* fh */
- 47 , /* fs */
- 24 , /* hd */
- 12 , /* ho */
- 137 , /* hu */
- 48 , /* i1 */
- 394 , /* i2 */
- 50 , /* i3 */
- 138 , /* iP */
- 52 , /* ic */
- 51 , /* if */
- 31 , /* im */
- 54 , /* ip */
- 49 , /* is */
- 65 , /* k0 */
- 66 , /* k1 */
- 68 , /* k2 */
- 69 , /* k3 */
- 70 , /* k4 */
- 71 , /* k5 */
- 72 , /* k6 */
- 73 , /* k7 */
- 74 , /* k8 */
- 75 , /* k9 */
- 67 , /* k; */
- 78 , /* kA */
- 148 , /* kB */
- 57 , /* kC */
- 59 , /* kD */
- 63 , /* kE */
- 84 , /* kF */
- 80 , /* kH */
- 77 , /* kI */
- 60 , /* kL */
- 62 , /* kM */
- 81 , /* kN */
- 82 , /* kP */
- 85 , /* kR */
- 64 , /* kS */
- 86 , /* kT */
- 56 , /* ka */
- 55 , /* kb */
- 61 , /* kd */
- 88 , /* ke */
- 76 , /* kh */
- 79 , /* kl */
- 398 , /* ko */
- 83 , /* kr */
- 89 , /* ks */
- 58 , /* kt */
- 87 , /* ku */
- 90 , /* l0 */
- 91 , /* l1 */
- 93 , /* l2 */
- 94 , /* l3 */
- 95 , /* l4 */
- 96 , /* l5 */
- 97 , /* l6 */
- 98 , /* l7 */
- 99 , /* l8 */
- 100 , /* l9 */
- 92 , /* la */
- 14 , /* le */
- 18 , /* ll */
- 399 , /* ma */
- 26 , /* mb */
- 27 , /* md */
- 39 , /* me */
- 30 , /* mh */
- 32 , /* mk */
- 411 , /* ml */
- 102 , /* mm */
- 101 , /* mo */
- 33 , /* mp */
- 34 , /* mr */
- 412 , /* mu */
- 17 , /* nd */
- 396 , /* nl */
- 103 , /* nw */
- 298 , /* oc */
- 297 , /* op */
- 144 , /* pO */
- 104 , /* pc */
- 119 , /* pf */
- 115 , /* pk */
- 116 , /* pl */
- 147 , /* pn */
- 120 , /* po */
- 118 , /* ps */
- 117 , /* px */
- 122 , /* r1 */
- 123 , /* r2 */
- 124 , /* r3 */
- 145 , /* rP */
- 126 , /* rc */
- 125 , /* rf */
- 121 , /* rp */
- 395 , /* rs */
- 364 , /* s0 */
- 365 , /* s1 */
- 366 , /* s2 */
- 367 , /* s3 */
- 392 , /* sA */
- 393 , /* sL */
- 131 , /* sa */
- 128 , /* sc */
- 43 , /* se */
- 129 , /* sf */
- 35 , /* so */
- 301 , /* sp */
- 130 , /* sr */
- 132 , /* st */
- 134 , /* ta */
- 40 , /* te */
- 28 , /* ti */
- 135 , /* ts */
- 287 , /* u0 */
- 288 , /* u1 */
- 289 , /* u2 */
- 290 , /* u3 */
- 291 , /* u4 */
- 292 , /* u5 */
- 293 , /* u6 */
- 294 , /* u7 */
- 295 , /* u8 */
- 296 , /* u9 */
- 136 , /* uc */
- 44 , /* ue */
- 19 , /* up */
- 36 , /* us */
- 45 , /* vb */
- 16 , /* ve */
- 13 , /* vi */
- 20 , /* vs */
- 133 , /* wi */
- 361 , /* xl */
-};
-
-static const bool bool_from_termcap[] = {
- TRUE, /* bw */
- TRUE, /* am */
- TRUE, /* xsb */
- TRUE, /* xhp */
- TRUE, /* xenl */
- TRUE, /* eo */
- TRUE, /* gn */
- TRUE, /* hc */
- TRUE, /* km */
- TRUE, /* hs */
- TRUE, /* in */
- TRUE, /* da */
- TRUE, /* db */
- TRUE, /* mir */
- TRUE, /* msgr */
- TRUE, /* os */
- TRUE, /* eslok */
- TRUE, /* xt */
- TRUE, /* hz */
- TRUE, /* ul */
- TRUE, /* xon */
- FALSE, /* nxon */
- FALSE, /* mc5i */
- FALSE, /* chts */
- FALSE, /* nrrmc */
- FALSE, /* npc */
- FALSE, /* ndscr */
- FALSE, /* ccc */
- FALSE, /* bce */
- FALSE, /* hls */
- FALSE, /* xhpa */
- FALSE, /* crxm */
- FALSE, /* daisy */
- FALSE, /* xvpa */
- FALSE, /* sam */
- FALSE, /* cpix */
- FALSE, /* lpix */
- TRUE, /* OTbs */
- TRUE, /* OTns */
- TRUE, /* OTnc */
- FALSE, /* OTMT */
- TRUE, /* OTNL */
- TRUE, /* OTpt */
- TRUE, /* OTxr */
-};
-
-static const bool num_from_termcap[] = {
- TRUE, /* cols */
- TRUE, /* it */
- TRUE, /* lines */
- TRUE, /* lm */
- TRUE, /* xmc */
- TRUE, /* pb */
- TRUE, /* vt */
- TRUE, /* wsl */
- FALSE, /* nlab */
- FALSE, /* lh */
- FALSE, /* lw */
- TRUE, /* ma */
- FALSE, /* wnum */
- FALSE, /* colors */
- FALSE, /* pairs */
- FALSE, /* ncv */
- FALSE, /* bufsz */
- FALSE, /* spinv */
- FALSE, /* spinh */
- FALSE, /* maddr */
- FALSE, /* mjump */
- FALSE, /* mcs */
- FALSE, /* mls */
- FALSE, /* npins */
- FALSE, /* orc */
- FALSE, /* orl */
- FALSE, /* orhi */
- FALSE, /* orvi */
- FALSE, /* cps */
- FALSE, /* widcs */
- FALSE, /* btns */
- FALSE, /* bitwin */
- FALSE, /* bitype */
- TRUE, /* OTug */
- TRUE, /* OTdC */
- TRUE, /* OTdN */
- TRUE, /* OTdB */
- TRUE, /* OTdT */
- FALSE, /* OTkn */
-};
-
-static const bool str_from_termcap[] = {
- TRUE, /* cbt */
- TRUE, /* bel */
- TRUE, /* cr */
- TRUE, /* csr */
- TRUE, /* tbc */
- TRUE, /* clear */
- TRUE, /* el */
- TRUE, /* ed */
- FALSE, /* hpa */
- TRUE, /* cmdch */
- TRUE, /* cup */
- TRUE, /* cud1 */
- TRUE, /* home */
- TRUE, /* civis */
- TRUE, /* cub1 */
- TRUE, /* mrcup */
- TRUE, /* cnorm */
- TRUE, /* cuf1 */
- TRUE, /* ll */
- TRUE, /* cuu1 */
- TRUE, /* cvvis */
- TRUE, /* dch1 */
- TRUE, /* dl1 */
- TRUE, /* dsl */
- TRUE, /* hd */
- TRUE, /* smacs */
- TRUE, /* blink */
- TRUE, /* bold */
- TRUE, /* smcup */
- TRUE, /* smdc */
- TRUE, /* dim */
- TRUE, /* smir */
- FALSE, /* invis */
- FALSE, /* prot */
- TRUE, /* rev */
- TRUE, /* smso */
- TRUE, /* smul */
- TRUE, /* ech */
- TRUE, /* rmacs */
- TRUE, /* sgr0 */
- TRUE, /* rmcup */
- TRUE, /* rmdc */
- TRUE, /* rmir */
- TRUE, /* rmso */
- TRUE, /* rmul */
- TRUE, /* flash */
- TRUE, /* ff */
- TRUE, /* fsl */
- TRUE, /* is1 */
- TRUE, /* is2 */
- TRUE, /* is3 */
- TRUE, /* if */
- TRUE, /* ich1 */
- TRUE, /* il1 */
- TRUE, /* ip */
- TRUE, /* kbs */
- FALSE, /* ktbc */
- FALSE, /* kclr */
- FALSE, /* kctab */
- TRUE, /* kdch1 */
- FALSE, /* kdl1 */
- TRUE, /* kcud1 */
- FALSE, /* krmir */
- FALSE, /* kel */
- FALSE, /* ked */
- TRUE, /* kf0 */
- TRUE, /* kf1 */
- FALSE, /* kf10 */
- TRUE, /* kf2 */
- TRUE, /* kf3 */
- TRUE, /* kf4 */
- TRUE, /* kf5 */
- TRUE, /* kf6 */
- TRUE, /* kf7 */
- TRUE, /* kf8 */
- TRUE, /* kf9 */
- TRUE, /* khome */
- TRUE, /* kich1 */
- FALSE, /* kil1 */
- TRUE, /* kcub1 */
- TRUE, /* kll */
- TRUE, /* knp */
- TRUE, /* kpp */
- TRUE, /* kcuf1 */
- FALSE, /* kind */
- FALSE, /* kri */
- FALSE, /* khts */
- TRUE, /* kcuu1 */
- TRUE, /* rmkx */
- TRUE, /* smkx */
- FALSE, /* lf0 */
- FALSE, /* lf1 */
- FALSE, /* lf10 */
- FALSE, /* lf2 */
- FALSE, /* lf3 */
- FALSE, /* lf4 */
- FALSE, /* lf5 */
- FALSE, /* lf6 */
- FALSE, /* lf7 */
- FALSE, /* lf8 */
- FALSE, /* lf9 */
- TRUE, /* rmm */
- TRUE, /* smm */
- TRUE, /* nel */
- TRUE, /* pad */
- TRUE, /* dch */
- TRUE, /* dl */
- TRUE, /* cud */
- TRUE, /* ich */
- TRUE, /* indn */
- TRUE, /* il */
- TRUE, /* cub */
- TRUE, /* cuf */
- TRUE, /* rin */
- TRUE, /* cuu */
- FALSE, /* pfkey */
- FALSE, /* pfloc */
- FALSE, /* pfx */
- FALSE, /* mc0 */
- FALSE, /* mc4 */
- FALSE, /* mc5 */
- TRUE, /* rep */
- FALSE, /* rs1 */
- FALSE, /* rs2 */
- FALSE, /* rs3 */
- FALSE, /* rf */
- TRUE, /* rc */
- FALSE, /* vpa */
- TRUE, /* sc */
- TRUE, /* ind */
- TRUE, /* ri */
- TRUE, /* sgr */
- TRUE, /* hts */
- FALSE, /* wind */
- TRUE, /* ht */
- TRUE, /* tsl */
- TRUE, /* uc */
- TRUE, /* hu */
- FALSE, /* iprog */
- TRUE, /* ka1 */
- TRUE, /* ka3 */
- TRUE, /* kb2 */
- TRUE, /* kc1 */
- TRUE, /* kc3 */
- FALSE, /* mc5p */
- FALSE, /* rmp */
- FALSE, /* acsc */
- FALSE, /* pln */
- FALSE, /* kcbt */
- FALSE, /* smxon */
- FALSE, /* rmxon */
- FALSE, /* smam */
- FALSE, /* rmam */
- FALSE, /* xonc */
- FALSE, /* xoffc */
- FALSE, /* enacs */
- FALSE, /* smln */
- FALSE, /* rmln */
- FALSE, /* kbeg */
- FALSE, /* kcan */
- FALSE, /* kclo */
- FALSE, /* kcmd */
- FALSE, /* kcpy */
- FALSE, /* kcrt */
- FALSE, /* kend */
- FALSE, /* kent */
- FALSE, /* kext */
- FALSE, /* kfnd */
- FALSE, /* khlp */
- FALSE, /* kmrk */
- FALSE, /* kmsg */
- FALSE, /* kmov */
- FALSE, /* knxt */
- FALSE, /* kopn */
- FALSE, /* kopt */
- FALSE, /* kprv */
- FALSE, /* kprt */
- FALSE, /* krdo */
- FALSE, /* kref */
- FALSE, /* krfr */
- FALSE, /* krpl */
- FALSE, /* krst */
- FALSE, /* kres */
- FALSE, /* ksav */
- FALSE, /* kspd */
- FALSE, /* kund */
- FALSE, /* kBEG */
- FALSE, /* kCAN */
- FALSE, /* kCMD */
- FALSE, /* kCPY */
- FALSE, /* kCRT */
- FALSE, /* kDC */
- FALSE, /* kDL */
- FALSE, /* kslt */
- FALSE, /* kEND */
- FALSE, /* kEOL */
- FALSE, /* kEXT */
- FALSE, /* kFND */
- FALSE, /* kHLP */
- FALSE, /* kHOM */
- FALSE, /* kIC */
- FALSE, /* kLFT */
- FALSE, /* kMSG */
- FALSE, /* kMOV */
- FALSE, /* kNXT */
- FALSE, /* kOPT */
- FALSE, /* kPRV */
- FALSE, /* kPRT */
- FALSE, /* kRDO */
- FALSE, /* kRPL */
- FALSE, /* kRIT */
- FALSE, /* kRES */
- FALSE, /* kSAV */
- FALSE, /* kSPD */
- FALSE, /* kUND */
- FALSE, /* rfi */
- FALSE, /* kf11 */
- FALSE, /* kf12 */
- FALSE, /* kf13 */
- FALSE, /* kf14 */
- FALSE, /* kf15 */
- FALSE, /* kf16 */
- FALSE, /* kf17 */
- FALSE, /* kf18 */
- FALSE, /* kf19 */
- FALSE, /* kf20 */
- FALSE, /* kf21 */
- FALSE, /* kf22 */
- FALSE, /* kf23 */
- FALSE, /* kf24 */
- FALSE, /* kf25 */
- FALSE, /* kf26 */
- FALSE, /* kf27 */
- FALSE, /* kf28 */
- FALSE, /* kf29 */
- FALSE, /* kf30 */
- FALSE, /* kf31 */
- FALSE, /* kf32 */
- FALSE, /* kf33 */
- FALSE, /* kf34 */
- FALSE, /* kf35 */
- FALSE, /* kf36 */
- FALSE, /* kf37 */
- FALSE, /* kf38 */
- FALSE, /* kf39 */
- FALSE, /* kf40 */
- FALSE, /* kf41 */
- FALSE, /* kf42 */
- FALSE, /* kf43 */
- FALSE, /* kf44 */
- FALSE, /* kf45 */
- FALSE, /* kf46 */
- FALSE, /* kf47 */
- FALSE, /* kf48 */
- FALSE, /* kf49 */
- FALSE, /* kf50 */
- FALSE, /* kf51 */
- FALSE, /* kf52 */
- FALSE, /* kf53 */
- FALSE, /* kf54 */
- FALSE, /* kf55 */
- FALSE, /* kf56 */
- FALSE, /* kf57 */
- FALSE, /* kf58 */
- FALSE, /* kf59 */
- FALSE, /* kf60 */
- FALSE, /* kf61 */
- FALSE, /* kf62 */
- FALSE, /* kf63 */
- FALSE, /* el1 */
- FALSE, /* mgc */
- FALSE, /* smgl */
- FALSE, /* smgr */
- FALSE, /* fln */
- FALSE, /* sclk */
- FALSE, /* dclk */
- FALSE, /* rmclk */
- FALSE, /* cwin */
- FALSE, /* wingo */
- FALSE, /* hup */
- FALSE, /* dial */
- FALSE, /* qdial */
- FALSE, /* tone */
- FALSE, /* pulse */
- FALSE, /* hook */
- FALSE, /* pause */
- FALSE, /* wait */
- FALSE, /* u0 */
- FALSE, /* u1 */
- FALSE, /* u2 */
- FALSE, /* u3 */
- FALSE, /* u4 */
- FALSE, /* u5 */
- FALSE, /* u6 */
- FALSE, /* u7 */
- FALSE, /* u8 */
- FALSE, /* u9 */
- FALSE, /* op */
- FALSE, /* oc */
- FALSE, /* initc */
- FALSE, /* initp */
- FALSE, /* scp */
- FALSE, /* setf */
- FALSE, /* setb */
- FALSE, /* cpi */
- FALSE, /* lpi */
- FALSE, /* chr */
- FALSE, /* cvr */
- FALSE, /* defc */
- FALSE, /* swidm */
- FALSE, /* sdrfq */
- FALSE, /* sitm */
- FALSE, /* slm */
- FALSE, /* smicm */
- FALSE, /* snlq */
- FALSE, /* snrmq */
- FALSE, /* sshm */
- FALSE, /* ssubm */
- FALSE, /* ssupm */
- FALSE, /* sum */
- FALSE, /* rwidm */
- FALSE, /* ritm */
- FALSE, /* rlm */
- FALSE, /* rmicm */
- FALSE, /* rshm */
- FALSE, /* rsubm */
- FALSE, /* rsupm */
- FALSE, /* rum */
- FALSE, /* mhpa */
- FALSE, /* mcud1 */
- FALSE, /* mcub1 */
- FALSE, /* mcuf1 */
- FALSE, /* mvpa */
- FALSE, /* mcuu1 */
- FALSE, /* porder */
- FALSE, /* mcud */
- FALSE, /* mcub */
- FALSE, /* mcuf */
- FALSE, /* mcuu */
- FALSE, /* scs */
- FALSE, /* smgb */
- FALSE, /* smgbp */
- FALSE, /* smglp */
- FALSE, /* smgrp */
- FALSE, /* smgt */
- FALSE, /* smgtp */
- FALSE, /* sbim */
- FALSE, /* scsd */
- FALSE, /* rbim */
- FALSE, /* rcsd */
- FALSE, /* subcs */
- FALSE, /* supcs */
- FALSE, /* docr */
- FALSE, /* zerom */
- FALSE, /* csnm */
- FALSE, /* kmous */
- FALSE, /* minfo */
- FALSE, /* reqmp */
- FALSE, /* getm */
- FALSE, /* setaf */
- FALSE, /* setab */
- FALSE, /* pfxl */
- FALSE, /* devt */
- FALSE, /* csin */
- FALSE, /* s0ds */
- FALSE, /* s1ds */
- FALSE, /* s2ds */
- FALSE, /* s3ds */
- FALSE, /* smglr */
- FALSE, /* smgtb */
- FALSE, /* birep */
- FALSE, /* binel */
- FALSE, /* bicr */
- FALSE, /* colornm */
- FALSE, /* defbi */
- FALSE, /* endbi */
- FALSE, /* setcolor */
- FALSE, /* slines */
- FALSE, /* dispc */
- FALSE, /* smpch */
- FALSE, /* rmpch */
- FALSE, /* smsc */
- FALSE, /* rmsc */
- FALSE, /* pctrm */
- FALSE, /* scesc */
- FALSE, /* scesa */
- FALSE, /* ehhlm */
- FALSE, /* elhlm */
- FALSE, /* elohlm */
- FALSE, /* erhlm */
- FALSE, /* ethlm */
- FALSE, /* evhlm */
- FALSE, /* sgr1 */
- FALSE, /* slength */
- TRUE, /* OTi2 */
- TRUE, /* OTrs */
- TRUE, /* OTnl */
- TRUE, /* OTbc */
- FALSE, /* OTko */
- TRUE, /* OTma */
- FALSE, /* OTG2 */
- FALSE, /* OTG3 */
- FALSE, /* OTG1 */
- FALSE, /* OTG4 */
- FALSE, /* OTGR */
- FALSE, /* OTGL */
- FALSE, /* OTGU */
- FALSE, /* OTGD */
- FALSE, /* OTGH */
- FALSE, /* OTGV */
- FALSE, /* OTGC */
- FALSE, /* meml */
- FALSE, /* memu */
- FALSE, /* pln */
- FALSE, /* smln */
- FALSE, /* rmln */
- FALSE, /* kf11 */
- FALSE, /* kf12 */
- FALSE, /* kf13 */
- FALSE, /* kf14 */
- FALSE, /* kf15 */
- FALSE, /* kf16 */
- FALSE, /* kf17 */
- FALSE, /* kf18 */
- FALSE, /* kf19 */
- FALSE, /* kf20 */
- FALSE, /* kf21 */
- FALSE, /* kf22 */
- FALSE, /* kf23 */
- FALSE, /* kf24 */
- FALSE, /* kf25 */
- FALSE, /* kf26 */
- FALSE, /* kf27 */
- FALSE, /* kf28 */
- FALSE, /* kf29 */
- FALSE, /* kf30 */
- FALSE, /* kf31 */
- FALSE, /* kf32 */
- FALSE, /* kf33 */
- FALSE, /* kf34 */
- FALSE, /* kf35 */
- FALSE, /* kf36 */
- FALSE, /* kf37 */
- FALSE, /* kf38 */
- FALSE, /* kf39 */
- FALSE, /* kf40 */
- FALSE, /* kf41 */
- FALSE, /* kf42 */
- FALSE, /* kf43 */
- FALSE, /* kf44 */
- FALSE, /* kf45 */
- FALSE, /* kf46 */
- FALSE, /* kf47 */
- FALSE, /* kf48 */
- FALSE, /* kf49 */
- FALSE, /* kf50 */
- FALSE, /* kf51 */
- FALSE, /* kf52 */
- FALSE, /* kf53 */
- FALSE, /* kf54 */
- FALSE, /* kf55 */
- FALSE, /* kf56 */
- FALSE, /* kf57 */
- FALSE, /* kf58 */
- FALSE, /* kf59 */
- FALSE, /* kf60 */
- FALSE, /* kf61 */
- FALSE, /* kf62 */
- FALSE, /* kf63 */
- FALSE, /* box1 */
- FALSE, /* box2 */
- FALSE, /* batt1 */
- FALSE, /* batt2 */
- FALSE, /* colb0 */
- FALSE, /* colb1 */
- FALSE, /* colb2 */
- FALSE, /* colb3 */
- FALSE, /* colb4 */
- FALSE, /* colb5 */
- FALSE, /* colb6 */
- FALSE, /* colb7 */
- FALSE, /* colf0 */
- FALSE, /* colf1 */
- FALSE, /* colf2 */
- FALSE, /* colf3 */
- FALSE, /* colf4 */
- FALSE, /* colf5 */
- FALSE, /* colf6 */
- FALSE, /* colf7 */
- FALSE, /* font0 */
- FALSE, /* font1 */
- FALSE, /* font2 */
- FALSE, /* font3 */
- FALSE, /* font4 */
- FALSE, /* font5 */
- FALSE, /* font6 */
- FALSE, /* font7 */
- FALSE, /* kbtab */
- FALSE, /* kdo */
- FALSE, /* kcmd */
- FALSE, /* kcpn */
- FALSE, /* kend */
- FALSE, /* khlp */
- FALSE, /* knl */
- FALSE, /* knpn */
- FALSE, /* kppn */
- FALSE, /* kppn */
- FALSE, /* kquit */
- FALSE, /* ksel */
- FALSE, /* kscl */
- FALSE, /* kscr */
- FALSE, /* ktab */
- FALSE, /* kmpf1 */
- FALSE, /* kmpt1 */
- FALSE, /* kmpf2 */
- FALSE, /* kmpt2 */
- FALSE, /* kmpf3 */
- FALSE, /* kmpt3 */
- FALSE, /* kmpf4 */
- FALSE, /* kmpt4 */
- FALSE, /* kmpf5 */
- FALSE, /* kmpt5 */
- FALSE, /* apstr */
- FALSE, /* kmpf6 */
- FALSE, /* kmpt6 */
- FALSE, /* kmpf7 */
- FALSE, /* kmpt7 */
- FALSE, /* kmpf8 */
- FALSE, /* kmpt8 */
- FALSE, /* kmpf9 */
- FALSE, /* kmpt9 */
- FALSE, /* ksf1 */
- FALSE, /* ksf2 */
- FALSE, /* ksf3 */
- FALSE, /* ksf4 */
- FALSE, /* ksf5 */
- FALSE, /* ksf6 */
- FALSE, /* ksf7 */
- FALSE, /* ksf8 */
- FALSE, /* ksf9 */
- FALSE, /* ksf10 */
- FALSE, /* kf11 */
- FALSE, /* kf12 */
- FALSE, /* kact */
- FALSE, /* topl */
- FALSE, /* btml */
- FALSE, /* rvert */
- FALSE, /* lvert */
-};
-
diff --git a/progs/tic b/progs/tic
deleted file mode 100755
index 7feefd2..0000000
--- a/progs/tic
+++ /dev/null
Binary files differ
diff --git a/progs/tic.c b/progs/tic.c
index 82bc3ea..10cc4d2 100644
--- a/progs/tic.c
+++ b/progs/tic.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -35,6 +35,7 @@
/*
* tic.c --- Main program for terminfo compiler
* by Eric S. Raymond
+ * and Thomas E Dickey
*
*/
@@ -42,9 +43,14 @@
#include <sys/stat.h>
#include <dump_entry.h>
+#include <tparm_type.h>
+#include <hashed_db.h>
+#include <parametrized.h>
#include <transform.h>
-MODULE_ID("$Id: tic.c,v 1.137 2008/09/13 16:59:24 tom Exp $")
+MODULE_ID("$Id: tic.c,v 1.211 2015/07/04 21:12:41 tom Exp $")
+
+#define STDIN_NAME "<stdin>"
const char *_nc_progname = "tic";
@@ -53,6 +59,7 @@
static bool capdump = FALSE; /* running as infotocap? */
static bool infodump = FALSE; /* running as captoinfo? */
static bool showsummary = FALSE;
+static char **namelst = 0;
static const char *to_remove;
static void (*save_check_termtype) (TERMTYPE *, bool);
@@ -69,11 +76,13 @@
1\
a\
C\
+D\
c\
f\
G\
g\
I\
+K\
L\
N\
r\
@@ -99,8 +108,10 @@
#endif
static void
-cleanup(char **namelst GCC_UNUSED)
+cleanup(void)
{
+ int rc;
+
#if NO_LEAKS
free_namelist(namelst);
#endif
@@ -108,10 +119,12 @@
fclose(tmp_fp);
if (to_remove != 0) {
#if HAVE_REMOVE
- remove(to_remove);
+ rc = remove(to_remove);
#else
- unlink(to_remove);
+ rc = unlink(to_remove);
#endif
+ if (rc != 0)
+ perror(to_remove);
}
}
@@ -119,61 +132,60 @@
failed(const char *msg)
{
perror(msg);
- cleanup((char **) 0);
ExitProgram(EXIT_FAILURE);
}
static void
usage(void)
{
- static const char *const tbl[] =
+#define DATA(s) s "\n"
+ static const char options_string[] =
{
- "Options:",
- " -1 format translation output one capability per line",
+ DATA("Options:")
+ DATA(" -1 format translation output one capability per line")
#if NCURSES_XNAMES
- " -a retain commented-out capabilities (sets -x also)",
+ DATA(" -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}",
- " -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",
+ DATA(" -C translate entries to termcap source form")
+ DATA(" -D print list of tic's database locations (first must be writable)")
+ DATA(" -c check only, validate input without compiling or translating")
+ DATA(" -e<names> translate/compile only entries named by comma-separated list")
+ DATA(" -f format complex strings for readability")
+ DATA(" -G format %{number} to %'char'")
+ DATA(" -g format %'char' to %{number}")
+ DATA(" -I translate entries to terminfo source form")
+ DATA(" -K translate entries to termcap source form with BSD syntax")
+ DATA(" -L translate entries to full terminfo source form")
+ DATA(" -N disable smart defaults for source translation")
+ DATA(" -o<dir> set output directory for compiled entry writes")
+ DATA(" -R<name> restrict translation to given terminfo/termcap version")
+ DATA(" -r force resolution of all use entries in source translation")
+ DATA(" -s print summary statistics")
+ DATA(" -T remove size-restrictions on compiled description")
#if NCURSES_XNAMES
- " -t suppress commented-out capabilities",
+ DATA(" -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",
+ DATA(" -U suppress post-processing of entries")
+ DATA(" -V print version")
+ DATA(" -v[n] set verbosity level")
+ DATA(" -w[n] set format width for translation output")
#if NCURSES_XNAMES
- " -x treat unknown capabilities as user-defined",
+ DATA(" -x treat unknown capabilities as user-defined")
#endif
- "",
- "Parameters:",
- " <file> file to translate or compile"
+ DATA("")
+ DATA("Parameters:")
+ DATA(" <file> file to translate or compile")
};
- size_t j;
+#undef DATA
fprintf(stderr, "Usage: %s %s\n", _nc_progname, usage_string);
- for (j = 0; j < SIZEOF(tbl); j++) {
- fputs(tbl[j], stderr);
- putc('\n', stderr);
- }
+ fputs(options_string, stderr);
ExitProgram(EXIT_FAILURE);
}
#define L_BRACE '{'
#define R_BRACE '}'
-#define S_QUOTE '\'';
+#define S_QUOTE '\''
static void
write_it(ENTRY * ep)
@@ -216,12 +228,12 @@
}
*d = 0;
if (strlen(result) < strlen(s))
- strcpy(s, result);
+ _nc_STRCPY(s, result, strlen(s) + 1);
}
}
_nc_set_type(_nc_first_name(ep->tterm.term_names));
- _nc_curr_line = ep->startline;
+ _nc_curr_line = (int) ep->startline;
_nc_write_entry(&ep->tterm);
}
@@ -286,8 +298,10 @@
if (in_name) {
if (used + 1 >= have) {
have += 132;
- namebuf = typeRealloc(char, have, namebuf);
- suffix = typeRealloc(char, have, suffix);
+ if ((namebuf = typeRealloc(char, have, namebuf)) == 0)
+ failed("put_translate namebuf");
+ if ((suffix = typeRealloc(char, have, suffix)) == 0)
+ failed("put_translate suffix");
}
if (c == '\n' || c == '@') {
namebuf[used++] = '\0';
@@ -308,7 +322,7 @@
if ((up = strchr(namebuf, '#')) != 0
|| (up = strchr(namebuf, '=')) != 0
|| ((up = strchr(namebuf, '@')) != 0 && up[1] == '>')) {
- (void) strcpy(suffix, up);
+ _nc_STRCPY(suffix, up, have);
*up = '\0';
}
@@ -339,32 +353,122 @@
static char *
stripped(char *src)
{
+ char *dst = 0;
+
while (isspace(UChar(*src)))
src++;
+
if (*src != '\0') {
- char *dst = strcpy((char *) malloc(strlen(src) + 1), src);
- size_t len = strlen(dst);
- while (--len != 0 && isspace(UChar(dst[len])))
- dst[len] = '\0';
- return dst;
+ size_t len;
+
+ if ((dst = strdup(src)) == NULL) {
+ failed("strdup");
+ } else {
+ len = strlen(dst);
+ while (--len != 0 && isspace(UChar(dst[len])))
+ dst[len] = '\0';
+ }
}
- return 0;
+ return dst;
}
static FILE *
-open_input(const char *filename)
+open_tempfile(char *filename)
{
- FILE *fp = fopen(filename, "r");
- struct stat sb;
+ FILE *result = 0;
- if (fp == 0) {
- fprintf(stderr, "%s: Can't open %s\n", _nc_progname, filename);
- ExitProgram(EXIT_FAILURE);
+ _nc_STRCPY(filename, "/tmp/XXXXXX", PATH_MAX);
+#if HAVE_MKSTEMP
+ {
+ int oldmask = (int) umask(077);
+ int fd = mkstemp(filename);
+ if (fd >= 0)
+ result = fdopen(fd, "w");
+ umask((mode_t) oldmask);
}
- if (fstat(fileno(fp), &sb) < 0
- || (sb.st_mode & S_IFMT) != S_IFREG) {
+#else
+ if (tmpnam(filename) != 0)
+ result = fopen(filename, "w");
+#endif
+ return result;
+}
+
+static FILE *
+copy_input(FILE *source, const char *filename, char *alt_file)
+{
+ char my_altfile[PATH_MAX];
+ FILE *result = 0;
+ FILE *target = 0;
+ int ch;
+
+ if (alt_file == 0)
+ alt_file = my_altfile;
+
+ if (source == 0) {
+ failed("copy_input (source)");
+ } else if ((target = open_tempfile(alt_file)) == 0) {
+ failed("copy_input (target)");
+ } else {
+ clearerr(source);
+ for (;;) {
+ ch = fgetc(source);
+ if (feof(source)) {
+ break;
+ } else if (ferror(source)) {
+ failed(filename);
+ } else if (ch == 0) {
+ /* don't loop in case someone wants to convert /dev/zero */
+ fprintf(stderr, "%s: %s is not a text-file\n", _nc_progname, filename);
+ ExitProgram(EXIT_FAILURE);
+ }
+ fputc(ch, target);
+ }
+ fclose(source);
+ /*
+ * rewind() does not force the target file's data to disk (not does
+ * fflush()...). So open a second stream on the data and then close
+ * the one that we were writing on before starting to read from the
+ * second stream.
+ */
+ result = fopen(alt_file, "r+");
+ fclose(target);
+ to_remove = strdup(alt_file);
+ }
+ return result;
+}
+
+static FILE *
+open_input(const char *filename, char *alt_file)
+{
+ FILE *fp;
+ struct stat sb;
+ int mode;
+
+ if (!strcmp(filename, "-")) {
+ fp = copy_input(stdin, STDIN_NAME, alt_file);
+ } else if (stat(filename, &sb) < 0) {
+ fprintf(stderr, "%s: %s %s\n", _nc_progname, filename, strerror(errno));
+ ExitProgram(EXIT_FAILURE);
+ } else if ((mode = (sb.st_mode & S_IFMT)) == S_IFDIR
+ || (mode != S_IFREG && mode != S_IFCHR && mode != S_IFIFO)) {
fprintf(stderr, "%s: %s is not a file\n", _nc_progname, filename);
ExitProgram(EXIT_FAILURE);
+ } else {
+ fp = fopen(filename, "r");
+
+ if (fp == 0) {
+ fprintf(stderr, "%s: Can't open %s\n", _nc_progname, filename);
+ ExitProgram(EXIT_FAILURE);
+ }
+ if (mode != S_IFREG) {
+ if (alt_file != 0) {
+ FILE *fp2 = copy_input(fp, filename, alt_file);
+ fp = fp2;
+ } else {
+ fprintf(stderr, "%s: %s is not a file\n", _nc_progname, filename);
+ ExitProgram(EXIT_FAILURE);
+ }
+ }
}
return fp;
}
@@ -382,7 +486,7 @@
if (src == 0) {
/* EMPTY */ ;
} else if (strchr(src, '/') != 0) { /* a filename */
- FILE *fp = open_input(src);
+ FILE *fp = open_input(src, (char *) 0);
for (pass = 1; pass <= 2; pass++) {
nn = 0;
@@ -396,7 +500,8 @@
}
}
if (pass == 1) {
- dst = typeCalloc(char *, nn + 1);
+ if ((dst = typeCalloc(char *, nn + 1)) == 0)
+ failed("make_namelist");
rewind(fp);
}
}
@@ -418,8 +523,10 @@
if (mark == '\0')
break;
}
- if (pass == 1)
- dst = typeCalloc(char *, nn + 1);
+ if (pass == 1) {
+ if ((dst = typeCalloc(char *, nn + 1)) == 0)
+ failed("make_namelist");
+ }
}
}
if (showsummary && (dst != 0)) {
@@ -449,26 +556,118 @@
return (code);
}
-static FILE *
-open_tempfile(char *name)
+static char *
+valid_db_path(const char *nominal)
{
- FILE *result = 0;
-#if HAVE_MKSTEMP
- int fd = mkstemp(name);
- if (fd >= 0)
- result = fdopen(fd, "w");
+ struct stat sb;
+#if USE_HASHED_DB
+ char suffix[] = DBM_SUFFIX;
+ size_t need = strlen(nominal) + sizeof(suffix);
+ char *result = malloc(need);
+
+ if (result == 0)
+ failed("valid_db_path");
+ _nc_STRCPY(result, nominal, need);
+ if (strcmp(result + need - sizeof(suffix), suffix)) {
+ _nc_STRCAT(result, suffix, need);
+ }
#else
- if (tmpnam(name) != 0)
- result = fopen(name, "w");
+ char *result = strdup(nominal);
#endif
+
+ DEBUG(1, ("** stat(%s)", result));
+ if (stat(result, &sb) >= 0) {
+#if USE_HASHED_DB
+ if (!S_ISREG(sb.st_mode)
+ || access(result, R_OK | W_OK) != 0) {
+ DEBUG(1, ("...not a writable file"));
+ free(result);
+ result = 0;
+ }
+#else
+ if (!S_ISDIR(sb.st_mode)
+ || access(result, R_OK | W_OK | X_OK) != 0) {
+ DEBUG(1, ("...not a writable directory"));
+ free(result);
+ result = 0;
+ }
+#endif
+ } else {
+ /* check if parent is directory and is writable */
+ unsigned leaf = _nc_pathlast(result);
+
+ DEBUG(1, ("...not found"));
+ if (leaf) {
+ char save = result[leaf];
+ result[leaf] = 0;
+ if (stat(result, &sb) >= 0
+ && S_ISDIR(sb.st_mode)
+ && access(result, R_OK | W_OK | X_OK) == 0) {
+ result[leaf] = save;
+ } else {
+ DEBUG(1, ("...parent directory %s is not writable", result));
+ free(result);
+ result = 0;
+ }
+ } else {
+ DEBUG(1, ("... no parent directory"));
+ free(result);
+ result = 0;
+ }
+ }
return result;
}
+/*
+ * Show the databases to which tic could write. The location to which it
+ * writes is always the first one. If none are writable, print an error
+ * message.
+ */
+static void
+show_databases(const char *outdir)
+{
+ bool specific = (outdir != 0) || getenv("TERMINFO") != 0;
+ char *result;
+ const char *tried = 0;
+
+ if (outdir == 0) {
+ outdir = _nc_tic_dir(0);
+ }
+ if ((result = valid_db_path(outdir)) != 0) {
+ printf("%s\n", result);
+ free(result);
+ } else {
+ tried = outdir;
+ }
+
+ if ((outdir = _nc_home_terminfo())) {
+ if ((result = valid_db_path(outdir)) != 0) {
+ printf("%s\n", result);
+ free(result);
+ } else if (!specific) {
+ tried = outdir;
+ }
+ }
+
+ /*
+ * If we can write in neither location, give an error message.
+ */
+ if (tried) {
+ fflush(stdout);
+ fprintf(stderr, "%s: %s (no permission)\n", _nc_progname, tried);
+ ExitProgram(EXIT_FAILURE);
+ }
+}
+
+#define VtoTrace(opt) (unsigned) ((opt > 0) ? opt : (opt == 0))
+
int
main(int argc, char *argv[])
{
char my_tmpname[PATH_MAX];
- int v_opt = -1, debug_level;
+ char my_altfile[PATH_MAX];
+ int v_opt = -1;
+ unsigned debug_level;
int smart_defaults = TRUE;
char *termcap;
ENTRY *qp;
@@ -479,6 +678,7 @@
int sortmode = S_TERMINFO; /* sort_mode */
int width = 60;
+ int height = 65535;
bool formatted = FALSE; /* reformat complex strings? */
bool literal = FALSE; /* suppress post-processing? */
int numbers = 0; /* format "%'char'" to/from "%{number}" */
@@ -486,7 +686,6 @@
bool limited = TRUE;
char *tversion = (char *) NULL;
const char *source_file = "terminfo";
- char **namelst = 0;
char *outdir = (char *) NULL;
bool check_only = FALSE;
bool suppress_untranslatable = FALSE;
@@ -494,18 +693,20 @@
log_fp = stderr;
_nc_progname = _nc_rootname(argv[0]);
+ atexit(cleanup);
- if ((infodump = (strcmp(_nc_progname, PROG_CAPTOINFO) == 0)) != FALSE) {
+ if ((infodump = same_program(_nc_progname, PROG_CAPTOINFO)) != FALSE) {
outform = F_TERMINFO;
sortmode = S_TERMINFO;
}
- if ((capdump = (strcmp(_nc_progname, PROG_INFOTOCAP) == 0)) != FALSE) {
+ if ((capdump = same_program(_nc_progname, PROG_INFOTOCAP)) != FALSE) {
outform = F_TERMCAP;
sortmode = S_TERMCAP;
}
#if NCURSES_XNAMES
use_extended_names(FALSE);
#endif
+ _nc_strict_bsd = 0;
/*
* Processing arguments is a little complicated, since someone made a
@@ -513,7 +714,7 @@
* be optional.
*/
while ((this_opt = getopt(argc, argv,
- "0123456789CILNR:TUVace:fGgo:rstvwx")) != -1) {
+ "0123456789CDIKLNR:TUVace:fGgo:rstvwx")) != -1) {
if (isdigit(this_opt)) {
switch (last_opt) {
case 'v':
@@ -523,19 +724,40 @@
width = (width * 10) + (this_opt - '0');
break;
default:
- if (this_opt != '1')
+ switch (this_opt) {
+ case '0':
+ last_opt = this_opt;
+ width = 65535;
+ height = 1;
+ break;
+ case '1':
+ last_opt = this_opt;
+ width = 0;
+ break;
+ default:
usage();
- last_opt = this_opt;
- width = 0;
+ }
}
continue;
}
switch (this_opt) {
+ case 'K':
+ _nc_strict_bsd = 1;
+ /* the initial version of -K in 20110730 fell-thru here, but the
+ * same flag is useful when reading sources -TD
+ */
+ break;
case 'C':
capdump = TRUE;
outform = F_TERMCAP;
sortmode = S_TERMCAP;
break;
+ case 'D':
+ debug_level = VtoTrace(v_opt);
+ set_trace_level(debug_level);
+ show_databases(outdir);
+ ExitProgram(EXIT_SUCCESS);
+ break;
case 'I':
infodump = TRUE;
outform = F_TERMINFO;
@@ -561,7 +783,6 @@
break;
case 'V':
puts(curses_version());
- cleanup(namelst);
ExitProgram(EXIT_SUCCESS);
case 'c':
check_only = TRUE;
@@ -611,7 +832,7 @@
last_opt = this_opt;
}
- debug_level = (v_opt > 0) ? v_opt : (v_opt == 0);
+ debug_level = VtoTrace(v_opt);
set_trace_level(debug_level);
if (_nc_tracing) {
@@ -631,8 +852,8 @@
*/
if (namelst && (!infodump && !capdump)) {
(void) fprintf(stderr,
- "Sorry, -e can't be used without -I or -C\n");
- cleanup(namelst);
+ "%s: Sorry, -e can't be used without -I or -C\n",
+ _nc_progname);
ExitProgram(EXIT_FAILURE);
}
#endif /* HAVE_BIG_CORE */
@@ -656,16 +877,16 @@
if (access(termcap, F_OK) == 0) {
/* file exists */
source_file = termcap;
- } else if ((tmp_fp = open_tempfile(strcpy(my_tmpname,
- "/tmp/XXXXXX")))
- != 0) {
- source_file = my_tmpname;
- fprintf(tmp_fp, "%s\n", termcap);
- fclose(tmp_fp);
- tmp_fp = open_input(source_file);
- to_remove = source_file;
} else {
- failed("tmpnam");
+ if ((tmp_fp = open_tempfile(my_tmpname)) != 0) {
+ source_file = my_tmpname;
+ fprintf(tmp_fp, "%s\n", termcap);
+ fclose(tmp_fp);
+ tmp_fp = open_input(source_file, (char *) 0);
+ to_remove = source_file;
+ } else {
+ failed("tmpnam");
+ }
}
}
} else {
@@ -675,24 +896,29 @@
_nc_progname,
_nc_progname,
usage_string);
- cleanup(namelst);
ExitProgram(EXIT_FAILURE);
}
}
- if (tmp_fp == 0)
- tmp_fp = open_input(source_file);
+ if (tmp_fp == 0) {
+ tmp_fp = open_input(source_file, my_altfile);
+ if (!strcmp(source_file, "-")) {
+ source_file = STDIN_NAME;
+ }
+ }
- if (infodump)
+ if (infodump || check_only) {
dump_init(tversion,
smart_defaults
? outform
: F_LITERAL,
- sortmode, width, debug_level, formatted);
- else if (capdump)
+ sortmode, width, height, debug_level, formatted ||
+ check_only, check_only);
+ } else if (capdump) {
dump_init(tversion,
outform,
- sortmode, width, debug_level, FALSE);
+ sortmode, width, height, debug_level, FALSE, FALSE);
+ }
/* parse entries out of the source file */
_nc_set_source(source_file);
@@ -709,13 +935,12 @@
/* do use resolution */
if (check_only || (!infodump && !capdump) || forceresolve) {
if (!_nc_resolve_uses2(TRUE, literal) && !check_only) {
- cleanup(namelst);
ExitProgram(EXIT_FAILURE);
}
}
/* length check */
- if (check_only && (capdump || infodump)) {
+ if (check_only && limited && (capdump || infodump)) {
for_entry_list(qp) {
if (matches(namelst, qp->tterm.term_names)) {
int len = fmt_entry(&qp->tterm, NULL, FALSE, TRUE, infodump, numbers);
@@ -730,7 +955,21 @@
}
/* write or dump all entries */
- if (!check_only) {
+ if (check_only) {
+ /* this is in case infotocap() generates warnings */
+ _nc_curr_col = _nc_curr_line = -1;
+
+ for_entry_list(qp) {
+ if (matches(namelst, qp->tterm.term_names)) {
+ /* this is in case infotocap() generates warnings */
+ _nc_set_type(_nc_first_name(qp->tterm.term_names));
+ _nc_curr_line = (int) qp->startline;
+ repair_acsc(&qp->tterm);
+ dump_entry(&qp->tterm, suppress_untranslatable,
+ limited, numbers, NULL);
+ }
+ }
+ } else {
if (!infodump && !capdump) {
_nc_set_writedir(outdir);
for_entry_list(qp) {
@@ -743,7 +982,7 @@
for_entry_list(qp) {
if (matches(namelst, qp->tterm.term_names)) {
- int j = qp->cend - qp->cstart;
+ long j = qp->cend - qp->cstart;
int len = 0;
/* this is in case infotocap() generates warnings */
@@ -757,9 +996,10 @@
put_translate(fgetc(tmp_fp));
}
+ repair_acsc(&qp->tterm);
dump_entry(&qp->tterm, suppress_untranslatable,
limited, numbers, NULL);
- for (j = 0; j < (int) qp->nuses; j++)
+ for (j = 0; j < (long) qp->nuses; j++)
dump_uses(qp->uses[j].name, !capdump);
len = show_entry();
if (debug_level != 0 && !limited)
@@ -803,7 +1043,6 @@
else
fprintf(log_fp, "No entries written\n");
}
- cleanup(namelst);
ExitProgram(EXIT_SUCCESS);
}
@@ -890,6 +1129,17 @@
if (!VALID_STRING(orig_pair) && !VALID_STRING(orig_colors))
_nc_warning("expected either op/oc string for resetting colors");
}
+ if (can_change) {
+ if (!VALID_STRING(initialize_pair) &&
+ !VALID_STRING(initialize_color)) {
+ _nc_warning("expected initc or initp because ccc is given");
+ }
+ } else {
+ if (VALID_STRING(initialize_pair) ||
+ VALID_STRING(initialize_color)) {
+ _nc_warning("expected ccc because initc is given");
+ }
+ }
}
static char
@@ -907,22 +1157,227 @@
return result;
}
-static int
+static long
keypad_index(const char *string)
{
char *test;
const char *list = "PQRSwxymtuvlqrsPpn"; /* app-keypad except "Enter" */
int ch;
- int result = -1;
+ long result = -1;
if ((ch = keypad_final(string)) != '\0') {
- test = strchr(list, ch);
+ test = (strchr) (list, ch);
if (test != 0)
- result = (test - list);
+ result = (long) (test - list);
}
return result;
}
+/*
+ * list[] is down, up, left, right
+ * "left" may be ^H rather than \E[D
+ * "down" may be ^J rather than \E[B
+ * But up/right are generally consistently escape sequences for ANSI terminals.
+ */
+static void
+check_ansi_cursor(char *list[4])
+{
+ int j, k;
+ int want;
+ size_t prefix = 0;
+ size_t suffix;
+ bool skip[4];
+ bool repeated = FALSE;
+
+ for (j = 0; j < 4; ++j) {
+ skip[j] = FALSE;
+ for (k = 0; k < j; ++k) {
+ if (j != k
+ && !strcmp(list[j], list[k])) {
+ char *value = _nc_tic_expand(list[k], TRUE, 0);
+ _nc_warning("repeated cursor control %s\n", value);
+ repeated = TRUE;
+ }
+ }
+ }
+ if (!repeated) {
+ char *up = list[1];
+
+ if (UChar(up[0]) == '\033') {
+ if (up[1] == '[') {
+ prefix = 2;
+ } else {
+ prefix = 1;
+ }
+ } else if (UChar(up[0]) == UChar('\233')) {
+ prefix = 1;
+ }
+ if (prefix) {
+ suffix = prefix;
+ while (up[suffix] && isdigit(UChar(up[suffix])))
+ ++suffix;
+ }
+ if (prefix && up[suffix] == 'A') {
+ skip[1] = TRUE;
+ if (!strcmp(list[0], "\n"))
+ skip[0] = TRUE;
+ if (!strcmp(list[2], "\b"))
+ skip[2] = TRUE;
+
+ for (j = 0; j < 4; ++j) {
+ if (skip[j] || strlen(list[j]) == 1)
+ continue;
+ if (memcmp(list[j], up, prefix)) {
+ char *value = _nc_tic_expand(list[j], TRUE, 0);
+ _nc_warning("inconsistent prefix for %s\n", value);
+ continue;
+ }
+ if (strlen(list[j]) < suffix) {
+ char *value = _nc_tic_expand(list[j], TRUE, 0);
+ _nc_warning("inconsistent length for %s, expected %d\n",
+ value, (int) suffix + 1);
+ continue;
+ }
+ want = "BADC"[j];
+ if (list[j][suffix] != want) {
+ char *value = _nc_tic_expand(list[j], TRUE, 0);
+ _nc_warning("inconsistent suffix for %s, expected %c, have %c\n",
+ value, want, list[j][suffix]);
+ }
+ }
+ }
+ }
+}
+
+#define EXPECTED(name) if (!PRESENT(name)) _nc_warning("expected " #name)
+#define UNEXPECTED(name) if (PRESENT(name)) _nc_warning("unexpected " #name ", for %s", why)
+
+static void
+check_noaddress(TERMTYPE *tp, const char *why)
+{
+ UNEXPECTED(column_address);
+ UNEXPECTED(cursor_address);
+ UNEXPECTED(cursor_home);
+ UNEXPECTED(cursor_mem_address);
+ UNEXPECTED(cursor_to_ll);
+ UNEXPECTED(row_address);
+ UNEXPECTED(row_address);
+}
+
+static void
+check_cursor(TERMTYPE *tp)
+{
+ int count;
+ char *list[4];
+
+ if (hard_copy) {
+ check_noaddress(tp, "hard_copy");
+ } else if (generic_type) {
+ check_noaddress(tp, "generic_type");
+ } else if (strchr(tp->term_names, '+') == 0) {
+ int y = 0;
+ int x = 0;
+ if (PRESENT(column_address))
+ ++y;
+ if (PRESENT(cursor_address))
+ y = x = 10;
+ if (PRESENT(cursor_home))
+ ++y, ++x;
+ if (PRESENT(cursor_mem_address))
+ y = x = 10;
+ if (PRESENT(cursor_to_ll))
+ ++y, ++x;
+ if (PRESENT(row_address))
+ ++x;
+ if (PRESENT(cursor_down))
+ ++y;
+ if (PRESENT(cursor_up))
+ ++y;
+ if (PRESENT(cursor_left))
+ ++x;
+ if (PRESENT(cursor_right))
+ ++x;
+ if (x < 2 && y < 2) {
+ _nc_warning("terminal lacks cursor addressing");
+ } else {
+ if (x < 2)
+ _nc_warning("terminal lacks cursor column-addressing");
+ if (y < 2)
+ _nc_warning("terminal lacks cursor row-addressing");
+ }
+ }
+
+ /* it is rare to have an insert-line feature without a matching delete */
+ ANDMISSING(parm_insert_line, insert_line);
+ ANDMISSING(parm_delete_line, delete_line);
+ ANDMISSING(parm_insert_line, parm_delete_line);
+
+ /* if we have a parameterized form, then the non-parameterized is easy */
+ ANDMISSING(parm_down_cursor, cursor_down);
+ ANDMISSING(parm_up_cursor, cursor_up);
+ ANDMISSING(parm_left_cursor, cursor_left);
+ ANDMISSING(parm_right_cursor, cursor_right);
+
+ /* Given any of a set of cursor movement, the whole set should be present.
+ * Technically this is not true (we could use cursor_address to fill in
+ * unsupported controls), but it is likely.
+ */
+ count = 0;
+ if (PRESENT(parm_down_cursor)) {
+ list[count++] = parm_down_cursor;
+ }
+ if (PRESENT(parm_up_cursor)) {
+ list[count++] = parm_up_cursor;
+ }
+ if (PRESENT(parm_left_cursor)) {
+ list[count++] = parm_left_cursor;
+ }
+ if (PRESENT(parm_right_cursor)) {
+ list[count++] = parm_right_cursor;
+ }
+ if (count == 4) {
+ check_ansi_cursor(list);
+ } else if (count != 0) {
+ EXPECTED(parm_down_cursor);
+ EXPECTED(parm_up_cursor);
+ EXPECTED(parm_left_cursor);
+ EXPECTED(parm_right_cursor);
+ }
+
+ count = 0;
+ if (PRESENT(cursor_down)) {
+ list[count++] = cursor_down;
+ }
+ if (PRESENT(cursor_up)) {
+ list[count++] = cursor_up;
+ }
+ if (PRESENT(cursor_left)) {
+ list[count++] = cursor_left;
+ }
+ if (PRESENT(cursor_right)) {
+ list[count++] = cursor_right;
+ }
+ if (count == 4) {
+ check_ansi_cursor(list);
+ } else if (count != 0) {
+ count = 0;
+ if (PRESENT(cursor_down) && strcmp(cursor_down, "\n"))
+ ++count;
+ if (PRESENT(cursor_left) && strcmp(cursor_left, "\b"))
+ ++count;
+ if (PRESENT(cursor_up) && strlen(cursor_up) > 1)
+ ++count;
+ if (PRESENT(cursor_right) && strlen(cursor_right) > 1)
+ ++count;
+ if (count) {
+ EXPECTED(cursor_down);
+ EXPECTED(cursor_up);
+ EXPECTED(cursor_left);
+ EXPECTED(cursor_right);
+ }
+ }
+}
+
#define MAX_KP 5
/*
* Do a quick sanity-check for vt100-style keypads to see if the 5-key keypad
@@ -939,11 +1394,11 @@
VALID_STRING(key_c1) &&
VALID_STRING(key_c3)) {
char final[MAX_KP + 1];
- int list[MAX_KP];
+ long list[MAX_KP];
int increase = 0;
int j, k, kk;
- int last;
- int test;
+ long last;
+ long test;
final[0] = keypad_final(key_a1);
final[1] = keypad_final(key_a3);
@@ -991,19 +1446,19 @@
assert(strlen(show) < (MAX_KP * 4));
switch (kk) {
case 0:
- strcat(show, " ka1");
+ _nc_STRCAT(show, " ka1", sizeof(show));
break;
case 1:
- strcat(show, " ka3");
+ _nc_STRCAT(show, " ka3", sizeof(show));
break;
case 2:
- strcat(show, " kb2");
+ _nc_STRCAT(show, " kb2", sizeof(show));
break;
case 3:
- strcat(show, " kc1");
+ _nc_STRCAT(show, " kc1", sizeof(show));
break;
case 4:
- strcat(show, " kc3");
+ _nc_STRCAT(show, " kc3", sizeof(show));
break;
}
}
@@ -1018,18 +1473,118 @@
VALID_STRING(key_c3)) {
show[0] = '\0';
if (keypad_index(key_a1) >= 0)
- strcat(show, " ka1");
+ _nc_STRCAT(show, " ka1", sizeof(show));
if (keypad_index(key_a3) >= 0)
- strcat(show, " ka3");
+ _nc_STRCAT(show, " ka3", sizeof(show));
if (keypad_index(key_b2) >= 0)
- strcat(show, " kb2");
+ _nc_STRCAT(show, " kb2", sizeof(show));
if (keypad_index(key_c1) >= 0)
- strcat(show, " kc1");
+ _nc_STRCAT(show, " kc1", sizeof(show));
if (keypad_index(key_c3) >= 0)
- strcat(show, " kc3");
+ _nc_STRCAT(show, " kc3", sizeof(show));
if (*show != '\0')
_nc_warning("vt100 keypad map incomplete:%s", show);
}
+
+ /*
+ * These warnings are useful for consistency checks - it is possible that
+ * there are real terminals with mismatches in these
+ */
+ ANDMISSING(key_ic, key_dc);
+}
+
+static void
+check_printer(TERMTYPE *tp)
+{
+ PAIRED(enter_doublewide_mode, exit_doublewide_mode);
+ PAIRED(enter_italics_mode, exit_italics_mode);
+ PAIRED(enter_leftward_mode, exit_leftward_mode);
+ PAIRED(enter_micro_mode, exit_micro_mode);
+ PAIRED(enter_shadow_mode, exit_shadow_mode);
+ PAIRED(enter_subscript_mode, exit_subscript_mode);
+ PAIRED(enter_superscript_mode, exit_superscript_mode);
+ PAIRED(enter_upward_mode, exit_upward_mode);
+
+ ANDMISSING(start_char_set_def, stop_char_set_def);
+
+ /* if we have a parameterized form, then the non-parameterized is easy */
+ ANDMISSING(set_bottom_margin_parm, set_bottom_margin);
+ ANDMISSING(set_left_margin_parm, set_left_margin);
+ ANDMISSING(set_right_margin_parm, set_right_margin);
+ ANDMISSING(set_top_margin_parm, set_top_margin);
+
+ ANDMISSING(parm_down_micro, micro_down);
+ ANDMISSING(parm_left_micro, micro_left);
+ ANDMISSING(parm_right_micro, micro_right);
+ ANDMISSING(parm_up_micro, micro_up);
+}
+
+static bool
+uses_SGR_39_49(const char *value)
+{
+ return (strstr(value, "39;49") != 0
+ || strstr(value, "49;39") != 0);
+}
+
+/*
+ * Check consistency of termcap extensions related to "screen".
+ */
+static void
+check_screen(TERMTYPE *tp)
+{
+#if NCURSES_XNAMES
+ if (_nc_user_definable) {
+ int have_XT = tigetflag("XT");
+ int have_XM = tigetflag("XM");
+ int have_bce = back_color_erase;
+ bool have_kmouse = FALSE;
+ bool use_sgr_39_49 = FALSE;
+ char *name = _nc_first_name(tp->term_names);
+
+ if (!VALID_BOOLEAN(have_bce)) {
+ have_bce = FALSE;
+ }
+ if (!VALID_BOOLEAN(have_XM)) {
+ have_XM = FALSE;
+ }
+ if (!VALID_BOOLEAN(have_XT)) {
+ have_XT = FALSE;
+ }
+ if (VALID_STRING(key_mouse)) {
+ have_kmouse = !strcmp("\033[M", key_mouse);
+ }
+ if (VALID_STRING(orig_colors)) {
+ use_sgr_39_49 = uses_SGR_39_49(orig_colors);
+ } else if (VALID_STRING(orig_pair)) {
+ use_sgr_39_49 = uses_SGR_39_49(orig_pair);
+ }
+
+ if (have_XM && have_XT) {
+ _nc_warning("Screen's XT capability conflicts with XM");
+ } else if (have_XT
+ && strstr(name, "screen") != 0
+ && strchr(name, '.') != 0) {
+ _nc_warning("Screen's \"screen\" entries should not have XT set");
+ } else if (have_XT) {
+ if (!have_kmouse && have_bce) {
+ if (VALID_STRING(key_mouse)) {
+ _nc_warning("Value of kmous inconsistent with screen's usage");
+ } else {
+ _nc_warning("Expected kmous capability with XT");
+ }
+ }
+ if (!have_bce && max_colors > 0)
+ _nc_warning("Expected bce capability with XT");
+ if (!use_sgr_39_49 && have_bce && max_colors > 0)
+ _nc_warning("Expected orig_colors capability with XT to have 39/49 parameters");
+ if (VALID_STRING(to_status_line))
+ _nc_warning("\"tsl\" capability is redundant, given XT");
+ } else {
+ if (have_kmouse && !have_XM)
+ _nc_warning("Expected XT to be set, given kmous");
+ }
+ }
+#endif
}
/*
@@ -1038,78 +1593,81 @@
static int
expected_params(const char *name)
{
+#define DATA(name,count) { { name }, count }
/* *INDENT-OFF* */
static const struct {
- const char *name;
+ const char name[9];
int count;
} table[] = {
- { "S0", 1 }, /* 'screen' extension */
- { "birep", 2 },
- { "chr", 1 },
- { "colornm", 1 },
- { "cpi", 1 },
- { "csnm", 1 },
- { "csr", 2 },
- { "cub", 1 },
- { "cud", 1 },
- { "cuf", 1 },
- { "cup", 2 },
- { "cuu", 1 },
- { "cvr", 1 },
- { "cwin", 5 },
- { "dch", 1 },
- { "defc", 3 },
- { "dial", 1 },
- { "dispc", 1 },
- { "dl", 1 },
- { "ech", 1 },
- { "getm", 1 },
- { "hpa", 1 },
- { "ich", 1 },
- { "il", 1 },
- { "indn", 1 },
- { "initc", 4 },
- { "initp", 7 },
- { "lpi", 1 },
- { "mc5p", 1 },
- { "mrcup", 2 },
- { "mvpa", 1 },
- { "pfkey", 2 },
- { "pfloc", 2 },
- { "pfx", 2 },
- { "pfxl", 3 },
- { "pln", 2 },
- { "qdial", 1 },
- { "rcsd", 1 },
- { "rep", 2 },
- { "rin", 1 },
- { "sclk", 3 },
- { "scp", 1 },
- { "scs", 1 },
- { "scsd", 2 },
- { "setab", 1 },
- { "setaf", 1 },
- { "setb", 1 },
- { "setcolor", 1 },
- { "setf", 1 },
- { "sgr", 9 },
- { "sgr1", 6 },
- { "slength", 1 },
- { "slines", 1 },
- { "smgbp", 1 }, /* 2 if smgtp is not given */
- { "smglp", 1 },
- { "smglr", 2 },
- { "smgrp", 1 },
- { "smgtb", 2 },
- { "smgtp", 1 },
- { "tsl", 1 },
- { "u6", -1 },
- { "vpa", 1 },
- { "wind", 4 },
- { "wingo", 1 },
+ DATA( "S0", 1 ), /* 'screen' extension */
+ DATA( "birep", 2 ),
+ DATA( "chr", 1 ),
+ DATA( "colornm", 1 ),
+ DATA( "cpi", 1 ),
+ DATA( "csnm", 1 ),
+ DATA( "csr", 2 ),
+ DATA( "cub", 1 ),
+ DATA( "cud", 1 ),
+ DATA( "cuf", 1 ),
+ DATA( "cup", 2 ),
+ DATA( "cuu", 1 ),
+ DATA( "cvr", 1 ),
+ DATA( "cwin", 5 ),
+ DATA( "dch", 1 ),
+ DATA( "defc", 3 ),
+ DATA( "dial", 1 ),
+ DATA( "dispc", 1 ),
+ DATA( "dl", 1 ),
+ DATA( "ech", 1 ),
+ DATA( "getm", 1 ),
+ DATA( "hpa", 1 ),
+ DATA( "ich", 1 ),
+ DATA( "il", 1 ),
+ DATA( "indn", 1 ),
+ DATA( "initc", 4 ),
+ DATA( "initp", 7 ),
+ DATA( "lpi", 1 ),
+ DATA( "mc5p", 1 ),
+ DATA( "mrcup", 2 ),
+ DATA( "mvpa", 1 ),
+ DATA( "pfkey", 2 ),
+ DATA( "pfloc", 2 ),
+ DATA( "pfx", 2 ),
+ DATA( "pfxl", 3 ),
+ DATA( "pln", 2 ),
+ DATA( "qdial", 1 ),
+ DATA( "rcsd", 1 ),
+ DATA( "rep", 2 ),
+ DATA( "rin", 1 ),
+ DATA( "sclk", 3 ),
+ DATA( "scp", 1 ),
+ DATA( "scs", 1 ),
+ DATA( "scsd", 2 ),
+ DATA( "setab", 1 ),
+ DATA( "setaf", 1 ),
+ DATA( "setb", 1 ),
+ DATA( "setcolor", 1 ),
+ DATA( "setf", 1 ),
+ DATA( "sgr", 9 ),
+ DATA( "sgr1", 6 ),
+ DATA( "slength", 1 ),
+ DATA( "slines", 1 ),
+ DATA( "smgbp", 1 ), /* 2 if smgtp is not given */
+ DATA( "smglp", 1 ),
+ DATA( "smglr", 2 ),
+ DATA( "smgrp", 1 ),
+ DATA( "smgtb", 2 ),
+ DATA( "smgtp", 1 ),
+ DATA( "tsl", 1 ),
+ DATA( "u6", -1 ),
+ DATA( "vpa", 1 ),
+ DATA( "wind", 4 ),
+ DATA( "wingo", 1 ),
};
/* *INDENT-ON* */
+#undef DATA
+
unsigned n;
int result = 0; /* function-keys, etc., use none */
@@ -1134,7 +1692,7 @@
int expected = expected_params(name);
int actual = 0;
int n;
- bool params[10];
+ bool params[NUM_PARM];
char *s = value;
#ifdef set_top_margin_parm
@@ -1143,7 +1701,7 @@
expected = 2;
#endif
- for (n = 0; n < 10; n++)
+ for (n = 0; n < NUM_PARM; n++)
params[n] = FALSE;
while (*s != 0) {
@@ -1182,6 +1740,228 @@
}
static char *
+check_1_infotocap(const char *name, NCURSES_CONST char *value, int count)
+{
+ int k;
+ int ignored;
+ long numbers[1 + NUM_PARM];
+ char *strings[1 + NUM_PARM];
+ char *p_is_s[NUM_PARM];
+ char *result;
+ char blob[NUM_PARM * 10];
+ char *next = blob;
+
+ *next++ = '\0';
+ for (k = 1; k <= NUM_PARM; k++) {
+ numbers[k] = count;
+ sprintf(next, "XYZ%d", count);
+ strings[k] = next;
+ next += strlen(next) + 1;
+ }
+
+ switch (tparm_type(name)) {
+ case Num_Str:
+ result = TPARM_2(value, numbers[1], strings[2]);
+ break;
+ case Num_Str_Str:
+ result = TPARM_3(value, numbers[1], strings[2], strings[3]);
+ break;
+ case Numbers:
+ default:
+ (void) _nc_tparm_analyze(value, p_is_s, &ignored);
+#define myParam(n) (p_is_s[n - 1] != 0 ? ((TPARM_ARG) strings[n]) : numbers[n])
+ result = TPARM_9(value,
+ myParam(1),
+ myParam(2),
+ myParam(3),
+ myParam(4),
+ myParam(5),
+ myParam(6),
+ myParam(7),
+ myParam(8),
+ myParam(9));
+ break;
+ }
+ return result;
+}
+
+#define IsDelay(ch) ((ch) == '.' || isdigit(UChar(ch)))
+
+static const char *
+parse_delay_value(const char *src, double *delays, int *always)
+{
+ int star = 0;
+
+ *delays = 0.0;
+ if (always)
+ *always = 0;
+
+ while (isdigit(UChar(*src))) {
+ (*delays) = (*delays) * 10 + (*src++ - '0');
+ }
+ if (*src == '.') {
+ int gotdot = 1;
+
+ ++src;
+ while (isdigit(UChar(*src))) {
+ gotdot *= 10;
+ (*delays) += (*src++ - '0') / gotdot;
+ }
+ }
+ while (*src == '*' || *src == '/') {
+ if (always == 0 && *src == '/')
+ break;
+ if (*src++ == '*') {
+ star = 1;
+ } else {
+ *always = 1;
+ }
+ }
+ if (star)
+ *delays = -(*delays);
+ return src;
+}
+
+static const char *
+parse_ti_delay(const char *ti, double *delays)
+{
+ *delays = 0.0;
+ while (*ti != '\0') {
+ if (*ti == '\\') {
+ ++ti;
+ }
+ if (ti[0] == '$'
+ && ti[1] == '<'
+ && IsDelay(UChar(ti[2]))) {
+ int ignored;
+ const char *last = parse_delay_value(ti + 2, delays, &ignored);
+ if (*last == '>') {
+ ti = last;
+ }
+ } else {
+ ++ti;
+ }
+ }
+ return ti;
+}
+
+static const char *
+parse_tc_delay(const char *tc, double *delays)
+{
+ return parse_delay_value(tc, delays, (int *) 0);
+}
+
+/*
+ * Compare terminfo- and termcap-strings, factoring out delays.
+ */
+static bool
+same_ti_tc(const char *ti, const char *tc, bool * embedded)
+{
+ bool same = TRUE;
+ double ti_delay = 0.0;
+ double tc_delay = 0.0;
+ const char *ti_last;
+
+ *embedded = FALSE;
+ ti_last = parse_ti_delay(ti, &ti_delay);
+ tc = parse_tc_delay(tc, &tc_delay);
+
+ while ((ti < ti_last) && *tc) {
+ if (*ti == '\\' && ispunct(UChar(ti[1]))) {
+ ++ti;
+ if ((*ti == '^') && !strncmp(tc, "\\136", 4)) {
+ ti += 1;
+ tc += 4;
+ continue;
+ }
+ } else if (ti[0] == '$' && ti[1] == '<') {
+ double no_delay;
+ const char *ss = parse_ti_delay(ti, &no_delay);
+ if (ss != ti) {
+ *embedded = TRUE;
+ ti = ss;
+ continue;
+ }
+ }
+ if (*tc == '\\' && ispunct(UChar(tc[1]))) {
+ ++tc;
+ }
+ if (*ti++ != *tc++) {
+ same = FALSE;
+ break;
+ }
+ }
+
+ if (*embedded) {
+ if (same) {
+ same = FALSE;
+ } else {
+ *embedded = FALSE; /* report only one problem */
+ }
+ }
+
+ return same;
+}
+
+/*
+ * Check terminfo to termcap translation.
+ */
+static void
+check_infotocap(TERMTYPE *tp, int i, const char *value)
+{
+ const char *name = ExtStrname(tp, i, strnames);
+ int params = (((i < (int) SIZEOF(parametrized)) &&
+ (i < STRCOUNT))
+ ? parametrized[i]
+ : ((*value == 'k')
+ ? 0
+ : has_params(value)));
+ int to_char = 0;
+ char *ti_value;
+ char *tc_value;
+ bool embedded;
+
+ if ((ti_value = _nc_tic_expand(value, TRUE, to_char)) == ABSENT_STRING) {
+ _nc_warning("tic-expansion of %s failed", name);
+ } else if ((tc_value = _nc_infotocap(name, ti_value, params)) == ABSENT_STRING) {
+ _nc_warning("tic-conversion of %s failed", name);
+ } else if (params > 0) {
+ int limit = 5;
+ int count;
+ bool first = TRUE;
+
+ if (!strcmp(name, "setf")
+ || !strcmp(name, "setb")
+ || !strcmp(name, "setaf")
+ || !strcmp(name, "setab")) {
+ limit = max_colors;
+ }
+ for (count = 0; count < limit; ++count) {
+ char *ti_check = check_1_infotocap(name, ti_value, count);
+ char *tc_check = check_1_infotocap(name, tc_value, count);
+
+ if (strcmp(ti_check, tc_check)) {
+ if (first) {
+ fprintf(stderr, "check_infotocap(%s)\n", name);
+ fprintf(stderr, "...ti '%s'\n", ti_value);
+ fprintf(stderr, "...tc '%s'\n", tc_value);
+ first = FALSE;
+ }
+ _nc_warning("tparm-conversion of %s(%d) differs between\n\tterminfo %s\n\ttermcap %s",
+ name, count, ti_check, tc_check);
+ }
+ }
+ } else if (params == 0 && !same_ti_tc(ti_value, tc_value, &embedded)) {
+ if (embedded) {
+ _nc_warning("termcap equivalent of %s cannot use embedded delay", name);
+ } else {
+ _nc_warning("tic-conversion of %s changed value\n\tfrom %s\n\tto %s",
+ name, ti_value, tc_value);
+ }
+ }
+}
+
+static char *
skip_delay(char *s)
{
while (*s == '/' || isdigit(UChar(*s)))
@@ -1235,19 +2015,21 @@
static bool
similar_sgr(int num, char *a, char *b)
{
- static const char *names[] =
+#define DATA(name) { #name }
+ static const char names[][11] =
{
- "none"
- ,"standout"
- ,"underline"
- ,"reverse"
- ,"blink"
- ,"dim"
- ,"bold"
- ,"invis"
- ,"protect"
- ,"altcharset"
+ DATA(none),
+ DATA(standout),
+ DATA(underline),
+ DATA(reverse),
+ DATA(blink),
+ DATA(dim),
+ DATA(bold),
+ DATA(invis),
+ DATA(protect),
+ DATA(altcharset),
};
+#undef DATA
char *base_a = a;
char *base_b = b;
int delaying = 0;
@@ -1268,6 +2050,8 @@
} else if (delaying) {
a = skip_delay(a);
b = skip_delay(b);
+ } else if ((*b == '0' || (*b == ';')) && *a == 'm') {
+ b++;
} else {
a++;
}
@@ -1341,9 +2125,9 @@
show_where(unsigned level)
{
if (_nc_tracing >= DEBUG_LEVEL(level)) {
- char my_name[256];
+ char my_name[MAX_NAME_SIZE];
_nc_get_type(my_name);
- fprintf(stderr, "\"%s\", line %d, '%s' ",
+ _tracef("\"%s\", line %d, '%s'",
_nc_get_source(),
_nc_curr_line, my_name);
}
@@ -1353,65 +2137,137 @@
#define show_where(level) /* nothing */
#endif
-/* other sanity-checks (things that we don't want in the normal
- * logic that reads a terminfo entry)
+typedef struct {
+ int keycode;
+ const char *name;
+ const char *value;
+} NAME_VALUE;
+
+static NAME_VALUE *
+get_fkey_list(TERMTYPE *tp)
+{
+ NAME_VALUE *result = typeMalloc(NAME_VALUE, NUM_STRINGS(tp) + 1);
+ const struct tinfo_fkeys *all_fkeys = _nc_tinfo_fkeys;
+ int used = 0;
+ int j;
+
+ if (result == 0)
+ failed("get_fkey_list");
+
+ for (j = 0; all_fkeys[j].code; j++) {
+ char *a = tp->Strings[all_fkeys[j].offset];
+ if (VALID_STRING(a)) {
+ result[used].keycode = (int) all_fkeys[j].code;
+ result[used].name = strnames[all_fkeys[j].offset];
+ result[used].value = a;
+ ++used;
+ }
+ }
+#if NCURSES_XNAMES
+ for (j = STRCOUNT; j < NUM_STRINGS(tp); ++j) {
+ const char *name = ExtStrname(tp, j, strnames);
+ if (*name == 'k') {
+ result[used].keycode = -1;
+ result[used].name = name;
+ result[used].value = tp->Strings[j];
+ ++used;
+ }
+ }
+#endif
+ result[used].keycode = 0;
+ return result;
+}
+
+static void
+show_fkey_name(NAME_VALUE * data)
+{
+ if (data->keycode > 0) {
+ fprintf(stderr, " %s", keyname(data->keycode));
+ fprintf(stderr, " (capability \"%s\")", data->name);
+ } else {
+ fprintf(stderr, " capability \"%s\"", data->name);
+ }
+}
+
+/*
+ * A terminal entry may contain more than one keycode assigned to a given
+ * string (e.g., KEY_END and KEY_LL). But curses will only return one (the
+ * last one assigned).
*/
static void
-check_termtype(TERMTYPE *tp, bool literal)
+check_conflict(TERMTYPE *tp)
{
bool conflict = FALSE;
unsigned j, k;
- char fkeys[STRCOUNT];
- /*
- * A terminal entry may contain more than one keycode assigned to
- * a given string (e.g., KEY_END and KEY_LL). But curses will only
- * return one (the last one assigned).
- */
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];
+ char *check = calloc((size_t) (NUM_STRINGS(tp) + 1), sizeof(char));
+ NAME_VALUE *given = get_fkey_list(tp);
+
+ if (check == 0)
+ failed("check_termtype");
+
+ for (j = 0; given[j].keycode; ++j) {
+ const char *a = given[j].value;
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])
+
+ for (k = j + 1; given[k].keycode; k++) {
+ const char *b = given[k].value;
+ if (check[k])
continue;
if (!_nc_capcmp(a, b)) {
- fkeys[j] = 1;
- fkeys[k] = 1;
+ check[j] = 1;
+ check[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));
+ fprintf(stderr, "...");
+ show_fkey_name(given + j);
+ fprintf(stderr, " is the same as");
+ show_fkey_name(given + k);
first = FALSE;
} else {
- fprintf(stderr, ", %s",
- keyname((int) _nc_tinfo_fkeys[k].code));
+ fprintf(stderr, ", ");
+ show_fkey_name(given + k);
}
}
}
if (!first)
fprintf(stderr, "\n");
}
+ free(given);
+ free(check);
}
+}
- for (j = 0; j < NUM_STRINGS(tp); j++) {
+/* other sanity-checks (things that we don't want in the normal
+ * logic that reads a terminfo entry)
+ */
+static void
+check_termtype(TERMTYPE *tp, bool literal)
+{
+ unsigned j;
+
+ check_conflict(tp);
+
+ for_each_string(j, tp) {
char *a = tp->Strings[j];
- if (VALID_STRING(a))
- check_params(tp, ExtStrname(tp, j, strnames), a);
+ if (VALID_STRING(a)) {
+ check_params(tp, ExtStrname(tp, (int) j, strnames), a);
+ if (capdump) {
+ check_infotocap(tp, (int) j, a);
+ }
+ }
}
check_acs(tp);
check_colors(tp);
+ check_cursor(tp);
check_keypad(tp);
+ check_printer(tp);
+ check_screen(tp);
/*
* These may be mismatched because the terminal description relies on
@@ -1432,6 +2288,11 @@
ANDMISSING(change_scroll_region, save_cursor);
ANDMISSING(change_scroll_region, restore_cursor);
+ /*
+ * If we can clear tabs, we should be able to initialize them.
+ */
+ ANDMISSING(clear_all_tabs, set_tab);
+
if (PRESENT(set_attributes)) {
char *zero = 0;
@@ -1476,13 +2337,15 @@
("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)));
}
}
+ if (check_sgr0 != exit_attribute_mode) {
+ free(check_sgr0);
+ }
}
#ifdef TRACE
show_where(2);
diff --git a/progs/toe b/progs/toe
deleted file mode 100755
index a0049a6..0000000
--- a/progs/toe
+++ /dev/null
Binary files differ
diff --git a/progs/toe.c b/progs/toe.c
index 8af6f37..0d299b4 100644
--- a/progs/toe.c
+++ b/progs/toe.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -44,12 +44,23 @@
#include <hashed_db.h>
#endif
-MODULE_ID("$Id: toe.c,v 1.51 2008/08/16 21:53:25 tom Exp $")
+MODULE_ID("$Id: toe.c,v 1.74 2013/12/15 01:08:28 tom Exp $")
#define isDotname(name) (!strcmp(name, ".") || !strcmp(name, ".."))
+typedef struct {
+ int db_index;
+ unsigned long checksum;
+ char *term_name;
+ char *description;
+} TERMDATA;
+
const char *_nc_progname;
+static TERMDATA *ptr_termdata; /* array of terminal data */
+static size_t use_termdata; /* actual usage in ptr_termdata[] */
+static size_t len_termdata; /* allocated size of ptr_termdata[] */
+
#if NO_LEAKS
#undef ExitProgram
static void ExitProgram(int code) GCC_NORETURN;
@@ -61,6 +72,159 @@
}
#endif
+static void failed(const char *) GCC_NORETURN;
+
+static void
+failed(const char *msg)
+{
+ perror(msg);
+ ExitProgram(EXIT_FAILURE);
+}
+
+static char *
+strmalloc(const char *value)
+{
+ char *result = strdup(value);
+ if (result == 0) {
+ failed("strmalloc");
+ }
+ return result;
+}
+
+static TERMDATA *
+new_termdata(void)
+{
+ size_t want = use_termdata + 1;
+
+ if (want >= len_termdata) {
+ len_termdata = (2 * want) + 10;
+ ptr_termdata = typeRealloc(TERMDATA, len_termdata, ptr_termdata);
+ if (ptr_termdata == 0)
+ failed("ptr_termdata");
+ }
+
+ return ptr_termdata + use_termdata++;
+}
+
+static int
+compare_termdata(const void *a, const void *b)
+{
+ const TERMDATA *p = (const TERMDATA *) a;
+ const TERMDATA *q = (const TERMDATA *) b;
+ int result = strcmp(p->term_name, q->term_name);
+
+ if (result == 0) {
+ result = (p->db_index - q->db_index);
+ }
+ return result;
+}
+
+/*
+ * Sort the array of TERMDATA and print it. If more than one database is being
+ * reported, add a column to show which database has a given entry.
+ */
+static void
+show_termdata(int eargc, char **eargv)
+{
+ int j, k;
+ size_t n;
+
+ if (use_termdata) {
+ if (eargc > 1) {
+ for (j = 0; j < eargc; ++j) {
+ for (k = 0; k <= j; ++k) {
+ printf("--");
+ }
+ printf("> ");
+ printf("%s\n", eargv[j]);
+ }
+ }
+ if (use_termdata > 1)
+ qsort(ptr_termdata, use_termdata, sizeof(TERMDATA), compare_termdata);
+ for (n = 0; n < use_termdata; ++n) {
+
+ /*
+ * If there is more than one database, show how they differ.
+ */
+ if (eargc > 1) {
+ unsigned long check = 0;
+ k = 0;
+ for (;;) {
+ for (; k < ptr_termdata[n].db_index; ++k) {
+ printf("--");
+ }
+
+ /*
+ * If this is the first entry, or its checksum differs
+ * from the first entry's checksum, print "*". Otherwise
+ * it looks enough like a duplicate to print "+".
+ */
+ printf("%c-", ((check == 0
+ || (check != ptr_termdata[n].checksum))
+ ? '*'
+ : '+'));
+ check = ptr_termdata[n].checksum;
+
+ ++k;
+ if ((n + 1) >= use_termdata
+ || strcmp(ptr_termdata[n].term_name,
+ ptr_termdata[n + 1].term_name)) {
+ break;
+ }
+ ++n;
+ }
+ for (; k < eargc; ++k) {
+ printf("--");
+ }
+ printf(":\t");
+ }
+
+ (void) printf("%-10s\t%s\n",
+ ptr_termdata[n].term_name,
+ ptr_termdata[n].description);
+ }
+ }
+}
+
+static void
+free_termdata(void)
+{
+ if (ptr_termdata != 0) {
+ while (use_termdata != 0) {
+ --use_termdata;
+ free(ptr_termdata[use_termdata].term_name);
+ free(ptr_termdata[use_termdata].description);
+ }
+ free(ptr_termdata);
+ ptr_termdata = 0;
+ }
+ use_termdata = 0;
+ len_termdata = 0;
+}
+
+static char **
+allocArgv(size_t count)
+{
+ char **result = typeCalloc(char *, count + 1);
+ if (result == 0)
+ failed("realloc eargv");
+
+ assert(result != 0);
+ return result;
+}
+
+static void
+freeArgv(char **argv)
+{
+ if (argv) {
+ int count = 0;
+ while (argv[count]) {
+ free(argv[count++]);
+ }
+ free(argv);
+ }
+}
+
#if USE_HASHED_DB
static bool
make_db_name(char *dst, const char *src, unsigned limit)
@@ -68,67 +232,100 @@
static const char suffix[] = DBM_SUFFIX;
bool result = FALSE;
- unsigned lens = sizeof(suffix) - 1;
- unsigned size = strlen(src);
- unsigned need = lens + size;
+ size_t lens = sizeof(suffix) - 1;
+ size_t size = strlen(src);
+ size_t 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_database(const char *path)
-{
- 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;
- }
+ && !strcmp(src + size - lens, suffix)) {
+ _nc_STRCPY(dst, src, PATH_MAX);
+ } else {
+ _nc_SPRINTF(dst, _nc_SLIMIT(PATH_MAX) "%s%s", src, suffix);
}
+ result = TRUE;
}
-#endif
return result;
}
+#endif
-static void
-deschook(const char *cn, TERMTYPE *tp)
-/* display a description for the type */
+typedef void (DescHook) (int /* db_index */ ,
+ int /* db_limit */ ,
+ const char * /* term_name */ ,
+ TERMTYPE * /* term */ );
+
+static const char *
+term_description(TERMTYPE *tp)
{
const char *desc;
- if ((desc = strrchr(tp->term_names, '|')) == 0 || *++desc == '\0')
+ if (tp->term_names == 0
+ || (desc = strrchr(tp->term_names, '|')) == 0
+ || (*++desc == '\0')) {
desc = "(No description)";
+ }
- (void) printf("%-10s\t%s\n", cn, desc);
+ return desc;
}
-#if USE_TERMCAP
+/* display a description for the type */
static void
-show_termcap(char *buffer,
- void (*hook) (const char *, TERMTYPE *tp))
+deschook(int db_index, int db_limit, const char *term_name, TERMTYPE *tp)
+{
+ (void) db_index;
+ (void) db_limit;
+ (void) printf("%-10s\t%s\n", term_name, term_description(tp));
+}
+
+static unsigned long
+string_sum(const char *value)
+{
+ unsigned long result = 0;
+
+ if ((intptr_t) value == (intptr_t) (-1)) {
+ result = ~result;
+ } else if (value) {
+ while (*value) {
+ result += UChar(*value);
+ ++value;
+ }
+ }
+ return result;
+}
+
+static unsigned long
+checksum_of(TERMTYPE *tp)
+{
+ unsigned long result = string_sum(tp->term_names);
+ unsigned i;
+
+ for (i = 0; i < NUM_BOOLEANS(tp); i++) {
+ result += (unsigned long) (tp->Booleans[i]);
+ }
+ for (i = 0; i < NUM_NUMBERS(tp); i++) {
+ result += (unsigned long) (tp->Numbers[i]);
+ }
+ for (i = 0; i < NUM_STRINGS(tp); i++) {
+ result += string_sum(tp->Strings[i]);
+ }
+ return result;
+}
+
+/* collect data, to sort before display */
+static void
+sorthook(int db_index, int db_limit, const char *term_name, TERMTYPE *tp)
+{
+ TERMDATA *data = new_termdata();
+
+ data->db_index = db_index;
+ data->checksum = ((db_limit > 1) ? checksum_of(tp) : 0);
+ data->term_name = strmalloc(term_name);
+ data->description = strmalloc(term_description(tp));
+}
+
+#if NCURSES_USE_TERMCAP
+static void
+show_termcap(int db_index, int db_limit, char *buffer, DescHook hook)
{
TERMTYPE data;
char *next = strchr(buffer, ':');
@@ -142,26 +339,42 @@
if (last)
++last;
- data.term_names = strdup(buffer);
+ memset(&data, 0, sizeof(data));
+ data.term_names = strmalloc(buffer);
while ((next = strtok(list, "|")) != 0) {
if (next != last)
- hook(next, &data);
+ hook(db_index, db_limit, next, &data);
list = 0;
}
free(data.term_names);
}
#endif
+#if NCURSES_USE_DATABASE
+static char *
+copy_entryname(DIRENT * src)
+{
+ size_t len = NAMLEN(src);
+ char *result = malloc(len + 1);
+ if (result == 0)
+ failed("copy entryname");
+ memcpy(result, src->d_name, len);
+ result[len] = '\0';
+
+ return result;
+}
+#endif
+
static int
typelist(int eargc, char *eargv[],
- bool verbosity,
- void (*hook) (const char *, TERMTYPE *tp))
+ int verbosity,
+ DescHook hook)
/* apply a function to each entry in given terminfo directories */
{
int i;
for (i = 0; i < eargc; i++) {
-#if USE_DATABASE
+#if NCURSES_USE_DATABASE
if (_nc_is_dir_path(eargv[i])) {
char *cwd_buf = 0;
DIR *termdir;
@@ -172,28 +385,35 @@
(void) fprintf(stderr,
"%s: can't open terminfo directory %s\n",
_nc_progname, eargv[i]);
- return (EXIT_FAILURE);
- } else if (verbosity)
+ continue;
+ }
+
+ if (verbosity)
(void) printf("#\n#%s:\n#\n", eargv[i]);
while ((subdir = readdir(termdir)) != 0) {
- size_t len = NAMLEN(subdir);
- size_t cwd_len = len + strlen(eargv[i]) + 3;
- char name_1[PATH_MAX];
+ size_t cwd_len;
+ char *name_1;
DIR *entrydir;
DIRENT *entry;
- cwd_buf = typeRealloc(char, cwd_len, cwd_buf);
- if (cwd_buf == 0) {
- perror("realloc cwd_buf");
+ name_1 = copy_entryname(subdir);
+ if (isDotname(name_1)) {
+ free(name_1);
continue;
}
- strncpy(name_1, subdir->d_name, len)[len] = '\0';
- if (isDotname(name_1))
- continue;
+ cwd_len = NAMLEN(subdir) + strlen(eargv[i]) + 3;
+ cwd_buf = typeRealloc(char, cwd_len, cwd_buf);
+ if (cwd_buf == 0)
+ failed("realloc cwd_buf");
- (void) sprintf(cwd_buf, "%s/%.*s/", eargv[i], (int) len, name_1);
+ assert(cwd_buf != 0);
+
+ _nc_SPRINTF(cwd_buf, _nc_SLIMIT(cwd_len)
+ "%s/%s/", eargv[i], name_1);
+ free(name_1);
+
if (chdir(cwd_buf) != 0)
continue;
@@ -203,15 +423,16 @@
continue;
}
while ((entry = readdir(entrydir)) != 0) {
- char name_2[PATH_MAX];
+ char *name_2;
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))
+ name_2 = copy_entryname(entry);
+ if (isDotname(name_2) || !_nc_is_file_path(name_2)) {
+ free(name_2);
continue;
+ }
status = _nc_read_file_entry(name_2, <erm);
if (status <= 0) {
@@ -219,6 +440,10 @@
(void) fprintf(stderr,
"%s: couldn't open terminfo file %s.\n",
_nc_progname, name_2);
+ free(cwd_buf);
+ free(name_2);
+ closedir(entrydir);
+ closedir(termdir);
return (EXIT_FAILURE);
}
@@ -226,21 +451,26 @@
cn = _nc_first_name(lterm.term_names);
if (!strcmp(cn, name_2)) {
/* apply the selected hook function */
- (*hook) (cn, <erm);
+ hook(i, eargc, cn, <erm);
}
_nc_free_termtype(<erm);
+ free(name_2);
}
closedir(entrydir);
}
closedir(termdir);
if (cwd_buf != 0)
free(cwd_buf);
+ continue;
}
#if USE_HASHED_DB
else {
DB *capdbp;
char filename[PATH_MAX];
+ if (verbosity)
+ (void) printf("#\n#%s:\n#\n", eargv[i]);
+
if (make_db_name(filename, eargv[i], sizeof(filename))) {
if ((capdbp = _nc_db_open(filename, FALSE)) != 0) {
DBT key, data;
@@ -258,7 +488,7 @@
/* only visit things once, by primary name */
cn = _nc_first_name(lterm.term_names);
/* apply the selected hook function */
- (*hook) (cn, <erm);
+ hook(i, eargc, cn, <erm);
_nc_free_termtype(<erm);
}
}
@@ -266,44 +496,51 @@
}
_nc_db_close(capdbp);
+ continue;
}
}
}
#endif
#endif
-#if USE_TERMCAP
+#if NCURSES_USE_TERMCAP
#if HAVE_BSD_CGETENT
- char *db_array[2];
- char *buffer = 0;
+ {
+ CGETENT_CONST char *db_array[2];
+ char *buffer = 0;
- if (verbosity)
- (void) printf("#\n#%s:\n#\n", eargv[i]);
+ if (verbosity)
+ (void) printf("#\n#%s:\n#\n", eargv[i]);
- db_array[0] = eargv[i];
- db_array[1] = 0;
+ 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);
+ if (cgetfirst(&buffer, db_array) > 0) {
+ show_termcap(i, eargc, buffer, hook);
free(buffer);
+ while (cgetnext(&buffer, db_array) > 0) {
+ show_termcap(i, eargc, buffer, hook);
+ free(buffer);
+ }
+ cgetclose();
+ continue;
}
}
- cgetclose();
#else
/* scan termcap text-file only */
if (_nc_is_file_path(eargv[i])) {
char buffer[2048];
FILE *fp;
+ if (verbosity)
+ (void) printf("#\n#%s:\n#\n", eargv[i]);
+
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);
+ show_termcap(i, eargc, buffer, hook);
}
fclose(fp);
}
@@ -312,13 +549,18 @@
#endif
}
+ if (hook == sorthook) {
+ show_termdata(eargc, eargv);
+ free_termdata();
+ }
+
return (EXIT_SUCCESS);
}
static void
usage(void)
{
- (void) fprintf(stderr, "usage: %s [-ahuUV] [-v n] [file...]\n", _nc_progname);
+ (void) fprintf(stderr, "usage: %s [-ahsuUV] [-v n] [file...]\n", _nc_progname);
ExitProgram(EXIT_FAILURE);
}
@@ -333,23 +575,24 @@
unsigned i;
int code;
int this_opt, last_opt = '?';
- int v_opt = 0;
+ unsigned v_opt = 0;
+ DescHook *hook = deschook;
_nc_progname = _nc_rootname(argv[0]);
- while ((this_opt = getopt(argc, argv, "0123456789ahu:vU:V")) != -1) {
+ while ((this_opt = getopt(argc, argv, "0123456789ahsu:vU:V")) != -1) {
/* handle optional parameter */
if (isdigit(this_opt)) {
switch (last_opt) {
case 'v':
- v_opt = (this_opt - '0');
+ v_opt = (unsigned) (this_opt - '0');
break;
default:
if (isdigit(last_opt))
v_opt *= 10;
else
v_opt = 0;
- v_opt += (this_opt - '0');
+ v_opt += (unsigned) (this_opt - '0');
last_opt = this_opt;
}
continue;
@@ -361,6 +604,9 @@
case 'h':
header = TRUE;
break;
+ case 's':
+ hook = sorthook;
+ break;
case 'u':
direct_dependencies = TRUE;
report_file = optarg;
@@ -443,7 +689,7 @@
* If we get this far, user wants a simple terminal type listing.
*/
if (optind < argc) {
- code = typelist(argc - optind, argv + optind, header, deschook);
+ code = typelist(argc - optind, argv + optind, header, hook);
} else if (all_dirs) {
DBDIRS state;
int offset;
@@ -453,60 +699,41 @@
code = EXIT_FAILURE;
for (pass = 0; pass < 2; ++pass) {
- unsigned count = 0;
+ size_t 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[count] = strmalloc(path);
}
+ ++count;
}
if (!pass) {
- eargv = typeCalloc(char *, count + 1);
+ eargv = allocArgv(count);
+ if (eargv == 0)
+ failed("eargv");
} else {
- code = typelist((int) count, eargv, header, deschook);
- while (count-- > 0)
- free(eargv[count]);
- free(eargv);
+ code = typelist((int) count, eargv, header, hook);
+ freeArgv(eargv);
}
}
} else {
DBDIRS state;
int offset;
const char *path;
- char *eargv[3];
- int count = 0;
+ char **eargv = allocArgv((size_t) 2);
+ size_t count = 0;
+ if (eargv == 0)
+ failed("eargv");
_nc_first_db(&state, &offset);
- while ((path = _nc_next_db(&state, &offset)) != 0) {
- if (is_database(path)) {
- eargv[count++] = strdup(path);
- break;
- }
+ if ((path = _nc_next_db(&state, &offset)) != 0) {
+ eargv[count++] = strmalloc(path);
}
- eargv[count] = 0;
- code = typelist(count, eargv, header, deschook);
+ code = typelist((int) count, eargv, header, hook);
- while (count-- > 0)
- free(eargv[count]);
+ freeArgv(eargv);
}
_nc_last_db();
diff --git a/progs/tparm_type.c b/progs/tparm_type.c
new file mode 100644
index 0000000..125e43c
--- /dev/null
+++ b/progs/tparm_type.c
@@ -0,0 +1,71 @@
+/****************************************************************************
+ * Copyright (c) 1998-2013,2015 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey *
+ ****************************************************************************/
+
+#include <tparm_type.h>
+
+MODULE_ID("$Id: tparm_type.c,v 1.2 2015/04/04 15:01:13 tom Exp $")
+
+/*
+ * Lookup the type of call we should make to tparm(). This ignores the actual
+ * terminfo capability (bad, because it is not extensible), but makes this
+ * code portable to platforms where sizeof(int) != sizeof(char *).
+ */
+TParams
+tparm_type(const char *name)
+{
+#define TD(code, longname, ti, tc) \
+ {code, {longname} }, \
+ {code, {ti} }, \
+ {code, {tc} }
+ TParams result = Numbers;
+ /* *INDENT-OFF* */
+ static const struct {
+ TParams code;
+ const char name[12];
+ } table[] = {
+ TD(Num_Str, "pkey_key", "pfkey", "pk"),
+ TD(Num_Str, "pkey_local", "pfloc", "pl"),
+ TD(Num_Str, "pkey_xmit", "pfx", "px"),
+ TD(Num_Str, "plab_norm", "pln", "pn"),
+ TD(Num_Str_Str, "pkey_plab", "pfxl", "xl"),
+ };
+ /* *INDENT-ON* */
+
+ unsigned n;
+ for (n = 0; n < SIZEOF(table); n++) {
+ if (!strcmp(name, table[n].name)) {
+ result = table[n].code;
+ break;
+ }
+ }
+ return result;
+}
diff --git a/progs/tparm_type.h b/progs/tparm_type.h
new file mode 100644
index 0000000..d143168
--- /dev/null
+++ b/progs/tparm_type.h
@@ -0,0 +1,52 @@
+/****************************************************************************
+ * Copyright (c) 2014 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey *
+ ****************************************************************************/
+
+/*
+ * $Id: tparm_type.h,v 1.1 2014/05/21 16:57:56 tom Exp $
+ *
+ * determine expected/actual number of parameters to setup for tparm
+ */
+#ifndef TPARM_TYPE_H
+#define TPARM_TYPE_H 1
+
+#define USE_LIBTINFO
+#include <progs.priv.h>
+
+typedef enum {
+ Numbers = 0
+ ,Num_Str
+ ,Num_Str_Str
+} TParams;
+
+extern TParams tparm_type(const char *name);
+
+#endif /* TPARM_TYPE_H */
diff --git a/progs/tput b/progs/tput
deleted file mode 100755
index 3328bcd..0000000
--- a/progs/tput
+++ /dev/null
Binary files differ
diff --git a/progs/tput.c b/progs/tput.c
index 022d494..f25cbaf 100644
--- a/progs/tput.c
+++ b/progs/tput.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2014,2015 Free 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,8 +39,7 @@
* Ross Ridge's mytinfo package.
*/
-#define USE_LIBTINFO
-#include <progs.priv.h>
+#include <tparm_type.h>
#if !PURE_TERMINFO
#include <dump_entry.h>
@@ -47,18 +47,12 @@
#endif
#include <transform.h>
-MODULE_ID("$Id: tput.c,v 1.42 2008/07/13 11:05:12 tom Exp $")
+MODULE_ID("$Id: tput.c,v 1.51 2015/05/23 23:42:55 tom Exp $")
#define PUTS(s) fputs(s, stdout)
#define PUTCHAR(c) putchar(c)
#define FLUSH fflush(stdout)
-typedef enum {
- Numbers = 0
- ,Num_Str
- ,Num_Str_Str
-} TParams;
-
static char *prg_name;
static bool is_init = FALSE;
static bool is_reset = FALSE;
@@ -86,44 +80,8 @@
static void
check_aliases(const char *name)
{
- is_init = (strcmp(name, PROG_INIT) == 0);
- is_reset = (strcmp(name, PROG_RESET) == 0);
-}
-
-/*
- * Lookup the type of call we should make to tparm(). This ignores the actual
- * terminfo capability (bad, because it is not extensible), but makes this
- * code portable to platforms where sizeof(int) != sizeof(char *).
- *
- * FIXME: If we want extensibility, analyze the capability string as we do
- * in tparm() to decide how to parse the varargs list.
- */
-static TParams
-tparm_type(const char *name)
-{
-#define TD(code, longname, ti, tc) {code,longname},{code,ti},{code,tc}
- TParams result = Numbers;
- /* *INDENT-OFF* */
- static const struct {
- TParams code;
- const char *name;
- } table[] = {
- TD(Num_Str, "pkey_key", "pfkey", "pk"),
- TD(Num_Str, "pkey_local", "pfloc", "pl"),
- TD(Num_Str, "pkey_xmit", "pfx", "px"),
- TD(Num_Str, "plab_norm", "pln", "pn"),
- TD(Num_Str_Str, "pkey_plab", "pfxl", "xl"),
- };
- /* *INDENT-ON* */
-
- unsigned n;
- for (n = 0; n < SIZEOF(table); n++) {
- if (!strcmp(name, table[n].name)) {
- result = table[n].code;
- break;
- }
- }
- return result;
+ is_init = same_program(name, PROG_INIT);
+ is_reset = same_program(name, PROG_RESET);
}
static int
@@ -153,13 +111,16 @@
int i, j, c;
int status;
FILE *f;
+#if !PURE_TERMINFO
+ bool termcap = FALSE;
+#endif
if ((name = argv[0]) == 0)
name = "";
check_aliases(name);
if (is_reset || is_init) {
if (init_prog != 0) {
- system(init_prog);
+ IGNORE_RC(system(init_prog));
}
FLUSH;
@@ -265,40 +226,45 @@
return 0;
}
#if !PURE_TERMINFO
- {
- const struct name_table_entry *np;
-
- if ((np = _nc_find_entry(name, _nc_get_hash_table(1))) != 0)
- switch (np->nte_type) {
- case BOOLEAN:
- if (bool_from_termcap[np->nte_index])
- name = boolnames[np->nte_index];
- break;
-
- case NUMBER:
- if (num_from_termcap[np->nte_index])
- name = numnames[np->nte_index];
- break;
-
- case STRING:
- if (str_from_termcap[np->nte_index])
- name = strnames[np->nte_index];
- break;
- }
- }
+ retry:
#endif
-
if ((status = tigetflag(name)) != -1) {
return exit_code(BOOLEAN, status);
} else if ((status = tigetnum(name)) != CANCELLED_NUMERIC) {
(void) printf("%d\n", status);
return exit_code(NUMBER, 0);
} else if ((s = tigetstr(name)) == CANCELLED_STRING) {
+#if !PURE_TERMINFO
+ if (!termcap) {
+ const struct name_table_entry *np;
+
+ termcap = TRUE;
+ if ((np = _nc_find_entry(name, _nc_get_hash_table(termcap))) != 0) {
+ switch (np->nte_type) {
+ case BOOLEAN:
+ if (bool_from_termcap[np->nte_index])
+ name = boolnames[np->nte_index];
+ break;
+
+ case NUMBER:
+ if (num_from_termcap[np->nte_index])
+ name = numnames[np->nte_index];
+ break;
+
+ case STRING:
+ if (str_from_termcap[np->nte_index])
+ name = strnames[np->nte_index];
+ break;
+ }
+ goto retry;
+ }
+ }
+#endif
quit(4, "unknown terminfo capability '%s'", name);
} else if (s != ABSENT_STRING) {
if (argc > 1) {
int k;
- int popcount;
+ int ignored;
long numbers[1 + NUM_PARM];
char *strings[1 + NUM_PARM];
char *p_is_s[NUM_PARM];
@@ -329,8 +295,8 @@
break;
case Numbers:
default:
- (void) _nc_tparm_analyze(s, p_is_s, &popcount);
-#define myParam(n) (p_is_s[n - 1] != 0 ? ((long) strings[n]) : numbers[n])
+ (void) _nc_tparm_analyze(s, p_is_s, &ignored);
+#define myParam(n) (p_is_s[n - 1] != 0 ? ((TPARM_ARG) strings[n]) : numbers[n])
s = TPARM_9(s,
myParam(1),
myParam(2),
diff --git a/progs/transform.c b/progs/transform.c
new file mode 100644
index 0000000..c0557f0
--- /dev/null
+++ b/progs/transform.c
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * Copyright (c) 2009-2010,2011 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey *
+ ****************************************************************************/
+#include <progs.priv.h>
+#include <string.h>
+
+#include <transform.h>
+
+MODULE_ID("$Id: transform.c,v 1.3 2011/05/14 22:41:17 tom Exp $")
+
+#ifdef SUFFIX_IGNORED
+static void
+trim_suffix(const char *a, size_t *len)
+{
+ const char ignore[] = SUFFIX_IGNORED;
+
+ if (sizeof(ignore) != 0) {
+ bool trim = FALSE;
+ size_t need = (sizeof(ignore) - 1);
+
+ if (*len > need) {
+ size_t first = *len - need;
+ size_t n;
+ trim = TRUE;
+ for (n = first; n < *len; ++n) {
+ if (tolower(UChar(a[n])) != tolower(UChar(ignore[n - first]))) {
+ trim = FALSE;
+ break;
+ }
+ }
+ if (trim) {
+ *len -= need;
+ }
+ }
+ }
+}
+#else
+#define trim_suffix(a, len) /* nothing */
+#endif
+
+bool
+same_program(const char *a, const char *b)
+{
+ size_t len_a = strlen(a);
+ size_t len_b = strlen(b);
+
+ trim_suffix(a, &len_a);
+ trim_suffix(b, &len_b);
+
+ return (len_a == len_b) && (strncmp(a, b, len_a) == 0);
+}
diff --git a/progs/transform.h b/progs/transform.h
deleted file mode 100644
index a2e7e43..0000000
--- a/progs/transform.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#define PROG_CAPTOINFO "captoinfo"
-#define PROG_INFOTOCAP "infotocap"
-#define PROG_RESET "reset"
-#define PROG_INIT "init"
diff --git a/progs/tset b/progs/tset
deleted file mode 100755
index 0ab0b97..0000000
--- a/progs/tset
+++ /dev/null
Binary files differ
diff --git a/progs/tset.c b/progs/tset.c
index 6a4d2d6..9a05b3d 100644
--- a/progs/tset.c
+++ b/progs/tset.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2013,2015 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -33,6 +33,22 @@
****************************************************************************/
/*
+ * Notes:
+ * The initial adaptation from 4.4BSD Lite sources in September 1995 used 686
+ * lines from that version, and made changes/additions for 150 lines. There
+ * was no reformatting, so with/without ignoring whitespace, the amount of
+ * change is the same.
+ *
+ * Comparing with current (2009) source, excluding this comment:
+ * a) 209 lines match identically to the 4.4BSD Lite sources, with 771 lines
+ * changed/added.
+ * a) Ignoring whitespace, the current version still uses 516 lines from the
+ * 4.4BSD Lite sources, with 402 lines changed/added.
+ *
+ * Raymond's original comment on this follows...
+ */
+
+/*
* tset.c - terminal initialization utility
*
* This code was mostly swiped from 4.4BSD tset, with some obsolescent
@@ -52,11 +68,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -107,7 +119,7 @@
#include <dump_entry.h>
#include <transform.h>
-MODULE_ID("$Id: tset.c,v 1.76 2008/10/11 19:26:19 tom Exp $")
+MODULE_ID("$Id: tset.c,v 1.96 2015/04/12 15:36:06 tom Exp $")
/*
* SCO defines TIOCGSIZE and the corresponding struct. Other systems (SunOS,
@@ -129,11 +141,17 @@
# endif
#endif
+#ifndef environ
extern char **environ;
+#endif
#undef CTRL
#define CTRL(x) ((x) & 0x1f)
+static void failed(const char *) GCC_NORETURN;
+static void exit_error(void) GCC_NORETURN;
+static void err(const char *,...) GCC_NORETURN;
+
const char *_nc_progname = "tset";
static TTY mode, oldmode, original;
@@ -146,7 +164,10 @@
static int terasechar = -1; /* new erase character */
static int intrchar = -1; /* new interrupt character */
static int tkillchar = -1; /* new kill character */
+
+#if HAVE_SIZECHANGE
static int tlines, tcolumns; /* window size */
+#endif
#define LOWERCASE(c) ((isalpha(UChar(c)) && isupper(UChar(c))) ? tolower(UChar(c)) : (c))
@@ -189,13 +210,13 @@
failed(const char *msg)
{
char temp[BUFSIZ];
- unsigned len = strlen(_nc_progname) + 2;
+ size_t len = strlen(_nc_progname) + 2;
if ((int) len < (int) sizeof(temp) - 12) {
- strcpy(temp, _nc_progname);
- strcat(temp, ": ");
+ _nc_STRCPY(temp, _nc_progname, sizeof(temp));
+ _nc_STRCAT(temp, ": ", sizeof(temp));
} else {
- strcpy(temp, "tset: ");
+ _nc_STRCPY(temp, "tset: ", sizeof(temp));
}
perror(strncat(temp, msg, sizeof(temp) - strlen(temp) - 2));
exit_error();
@@ -286,87 +307,89 @@
static MAP *cur, *maplist;
+#define DATA(name,value) { { name }, value }
+
typedef struct speeds {
- const char *string;
+ const char string[7];
int speed;
} SPEEDS;
static const SPEEDS speeds[] =
{
- {"0", B0},
- {"50", B50},
- {"75", B75},
- {"110", B110},
- {"134", B134},
- {"134.5", B134},
- {"150", B150},
- {"200", B200},
- {"300", B300},
- {"600", B600},
- {"1200", B1200},
- {"1800", B1800},
- {"2400", B2400},
- {"4800", B4800},
- {"9600", B9600},
+ DATA("0", B0),
+ DATA("50", B50),
+ DATA("75", B75),
+ DATA("110", B110),
+ DATA("134", B134),
+ DATA("134.5", B134),
+ DATA("150", B150),
+ DATA("200", B200),
+ DATA("300", B300),
+ DATA("600", B600),
+ DATA("1200", B1200),
+ DATA("1800", B1800),
+ DATA("2400", B2400),
+ DATA("4800", B4800),
+ DATA("9600", B9600),
/* sgttyb may define up to this point */
#ifdef B19200
- {"19200", B19200},
+ DATA("19200", B19200),
#endif
#ifdef B38400
- {"38400", B38400},
+ DATA("38400", B38400),
#endif
#ifdef B19200
- {"19200", B19200},
+ DATA("19200", B19200),
#endif
#ifdef B38400
- {"38400", B38400},
+ DATA("38400", B38400),
#endif
#ifdef B19200
- {"19200", B19200},
+ DATA("19200", B19200),
#else
#ifdef EXTA
- {"19200", EXTA},
+ DATA("19200", EXTA),
#endif
#endif
#ifdef B38400
- {"38400", B38400},
+ DATA("38400", B38400),
#else
#ifdef EXTB
- {"38400", EXTB},
+ DATA("38400", EXTB),
#endif
#endif
#ifdef B57600
- {"57600", B57600},
+ DATA("57600", B57600),
#endif
#ifdef B115200
- {"115200", B115200},
+ DATA("115200", B115200),
#endif
#ifdef B230400
- {"230400", B230400},
+ DATA("230400", B230400),
#endif
#ifdef B460800
- {"460800", B460800},
+ DATA("460800", B460800),
#endif
- {(char *) 0, 0}
};
+#undef DATA
static int
tbaudrate(char *rate)
{
- const SPEEDS *sp;
- int found = FALSE;
+ const SPEEDS *sp = 0;
+ size_t n;
/* The baudrate number can be preceded by a 'B', which is ignored. */
if (*rate == 'B')
++rate;
- for (sp = speeds; sp->string; ++sp) {
- if (!CaselessCmp(rate, sp->string)) {
- found = TRUE;
+ for (n = 0; n < SIZEOF(speeds); ++n) {
+ if (!CaselessCmp(rate, speeds[n].string)) {
+ sp = speeds + n;
break;
}
}
- if (!found)
+ if (sp == 0)
err("unknown baud rate %s", rate);
return (sp->speed);
}
@@ -385,9 +408,13 @@
char *base = 0;
copy = strdup(arg);
- mapp = (MAP *) malloc(sizeof(MAP));
+ mapp = typeMalloc(MAP, 1);
if (copy == 0 || mapp == 0)
failed("malloc");
+
+ assert(copy != 0);
+ assert(mapp != 0);
+
mapp->next = 0;
if (maplist == 0)
cur = maplist = mapp;
@@ -449,9 +476,6 @@
mapp->speed = tbaudrate(p);
}
- if (arg == (char *) 0) /* Non-optional type. */
- goto badmopt;
-
mapp->type = arg;
/* Terminate porttype, if specified. */
@@ -509,19 +533,19 @@
match = TRUE;
break;
case EQ:
- match = (ospeed == mapp->speed);
+ match = ((int) ospeed == mapp->speed);
break;
case GE:
- match = (ospeed >= mapp->speed);
+ match = ((int) ospeed >= mapp->speed);
break;
case GT:
- match = (ospeed > mapp->speed);
+ match = ((int) ospeed > mapp->speed);
break;
case LE:
- match = (ospeed <= mapp->speed);
+ match = ((int) ospeed <= mapp->speed);
break;
case LT:
- match = (ospeed < mapp->speed);
+ match = ((int) ospeed < mapp->speed);
break;
default:
match = FALSE;
@@ -613,13 +637,14 @@
* 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 && !_nc_is_abs_path(p)) {
+ found:
+ if ((p = getenv("TERMCAP")) != 0 && !_nc_is_abs_path(p)) {
/* 'unsetenv("TERMCAP")' is not portable.
* The 'environ' array is better.
*/
int n;
for (n = 0; environ[n] != 0; n++) {
- if (!strncmp("TERMCAP=", environ[n], 8)) {
+ if (!strncmp("TERMCAP=", environ[n], (size_t) 8)) {
while ((environ[n] = environ[n + 1]) != 0) {
n++;
}
@@ -722,7 +747,7 @@
#define DISABLED(val) ((int)(val) <= 0)
#endif
-#define CHK(val, dft) (DISABLED(val) ? dft : val)
+#define CHK(val, dft) (unsigned char) (DISABLED(val) ? dft : val)
static bool set_tabs(void);
@@ -770,14 +795,14 @@
mode.c_cc[VWERASE] = CHK(mode.c_cc[VWERASE], CWERASE);
#endif
- mode.c_iflag &= ~(IGNBRK | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
+ mode.c_iflag &= ~((unsigned) (IGNBRK | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
#ifdef IUCLC
- | IUCLC
+ | IUCLC
#endif
#ifdef IXANY
- | IXANY
+ | IXANY
#endif
- | IXOFF);
+ | IXOFF));
mode.c_iflag |= (BRKINT | IGNPAR | ICRNL | IXON
#ifdef IMAXBEL
@@ -785,44 +810,44 @@
#endif
);
- mode.c_oflag &= ~(0
+ mode.c_oflag &= ~((unsigned) (0
#ifdef OLCUC
- | OLCUC
+ | OLCUC
#endif
#ifdef OCRNL
- | OCRNL
+ | OCRNL
#endif
#ifdef ONOCR
- | ONOCR
+ | ONOCR
#endif
#ifdef ONLRET
- | ONLRET
+ | ONLRET
#endif
#ifdef OFILL
- | OFILL
+ | OFILL
#endif
#ifdef OFDEL
- | OFDEL
+ | OFDEL
#endif
#ifdef NLDLY
- | NLDLY
+ | NLDLY
#endif
#ifdef CRDLY
- | CRDLY
+ | CRDLY
#endif
#ifdef TABDLY
- | TABDLY
+ | TABDLY
#endif
#ifdef BSDLY
- | BSDLY
+ | BSDLY
#endif
#ifdef VTDLY
- | VTDLY
+ | VTDLY
#endif
#ifdef FFDLY
- | FFDLY
+ | FFDLY
#endif
- );
+ ));
mode.c_oflag |= (OPOST
#ifdef ONLCR
@@ -830,19 +855,19 @@
#endif
);
- mode.c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD | CLOCAL);
+ mode.c_cflag &= ~((unsigned) (CSIZE | CSTOPB | PARENB | PARODD | CLOCAL));
mode.c_cflag |= (CS8 | CREAD);
- mode.c_lflag &= ~(ECHONL | NOFLSH
+ mode.c_lflag &= ~((unsigned) (ECHONL | NOFLSH
#ifdef TOSTOP
- | TOSTOP
+ | TOSTOP
#endif
#ifdef ECHOPTR
- | ECHOPRT
+ | ECHOPRT
#endif
#ifdef XCASE
- | XCASE
+ | XCASE
#endif
- );
+ ));
mode.c_lflag |= (ISIG | ICANON | ECHO | ECHOE | ECHOK
#ifdef ECHOCTL
@@ -889,14 +914,23 @@
set_control_chars(void)
{
#ifdef TERMIOS
- if (DISABLED(mode.c_cc[VERASE]) || terasechar >= 0)
- mode.c_cc[VERASE] = (terasechar >= 0) ? terasechar : default_erase();
+ if (DISABLED(mode.c_cc[VERASE]) || terasechar >= 0) {
+ mode.c_cc[VERASE] = UChar((terasechar >= 0)
+ ? terasechar
+ : default_erase());
+ }
- if (DISABLED(mode.c_cc[VINTR]) || intrchar >= 0)
- mode.c_cc[VINTR] = (intrchar >= 0) ? intrchar : CINTR;
+ if (DISABLED(mode.c_cc[VINTR]) || intrchar >= 0) {
+ mode.c_cc[VINTR] = UChar((intrchar >= 0)
+ ? intrchar
+ : CINTR);
+ }
- if (DISABLED(mode.c_cc[VKILL]) || tkillchar >= 0)
- mode.c_cc[VKILL] = (tkillchar >= 0) ? tkillchar : CKILL;
+ if (DISABLED(mode.c_cc[VKILL]) || tkillchar >= 0) {
+ mode.c_cc[VKILL] = UChar((tkillchar >= 0)
+ ? tkillchar
+ : CKILL);
+ }
#endif
}
@@ -952,9 +986,9 @@
if (newline != (char *) 0 && newline[0] == '\n' && !newline[1]) {
/* Newline, not linefeed. */
#ifdef ONLCR
- mode.c_oflag &= ~ONLCR;
+ mode.c_oflag &= ~((unsigned) ONLCR);
#endif
- mode.c_iflag &= ~ICRNL;
+ mode.c_iflag &= ~((unsigned) ICRNL);
}
#ifdef __OBSOLETE__
if (tgetflag("HD")) /* Half duplex. */
@@ -1025,11 +1059,18 @@
{
if (set_tab && clear_all_tabs) {
int c;
+ int lim =
+#if HAVE_SIZECHANGE
+ tcolumns
+#else
+ columns
+#endif
+ ;
(void) putc('\r', stderr); /* Force to left margin. */
tputs(clear_all_tabs, 0, outc);
- for (c = 8; c < tcolumns; c += 8) {
+ for (c = 8; c < lim; c += 8) {
/* Get to the right column. In BSD tset, this
* used to try a bunch of half-clever things
* with cup and hpa, for an average saving of
@@ -1128,26 +1169,26 @@
static void
usage(void)
{
- static const char *tbl[] =
+#define DATA(s) s "\n"
+ static const char msg[] =
{
- ""
- ,"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"
+ DATA("")
+ DATA("Options:")
+ DATA(" -c set control characters")
+ DATA(" -e ch erase character")
+ DATA(" -I no initialization strings")
+ DATA(" -i ch interrupt character")
+ DATA(" -k ch kill character")
+ DATA(" -m mapping map identifier to type")
+ DATA(" -Q do not output control key settings")
+ DATA(" -r display term on stderr")
+ DATA(" -s output TERM set command")
+ DATA(" -V print curses-version")
+ DATA(" -w set window-size")
};
- unsigned n;
+#undef DATA
(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]);
+ fputs(msg, stderr);
exit_error();
/* NOTREACHED */
}
@@ -1247,18 +1288,18 @@
ospeed = (NCURSES_OSPEED) mode.sg_ospeed;
#endif
- if (!strcmp(_nc_progname, PROG_RESET)) {
+ if (same_program(_nc_progname, PROG_RESET)) {
isreset = TRUE;
reset_mode();
}
- ttype = get_termcap_entry(*argv);
+ (void) get_termcap_entry(*argv);
if (!noset) {
+#if HAVE_SIZECHANGE
tcolumns = columns;
tlines = lines;
-#if HAVE_SIZECHANGE
if (opt_w) {
STRUCT_WINSIZE win;
/* Set window size if not set already */
@@ -1266,8 +1307,8 @@
if (WINSIZE_ROWS(win) == 0 &&
WINSIZE_COLS(win) == 0 &&
tlines > 0 && tcolumns > 0) {
- WINSIZE_ROWS(win) = tlines;
- WINSIZE_COLS(win) = tcolumns;
+ WINSIZE_ROWS(win) = (unsigned short) tlines;
+ WINSIZE_COLS(win) = (unsigned short) tcolumns;
(void) ioctl(STDERR_FILENO, IOCTL_SET_WINSIZE, &win);
}
}