]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Portability to systems with GNU termcap.
authorBruno Haible <bruno@clisp.org>
Tue, 12 Dec 2006 14:16:34 +0000 (14:16 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:14:27 +0000 (12:14 +0200)
gnulib-local/ChangeLog
gnulib-local/lib/term-ostream.oo.c
gnulib-local/lib/termcap.h
gnulib-local/m4/termcap.m4

index fbf59caa2603870a5674ffd5df75869799e46d21..2b6a92e1905a6d717cd519dbaf1de83669de8435 100644 (file)
@@ -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.
index 64dbc8fc69b4b2900fb0f59b8a9ef79fc017fbd1..6d1d469a3f263b509743beb5e116f4558729f988 100644 (file)
 
 #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]))
 
 
index 4c7b17ed6fe419bd2035988b634b0b929d66885d..50386d28cd3edab25c0f86bc4ea4ee3f9d50e132 100644 (file)
@@ -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.  */
index aef68b9db99bf5c3a344a96578ea671901aac5ef..7cf37739a54006d7cf377ed561ce6f4bc2a7354e 100644 (file)
@@ -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
 ])