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.
18 #define USE_ORIGINAL_MANAGER_FUNCS 1
19 // new aspell pspell missing extern "C"
21 #include <pspell/pspell.h>
25 #include "WordLangTuple.h"
27 #include <boost/assert.hpp>
33 PSpell::PSpell(BufferParams const &, string const & lang)
34 : els(0), spell_error_object(0)
37 lyxerr[Debug::GUI] << "created pspell" << endl;
43 lyxerr[Debug::GUI] << "killed pspell" << endl;
45 if (spell_error_object) {
46 delete_pspell_can_have_error(spell_error_object);
47 spell_error_object = 0;
51 delete_pspell_string_emulation(els);
53 Managers::iterator it = managers_.begin();
54 Managers::iterator end = managers_.end();
56 for (; it != end; ++it) {
57 pspell_manager_save_all_word_lists(it->second.manager);
58 delete_pspell_manager(it->second.manager);
59 delete_pspell_config(it->second.config);
64 void PSpell::addManager(string const & lang)
66 PspellConfig * config = new_pspell_config();
67 pspell_config_replace(config, "language-tag", lang.c_str());
68 PspellCanHaveError * err = new_pspell_manager(config);
69 if (spell_error_object)
70 delete_pspell_can_have_error(spell_error_object);
71 spell_error_object = 0;
73 if (pspell_error_number(err) == 0) {
75 m.manager = to_pspell_manager(err);
79 spell_error_object = err;
84 enum PSpell::Result PSpell::check(WordLangTuple const & word)
86 Result res = UNKNOWN_WORD;
88 Managers::iterator it = managers_.find(word.lang_code());
89 if (it == managers_.end()) {
90 addManager(word.lang_code());
91 it = managers_.find(word.lang_code());
93 if (it == managers_.end())
97 PspellManager * m = it->second.manager;
99 int word_ok = pspell_manager_check(m, word.word().c_str());
100 BOOST_ASSERT(word_ok != -1);
105 PspellWordList const * sugs =
106 pspell_manager_suggest(m, word.word().c_str());
107 BOOST_ASSERT(sugs != 0);
108 els = pspell_word_list_elements(sugs);
109 if (pspell_word_list_empty(sugs))
112 res = SUGGESTED_WORDS;
118 void PSpell::insert(WordLangTuple const & word)
120 Managers::iterator it = managers_.find(word.lang_code());
121 if (it != managers_.end())
122 pspell_manager_add_to_personal(it->second.manager, word.word().c_str());
126 void PSpell::accept(WordLangTuple const & word)
128 Managers::iterator it = managers_.find(word.lang_code());
129 if (it != managers_.end())
130 pspell_manager_add_to_session(it->second.manager, word.word().c_str());
134 string const PSpell::nextMiss()
136 char const * str = 0;
139 str = pspell_string_emulation_next(els);
146 string const PSpell::error()
148 char const * err = 0;
150 if (spell_error_object && pspell_error_number(spell_error_object) != 0) {
151 err = pspell_error_message(spell_error_object);