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"
17 #define USE_ORIGINAL_MANAGER_FUNCS 1
18 // new aspell pspell missing extern "C"
20 #include <pspell/pspell.h>
24 #include "WordLangTuple.h"
28 PSpell::PSpell(BufferParams const &, string const & lang)
29 : els(0), spell_error_object(0)
32 lyxerr[Debug::GUI] << "created pspell" << endl;
38 lyxerr[Debug::GUI] << "killed pspell" << endl;
40 if (spell_error_object) {
41 delete_pspell_can_have_error(spell_error_object);
42 spell_error_object = 0;
46 delete_pspell_string_emulation(els);
48 Managers::iterator it = managers_.begin();
49 Managers::iterator end = managers_.end();
51 for (; it != end; ++it) {
52 pspell_manager_save_all_word_lists(it->second.manager);
53 delete_pspell_manager(it->second.manager);
54 delete_pspell_config(it->second.config);
59 void PSpell::addManager(string const & lang)
61 PspellConfig * config = new_pspell_config();
62 pspell_config_replace(config, "language-tag", lang.c_str());
63 PspellCanHaveError * err = new_pspell_manager(config);
64 if (spell_error_object)
65 delete_pspell_can_have_error(spell_error_object);
66 spell_error_object = 0;
68 if (pspell_error_number(err) == 0) {
70 m.manager = to_pspell_manager(err);
74 spell_error_object = err;
79 enum PSpell::Result PSpell::check(WordLangTuple const & word)
83 Managers::iterator it = managers_.find(word.lang_code());
84 if (it == managers_.end()) {
85 addManager(word.lang_code());
86 it = managers_.find(word.lang_code());
88 if (it == managers_.end())
92 PspellManager * m = it->second.manager;
94 int word_ok = pspell_manager_check(m, word.word().c_str());
95 lyx::Assert(word_ok != -1);
100 PspellWordList const * sugs =
101 pspell_manager_suggest(m, word.word().c_str());
102 lyx::Assert(sugs != 0);
103 els = pspell_word_list_elements(sugs);
104 if (pspell_word_list_empty(sugs))
113 void PSpell::insert(WordLangTuple const & word)
115 Managers::iterator it = managers_.find(word.lang_code());
116 if (it != managers_.end())
117 pspell_manager_add_to_personal(it->second.manager, word.word().c_str());
121 void PSpell::accept(WordLangTuple const & word)
123 Managers::iterator it = managers_.find(word.lang_code());
124 if (it != managers_.end())
125 pspell_manager_add_to_session(it->second.manager, word.word().c_str());
129 string const PSpell::nextMiss()
131 char const * str = 0;
134 str = pspell_string_emulation_next(els);
141 string const PSpell::error()
143 char const * err = 0;
145 if (spell_error_object && pspell_error_number(spell_error_object) != 0) {
146 err = pspell_error_message(spell_error_object);