aboutsummaryrefslogtreecommitdiff
path: root/progs
diff options
context:
space:
mode:
authorEd Schouten <ed@FreeBSD.org>2011-04-30 10:55:14 +0000
committerEd Schouten <ed@FreeBSD.org>2011-04-30 10:55:14 +0000
commit0294a182a1629b1d854b84906e73487d6cb75fba (patch)
treee563e21bcc0164ba11452983316bda26eebb1d3c /progs
parent22b11c4db16996bf8d4878fab98762c348676df3 (diff)
downloadsrc-0294a182a1629b1d854b84906e73487d6cb75fba.tar.gz
src-0294a182a1629b1d854b84906e73487d6cb75fba.zip
Import a stock copy of ncurses 5.8 into the vendor space.vendor/ncurses/5.8-20110226
It seems both local changes we made to 5.7 have already been fixed upstream properly, so there is no need to preserve the changes. Also, with SVN we import full source trees. Unlike CVS, where we removed unneeded cruft.
Notes
Notes: svn path=/vendor/ncurses/dist/; revision=221243 svn path=/vendor/ncurses/5.8-20110226/; revision=221244; tag=vendor/ncurses/5.8-20110226
Diffstat (limited to 'progs')
-rw-r--r--progs/Makefile.in49
-rw-r--r--progs/dump_entry.c16
-rw-r--r--progs/infocmp.c24
-rw-r--r--progs/modules10
-rw-r--r--progs/tabs.c510
-rw-r--r--progs/tic.c207
-rw-r--r--progs/toe.c23
-rw-r--r--progs/tput.c60
-rw-r--r--progs/transform.c79
-rw-r--r--progs/tset.c38
10 files changed, 932 insertions, 84 deletions
diff --git a/progs/Makefile.in b/progs/Makefile.in
index 886fd5be2465..bdb8a0f04898 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.85 2010/11/27 21:45:27 tom Exp $
##############################################################################
-# Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. #
+# Copyright (c) 1998-2009,2010 Free 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"), #
@@ -43,6 +43,7 @@
.SUFFIXES:
SHELL = /bin/sh
+VPATH = @srcdir@
THIS = Makefile
CF_MFLAGS = @cf_cv_makeflags@
@@ -76,6 +77,9 @@ transform = @program_transform_name@
AWK = @AWK@
LN_S = @LN_S@
+CTAGS = @CTAGS@
+ETAGS = @ETAGS@
+
CC = @CC@
CPP = @CPP@
CFLAGS = @CFLAGS@
@@ -124,7 +128,7 @@ AUTO_SRC = \
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 +163,7 @@ actual_infocmp = `echo infocmp$x| $(TRANSFORM)`
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 +176,16 @@ define_init = `echo init| $(TRANSFORM)`
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 *);" >>$@
+ -sh -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 +198,7 @@ install.progs: $(AUTO_SRC) $(PROGS) $(DESTDIR)$(bindir)
@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 +212,13 @@ uninstall.progs:
@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,7 +226,8 @@ $(DESTDIR)$(bindir) :
DEPS_TIC = \
$(MODEL)/tic$o \
- $(MODEL)/dump_entry$o
+ $(MODEL)/dump_entry$o \
+ $(MODEL)/transform$o
tic$x: $(DEPS_TIC) $(DEPS_CURSES) transform.h
@ECHO_LINK@ $(LINK) $(DEPS_TIC) $(LDFLAGS_TIC) -o $@
@@ -230,8 +244,15 @@ DEPS_CLEAR = \
clear$x: $(DEPS_CLEAR) $(DEPS_CURSES)
@ECHO_LINK@ $(LINK) $(DEPS_CLEAR) $(LDFLAGS_TINFO) -o $@
+DEPS_TABS = \
+ $(MODEL)/tabs$o
+
+tabs$x: $(DEPS_TABS) $(DEPS_TABS)
+ @ECHO_LINK@ $(LINK) $(DEPS_TABS) $(LDFLAGS_TINFO) -o $@
+
DEPS_TPUT = \
- $(MODEL)/tput$o
+ $(MODEL)/tput$o \
+ $(MODEL)/transform$o
tput$x: $(DEPS_TPUT) $(DEPS_CURSES) transform.h
@ECHO_LINK@ $(LINK) $(DEPS_TPUT) $(LDFLAGS_TINFO) -o $@
@@ -244,7 +265,8 @@ infocmp$x: $(DEPS_INFOCMP) $(DEPS_CURSES)
@ECHO_LINK@ $(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 $@
@@ -257,10 +279,10 @@ termsort.c: $(srcdir)/MKtermsort.sh
#
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
@@ -289,6 +311,7 @@ lint:
@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/dump_entry.c b/progs/dump_entry.c
index bd2422008bf7..485bbbd91d64 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-2008,2010 Free 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.89 2010/05/01 22:04:08 tom Exp $")
#define INDENT 8
#define DISCARD(string) string = ABSENT_STRING
@@ -1040,7 +1040,7 @@ dump_entry(TERMTYPE *tterm,
save_sgr = set_attributes;
- if (((len = FMT_ENTRY()) > critlen)
+ if ((FMT_ENTRY() > critlen)
&& limited) {
save_tterm = *tterm;
@@ -1049,7 +1049,7 @@ dump_entry(TERMTYPE *tterm,
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
@@ -1075,7 +1075,7 @@ dump_entry(TERMTYPE *tterm,
critlen);
}
changed = TRUE;
- if ((len = FMT_ENTRY()) <= critlen)
+ if (FMT_ENTRY() <= critlen)
break;
}
}
@@ -1086,7 +1086,7 @@ dump_entry(TERMTYPE *tterm,
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 +1094,7 @@ dump_entry(TERMTYPE *tterm,
changed = TRUE;
}
}
- if (!changed || ((len = FMT_ENTRY()) > critlen)) {
+ if (!changed || (FMT_ENTRY() > critlen)) {
int oldversion = tversion;
tversion = V_BSD;
@@ -1130,7 +1130,7 @@ dump_entry(TERMTYPE *tterm,
} 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;
}
diff --git a/progs/infocmp.c b/progs/infocmp.c
index 84989ffc63d4..2af9cb50b1d7 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-2009,2010 Free 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.105 2010/05/01 22:04:08 tom Exp $")
#define L_CURL "{"
#define R_CURL "}"
@@ -894,8 +894,6 @@ file_comparison(int argc, char *argv[])
(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];
@@ -1255,6 +1253,15 @@ terminal_env(void)
*
***************************************************************************/
+#if NO_LEAKS
+#define MAIN_LEAKS() \
+ free(myargv); \
+ free(tfile); \
+ free(tname)
+#else
+#define MAIN_LEAKS() /* nothing */
+#endif
+
int
main(int argc, char *argv[])
{
@@ -1514,6 +1521,7 @@ main(int argc, char *argv[])
#else
(void) fprintf(stderr, "%s: terminfo files not supported\n",
_nc_progname);
+ MAIN_LEAKS();
ExitProgram(EXIT_FAILURE);
#endif
} else {
@@ -1526,7 +1534,6 @@ main(int argc, char *argv[])
status = _nc_read_entry(tname[termcount],
tfile[termcount],
&entries[termcount].tterm);
- directory = TERMINFO; /* for error message */
}
if (status <= 0) {
@@ -1534,6 +1541,7 @@ main(int argc, char *argv[])
"%s: couldn't open terminfo file %s.\n",
_nc_progname,
tfile[termcount]);
+ MAIN_LEAKS();
ExitProgram(EXIT_FAILURE);
}
repair_acsc(&entries[termcount].tterm);
@@ -1642,11 +1650,7 @@ main(int argc, char *argv[])
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 3b4f3b602369..55d7a9fb9694 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.17 2010/01/23 17:47:23 tom Exp $
# Program modules (some are in ncurses lib!)
##############################################################################
-# Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. #
+# Copyright (c) 1998-2009,2010 Free 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"), #
@@ -34,10 +34,12 @@
@ 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
+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)
+tput progs $(srcdir) $(HEADER_DEPS) transform.h $(srcdir)/dump_entry.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/tabs.c b/progs/tabs.c
new file mode 100644
index 000000000000..b59c9086d8d3
--- /dev/null
+++ b/progs/tabs.c
@@ -0,0 +1,510 @@
+/****************************************************************************
+ * Copyright (c) 2008-2009,2010 Free 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.19 2010/10/23 22:26:01 tom Exp $")
+
+static void usage(void) GCC_NORETURN;
+
+static int max_cols;
+
+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('\n');
+}
+
+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) {
+ 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,
+ "tab-stops are not in increasing order: %d %d\n",
+ 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;
+ 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];
+ sprintf(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) {
+ unsigned 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 = ",";
+ unsigned 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) {
+ *result = '\0';
+ if (*append != 0) {
+ strcpy(result, *append);
+ free(*append);
+ }
+ strcat(result, comma);
+ strcat(result, copied);
+ }
+
+ *append = result;
+ }
+ return result;
+}
+
+/*
+ * Check for illegal characters in the tab-list.
+ */
+static bool
+legal_tab_list(const char *program, 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",
+ program, ch);
+ result = FALSE;
+ break;
+ }
+ }
+ } else {
+ fprintf(stderr, "%s: trailing comma found '%s'\n", program, tab_list);
+ result = FALSE;
+ }
+ } else {
+ fprintf(stderr, "%s: no tab-list given\n", program);
+ result = FALSE;
+ }
+ return result;
+}
+
+static void
+usage(void)
+{
+ static const char *msg[] =
+ {
+ "Usage: tabs [options] [tabstop-list]"
+ ,""
+ ,"Options:"
+ ," -0 reset tabs"
+ ," -8 set tabs to standard interval"
+ ," -a Assembler, IBM S/370, first format"
+ ," -a2 Assembler, IBM S/370, second format"
+ ," -c COBOL, normal format"
+ ," -c2 COBOL compact format"
+ ," -c3 COBOL compact format extended"
+ ," -d debug (show ruler with expected/actual tab positions)"
+ ," -f FORTRAN"
+ ," -n no-op (do not modify terminal settings)"
+ ," -p PL/I"
+ ," -s SNOBOL"
+ ," -u UNIVAC 1100 Assembler"
+ ," -T name use terminal type 'name'"
+ ,""
+ ,"A tabstop-list is an ordered list of column numbers, e.g., 1,11,21"
+ ,"or 1,+10,+10 which is the same."
+ };
+ unsigned n;
+
+ fflush(stdout);
+ for (n = 0; n < SIZEOF(msg); ++n) {
+ fprintf(stderr, "%s\n", msg[n]);
+ }
+ 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;
+ const char *mar_list = 0; /* ignored */
+ char *append = 0;
+ const char *tab_list = 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) {
+ case '\0':
+ tab_list = "1,10,16,36,72";
+ /* Assembler, IBM S/370, first format */
+ break;
+ case '2':
+ tab_list = "1,10,16,40,72";
+ /* Assembler, IBM S/370, second format */
+ break;
+ default:
+ usage();
+ }
+ break;
+ case 'c':
+ switch (*option) {
+ case '\0':
+ tab_list = "1,8,12,16,20,55";
+ /* 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;
+ default:
+ usage();
+ }
+ 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 += ((int) strlen(option)) - 1;
+ continue;
+ default:
+ if (isdigit(UChar(*option))) {
+ tab_list = option;
+ ++n;
+ } else {
+ usage();
+ }
+ option += ((int) strlen(option)) - 1;
+ break;
+ }
+ }
+ break;
+ case '+':
+ while ((ch = *++option) != '\0') {
+ switch (ch) {
+ case 'm':
+ mar_list = 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",
+ argv[0], term_name);
+ } else if (!VALID_STRING(set_tab)) {
+ fprintf(stderr,
+ "%s: terminal type '%s' cannot set tabs\n",
+ argv[0], term_name);
+ } else if (legal_tab_list(argv[0], 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/tic.c b/progs/tic.c
index 82bc3ea0d789..8e89095fc676 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-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 *
@@ -44,7 +44,7 @@
#include <dump_entry.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.147 2011/02/12 18:39:08 tom Exp $")
const char *_nc_progname = "tic";
@@ -342,8 +342,15 @@ stripped(char *src)
while (isspace(UChar(*src)))
src++;
if (*src != '\0') {
- char *dst = strcpy((char *) malloc(strlen(src) + 1), src);
- size_t len = strlen(dst);
+ char *dst;
+ size_t len;
+
+ if ((dst = strdup(src)) == NULL)
+ failed("strdup");
+
+ assert(dst != 0);
+
+ len = strlen(dst);
while (--len != 0 && isspace(UChar(dst[len])))
dst[len] = '\0';
return dst;
@@ -495,11 +502,11 @@ main(int argc, char *argv[])
_nc_progname = _nc_rootname(argv[0]);
- 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;
}
@@ -757,6 +764,7 @@ main(int argc, char *argv[])
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++)
@@ -923,6 +931,156 @@ keypad_index(const char *string)
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)
+
+static void
+check_cursor(TERMTYPE *tp)
+{
+ int count;
+ char *list[4];
+
+ /* 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
@@ -1032,6 +1190,32 @@ check_keypad(TERMTYPE *tp)
}
}
+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);
+}
+
/*
* Returns the expected number of parameters for the given capability.
*/
@@ -1268,6 +1452,8 @@ similar_sgr(int num, char *a, char *b)
} else if (delaying) {
a = skip_delay(a);
b = skip_delay(b);
+ } else if ((*b == '0' || (*b == ';')) && *a == 'm') {
+ b++;
} else {
a++;
}
@@ -1343,7 +1529,7 @@ show_where(unsigned level)
if (_nc_tracing >= DEBUG_LEVEL(level)) {
char my_name[256];
_nc_get_type(my_name);
- fprintf(stderr, "\"%s\", line %d, '%s' ",
+ _tracef("\"%s\", line %d, '%s'",
_nc_get_source(),
_nc_curr_line, my_name);
}
@@ -1411,7 +1597,9 @@ check_termtype(TERMTYPE *tp, bool literal)
check_acs(tp);
check_colors(tp);
+ check_cursor(tp);
check_keypad(tp);
+ check_printer(tp);
/*
* These may be mismatched because the terminal description relies on
@@ -1432,6 +1620,11 @@ check_termtype(TERMTYPE *tp, bool literal)
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;
diff --git a/progs/toe.c b/progs/toe.c
index 8af6f371b77b..6f45992f7124 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-2008,2010 Free 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,7 +44,7 @@
#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.52 2010/05/01 22:04:08 tom Exp $")
#define isDotname(name) (!strcmp(name, ".") || !strcmp(name, ".."))
@@ -61,6 +61,13 @@ ExitProgram(int code)
}
#endif
+static void
+failed(const char *msg)
+{
+ perror(msg);
+ ExitProgram(EXIT_FAILURE);
+}
+
#if USE_HASHED_DB
static bool
make_db_name(char *dst, const char *src, unsigned limit)
@@ -184,10 +191,10 @@ typelist(int eargc, char *eargv[],
DIRENT *entry;
cwd_buf = typeRealloc(char, cwd_len, cwd_buf);
- if (cwd_buf == 0) {
- perror("realloc cwd_buf");
- continue;
- }
+ if (cwd_buf == 0)
+ failed("realloc cwd_buf");
+
+ assert(cwd_buf != 0);
strncpy(name_1, subdir->d_name, len)[len] = '\0';
if (isDotname(name_1))
@@ -480,6 +487,10 @@ main(int argc, char *argv[])
}
if (!pass) {
eargv = typeCalloc(char *, count + 1);
+ if (eargv == 0)
+ failed("realloc eargv");
+
+ assert(eargv != 0);
} else {
code = typelist((int) count, eargv, header, deschook);
while (count-- > 0)
diff --git a/progs/tput.c b/progs/tput.c
index 022d4940c2a1..2e67cfecbef4 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-2009,2010 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -47,7 +47,7 @@
#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.46 2010/01/09 16:53:24 tom Exp $")
#define PUTS(s) fputs(s, stdout)
#define PUTCHAR(c) putchar(c)
@@ -86,8 +86,8 @@ usage(void)
static void
check_aliases(const char *name)
{
- is_init = (strcmp(name, PROG_INIT) == 0);
- is_reset = (strcmp(name, PROG_RESET) == 0);
+ is_init = same_program(name, PROG_INIT);
+ is_reset = same_program(name, PROG_RESET);
}
/*
@@ -153,6 +153,9 @@ tput(int argc, char *argv[])
int i, j, c;
int status;
FILE *f;
+#if !PURE_TERMINFO
+ bool termcap = FALSE;
+#endif
if ((name = argv[0]) == 0)
name = "";
@@ -265,35 +268,40 @@ tput(int argc, char *argv[])
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) {
diff --git a/progs/transform.c b/progs/transform.c
new file mode 100644
index 000000000000..75f4573357c3
--- /dev/null
+++ b/progs/transform.c
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * Copyright (c) 2009,2010 Free 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.2 2010/09/04 21:16:17 tom Exp $")
+
+#ifdef SUFFIX_IGNORED
+static void
+trim_suffix(const char *a, unsigned *len)
+{
+ const char ignore[] = SUFFIX_IGNORED;
+
+ if (sizeof(ignore) != 0) {
+ bool trim = FALSE;
+ unsigned need = (sizeof(ignore) - 1);
+
+ if (*len > need) {
+ unsigned first = *len - need;
+ unsigned 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)
+{
+ unsigned len_a = strlen(a);
+ unsigned 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/tset.c b/progs/tset.c
index 6a4d2d61c3de..084e41d6db24 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-2009,2010 Free 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 @@ char *ttyname(int fd);
#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.82 2010/05/01 21:42:46 tom Exp $")
/*
* SCO defines TIOCGSIZE and the corresponding struct. Other systems (SunOS,
@@ -129,7 +141,9 @@ MODULE_ID("$Id: tset.c,v 1.76 2008/10/11 19:26:19 tom Exp $")
# endif
#endif
+#ifndef environ
extern char **environ;
+#endif
#undef CTRL
#define CTRL(x) ((x) & 0x1f)
@@ -385,9 +399,13 @@ add_mapping(const char *port, char *arg)
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;
@@ -1247,12 +1265,12 @@ main(int argc, char **argv)
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) {
tcolumns = columns;