diff -Nur trunk-bak/configure.ac trunk/configure.ac --- trunk-bak/configure.ac 2005-02-08 03:36:19.000000000 +0900 +++ trunk/configure.ac 2005-02-08 04:30:12.000000000 +0900 @@ -398,6 +398,51 @@ ], [ use_dict="no" ]) +dnl **************************** +dnl *** Tests for EB Library *** +dnl **************************** + +use_eb="no" +AC_ARG_WITH(eb, + AS_HELP_STRING([--without-eb], + [Don't build against eb]), + [ + if test "x$with_eb" = "xyes"; then + _SAVE_LDFLAGS=$LDFLAGS + EB_LDFLAGS="-lz" + LDFLAGS="$LDFLAGS $EB_LDFLAGS" + AC_CHECK_LIB(eb, eb_initialize_library, HAVE_EBLIB=yes, HAVE_EBLIB=no) + if test "x$HAVE_EBLIB" = "xyes"; then + AC_CHECK_HEADER(eb/eb.h, HAVE_EBLIB=yes, HAVE_EBLIB=no) + if test "x$HAVE_EBLIB" = "xyes"; then + AC_DEFINE(HAVE_EBLIB, 1, + [Define to 1 if you have EB library and header file]) + EBLIB_LIBS="-leb -lz" + use_eb="yes" + fi + LDFLAGS=$_SAVE_LDFLAGS + fi + fi + ], + [ + _SAVE_LDFLAGS=$LDFLAGS + EB_LDFLAGS="-lz" + LDFLAGS="$LDFLAGS $EB_LDFLAGS" + AC_CHECK_LIB(eb, eb_initialize_library, HAVE_EBLIB=yes, HAVE_EBLIB=no) + if test "x$HAVE_EBLIB" = "xyes"; then + AC_CHECK_HEADER(eb/eb.h, HAVE_EBLIB=yes, HAVE_EBLIB=no) + if test "x$HAVE_EBLIB" = "xyes"; then + AC_DEFINE(HAVE_EBLIB, 1, + [Define to 1 if you have EB library and header file]) + EBLIB_LIBS="-leb" + use_eb="yes" + fi + fi + LDFLAGS=$_SAVE_LDFLAGS +]) + +AC_SUBST(EBLIB_LIBS) + AM_CONDITIONAL(M17NLIB, test x$use_m17nlib = xyes) AM_CONDITIONAL(SCIM, test x$use_scim = xyes) @@ -414,6 +459,7 @@ AM_CONDITIONAL(UIM_FEP, test x$use_uim_fep = xyes) AM_CONDITIONAL(XIM, test x$use_xim = xyes) AM_CONDITIONAL(DICT, test x$use_dict = xyes) +AM_CONDITIONAL(EB, test x$use_eb = xyes) AM_CONDITIONAL(DEBUG, test x$enable_debug = xyes) AM_CONDITIONAL(COMPAT_SCM, test x$enable_compat_scm = xyes) AM_CONDITIONAL(COMPAT_TABLE, test x$enable_compat_table = xyes) @@ -684,6 +730,7 @@ FEP : ${use_uim_fep} XIM : ${use_xim} DICT : ${use_dict} + EB : ${use_eb} Default toolkit : ${default_toolkit} ]) diff -Nur trunk-bak/gtk/Makefile.am trunk/gtk/Makefile.am --- trunk-bak/gtk/Makefile.am 2005-02-08 03:36:19.000000000 +0900 +++ trunk/gtk/Makefile.am 2005-02-08 04:28:46.000000000 +0900 @@ -11,13 +11,17 @@ im_uim_la_SOURCES = $(IM_UIM_SOURCES) im_uim_la_LDFLAGS = -module -avoid-version @GTK2_LIBS@ -im_uim_la_LIBADD = $(top_builddir)/uim/libuim.la +im_uim_la_LIBADD = $(top_builddir)/uim/libuim.la $(EBLIB_LIBS) IM_UIM_SOURCES = \ gtk-im-uim.c \ uim-cand-win-gtk.c uim-cand-win-gtk.h +if EB +IM_UIM_SOURCES += uim-eb.c uim-eb.h +endif + install-data-hook: if test -f $(GTK_IMMODULES); then \ gtk-query-immodules-2.0 > $(GTK_IMMODULES); \ diff -Nur trunk-bak/gtk/uim-cand-win-gtk.c trunk/gtk/uim-cand-win-gtk.c --- trunk-bak/gtk/uim-cand-win-gtk.c 2005-02-08 03:36:19.000000000 +0900 +++ trunk/gtk/uim-cand-win-gtk.c 2005-02-08 04:29:09.000000000 +0900 @@ -33,7 +33,12 @@ #include "uim-cand-win-gtk.h" #include +#include "uim/config.h" #include +#include +#if HAVE_EBLIB +#include "uim-eb.h" +#endif /* HAVE_EBLIB */ #define NR_CANDIDATES 20 /* FIXME! not used yet */ #define DEFAULT_MIN_WINDOW_WIDTH 80 @@ -341,9 +346,33 @@ if (gtk_tree_selection_get_selected(selection, &model, &iter)) { gchar *annotation = NULL; +#if HAVE_EBLIB + if (uim_scm_symbol_value_bool("generic-use-eb?")) { + gchar *cand = NULL; + + gtk_tree_model_get(model, &iter, + COLUMN_CANDIDATE, &cand, + -1); + if (cand && *cand) { + char *book; + uim_eb *ueb; + + book = uim_scm_symbol_value_str("generic-eb-dic-path"); + ueb = uim_eb_new(book); + if (ueb) { + annotation = uim_eb_search_text(ueb, cand); + uim_eb_destroy(ueb); + } + g_free(book); + } + g_free(cand); + } +#else /* HAVE_EB_LIB */ gtk_tree_model_get(model, &iter, COLUMN_ANNOTATION, &annotation, -1); +#endif /* HAVE_EB_LIB */ + if (annotation && *annotation) { if (!cwin->sub_window.window) uim_cand_win_gtk_create_sub_window(cwin); diff -Nur trunk-bak/gtk/uim-eb.c trunk/gtk/uim-eb.c --- trunk-bak/gtk/uim-eb.c 1970-01-01 09:00:00.000000000 +0900 +++ trunk/gtk/uim-eb.c 2005-02-08 04:29:19.000000000 +0900 @@ -0,0 +1,195 @@ +/* + + Copyright (c) 2003,2004 uim Project http://uim.freedesktop.org/ + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of authors nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "uim-eb.h" + +#define MAX_HITS 10 +#define MAX_TEXT 1000 +#define MAX_LENGTH 10000 + +/* FIXME! */ +#define DEFAULT_DICT "/home/aho/EDICT" + +struct _uim_eb { + EB_Book book; + EB_Subbook_Code subCodes[EB_MAX_SUBBOOKS]; + int subCount; +}; + +static void go_text_eb (uim_eb *ueb, + EB_Position position, + GString *str); + +static unsigned int eb_ref_count = 0; + +uim_eb * +uim_eb_new (const char *bookpath) +{ + uim_eb *ueb; + EB_Error_Code err; + + ueb = malloc(sizeof(uim_eb)); + eb_ref_count++; + + err = eb_initialize_library(); + if (err != EB_SUCCESS) + fprintf(stderr, "failed to initialize EB library : error = %s\n", + eb_error_message(err)); + + eb_initialize_book(&ueb->book); + + err = eb_bind(&ueb->book, bookpath); + if (err != EB_SUCCESS) { + fprintf(stderr, "wrong bookpath\n"); + free(ueb); + return NULL; + } + + err = eb_subbook_list(&ueb->book, ueb->subCodes, &ueb->subCount); + if (err != EB_SUCCESS) { + g_printerr("eb_subbook_list() failed\n"); + free(ueb); + return NULL; + } + + return ueb; +} + + +void +uim_eb_destroy (uim_eb *ueb) +{ + if (!ueb) + return; + + eb_finalize_book(&ueb->book); + + eb_ref_count--; + if (eb_ref_count == 0) + eb_finalize_library(); +} + + +char * +uim_eb_search_text (uim_eb *ueb, const gchar *text_utf8) +{ + gchar *text; + int i; + gsize bytes_read, bytes_written; + GString *str; + + /* FIXME! check return value */ + text = g_convert(text_utf8, strlen(text_utf8), + "EUC-JP", "UTF-8", + &bytes_read, &bytes_written, + NULL); + g_return_val_if_fail(text, FALSE); + + str = g_string_new(""); + + for (i = 0; i < ueb->subCount; i++) { + EB_Hit hits[MAX_HITS]; + int hitCount; + int j; + + /* specify subbook */ + if (eb_set_subbook(&ueb->book, ueb->subCodes[i]) != EB_SUCCESS) { + g_print("eb_set_subbook() failed\n"); continue; + } + + eb_search_word(&ueb->book, text); + eb_hit_list(&ueb->book, MAX_HITS, hits, &hitCount); + for (j = 0; j < hitCount; j++) { + /*EB_Position headp = hits[j].heading;*/ + EB_Position textp = hits[j].text; + + go_text_eb(ueb, textp, str); + g_string_append(str, "\n"); + } + } + + g_free(text); + + return g_string_free(str, FALSE); +} + + +static void +go_text_eb (uim_eb *ueb, EB_Position position, GString *str) +{ + EB_Hookset hookset; + char text[MAX_TEXT + 1]; + int text_length; + int bytes; + int i; + + if (eb_seek_text(&ueb->book, &position) != EB_SUCCESS) { + g_print("eb_seek_text error occurs"); + return; + } + + eb_initialize_hookset(&hookset); + for (i = 0; i < 1; i++) { + gchar *text_utf8; + gsize bytes_read, bytes_written; + + if (eb_read_text(&ueb->book, NULL, &hookset, + NULL, MAX_TEXT, text, &text_length) != EB_SUCCESS) { + bytes = 0; + g_print("eb_read_text : an error occurs.\n"); + return; + } + + bytes += text_length; + if (text_length < 1) + break; + + /* FIXME! check return value */ + text_utf8 = g_convert(text, strlen(text), + "UTF-8", "EUC-JP", + &bytes_read, &bytes_written, + NULL); + g_string_append(str, text_utf8); + g_free(text_utf8); + } + eb_finalize_hookset(&hookset); +} diff -Nur trunk-bak/gtk/uim-eb.h trunk/gtk/uim-eb.h --- trunk-bak/gtk/uim-eb.h 1970-01-01 09:00:00.000000000 +0900 +++ trunk/gtk/uim-eb.h 2005-02-08 04:29:19.000000000 +0900 @@ -0,0 +1,50 @@ +/* + + Copyright (c) 2003,2004 uim Project http://uim.freedesktop.org/ + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of authors nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + +*/ + +#ifndef _uim_eb_h_included_ +#define _uim_eb_h_included_ + +#include + +G_BEGIN_DECLS + +typedef struct _uim_eb uim_eb; + +uim_eb *uim_eb_new (const char *bookpath); +char *uim_eb_search_text (uim_eb *ueb, + const gchar *text); +void uim_eb_destroy (uim_eb *ueb); + +G_END_DECLS + +#endif /* _uim_eb_h_included_ */ diff -Nur trunk-bak/po/ja.po trunk/po/ja.po --- trunk-bak/po/ja.po 2005-02-08 03:36:20.000000000 +0900 +++ trunk/po/ja.po 2005-02-08 04:29:37.000000000 +0900 @@ -1227,6 +1227,14 @@ msgid "Enable lazy input method loading for fast startup" msgstr "高速起動のための遅延ローディングを有効にする" +#: scm/im-custom.lisp:317 +msgid "Use EB library to search annotations" +msgstr "注釈の検索にEBライブラリを使用する" + +#: scm/im-custom.lisp:324 +msgid "The directory which contains EB dictionary file" +msgstr "EB辞書ファイルを格納しているディレクトリ" + #: scm/ipa.lisp:227 scm/ipa.lisp:228 msgid "International Phonetic Alphabet (X-SAMPA)" msgstr "IPA (国際発声記号 X-SAMPA版)" diff -Nur trunk-bak/scm/im-custom.scm trunk/scm/im-custom.scm --- trunk-bak/scm/im-custom.scm 2005-02-08 03:36:23.000000000 +0900 +++ trunk/scm/im-custom.scm 2005-02-08 04:29:45.000000000 +0900 @@ -308,3 +308,18 @@ '(boolean) (_ "Enable lazy input method loading for fast startup") (_ "long description will be here.")) + + +;; EB Library support +(define-custom 'generic-use-eb? #t + '(global candwin) + '(boolean) + (_ "Use EB library to search annotations") + (_ "long description will be here.")) + +(define-custom 'generic-eb-dic-path + (string-append (getenv "HOME") "/dict") + '(global candwin) + '(pathname) + (_ "The directory which contains EB dictionary file") + (_ "long description will be here."))