]> git.lyx.org Git - features.git/blobdiff - src/spellchecker.C
Dekel language/encoding patch + a few fixes
[features.git] / src / spellchecker.C
index 6783f2989ea4950c15c53468b69f8965233baf0c..fa208ce3637a4c23a1e9fa0ffb014bfea7648986 100644 (file)
 #ifdef HAVE_SYS_SELECT_H
 # ifdef HAVE_STRINGS_H
    // <strings.h> is needed at least on AIX because FD_ZERO uses bzero().
-# include <strings.h> 
+   // BUT we cannot include both string.h and strings.h on Irix 6.5 :(
+#  ifdef _AIX
+#   include <strings.h>
+#  endif
 # endif
 #include <sys/select.h>
 #endif
@@ -58,7 +61,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
 
@@ -390,7 +395,7 @@ void init_spell_checker(BufferParams const & params, string const & lang)
                if (lyxrc.isp_use_input_encoding &&
                    params.inputenc != "default") {
                        string enc = (params.inputenc == "auto")
-                               ? params.language_info->encoding()->LatexName()
+                               ? params.language->encoding()->LatexName()
                                : params.inputenc;
                        string::size_type n = enc.length();
                        tmp = new char[3];
@@ -486,7 +491,7 @@ bool sc_still_alive() {
 static
 void sc_clean_up_after_error() 
 {
-       fclose(out);
+       ::fclose(out);
 }
 
 // Send word to ispell and get reply
@@ -495,11 +500,11 @@ isp_result * sc_check_word(string const & word)
 {
        //Please rewrite to use string.
 
-       fputs(word.c_str(), out);
-       fputc('\n', out);
+       ::fputs(word.c_str(), out);
+       ::fputc('\n', out);
   
        char buf[1024];
-       fgets(buf, 1024, in); 
+       ::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 */
@@ -563,28 +568,28 @@ void close_spell_checker()
 static inline 
 void sc_insert_word(string const & word)
 {
-       fputc('*', out); // Insert word in personal dictionary
-       fputs(word.c_str(), 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(string const & word) 
 {
-       fputc('@', out); // Accept in this session
-       fputs(word.c_str(), out);
-       fputc('\n', out);
+       ::fputc('@', out); // Accept in this session
+       ::fputs(word.c_str(), out);
+       ::fputc('\n', out);
 }
 
 static inline
 void sc_store_replacement(string const & mis, string const & cor) {
         if(actual_spell_checker == ASC_ASPELL) {
-                fputs("$$ra ", out);
-                fputs(mis.c_str(), 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);
         }
 }
 
@@ -596,6 +601,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);
@@ -624,14 +632,15 @@ static
 isp_result * sc_check_word(string const & word)
 {
        isp_result * result = new isp_result;
-       int word_ok = pspell_manager_check(sc, word);
+#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 {
-
-               PspellWordList const * sugs = pspell_manager_suggest(sc, word);
+               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)) 
@@ -653,14 +662,14 @@ void close_spell_checker()
 static inline 
 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(string const & word) 
 {
-       pspell_manager_add_to_session(sc, word);
+       pspell_manager_add_to_session(sc, word.c_str());
 }
 
 
@@ -721,12 +730,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);
@@ -787,7 +796,7 @@ void ShowSpellChecker(BufferView * bv)
 }
 
 
-// Perform an ispell session
+// Perform a spell session
 static
 bool RunSpellChecker(BufferView * bv)
 {
@@ -795,8 +804,20 @@ 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->code();
+#else
+       string tmp = (lyxrc.isp_use_alt_lang) ?
+           lyxrc.isp_alt_lang : bv->buffer()->params.language->lang();
+#endif
+       bool rtl = false;
+       if (lyxrc.isp_use_alt_lang) {
+               Language const * lang = languages.getLanguage(tmp);
+               if (lang)
+                       rtl = lang->RightToLeft();
+       } else
+           rtl = bv->buffer()->params.language->RightToLeft();
 
        int oldval = 0;  /* used for updating slider only when needed */
        float newval = 0.0;