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 #include "support/LAssert.h"
19 #define USE_ORIGINAL_MANAGER_FUNCS 1
20 // new aspell pspell missing extern "C"
22 #include <pspell/pspell.h>
26 #include "WordLangTuple.h"
28 using namespace lyx::support;
32 PSpell::PSpell(BufferParams const &, string const & lang)
33 : els(0), spell_error_object(0)
36 lyxerr[Debug::GUI] << "created pspell" << endl;
42 lyxerr[Debug::GUI] << "killed pspell" << endl;
44 if (spell_error_object) {
45 delete_pspell_can_have_error(spell_error_object);
46 spell_error_object = 0;
50 delete_pspell_string_emulation(els);
52 Managers::iterator it = managers_.begin();
53 Managers::iterator end = managers_.end();
55 for (; it != end; ++it) {
56 pspell_manager_save_all_word_lists(it->second.manager);
57 delete_pspell_manager(it->second.manager);
58 delete_pspell_config(it->second.config);
63 void PSpell::addManager(string const & lang)
65 PspellConfig * config = new_pspell_config();
66 pspell_config_replace(config, "language-tag", lang.c_str());
67 PspellCanHaveError * err = new_pspell_manager(config);
68 if (spell_error_object)
69 delete_pspell_can_have_error(spell_error_object);
70 spell_error_object = 0;
72 if (pspell_error_number(err) == 0) {
74 m.manager = to_pspell_manager(err);
78 spell_error_object = err;
83 enum PSpell::Result PSpell::check(WordLangTuple const & word)
87 Managers::iterator it = managers_.find(word.lang_code());
88 if (it == managers_.end()) {
89 addManager(word.lang_code());
90 it = managers_.find(word.lang_code());
92 if (it == managers_.end())
96 PspellManager * m = it->second.manager;
98 int word_ok = pspell_manager_check(m, word.word().c_str());
99 Assert(word_ok != -1);
104 PspellWordList const * sugs =
105 pspell_manager_suggest(m, word.word().c_str());
107 els = pspell_word_list_elements(sugs);
108 if (pspell_word_list_empty(sugs))
117 void PSpell::insert(WordLangTuple const & word)
119 Managers::iterator it = managers_.find(word.lang_code());
120 if (it != managers_.end())
121 pspell_manager_add_to_personal(it->second.manager, word.word().c_str());
125 void PSpell::accept(WordLangTuple const & word)
127 Managers::iterator it = managers_.find(word.lang_code());
128 if (it != managers_.end())
129 pspell_manager_add_to_session(it->second.manager, word.word().c_str());
133 string const PSpell::nextMiss()
135 char const * str = 0;
138 str = pspell_string_emulation_next(els);
145 string const PSpell::error()
147 char const * err = 0;
149 if (spell_error_object && pspell_error_number(spell_error_object) != 0) {
150 err = pspell_error_message(spell_error_object);