[Hieroglyph] GNU readline patch
mpsuzuki at hiroshima-u.ac.jp
mpsuzuki at hiroshima-u.ac.jp
Thu Mar 30 19:29:36 PST 2006
お世話になっております、広大の鈴木です。
たぶんライセンスの問題(できるだけLGPL 2.0未満の
依存関係ですませる)でlibeditを使っていると想像
するのですが、一応、フォールバックでGNU readlineも
探すパッチを書きました。
readlineが依存する端末制御ライブラリが暗黙には
見つからなかった場合、
ncurses → terminfo → termcap
の順番で探していますが、一般にはどうするのが良いか、
経験のある方にアドバイスをいただければ幸いです。
diff -Burb hieroglyph.orig/configure.ac hieroglyph/configure.ac
--- hieroglyph.orig/configure.ac Wed Mar 29 20:04:19 2006
+++ hieroglyph/configure.ac Fri Mar 31 11:48:36 2006
@@ -44,6 +44,11 @@
changequote([,])dnl
dnl ======================================================================
+dnl headers testing
+dnl ======================================================================
+AC_CHECK_HEADERS(stdio.h, , )
+
+dnl ======================================================================
dnl functions testing
dnl ======================================================================
AC_FUNC_FSEEKO
@@ -78,14 +83,47 @@
gobject gmodule gthread)
dnl ======================================================================
-dnl check another libraries
+dnl check libraries for CLI
dnl ======================================================================
AC_CHECK_LIB(edit, readline, [
READLINE_LIBS="-ledit"
- AC_DEFINE(USE_LIBEDIT,1,[build with readline])
- ],
+ AC_DEFINE(USE_LIBEDIT,1,[build with libedit])
+ ], [
+ LIBTERM=""
+ AC_MSG_WARN([*** libedit is recommended, search GNU readline])
+ AC_CHECK_LIB(readline, rl_reset_screen_size, , [
+ unset ac_cv_lib_readline_rl_reset_screen_size
+ orig_LIBS="${LIBS}"
+ AC_CHECK_LIB(ncurses, tcgetattr, [have_ncurses=yes], [have_ncurses=no])
+ LIBS="${orig_LIBS}"
+ AC_CHECK_LIB(terminfo, tcgetattr, [have_terminfo=yes], [have_terminfo=no])
+ LIBS="${orig_LIBS}"
+ AC_CHECK_LIB(termcap, tcgetattr, [have_termcap=yes], [have_termcap=no])
+ LIBS="${orig_LIBS}"
+ if test xyes = x"${have_ncurses}"
+ then
+ LIBTERM="-lncurses"
+ elif test xyes = x"${have_terminfo}"
+ then
+ LIBTERM="-lterminfo"
+ elif test xyes = x"${have_termcap}"
+ then
+ LIBTERM="-ltermcap"
+ fi
+ AC_CHECK_LIB(readline, rl_reset_screen_size, , [
+ AC_MSG_ERROR([
+*** libedit or GNU readline is required]) ], [
+ ${LIBTERM}
+ ] )
+ ], ${LIBTERM} )
+ AC_CHECK_LIB(history, add_history, [
+ READLINE_LIBS="-lreadline -lhistory ${LIBTERM}"
+ AC_DEFINE(USE_LIBREADLINE,1,[build with GNU readline])
+ ], [
AC_MSG_ERROR([
-*** libedit is required.]), )
+*** GNU readline is found but libhistory is not found ])
+ ], [ -lreadline ${LIBTERM} ] )
+ ] )
AC_SUBST(READLINE_LIBS)
dnl ======================================================================
diff -Burb hieroglyph.orig/hieroglyph/hglineedit.c hieroglyph/hieroglyph/hglineedit.c
--- hieroglyph.orig/hieroglyph/hglineedit.c Wed Mar 29 20:04:18 2006
+++ hieroglyph/hieroglyph/hglineedit.c Fri Mar 31 10:15:07 2006
@@ -25,10 +25,20 @@
#include <config.h>
#endif
+#ifdef HAVE_STDLIB_H
#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
#include <string.h>
-#ifdef USE_LIBEDIT
+#endif
+#if defined(USE_LIBEDIT)
#include <editline/readline.h>
+#elif defined(USE_LIBREADLINE)
+#ifdef HAVE_STDIO_H
+#include <stdio.h>
+#endif
+#include <readline/readline.h>
+#include <readline/history.h>
#endif
#include "hglineedit.h"
@@ -47,7 +57,7 @@
{
g_return_val_if_fail (stdin != NULL, NULL);
-#ifdef USE_LIBEDIT
+#if defined(USE_LIBEDIT) || defined(USE_LIBREADLINE)
G_STMT_START {
gchar *retval;
@@ -111,7 +121,7 @@
p = g_strdup(retval);
g_strchomp(p);
len = strlen(p);
-#ifdef USE_LIBEDIT
+#if defined(USE_LIBEDIT) || defined(USE_LIBREADLINE)
if (len > 0) {
add_history(p);
}
@@ -128,7 +138,7 @@
{
g_return_val_if_fail (filename != NULL, FALSE);
-#ifdef USE_LIBEDIT
+#if defined(USE_LIBEDIT) || defined(USE_LIBREADLINE)
read_history(filename);
#else
#error FIXME: implement me!
@@ -142,7 +152,7 @@
{
g_return_val_if_fail (filename != NULL, FALSE);
-#ifdef USE_LIBEDIT
+#if defined(USE_LIBEDIT) || defined(USE_LIBREADLINE)
write_history(filename);
#else
#error FIXME: implement me!
More information about the Hieroglyph
mailing list