]> diplodocus.org Git - nmh/commitdiff
Create an autoconf test to determine the argument of the tputs() callback.
authorKen Hornstein <kenh@pobox.com>
Fri, 3 Jan 2014 15:44:59 +0000 (10:44 -0500)
committerKen Hornstein <kenh@pobox.com>
Fri, 3 Jan 2014 15:44:59 +0000 (10:44 -0500)
configure.ac
m4/tputs.m4 [new file with mode: 0644]
sbr/terminal.c

index 7f01142..8db3acf 100644 (file)
@@ -402,13 +402,16 @@ NMH_LOCKING
 dnl Check for iconv
 NMH_CHECK_ICONV
 
 dnl Check for iconv
 NMH_CHECK_ICONV
 
+dnl Check for tputs() callback argument
+NMH_TPUTS_PUTC_ARG
+
 termcap_curses_order="termcap curses ncurses"
 for lib in $termcap_curses_order; do
 termcap_curses_order="termcap curses ncurses"
 for lib in $termcap_curses_order; do
-  AC_CHECK_LIB(${lib}, tgetent, [TERMLIB="-l$lib"; break])
+  AC_CHECK_LIB([${lib}], [setupterm], [TERMLIB="-l$lib"; break])
 done
 AC_SUBST([TERMLIB])dnl
 AS_IF([test "x$TERMLIB" = "x"],
 done
 AC_SUBST([TERMLIB])dnl
 AS_IF([test "x$TERMLIB" = "x"],
-      [AC_MSG_FAILURE([Could not find tgetent in any library.  Is there a curses
+      [AC_MSG_FAILURE([Could not find setupterm in any library.  Is there a curses
 or ncurses library or package that you can install?])])
 
 dnl --------------
 or ncurses library or package that you can install?])])
 
 dnl --------------
diff --git a/m4/tputs.m4 b/m4/tputs.m4
new file mode 100644 (file)
index 0000000..15265dc
--- /dev/null
@@ -0,0 +1,31 @@
+dnl
+dnl Some systems have different arguments to the tputs callback; it can
+dnl be int (*)(int), or int (*)(char).  Try to probe to see which one it
+dnl actually is, so our callback can match the prototype.
+dnl
+dnl The first argument to tputs sometimes is char *, other times is
+dnl const char *, so we have to include that in the test as well, but
+dnl we don't provide any definitions for it (since it's not necessary)
+dnl
+
+AC_DEFUN([NMH_TPUTS_PUTC_ARG],
+[AC_CACHE_CHECK([the argument of the tputs() callback],
+               [nmh_cv_tputs_putc_arg],
+  [for tputs_arg1 in 'const char *' 'char *'; do
+    for tputs_putc_arg in 'int' 'char'; do
+      AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM(
+[AC_INCLUDES_DEFAULT
+#include <curses.h>
+#include <term.h>
+],
+         [extern int tputs($tputs_arg1, int, int (*)($tputs_putc_arg));])],
+       [nmh_cv_tputs_putc_arg="$tputs_putc_arg"; break 2])
+    done
+  done
+  AS_IF([test "X$nmh_cv_tputs_putc_arg" = X],
+    [AC_MSG_FAILURE([cannot determine tputs callback argument])])])
+AC_MSG_RESULT([$nmh_cv_tputs_putc_arg])
+AC_DEFINE_UNQUOTED([TPUTS_PUTC_ARG], [$nmh_cv_tputs_putc_arg],
+                  [The type of the argument of the tputs() callback])
+])
index c6768c4..9ce9a3b 100644 (file)
@@ -35,7 +35,7 @@ static char *termcbufp = NULL;           /* tputs() output buffer pointer          */
 static size_t termcbufsz = 0;     /* Size of termcbuf                       */
 
 static void initialize_terminfo(void);
 static size_t termcbufsz = 0;     /* Size of termcbuf                       */
 
 static void initialize_terminfo(void);
-static int termbytes(int);
+static int termbytes(TPUTS_PUTC_ARG);
 
 /*
  * Initialize the terminfo library.
 
 /*
  * Initialize the terminfo library.
@@ -185,7 +185,7 @@ get_term_stringcap(char *capability)
  */
 
 static int
  */
 
 static int
-termbytes(int c)
+termbytes(TPUTS_PUTC_ARG c)
 {
     size_t offset;
 
 {
     size_t offset;