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"
26 using namespace lyx::support;
30 PSpell::PSpell(BufferParams const &, string const & lang)
31 : els(0), spell_error_object(0)
34 lyxerr[Debug::GUI] << "created pspell" << endl;
40 lyxerr[Debug::GUI] << "killed pspell" << endl;
42 if (spell_error_object) {
43 delete_pspell_can_have_error(spell_error_object);
44 spell_error_object = 0;
48 delete_pspell_string_emulation(els);
50 Managers::iterator it = managers_.begin();
51 Managers::iterator end = managers_.end();
53 for (; it != end; ++it) {
54 pspell_manager_save_all_word_lists(it->second.manager);
55 delete_pspell_manager(it->second.manager);
56 delete_pspell_config(it->second.config);
61 void PSpell::addManager(string const & lang)
63 PspellConfig * config = new_pspell_config();
64 pspell_config_replace(config, "language-tag", lang.c_str());
65 PspellCanHaveError * err = new_pspell_manager(config);
66 if (spell_error_object)
67 delete_pspell_can_have_error(spell_error_object);
68 spell_error_object = 0;
70 if (pspell_error_number(err) == 0) {
72 m.manager = to_pspell_manager(err);
76 spell_error_object = err;
81 enum PSpell::Result PSpell::check(WordLangTuple const & word)
85 Managers::iterator it = managers_.find(word.lang_code());
86 if (it == managers_.end()) {
87 addManager(word.lang_code());
88 it = managers_.find(word.lang_code());
90 if (it == managers_.end())
94 PspellManager * m = it->second.manager;
96 int word_ok = pspell_manager_check(m, word.word().c_str());
97 Assert(word_ok != -1);
102 PspellWordList const * sugs =
103 pspell_manager_suggest(m, word.word().c_str());
105 els = pspell_word_list_elements(sugs);
106 if (pspell_word_list_empty(sugs))
115 void PSpell::insert(WordLangTuple const & word)
117 Managers::iterator it = managers_.find(word.lang_code());
118 if (it != managers_.end())
119 pspell_manager_add_to_personal(it->second.manager, word.word().c_str());
123 void PSpell::accept(WordLangTuple const & word)
125 Managers::iterator it = managers_.find(word.lang_code());
126 if (it != managers_.end())
127 pspell_manager_add_to_session(it->second.manager, word.word().c_str());
131 string const PSpell::nextMiss()
133 char const * str = 0;
136 str = pspell_string_emulation_next(els);
143 string const PSpell::error()
145 char const * err = 0;
147 if (spell_error_object && pspell_error_number(spell_error_object) != 0) {
148 err = pspell_error_message(spell_error_object);