]> git.lyx.org Git - lyx.git/blobdiff - src/sp_spell.C
More ascii-export fixes and when making copy of single tabular cells now the
[lyx.git] / src / sp_spell.C
index e10adc3f5134e2d7cd4861df7af9d3f27207a461..67c3af6e3d26974d3b162de40792f282bae8b7d8 100644 (file)
 #pragma implementation
 #endif
 
-#ifdef USE_PSPELL
-
 #include <unistd.h>
 #include <fcntl.h>
 #include <stdio.h>
 
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <ctime>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <ctime>
+# endif
+#endif
+
 #ifdef HAVE_SYS_SELECT_H
 # ifdef HAVE_STRINGS_H
    // <strings.h> is needed at least on AIX because FD_ZERO uses bzero().
 
 #include "LString.h"
 #include "support/lstrings.h"
+#include "lyxrc.h"
+#include "language.h"
+#include "debug.h"
+#include "encoding.h"
+#include "sp_ispell.h"
+
+using std::endl;
+
+namespace {
+       /// pid for the `ispell' process. 
+       pid_t isp_pid = -1; 
+}
+
+/// can be found in src/insets/figinset.C
+extern void sigchldchecker(pid_t pid, int * status);
+
+///
+// ------------------- start special pspell code/class --------------------
+///
+#ifdef USE_PSPELL
+
 #include "support/LAssert.h"
 
 #define USE_ORIGINAL_MANAGER_FUNCS 1
 
 #include "sp_pspell.h"
 
-extern void sigchldchecker(pid_t pid, int *status);
-
 
 PSpell::PSpell() 
+       : sc(0), els(0), spell_error_object(0), flag(ISP_UNKNOWN),
+         alive_(false)
 {
-       els = 0;
-       sc = 0;
-       spell_error_object = 0;
-       flag = ISP_UNKNOWN;
 }
 
+
 PSpell::PSpell(BufferParams const & params, string const & lang)
+       : sc(0), els(0), spell_error_object(0), flag(ISP_UNKNOWN),
+         alive_(false)
 {
-       els = 0;
-       sc = 0;
-       spell_error_object = 0;
-       flag = ISP_UNKNOWN;
        initialize(params, lang);
 }
 
