]> git.lyx.org Git - lyx.git/commitdiff
Adapt to new hunspell C++ ABI
authorJuergen Spitzmueller <spitz@lyx.org>
Thu, 29 Mar 2018 16:43:11 +0000 (18:43 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Thu, 29 Mar 2018 16:43:11 +0000 (18:43 +0200)
Fixes: #10547
CMake support still missing.

INSTALL
config/spell.m4
src/HunspellChecker.cpp

diff --git a/INSTALL b/INSTALL
index 067b12ef98e5f1eba4e4e05b105b663bd6fdf53b..40c674169f21cfbff20bd7a34bec1c6380ff8d2d 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -227,6 +227,9 @@ The following options allow you to tweak the generated code more precisely (see
     --without-included-boost is specified). You may have to use
     --disable-stdlib-debug when linking development versions against
     your system's boost library.
+    The same problem applies to hunspell (as of hunspell 1.5). So either
+    compile --with-included-hunspell or --disable-stdlib-debug when
+    linking development versions against your system's hunspell library.
 
   o --enable-monolithic-build[=boost,client,insets,mathed,core,tex2lyx,frontend-qt4]
     that enables monolithic build of the given parts of the source
index 27b79d3301f8d549a287ca6a6fdae002b315a3b4..a13fb0a7babe18f8daab39dd9f337ab14bf5b885 100644 (file)
@@ -60,6 +60,23 @@ AC_DEFUN([CHECK_WITH_ENCHANT],
        fi
     ])
 
+AC_DEFUN([LYX_HAVE_HUNSPELL_CXXABI],
+[
+  AC_MSG_CHECKING([whether hunspell C++ (rather than C) ABI is provided])
+  save_CXXFLAGS=$CXXFLAGS
+  CXXFLAGS="$ENCHANT_CFLAGS $AM_CXXFLAGS $CXXFLAGS"
+
+# in the C++ ABI, stem() returns a vector, in the C ABI, it returns an int
+  AC_TRY_COMPILE([#include <hunspell/hunspell.hxx>],
+      [Hunspell sp("foo", "bar");
+       int i = sp.stem("test").size();],
+      [AC_MSG_RESULT(yes)
+       AC_DEFINE(HAVE_HUNSPELL_CXXABI, 1, [Define to 1 if hunspell C++ (rather than C) ABI is detected])
+      ],
+      [AC_MSG_RESULT(no)])
+  CXXFLAGS=$save_CXXFLAGS
+])
+
 # Macro to add for using hunspell spellchecker libraries!     -*- sh -*-
 AC_DEFUN([CHECK_WITH_HUNSPELL],
 [
@@ -83,6 +100,7 @@ AC_DEFUN([CHECK_WITH_HUNSPELL],
                AC_MSG_RESULT(no)
        fi
     fi
+               LYX_HAVE_HUNSPELL_CXXABI
     ])
 
 dnl Usage: LYX_USE_INCLUDED_HUNSPELL : select if the included hunspell should
@@ -113,6 +131,7 @@ AC_DEFUN([LYX_CHECK_SPELL_ENGINES],
 dnl the user wanted to use the included hunspell, so do not check for external hunspell
                lyx_use_hunspell=true
                AC_DEFINE(USE_HUNSPELL, 1, [Define as 1 to use the hunspell library])
+               AC_DEFINE(HAVE_HUNSPELL_CXXABI, 1, [Define to 1 if hunspell C++ (rather than C) ABI is detected])
                lyx_flags="$lyx_flags use-hunspell"
        else
                CHECK_WITH_HUNSPELL
index 6dc6647b5cf4829687bc1418ef89dd9b707a09c4..1c2612e78e0fdc973e3e3a6302fc6e213626741e 100644 (file)
@@ -356,7 +356,11 @@ SpellChecker::Result HunspellChecker::check(WordLangTuple const & wl)
 
        LYXERR(Debug::GUI, "spellCheck: \"" <<
                   wl.word() << "\", lang = " << wl.lang()->lang()) ;
+#ifdef HAVE_HUNSPELL_CXXABI
+       if (h->spell(word_to_check, &info))
+#else
        if (h->spell(word_to_check.c_str(), &info))
+#endif
                return d->learned(wl) ? LEARNED_WORD : WORD_OK;
 
        if (info & SPELL_COMPOUND) {
@@ -411,6 +415,11 @@ void HunspellChecker::suggest(WordLangTuple const & wl,
                return;
        string const encoding = h->get_dic_encoding();
        string const word_to_check = to_iconv_encoding(wl.word(), encoding);
+#ifdef HAVE_HUNSPELL_CXXABI
+       vector<string> wlst = h->suggest(word_to_check);
+       for (auto const s : wlst)
+               suggestions.push_back(from_iconv_encoding(s, encoding));
+#else
        char ** suggestion_list;
        int const suggestion_number = h->suggest(&suggestion_list, word_to_check.c_str());
        if (suggestion_number <= 0)
@@ -418,6 +427,7 @@ void HunspellChecker::suggest(WordLangTuple const & wl,
        for (int i = 0; i != suggestion_number; ++i)
                suggestions.push_back(from_iconv_encoding(suggestion_list[i], encoding));
        h->free_list(&suggestion_list, suggestion_number);
+#endif
 }
 
 
@@ -430,6 +440,11 @@ void HunspellChecker::stem(WordLangTuple const & wl,
                return;
        string const encoding = h->get_dic_encoding();
        string const word_to_check = to_iconv_encoding(wl.word(), encoding);
+#ifdef HAVE_HUNSPELL_CXXABI
+       vector<string> wlst = h->stem(word_to_check);
+       for (auto const s : wlst)
+               suggestions.push_back(from_iconv_encoding(s, encoding));
+#else
        char ** suggestion_list;
        int const suggestion_number = h->stem(&suggestion_list, word_to_check.c_str());
        if (suggestion_number <= 0)
@@ -437,6 +452,7 @@ void HunspellChecker::stem(WordLangTuple const & wl,
        for (int i = 0; i != suggestion_number; ++i)
                suggestions.push_back(from_iconv_encoding(suggestion_list[i], encoding));
        h->free_list(&suggestion_list, suggestion_number);
+#endif
 }