3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Kevin Atkinson
9 * Full author contact details are available in file CREDITS.
16 #define USE_ORIGINAL_MANAGER_FUNCS 1
17 // new aspell pspell missing extern "C"
19 #include <pspell/pspell.h>
23 #include "WordLangTuple.h"
25 #include <boost/assert.hpp>
31 PSpell::PSpell(BufferParams const &, string const & lang)
32 : els(0), spell_error_object(0)
35 lyxerr[Debug::GUI] << "created pspell" << endl;
41 lyxerr[Debug::GUI] << "killed pspell" << endl;
43 if (spell_error_object) {
44 delete_pspell_can_have_error(spell_error_object);
45 spell_error_object = 0;
49 delete_pspell_string_emulation(els);
51 Managers::iterator it = managers_.begin();
52 Managers::iterator end = managers_.end();
54 for (; it != end; ++it) {
55 pspell_manager_save_all_word_lists(it->second.manager);
56 delete_pspell_manager(it->second.manager);
57 delete_pspell_config(it->second.config);
62 void PSpell::addManager(string const & lang)
64 PspellConfig * config = new_pspell_config();
65 pspell_config_replace(config, "language-tag", lang.c_str());
66 PspellCanHaveError * err = new_pspell_manager(config);
67 if (spell_error_object)
68 delete_pspell_can_have_error(spell_error_object);
69 spell_error_object = 0;
71 if (pspell_error_number(err) == 0) {
73 m.manager = to_pspell_manager(err);
77 spell_error_object = err;
82 enum PSpell::Result PSpell::check(WordLangTuple const & word)
84 Result res = UNKNOWN_WORD;
86 Managers::iterator it = managers_.find(word.lang_code());
87 if (it == managers_.end()) {
88 addManager(word.lang_code());
89 it = managers_.find(word.lang_code());
91 if (it == managers_.end())
95 PspellManager * m = it->second.manager;
97 int word_ok = pspell_manager_check(m, word.word().c_str());
98 BOOST_ASSERT(word_ok != -1);
103 PspellWordList const * sugs =
104 pspell_manager_suggest(m, word.word().c_str());
105 BOOST_ASSERT(sugs != 0);
106 els = pspell_word_list_elements(sugs);
107 if (pspell_word_list_empty(sugs))
110 res = SUGGESTED_WORDS;
116 void PSpell::insert(WordLangTuple const & word)
118 Managers::iterator it = managers_.find(word.lang_code());
119 if (it != managers_.end())
120 pspell_manager_add_to_personal(it->second.manager, word.word().c_str());
124 void PSpell::accept(WordLangTuple const & word)
126 Managers::iterator it = managers_.find(word.lang_code());
127 if (it != managers_.end())
128 pspell_manager_add_to_session(it->second.manager, word.word().c_str());
132 string const PSpell::nextMiss()
134 char const * str = 0;
137 str = pspell_string_emulation_next(els);
144 string const PSpell::error()
146 char const * err = 0;
148 if (spell_error_object && pspell_error_number(spell_error_object) != 0) {
149 err = pspell_error_message(spell_error_object);