]> git.lyx.org Git - lyx.git/blobdiff - src/sp_spell.C
fix typo that put too many include paths for most people
[lyx.git] / src / sp_spell.C
index ee9b546cd6cfe909506a6ac9a30cdc44e716b2de..a47903f65058f456c2b653bc1a6bfbceba6d720d 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of
- * ====================================================== 
+ * ======================================================
  *
  *           LyX, The Document Processor
  *
@@ -17,6 +17,8 @@
 #pragma implementation
 #endif
 
+#include <sys/types.h>
+#include <sys/wait.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <stdio.h>
 using std::endl;
 
 namespace {
-       /// pid for the `ispell' process. 
-       pid_t isp_pid = -1; 
+       /// 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 --------------------
 ///
@@ -74,7 +73,7 @@ extern void sigchldchecker(pid_t pid, int * status);
 #include "sp_pspell.h"
 
 
-PSpell::PSpell() 
+PSpell::PSpell()
        : sc(0), els(0), spell_error_object(0), flag(ISP_UNKNOWN),
          alive_(false)
 {
@@ -89,14 +88,14 @@ PSpell::PSpell(BufferParams const & params, string const & lang)
 }
 
 
-PSpell::~PSpell() 
+PSpell::~PSpell()
 {
        cleanUp();
        close();
        if (els)
                delete_pspell_string_emulation(els);
 }
-       
+
 
 void PSpell::initialize(BufferParams const &, string const & lang)
 {
@@ -114,7 +113,7 @@ void PSpell::initialize(BufferParams const &, string const & lang)
 }
 
 
-void PSpell::cleanUp() 
+void PSpell::cleanUp()
 {
        if (spell_error_object) {
                delete_pspell_can_have_error(spell_error_object);
@@ -138,9 +137,9 @@ enum PSpell::spellStatus PSpell::check(string const & word)
                        pspell_manager_suggest(sc, word.c_str());
                lyx::Assert(sugs != 0);
                els = pspell_word_list_elements(sugs);
-               if (pspell_word_list_empty(sugs)) 
+               if (pspell_word_list_empty(sugs))
                        flag = ISP_UNKNOWN;
-               else 
+               else
                        flag = ISP_MISSED;
        }
        return flag;
@@ -161,7 +160,7 @@ void PSpell::insert(string const & word)
 }
 
 
-void PSpell::accept(string const & word) 
+void PSpell::accept(string const & word)
 {
        if (sc)
                pspell_manager_add_to_session(sc, word.c_str());
@@ -189,11 +188,6 @@ char const * PSpell::error()
 }
 
 
-void PSpell::sigchldhandler(pid_t pid, int * status)
-{
-       sigchldchecker(pid, status);
-}
-
 #endif
 
 ///
@@ -266,8 +260,8 @@ void ISpell::initialize(BufferParams const & params, string const & lang)
                       << endl;
                goto END;
        }
-       
-       if (isp_pid == 0) {        
+
+       if (isp_pid == 0) {
                /* child process */
                dup2(pipein[0], STDIN_FILENO);
                dup2(pipeout[1], STDOUT_FILENO);
@@ -302,16 +296,16 @@ void ISpell::initialize(BufferParams const & params, string const & lang)
                } else {
                        // Report run-together words with
                        // missing blanks as errors
-                       tmp = new char[3]; 
+                       tmp = new char[3];
                        string("-B").copy(tmp, 2); tmp[2] = '\0';
-                       argv[argc++] = tmp; 
+                       argv[argc++] = tmp;
                }
                if (lyxrc.isp_use_esc_chars) {
                        // Specify additional characters that
                        // can be part of a word
                        tmp = new char[3];
                        string("-w").copy(tmp, 2); tmp[2] = '\0';
-                       argv[argc++] = tmp; 
+                       argv[argc++] = tmp;
                        // Put the escape chars in ""s
                        string tms = "\"" + lyxrc.isp_esc_chars + "\"";
                        tmp = new char[tms.length() + 1];
@@ -353,7 +347,7 @@ void ISpell::initialize(BufferParams const & params, string const & lang)
                // setup of argv
                for (int i = 0; i < argc - 1; ++i)
                        delete[] argv[i];
-               
+
                lyxerr << "LyX: Failed to start ispell!" << endl;
                _exit(0);
        }
@@ -374,17 +368,17 @@ void ISpell::initialize(BufferParams const & params, string const & lang)
 
                // Configure provides us with macros which are supposed to do
                // the right typecast.
-               retval = select(SELECT_TYPE_ARG1 (pipeout[0]+1), 
-                               SELECT_TYPE_ARG234 (&infds), 
-                               0, 
-                               0, 
+               retval = select(SELECT_TYPE_ARG1 (pipeout[0]+1),
+                               SELECT_TYPE_ARG234 (&infds),
+                               0,
+                               0,
                                SELECT_TYPE_ARG5 (&tv));
 
                if (retval > 0) {
                        // Ok, do the reading. We don't have to FD_ISSET since
                        // there is only one fd in infds.
                        fgets(buf, 2048, in);
-               
+
                        // determine if the spell checker is really Aspell
                        if (strstr(buf, "Aspell"))
                                actual_spell_checker = ASC_ASPELL;
@@ -393,7 +387,7 @@ void ISpell::initialize(BufferParams const & params, string const & lang)
 
                        fputs("!\n", out); // Set terse mode (silently accept correct words)
 
-               
+
                } else if (retval == 0) {
                        // timeout. Give nice message to user.
                        lyxerr << "Ispell read timed out, what now?" << endl;
@@ -411,26 +405,40 @@ void ISpell::initialize(BufferParams const & params, string const & lang)
        }
   END:
        if (isp_pid == -1) {
-               error_ = 
+               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;
        }
 }
 
 
+/* FIXME: this is a minimalist solution until the above
+ * code is able to work with forkedcall.h. We only need
+ * to reap the zombies here.
+ */
+void reapSpellchecker(void)
+{
+       if (isp_pid == -1)
+               return;
+
+       waitpid(isp_pid, 0, WNOHANG);
+}
+
+
 bool ISpell::alive()
 {
        return isp_pid != -1;
 }
 
 
-void ISpell::cleanUp() 
+void ISpell::cleanUp()
 {
        ::fclose(out);
 }
@@ -442,12 +450,12 @@ enum ISpell::spellStatus ISpell::check(string const & word)
 
        ::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 
+       // the signal-handler could have disabled blocking on the fd
        if (!alive()) return ISP_UNKNOWN;
 
        switch (*buf) {
@@ -490,8 +498,8 @@ 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 
+       // 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)
 
@@ -510,7 +518,7 @@ void ISpell::insert(string const & word)
 }
 
 
-void ISpell::accept(string const & word) 
+void ISpell::accept(string const & word)
 {
        ::fputc('@', out); // Accept in this session
        ::fputs(word.c_str(), out);
@@ -530,20 +538,6 @@ void ISpell::store(string const & mis, string const & cor)
 }
 
 
-void ISpell::sigchldhandler(pid_t pid, int * status)
-{
-       if (isp_pid > 0) {
-               if (pid == isp_pid) {
-                       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_;