null+****@clear*****
null+****@clear*****
2010年 7月 9日 (金) 11:27:12 JST
Kouhei Sutou 2010-07-09 02:27:12 +0000 (Fri, 09 Jul 2010)
New Revision: 116f54d6ac0047cdf2fd5282e771b79a0473da0d
Log:
use libedit with multibyte support.
Modified files:
configure.ac
src/Makefile.am
src/groonga.c
Modified: configure.ac (+21 -12)
===================================================================
--- configure.ac 2010-07-09 04:05:31 +0000 (5f63cd1)
+++ configure.ac 2010-07-09 02:27:12 +0000 (f54b3d5)
@@ -456,19 +456,28 @@ AM_CONDITIONAL([WITH_RUBY], [test "$ac_cv_ruby_available" = "yes"])
# libedit
AC_ARG_WITH(libedit,
- [AS_HELP_STRING([--with-libedit],
- [use libedit for console. [default=yes]])],
- [with_libedit="$withval"],
- [with_libedit="yes"])
-AC_CHECK_LIB(edit,el_init,
- [with_libedit="yes"],
- [with_libedit="no"])
-if test "x$with_libedit" = "xyes"; then
- AC_DEFINE(WITH_LIBEDIT, [1], [with libedit])
- EDIT_LIBS="-ledit"
+ [AS_HELP_STRING([--disable-libedit],
+ [use libedit for console. [default=auto-detect]])],
+ [enable_libedit="$withval"],
+ [enable_libedit="auto"])
+if test "x$enable_libedit" != "xno"; then
+ PKG_CHECK_MODULES([LIBEDIT], [libedit >= 3.0],
+ [LDFLAGS_SAVE="$LDFLAGS"
+ LDFLAGS="$LIBEDIT_LIBS $LDFLAGS"
+ AC_CHECK_LIB(edit, el_wline,
+ [libedit_available=yes],
+ [libedit_available=no])
+ LDFLAGS="$LDFLAGS_SAVE"],
+ [libedit_available=no])
+ if test "x$libedit_available" = "xyes"; then
+ AC_DEFINE(HAVE_LIBEDIT, [1], [Use libedit with multibyte support.])
+ else
+ if test "x$enable_editline" = "xyes"; then
+ AC_MSG_ERROR("No libedit found")
+ fi
+ fi
fi
-
# zlib
AC_ARG_WITH(zlib,
[AS_HELP_STRING([--with-zlib],
@@ -584,7 +593,7 @@ AC_DEFINE_UNQUOTED(GRN_MODULE_SUFFIX, ["$suffix"], "module suffix")
# flags for compile groonga
CFLAGS="$CFLAGS $OPT_CFLAGS "
CFLAGS="$CFLAGS -DMODULES_DIR=\\\"\"\$(modulesdir)\"\\\""
-LIBS="$LIBS $ZLIB_LIBS $LZO_LIBS $PTHREAD_LIBS $M_LIBS $NSL_LIBS $SOCKET_LIBS $WINDOWS_LIBS $EDIT_LIBS"
+LIBS="$LIBS $ZLIB_LIBS $LZO_LIBS $PTHREAD_LIBS $M_LIBS $NSL_LIBS $SOCKET_LIBS $WINDOWS_LIBS"
AC_DEFINE_UNQUOTED(CONFIGURE_OPTIONS, "$ac_configure_args", "specified configure options")
# flags for groonga-cfg
Modified: src/Makefile.am (+2 -1)
===================================================================
--- src/Makefile.am 2010-07-09 04:05:31 +0000 (86a0d3a)
+++ src/Makefile.am 2010-07-09 02:27:12 +0000 (3408402)
@@ -7,7 +7,8 @@ AM_CFLAGS = -fno-strict-aliasing $(COVERAGE_CFLAGS) \
DEFAULT_INCLUDES = -I$(top_builddir) -I$(srcdir) -I$(top_srcdir) $(GROONGA_INCLUDEDIR)
groonga_SOURCES = groonga.c
-groonga_LDADD = $(top_builddir)/lib/libgroonga.la
+groonga_CFLAGS = $(AM_CFLAGS) $(LIBEDIT_CFLAGS)
+groonga_LDADD = $(top_builddir)/lib/libgroonga.la $(LIBEDIT_LIBS)
grnslap_SOURCES = grnslap.c
grnslap_LDADD = $(top_builddir)/lib/libgroonga.la
Modified: src/groonga.c (+31 -19)
===================================================================
--- src/groonga.c 2010-07-09 04:05:31 +0000 (5271eb2)
+++ src/groonga.c 2010-07-09 02:27:12 +0000 (ddcdeb8)
@@ -59,16 +59,17 @@ static int (*do_server)(char *path);
static uint32_t default_max_nfthreads = DEFAULT_MAX_NFTHREADS;
static const char *pidfile_path;
-#ifdef WITH_LIBEDIT
+#ifdef HAVE_LIBEDIT
+#include <locale.h>
#include <histedit.h>
static EditLine *el;
-static History *elh;
-static HistEvent elhv;
+static HistoryW *elh;
+static HistEventW elhv;
-inline static const char *
+inline static const wchar_t *
disp_prompt(EditLine *e __attribute__((unused)))
{
- return "> ";
+ return L"> ";
}
#endif
@@ -162,12 +163,22 @@ prompt(char *buf)
{
int len;
if (!batchmode) {
-#ifdef WITH_LIBEDIT
- const char *es;
- es = el_gets(el, &len);
- if (len > 0 && BUFSIZE > len) {
- history(elh, &elhv, H_ENTER, es);
- strncpy(buf, es, len);
+#ifdef HAVE_LIBEDIT
+ const wchar_t *es;
+ int nchar;
+ es = el_wgets(el, &nchar);
+ if (nchar > 0 && BUFSIZE > (MB_LEN_MAX * nchar + 1)) {
+ int i;
+ char *p;
+ mbstate_t ps;
+ history_w(elh, &elhv, H_ENTER, es);
+ wcrtomb(NULL, L'\0', &ps);
+ p = buf;
+ for (i = 0; i < nchar; i++) {
+ p += wcrtomb(p, es[i], &ps);
+ }
+ p[0] = '\0';
+ len = p - buf;
} else {
len = 0;
}
@@ -1860,14 +1871,15 @@ main(int argc, char **argv)
max_nfthreads = default_max_nfthreads;
}
batchmode = !isatty(0);
-#ifdef WITH_LIBEDIT
+#ifdef HAVE_LIBEDIT
if (!batchmode) {
+ setlocale(LC_ALL, "");
el = el_init(argv[0],stdin,stdout,stderr);
- el_set(el, EL_PROMPT, &disp_prompt);
- el_set(el, EL_EDITOR, "emacs");
- elh = history_init();
- history(elh, &elhv, H_SETSIZE, 200);
- el_set(el, EL_HIST, history, elh);
+ el_wset(el, EL_PROMPT, &disp_prompt);
+ el_wset(el, EL_EDITOR, L"emacs");
+ elh = history_winit();
+ history_w(elh, &elhv, H_SETSIZE, 200);
+ el_set(el, EL_HIST, history_w, elh);
}
#endif
if (grn_init()) { return -1; }
@@ -1915,9 +1927,9 @@ main(int argc, char **argv)
r = -1;
break;
}
-#ifdef WITH_LIBEDIT
+#ifdef HAVE_LIBEDIT
if (!batchmode) {
- history_end(elh);
+ history_wend(elh);
el_end(el);
}
#endif