summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gnulib-local/ChangeLog8
-rw-r--r--gnulib-local/lib/term-ostream.oo.c10
-rw-r--r--gnulib-local/lib/termcap.h18
-rw-r--r--gnulib-local/m4/termcap.m427
4 files changed, 62 insertions, 1 deletions
diff --git a/gnulib-local/ChangeLog b/gnulib-local/ChangeLog
index fbf59ca..2b6a92e 100644
--- a/gnulib-local/ChangeLog
+++ b/gnulib-local/ChangeLog
@@ -1,3 +1,11 @@
+2006-12-11 Bruno Haible <bruno@clisp.org>
+
+ Portability to systems with GNU termcap.
+ * m4/termcap.m4 (gl_TERMCAP_BODY): Also test for the tparam function.
+ * lib/termcap.h (tparam): New declaration.
+ * lib/term-ostream.oo.c (tparambuf): New variable.
+ (tparm): Define in terms of tparam when tparam exists.
+
2006-12-01 Bruno Haible <bruno@clisp.org>
* modules/term-ostream: Depend on termcap-h, not termcap.
diff --git a/gnulib-local/lib/term-ostream.oo.c b/gnulib-local/lib/term-ostream.oo.c
index 64dbc8f..6d1d469 100644
--- a/gnulib-local/lib/term-ostream.oo.c
+++ b/gnulib-local/lib/term-ostream.oo.c
@@ -40,6 +40,16 @@
#define _(str) gettext (str)
+#if HAVE_TPARAM
+/* GNU termcap's tparam() function requires a buffer argument. Make it so
+ large that there is no risk that tparam() needs to call malloc(). */
+static char tparambuf[100];
+/* Define tparm in terms of tparam. In the scope of this file, it is called
+ with at most one argument after the string. */
+# define tparm(str, arg1) \
+ tparam (str, tparambuf, sizeof (tparambuf), arg1)
+#endif
+
#define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
diff --git a/gnulib-local/lib/termcap.h b/gnulib-local/lib/termcap.h
index 4c7b17e..50386d2 100644
--- a/gnulib-local/lib/termcap.h
+++ b/gnulib-local/lib/termcap.h
@@ -43,10 +43,28 @@ extern int tgetflag (const char *id);
Also, if AREA != NULL, stores it at *AREA and advances *AREA. */
extern const char * tgetstr (const char *id, char **area);
+#if HAVE_TPARAM
+
+/* API provided by GNU termcap in <termcap.h>. */
+
+/* Instantiates a string capability with format strings.
+ BUF must be a buffer having room for BUFSIZE bytes.
+ The return value is either equal to BUF or freshly malloc()ed. */
+extern char * tparam (const char *str, void *buf, int bufsize, ...);
+
+#else
+
+/* API provided by
+ - GNU ncurses in <term.h>, <curses.h>, <ncurses.h>,
+ - OSF/1 curses in <term.h>, <curses.h>,
+ - Solaris, AIX, HP-UX, IRIX curses in <term.h>. */
+
/* Instantiates a string capability with format strings.
The return value is statically allocated and must not be freed. */
extern char * tparm (const char *str, ...);
+#endif
+
/* Retrieves a string that causes cursor positioning to (column, row).
This function is necessary because the string returned by tgetstr ("cm")
is in a special format. */
diff --git a/gnulib-local/m4/termcap.m4 b/gnulib-local/m4/termcap.m4
index aef68b9..7cf3773 100644
--- a/gnulib-local/m4/termcap.m4
+++ b/gnulib-local/m4/termcap.m4
@@ -1,4 +1,4 @@
-# termcap.m4 serial 1 (gettext-0.16.2)
+# termcap.m4 serial 2 (gettext-0.16.2)
dnl Copyright (C) 2000-2002, 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -20,6 +20,8 @@ AC_DEFUN([gl_TERMCAP_BODY],
dnl because libtermcap is unsecure by design and obsolete since 1994.
dnl libcurses is useless: all platforms which have libcurses also have
dnl libtermcap, and libcurses is unusable on some old Unices.
+ dnl Some systems, like BeOS, use GNU termcap, which has tparam() instead of
+ dnl tparm().
dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
@@ -81,4 +83,27 @@ AC_DEFUN([gl_TERMCAP_BODY],
AC_SUBST([LIBTERMCAP])
AC_SUBST([LTLIBTERMCAP])
AC_SUBST([INCTERMCAP])
+
+ dnl Test against the old GNU termcap, which provides a tparam() function
+ dnl instead of the classical tparm() function.
+ AC_CACHE_CHECK([for tparam], [gl_cv_func_tparam], [
+ gl_save_LIBS="$LIBS"
+ LIBS="$LIBS $LIBTERMCAP"
+ gl_save_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $INCTERMCAP"
+ AC_TRY_LINK([extern
+ #ifdef __cplusplus
+ "C"
+ #endif
+ char * tparam (const char *, void *, int, ...);
+ char buf;
+ ], [return tparam ("\033\133%dm", &buf, 1, 8);],
+ [gl_cv_func_tparam=yes], [gl_cv_func_tparam=no])
+ CPPFLAGS="$gl_save_CPPFLAGS"
+ LIBS="$gl_save_LIBS"
+ ])
+ if test $gl_cv_func_tparam = yes; then
+ AC_DEFINE([HAVE_TPARAM], 1,
+ [Define if tparam() is among the termcap library functions.])
+ fi
])