3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author Kevin Atkinson
7 * \author John Levon <levon@movementarian.org>
14 #include "support/LAssert.h"
16 #define USE_ORIGINAL_MANAGER_FUNCS 1
17 // new aspell pspell missing extern "C"
19 #include <pspell/pspell.h>
23 #include "WordLangTuple.h"
25 PSpell::PSpell(BufferParams const &, string const & lang)
26 : els(0), spell_error_object(0)
37 delete_pspell_string_emulation(els);
38 Managers::iterator it = managers_.begin();
39 Managers::iterator end = managers_.end();
41 for (; it != end; ++it) {
42 delete_pspell_manager(it->second.manager);
43 delete_pspell_config(it->second.config);
48 void PSpell::cleanUp()
50 if (spell_error_object) {
51 delete_pspell_can_have_error(spell_error_object);
52 spell_error_object = 0;
57 void PSpell::addManager(string const & lang)
59 PspellConfig * config = new_pspell_config();
60 pspell_config_replace(config, "language-tag", lang.c_str());
61 PspellCanHaveError * err = new_pspell_manager(config);
62 if (spell_error_object)
63 delete_pspell_can_have_error(spell_error_object);
64 spell_error_object = 0;
66 if (pspell_error_number(err) == 0) {
68 m.manager = to_pspell_manager(err);
72 spell_error_object = err;
77 enum PSpell::Result PSpell::check(WordLangTuple const & word)
81 Managers::iterator it = managers_.find(word.lang_code());
82 if (it == managers_.end()) {
83 addManager(word.lang_code());
84 it = managers_.find(word.lang_code());
86 if (it == managers_.end())
90 PspellManager * m = it->second.manager;
92 int word_ok = pspell_manager_check(m, word.word().c_str());
93 lyx::Assert(word_ok != -1);
98 PspellWordList const * sugs =
99 pspell_manager_suggest(m, word.word().c_str());
100 lyx::Assert(sugs != 0);
101 els = pspell_word_list_elements(sugs);
102 if (pspell_word_list_empty(sugs))
113 Managers::iterator it = managers_.begin();
114 Managers::iterator end = managers_.end();
116 for (; it != end; ++it) {
117 pspell_manager_save_all_word_lists(it->second.manager);
122 void PSpell::insert(WordLangTuple const & word)
124 Managers::iterator it = managers_.find(word.lang_code());
125 if (it != managers_.end())
126 pspell_manager_add_to_personal(it->second.manager, word.word().c_str());
130 void PSpell::accept(WordLangTuple const & word)
132 Managers::iterator it = managers_.find(word.lang_code());
133 if (it != managers_.end())
134 pspell_manager_add_to_session(it->second.manager, word.word().c_str());
138 string const PSpell::nextMiss()
140 char const * str = 0;
143 str = pspell_string_emulation_next(els);
150 string const PSpell::error()
152 char const * err = 0;
154 if (spell_error_object && pspell_error_number(spell_error_object) != 0) {
155 err = pspell_error_message(spell_error_object);