diff --git a/golded3/gecfgg.h b/golded3/gecfgg.h index 4088808..5a652a0 100644 --- a/golded3/gecfgg.h +++ b/golded3/gecfgg.h @@ -402,7 +402,7 @@ public: gstrarray robotname; #if defined(GCFG_SPELL_INCLUDED) int scheckerenabled; - char scheckerdeflang[100]; + char scheckerdeflang[10240]; Path scheckeruserdic; Path scheckerdicpath; #endif diff --git a/golded3/geedit.cpp b/golded3/geedit.cpp index e86a410..e2a1960 100644 --- a/golded3/geedit.cpp +++ b/golded3/geedit.cpp @@ -2094,7 +2094,7 @@ void IEclass::SaveMsg() { #if defined(GCFG_SPELL_INCLUDED) void IEclass::SCheckerMenu() { - if (!schecker.IsLoaded()) + if (!schecker.IsInited()) return; const char *txt = currline->txt.c_str(); @@ -2852,7 +2852,15 @@ int IEclass::Start(int __mode, uint* __position, GMsg* __msg) { if (CFG->scheckerenabled) { schecker.Init(CFG->xlatlocalset, CFG->scheckerdicpath); - schecker.Load(AA->adat->scheckerdeflang, CFG->scheckeruserdic); + char str[sizeof(AA->adat->scheckerdeflang)]; + strncpy(str, AA->adat->scheckerdeflang, sizeof(str)); + char *token = strtok(str, " "); + while(token != NULL) + { + schecker.Load(token, CFG->scheckeruserdic); + /* Get next token: */ + token = strtok(NULL, " "); + } } #endif diff --git a/golded3/gemnus.cpp b/golded3/gemnus.cpp index f44548c..d759aef 100644 --- a/golded3/gemnus.cpp +++ b/golded3/gemnus.cpp @@ -1113,7 +1113,7 @@ int GMenuSChecker::Run(CSpellChecker &schecker, const char *word) size_t numrows = 7; CSpellLangV &langs = schecker.GetLangs(); - const char *lcode = schecker.GetLangCode(); + std::vector lcodes = schecker.GetLangCodes(); std::vector langstr; size_t langcount = langs.size(); @@ -1126,7 +1126,19 @@ int GMenuSChecker::Run(CSpellChecker &schecker, const char *word) const char *code = langs[idx]->GetLangCode(); std::string buff = " "; - buff += streql(lcode, code) ? '\x10' : ' '; + + bool loaded = false; + std::vector::iterator langit; + for (langit = lcodes.begin(); langit != lcodes.end(); langit++) + { + if (streql(*langit, code)) + { + loaded = true; + break; + } + } + + buff += loaded ? '\x10' : ' '; #if !(defined(GCFG_NO_MSSPELL) || defined(GCFG_NO_MYSPELL)) if (type == SCHECKET_TYPE_MSSPELL) @@ -1224,7 +1236,14 @@ int GMenuSChecker::Run(CSpellChecker &schecker, const char *word) } else if ((finaltag > TAG_LANG) && (finaltag < TAG_MORE)) { - schecker.Load(langs[finaltag-TAG_LANG-1]->GetLangCode(), CFG->scheckeruserdic); + if (!schecker.IsLoaded(langs[finaltag-TAG_LANG-1]->GetLangCode())) + { + schecker.Load(langs[finaltag-TAG_LANG-1]->GetLangCode(), CFG->scheckeruserdic); + } + else + { + schecker.UnLoad(langs[finaltag-TAG_LANG-1]->GetLangCode()); + } return -2; } diff --git a/golded3/gmarea.h b/golded3/gmarea.h index a388e61..108c9da 100644 --- a/golded3/gmarea.h +++ b/golded3/gmarea.h @@ -384,7 +384,7 @@ struct AreaData GPlay play; int replyre; #if defined(GCFG_SPELL_INCLUDED) - char scheckerdeflang[100]; + char scheckerdeflang[10240]; #endif char tagline[76]; char taglinechar; diff --git a/goldlib/gall/gespell.cpp b/goldlib/gall/gespell.cpp index cace3b0..ea96f47 100644 --- a/goldlib/gall/gespell.cpp +++ b/goldlib/gall/gespell.cpp @@ -583,7 +583,6 @@ void CSpellLang::RecodeText(const char *srcText, char *dstText, bool flag) CSpellChecker::CSpellChecker() { mInited = false; - mLang = NULL; mText[0] = 0; } @@ -671,20 +670,22 @@ bool CSpellChecker::Load(const char *langId, const char *userDic) { if (!IsInited()) return false; - if (IsLoaded() && streql(mLang->GetLangCode(), langId)) return true; + if (IsLoaded(langId)) + { + return true; + } CSpellLangV::iterator it; for (it = mLangs.begin(); it != mLangs.end(); it++) { if (streql((*it)->GetLangCode(), langId) && (*it)->Load(mXlatLocalset, userDic)) { - UnLoad(); - mLang = *it; - break; + mLangsLoaded.push_back(*it); + return true; } } - return IsLoaded(); + return false; } @@ -693,8 +694,32 @@ bool CSpellChecker::Load(const char *langId, const char *userDic) void CSpellChecker::UnLoad() { if (!IsLoaded()) return; - mLang->UnLoad(); - mLang = NULL; + + CSpellLangV::iterator it; + for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++) + { + (*it)->UnLoad(); + } + mLangsLoaded.clear(); +} + + +// ------------------------------------------------------------------ + +void CSpellChecker::UnLoad(const char *langId) +{ + if (!IsLoaded()) return; + + CSpellLangV::iterator it; + for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++) + { + if (streql((*it)->GetLangCode(), langId)) + { + (*it)->UnLoad(); + mLangsLoaded.erase(it); + return; + } + } } @@ -704,8 +729,16 @@ bool CSpellChecker::Check(const char *text) { if (!IsLoaded()) return true; - mLang->RecodeText(text, mText, true); - return mLang->SpellCheck(mText); + CSpellLangV::iterator it; + for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++) + { + (*it)->RecodeText(text, mText, true); + if ((*it)->SpellCheck(mText)) + { + return true; + } + } + return false; } @@ -716,12 +749,110 @@ CSpellSuggestV &CSpellChecker::Suggest() mSuggest.clear(); if (!IsLoaded()) return mSuggest; - mLang->BuildSuggest(mText, mSuggest); + CSpellSuggestV allSuggests; + + CSpellLangV::iterator it; + for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++) + { + (*it)->BuildSuggest(mText, allSuggests); + } + + CSpellSuggestV::iterator all; + for (all = allSuggests.begin(); all != allSuggests.end(); all++) + { + CSpellSuggestV::iterator distinct; + bool exists = false; + for (distinct = mSuggest.begin(); distinct != mSuggest.end(); distinct++) + { + if ((*distinct).second.compare((*all).second) == 0) + { + exists = true; + break; + } + } + + if (!exists) + { + mSuggest.push_back(*all); + } + } return mSuggest; } +// ------------------------------------------------------------------ + +bool CSpellChecker::AddWord() +{ + if (IsLoaded()) + { + CSpellLangV::iterator it; + for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++) + { + if ((*it)->GetSpellType() == SCHECKET_TYPE_MSSPELL) + { + return (*it)->AddWord(mText); + } + } + } + + return false; +} + + +// ------------------------------------------------------------------ + +const std::vector CSpellChecker::GetLangCodes() +{ + std::vector codes; + + CSpellLangV::iterator it; + for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++) + { + codes.push_back((*it)->GetLangCode()); + } + return codes; +} + + +// ------------------------------------------------------------------ + +bool CSpellChecker::IsUdrLoaded() +{ + if (IsLoaded()) + { + CSpellLangV::iterator it; + for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++) + { + if ((*it)->GetSpellType() == SCHECKET_TYPE_MSSPELL) + { + return (*it)->IsUdrLoaded(); + } + } + } + + return false; +} + + +// ------------------------------------------------------------------ + +bool CSpellChecker::IsLoaded(const char *langId) +{ + CSpellLangV::iterator it; + for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++) + { + if (streql((*it)->GetLangCode(), langId)) + { + return true; + } + } + + return false; +} + + // ------------------------------------------------------------------ #if !defined(GCFG_NO_MSSPELL) diff --git a/goldlib/gall/gespell.h b/goldlib/gall/gespell.h index 5488804..b257dad 100644 --- a/goldlib/gall/gespell.h +++ b/goldlib/gall/gespell.h @@ -291,7 +291,7 @@ private: char mXlatLocalset[256]; - CSpellLang *mLang; + CSpellLangV mLangsLoaded; CSpellLangV mLangs; CSpellSuggestV mSuggest; @@ -303,22 +303,25 @@ public: void Close(); bool Load(const char *langId, const char *userDic); + void UnLoad(const char *langId); void UnLoad(); bool Check(const char *text); CSpellSuggestV &Suggest(); bool Check(std::string &text) { return Check(text.c_str()); } - bool AddWord() { return IsLoaded() ? mLang->AddWord(mText) : false; }; + bool AddWord(); CSpellSuggestV &GetSuggest() { return mSuggest; } CSpellLangV &GetLangs() { return mLangs; } + CSpellLangV &GetLangsLoaded() { return mLangsLoaded; } + const std::vector GetLangCodes(); - const char *GetLangCode() { return IsLoaded() ? mLang->GetLangCode() : "?*N/A*?"; } - bool IsUdrLoaded() { return IsLoaded() ? mLang->IsUdrLoaded() : false; } + bool IsUdrLoaded(); bool IsInited() { return mInited; } - bool IsLoaded() { return mLang != NULL; } + bool IsLoaded() { return !mLangsLoaded.empty(); } + bool IsLoaded(const char *langId); };