X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fspellchecker.C;h=81153c61e0a01bbc0b1fef0ff59f4055e07f8c2a;hb=2b300d130c21037e9ae9cb547024be53111d2014;hp=3a36462599f9be0e5f4dd915470833dcaa56f594;hpb=a826cf25b505954920ee6ef72ab0f4b94107fb79;p=lyx.git diff --git a/src/spellchecker.C b/src/spellchecker.C index 3a36462599..81153c61e0 100644 --- a/src/spellchecker.C +++ b/src/spellchecker.C @@ -58,7 +58,9 @@ #include "lyx_gui_misc.h" #include "debug.h" #include "support/lstrings.h" +#include "language.h" #include "encoding.h" +#include "support/lstrings.h" //#define USE_PSPELL 1 @@ -486,27 +488,26 @@ bool sc_still_alive() { static void sc_clean_up_after_error() { - fclose(out); + ::fclose(out); } // Send word to ispell and get reply static -isp_result * sc_check_word(char *word) +isp_result * sc_check_word(string const & word) { //Please rewrite to use string. - isp_result *result; - char buf[1024]; - fputs(word, out); - fputc('\n', out); + ::fputs(word.c_str(), out); + ::fputc('\n', out); - fgets(buf, 1024, in); + char buf[1024]; + ::fgets(buf, 1024, in); /* I think we have to check if ispell is still alive here because the signal-handler could have disabled blocking on the fd */ - if (isp_pid == -1) return 0; + if (!sc_still_alive()) return 0; - result = new isp_result; + isp_result * result = new isp_result; switch (*buf) { case '*': // Word found @@ -562,30 +563,30 @@ void close_spell_checker() static inline -void sc_insert_word(char const *word) +void sc_insert_word(string const & word) { - fputc('*', out); // Insert word in personal dictionary - fputs(word, out); - fputc('\n', out); + ::fputc('*', out); // Insert word in personal dictionary + ::fputs(word.c_str(), out); + ::fputc('\n', out); } static inline -void sc_accept_word(char const *word) +void sc_accept_word(string const & word) { - fputc('@', out); // Accept in this session - fputs(word, out); - fputc('\n', out); + ::fputc('@', out); // Accept in this session + ::fputs(word.c_str(), out); + ::fputc('\n', out); } static inline -void sc_store_replacement(char const *mis, string const & cor) { +void sc_store_replacement(string const & mis, string const & cor) { if(actual_spell_checker == ASC_ASPELL) { - fputs("$$ra ", out); - fputs(mis, out); - fputc(',', out); - fputs(cor.c_str(), out); - fputc('\n', out); + ::fputs("$$ra ", out); + ::fputs(mis.c_str(), out); + ::fputc(',', out); + ::fputs(cor.c_str(), out); + ::fputc('\n', out); } } @@ -597,6 +598,9 @@ static void init_spell_checker(BufferParams const &, string const & lang) { PspellConfig * config = new_pspell_config(); + string code; + split(lang, code, '_'); + config->replace("language-tag", code.c_str()); spell_error_object = new_pspell_manager(config); if (pspell_error_number(spell_error_object) != 0) { spell_error = pspell_error_message(spell_error_object); @@ -622,26 +626,24 @@ void sc_clean_up_after_error() // Send word to ispell and get reply static -isp_result * sc_check_word(char *word) +isp_result * sc_check_word(string const & word) { isp_result * result = new isp_result; - int word_ok = pspell_manager_check(sc, word); - assert(word_ok != -1); +#warning Why isnt word_ok a bool? (Lgb) + int word_ok = pspell_manager_check(sc, word.c_str()); + Assert(word_ok != -1); if (word_ok) { - result->flag = ISP_OK; - } else { - - const PspellWordList * sugs = pspell_manager_suggest(sc, word); - assert(sugs != 0); + PspellWordList const * sugs = + pspell_manager_suggest(sc, word.c_str()); + Assert(sugs != 0); result->els = pspell_word_list_elements(sugs); if (pspell_word_list_empty(sugs)) result->flag = ISP_UNKNOWN; else result->flag = ISP_MISSED; - } return result; } @@ -653,22 +655,25 @@ void close_spell_checker() pspell_manager_save_all_word_lists(sc); } + static inline -void sc_insert_word(char const *word) +void sc_insert_word(string const & word) { - pspell_manager_add_to_personal(sc, word); + pspell_manager_add_to_personal(sc, word.c_str()); } static inline -void sc_accept_word(char const *word) +void sc_accept_word(string const & word) { - pspell_manager_add_to_session(sc, word); + pspell_manager_add_to_session(sc, word.c_str()); } + static inline -void sc_store_replacement(char const *mis, string const & cor) { - pspell_manager_store_replacement(sc, mis, cor.c_str()); +void sc_store_replacement(string const & mis, string const & cor) +{ + pspell_manager_store_replacement(sc, mis.c_str(), cor.c_str()); } #endif @@ -722,12 +727,12 @@ void ShowSpellChecker(BufferView * bv) fl_set_object_lcol(fd_form_spell_check->input, FL_INACTIVE); fl_set_object_lcol(fd_form_spell_check->browser, FL_INACTIVE); - while (true){ + while (true) { obj = fl_do_forms(); - if (obj == fd_form_spell_check->options){ + if (obj == fd_form_spell_check->options) { SpellCheckerOptions(); } - if (obj == fd_form_spell_check->start){ + if (obj == fd_form_spell_check->start) { // activate insert, accept, and stop fl_activate_object(fd_form_spell_check->insert); fl_activate_object(fd_form_spell_check->accept); @@ -788,7 +793,7 @@ void ShowSpellChecker(BufferView * bv) } -// Perform an ispell session +// Perform a spell session static bool RunSpellChecker(BufferView * bv) { @@ -796,8 +801,22 @@ bool RunSpellChecker(BufferView * bv) int newvalue; FL_OBJECT * obj; - string tmp = (lyxrc.isp_use_alt_lang) ? lyxrc.isp_alt_lang : bv->buffer()->GetLanguage(); - bool rtl = tmp == "hebrew" || tmp == "arabic"; +#ifdef USE_PSPELL + string tmp = (lyxrc.isp_use_alt_lang) ? + lyxrc.isp_alt_lang : bv->buffer()->params.language_info->code(); +#else + string tmp = (lyxrc.isp_use_alt_lang) ? + lyxrc.isp_alt_lang : bv->buffer()->GetLanguage(); +#endif +#warning This is not good we should find a way to identify a rtl-language in a more general way. Please have a look Dekel! (Jug) +// For now I'll change this to a bit more general solution but +// Please comment on this if you don't like it. We probaly need +// anoter flag something like lyxrc.isp_use_alt_lang_rtl (true/false)! + bool rtl; + if (lyxrc.isp_use_alt_lang) + rtl = (tmp == "hebrew" || tmp == "arabic"); + else + rtl = bv->buffer()->params.language_info->RightToLeft(); int oldval = 0; /* used for updating slider only when needed */ float newval = 0.0; @@ -814,8 +833,8 @@ bool RunSpellChecker(BufferView * bv) unsigned int word_count = 0; while (true) { - char * word = bv->nextWord(newval); - if (word == 0) break; + string const word = bv->nextWord(newval); + if (word.empty()) break; ++word_count; // Update slider if and only if value has changed @@ -828,12 +847,10 @@ bool RunSpellChecker(BufferView * bv) if (word_count%1000 == 0) { obj = fl_check_forms(); if (obj == fd_form_spell_check->stop) { - delete[] word; close_spell_checker(); return true; } if (obj == fd_form_spell_check->done) { - delete[] word; close_spell_checker(); return false; } @@ -842,7 +859,6 @@ bool RunSpellChecker(BufferView * bv) result = sc_check_word(word); if (!sc_still_alive()) { delete result; - delete[] word; break; } @@ -856,8 +872,8 @@ bool RunSpellChecker(BufferView * bv) reverse(tmp.begin(),tmp.end()); fl_set_object_label(fd_form_spell_check->text, tmp.c_str()); } else - fl_set_object_label(fd_form_spell_check->text, word); - fl_set_input(fd_form_spell_check->input, word); + fl_set_object_label(fd_form_spell_check->text, word.c_str()); + fl_set_input(fd_form_spell_check->input, word.c_str()); fl_clear_browser(fd_form_spell_check->browser); const char * w; while ((w = result->next_miss()) != 0) { @@ -913,14 +929,12 @@ bool RunSpellChecker(BufferView * bv) } if (obj == fd_form_spell_check->stop) { delete result; - delete[] word; close_spell_checker(); return true; } if (obj == fd_form_spell_check->done) { delete result; - delete[] word; close_spell_checker(); return false; } @@ -928,7 +942,6 @@ bool RunSpellChecker(BufferView * bv) } default: delete result; - delete[] word; } }