3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author Kevin Atkinson
7 * \author John Levon <levon@movementarian.org>
13 #pragma implementation
18 #include "support/LAssert.h"
20 #define USE_ORIGINAL_MANAGER_FUNCS 1
21 // new aspell pspell missing extern "C"
23 #include <pspell/pspell.h>
27 #include "WordLangTuple.h"
31 PSpell::PSpell(BufferParams const &, string const & lang)
32 : els(0), spell_error_object(0)
43 delete_pspell_string_emulation(els);
44 Managers::iterator it = managers_.begin();
45 Managers::iterator end = managers_.end();
47 for (; it != end; ++it) {
48 delete_pspell_manager(it->second.manager);
49 delete_pspell_config(it->second.config);
54 void PSpell::cleanUp()
56 if (spell_error_object) {
57 delete_pspell_can_have_error(spell_error_object);
58 spell_error_object = 0;
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 lyx::Assert(word_ok != -1);
104 PspellWordList const * sugs =
105 pspell_manager_suggest(m, word.word().c_str());
106 lyx::Assert(sugs != 0);
107 els = pspell_word_list_elements(sugs);
108 if (pspell_word_list_empty(sugs))
119 Managers::iterator it = managers_.begin();
120 Managers::iterator end = managers_.end();
122 for (; it != end; ++it) {
123 pspell_manager_save_all_word_lists(it->second.manager);
128 void PSpell::insert(WordLangTuple const & word)
130 Managers::iterator it = managers_.find(word.lang_code());
131 if (it != managers_.end())
132 pspell_manager_add_to_personal(it->second.manager, word.word().c_str());
136 void PSpell::accept(WordLangTuple const & word)
138 Managers::iterator it = managers_.find(word.lang_code());
139 if (it != managers_.end())
140 pspell_manager_add_to_session(it->second.manager, word.word().c_str());
144 string const PSpell::nextMiss()
146 char const * str = 0;
149 str = pspell_string_emulation_next(els);
156 string const PSpell::error()
158 char const * err = 0;
160 if (spell_error_object && pspell_error_number(spell_error_object) != 0) {
161 err = pspell_error_message(spell_error_object);