+
 PSpell::~PSpell() 
 {
        cleanUp();
@@ -75,9 +101,7 @@ PSpell::~PSpell()
 void PSpell::initialize(BufferParams const &, string const & lang)
 {
        PspellConfig * config = new_pspell_config();
-       string code;
-       split(lang, code, '_');
-       config->replace("language-tag", code.c_str());
+       config->replace("language-tag", lang.c_str());
        spell_error_object = new_pspell_manager(config);
        if (pspell_error_number(spell_error_object) != 0) {
                error_ = pspell_error_message(spell_error_object);
@@ -85,6 +109,7 @@ void PSpell::initialize(BufferParams const &, string const & lang)
                error_ = 0;
                sc = to_pspell_manager(spell_error_object);
                spell_error_object = 0;
+               alive_ = true;
        }
 }
 
@@ -154,89 +179,35 @@ char const * PSpell::nextMiss()
 {
        if (els)
                return pspell_string_emulation_next(els);
+       return "";
 }
 
+
 char const * PSpell::error()
 {
        return error_;
 }
 
+
 void PSpell::sigchldhandler(pid_t pid, int * status)
 {
        sigchldchecker(pid, status);
 }
 
-
-
-#else
-
-/*
- *This file is part of
- * ====================================================== 
- * 
- *           LyX, The Document Processor
- *      
- *         Copyright 1995 Matthias Ettrich
- *          Copyright 1995-1998 The LyX Team
- *
- * ====================================================== 
- */
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdio.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <ctime>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <ctime>
-# endif
 #endif
 
-#ifdef HAVE_SYS_SELECT_H
-# ifdef HAVE_STRINGS_H
-   // <strings.h> is needed at least on AIX because FD_ZERO uses bzero().
-   // 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
-
-#include "LString.h"
-#include "support/lstrings.h"
-#include "lyxrc.h"
-#include "debug.h"
-#include "encoding.h"
-#include "sp_ispell.h"
-
-using std::endl;
-
-/// can be found in src/insets/figinset.C
-extern void sigchldchecker(pid_t pid, int * status);
-
-namespace {
-/// pid for the `ispell' process. 
-pid_t isp_pid = -1; 
-}
-
+///
+// ------------------- start special ispell code/class --------------------
+///
 
 ISpell::ISpell()
-{
-       str = 0;
-       flag = ISP_UNKNOWN;
-}
+       : str(0), flag(ISP_UNKNOWN)
+{}
 
 
 ISpell::ISpell(BufferParams const & params, string const & lang)
+       : str(0), flag(ISP_UNKNOWN)
 {
-       str = 0;
-       flag = ISP_UNKNOWN;
        initialize(params, lang);
 }
 
@@ -260,7 +231,8 @@ char const * ISpell::nextMiss()
 void ISpell::initialize(BufferParams const & params, string const & lang)
 {
        static char o_buf[BUFSIZ];  // jc: it could be smaller
-       int pipein[2], pipeout[2];
+       int pipein[2];
+       int pipeout[2];
        char * argv[14];
        int argc;
 
@@ -364,7 +336,8 @@ void ISpell::initialize(BufferParams const & params, string const & lang)
                                : params.inputenc;
                        string::size_type n = enc.length();
                        tmp = new char[3];
-                       string("-T").copy(tmp, 2); tmp[2] = '\0';
+                       string("-T").copy(tmp, 2);
+                       tmp[2] = '\0';
                        argv[argc++] = tmp; // Input encoding
                        tmp = new char[n + 1];
                        enc.copy(tmp, n);
@@ -378,7 +351,7 @@ void ISpell::initialize(BufferParams const & params, string const & lang)
 
                // free the memory used by string::copy in the
                // setup of argv
-               for (int i= 0; i < argc -1; ++i)
+               for (int i = 0; i < argc - 1; ++i)
                        delete[] argv[i];
                
                lyxerr << "LyX: Failed to start ispell!" << endl;
@@ -440,11 +413,12 @@ void ISpell::initialize(BufferParams const & params, string const & lang)
        if (isp_pid == -1) {
                error_ = 
                        "\n\n"
-                       "The ispell-process has died for some reason. *One* possible reason\n"
-                       "could be that you do not have a dictionary file\n"
-                       "for the language of this document installed.\n"
-                       "Check /usr/lib/ispell or set another\n"
-                       "dictionary in the Spellchecker Options menu.";
+                       "The spellcheck-process has died for some reason.\n"
+                       "*One* possible reason could be that you do not have\n"
+                       "a dictionary file for the language of this document\n"
+                       "installed.\n"
+                       "Check your spellchecker or set another dictionary\n"
+                       "in the Spellchecker Options menu.\n\n";
        } else {
                error_ = 0;
        }
@@ -473,8 +447,8 @@ enum ISpell::spellStatus ISpell::check(string const & word)
        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 */
+       // I think we have to check if ispell is still alive here because
+       // the signal-handler could have disabled blocking on the fd 
        if (!alive()) return ISP_UNKNOWN;
 
        switch (*buf) {
@@ -517,10 +491,10 @@ enum ISpell::spellStatus ISpell::check(string const & word)
 
 void ISpell::close()
 {
-        // Note: If you decide to optimize this out when it is not 
-        // needed please note that when Aspell is used this command 
-        // is also needed to save the replacement dictionary.
-        // -- Kevin Atkinson (kevinatk@home.com)
+       // Note: If you decide to optimize this out when it is not 
+       // needed please note that when Aspell is used this command 
+       // is also needed to save the replacement dictionary.
+       // -- Kevin Atkinson (kevinatk@home.com)
 
        fputs("#\n", out); // Save personal dictionary
 
@@ -547,13 +521,13 @@ void ISpell::accept(string const & word)
 
 void ISpell::store(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);
-        }
+       if (actual_spell_checker == ASC_ASPELL) {
+               ::fputs("$$ra ", out);
+               ::fputs(mis.c_str(), out);
+               ::fputc(',', out);
+               ::fputs(cor.c_str(), out);
+               ::fputc('\n', out);
+       }
 }
 
 
@@ -561,20 +535,17 @@ void ISpell::sigchldhandler(pid_t pid, int * status)
 {
        if (isp_pid > 0) {
                if (pid == isp_pid) {
-                       isp_pid= -1;
-                       fcntl(isp_fd, F_SETFL, O_NONBLOCK); /* set the file descriptor
-                                                              to nonblocking so we can 
-                                                              continue */
+                       isp_pid = -1;
+                       // set the file descriptor to nonblocking so we can
+                       // continue 
+                       fcntl(isp_fd, F_SETFL, O_NONBLOCK);
                }
        }
        sigchldchecker(pid, status);
 }
 
+
 char const * ISpell::error()
 {
        return error_;
 }
-
-
-
-#endif