[prev in list] [next in list] [prev in thread] [next in thread] 

List:       klyx
Subject:    KLyx: spell as you type context diffs
From:       "Sam O'Connor" <samoc () netspace ! net ! au>
Date:       1998-11-13 11:57:34
[Download RAW message or body]

Jochen gave me some help on creating a context diff.
So here it is.
This version doesn't seg fault as much as the pervious one either.
Sam
["diff" (text/plain)]

============================================================
diff for text.C:
============================================================
*** klyx-0.9.8a/src/text.C	Mon Jul 20 07:03:03 1998
--- klyx-0.9.8a.hack/src/text.C	Fri Nov 13 22:40:10 1998
***************
*** 11,16 ****
--- 11,19 ----
  #include <config.h>
  #include <stdlib.h>
  #include <ctype.h>
+ //sam's hack
+ #include "spellchecker.h"
+ //endsam
  
  #include <kapp.h>
  #include <klocale.h>
***************
*** 1390,1395 ****
--- 1393,1403 ----
     if (cursor.pos < cursor.par->Last()
         && cursor.par->IsLineSeparator(cursor.pos))
       cursor.pos++;
+ 
+ //sam's hack
+    if (cursor.pos && cursor.par->IsLetter(cursor.pos-1))
+ 	   QuickSpellPreviousWord();
+ //samend
     
     /* break the paragraph */
     if (keep_layout)
***************
*** 2230,2235 ****
--- 2238,2246 ----
  	LyXFont rawtmpfont;
  	int lastpos;
  	LyXFont rawparfont;
+ //sam's hack
+ 	int sam_end_of_word=0;
+ //endsam
     
  	SetUndo(Undo::INSERT, 
  		cursor.par->ParFromPos(cursor.pos)->previous, 
***************
*** 2279,2284 ****
--- 2290,2298 ----
  	jumped_over_space = false;
     
  	if (IsLineSeparatorChar(c)) {
+ //sam's hack
+ 		sam_end_of_word = 1;
+ //endsam
  	   
  		if (cursor.pos < lastpos
  		    && cursor.par->IsLineSeparator(cursor.pos)) {
***************
*** 2329,2335 ****
--- 2343,2359 ----
  		    cursor.par->IsLineSeparator(cursor.pos))
  			CursorRightIntern(); // newline always after a blank!
  		cursor.row->fill = -1;	       // to force a new break
+ //sam's hack
+ 		if (cursor.pos && cursor.par->IsLetter(cursor.pos-1))
+ 			sam_end_of_word = 1;
+ //endsam
  	}
+ 
+ //sam's hack
+ 		if(sam_end_of_word) {
+ 			QuickSpellPreviousWord();
+ 		}
+ //endsam
     
  	/* the display inset stuff */ 
  	if (cursor.row->par->GetChar(cursor.row->pos) == LYX_META_INSET
***************
*** 2802,2807 ****
--- 2826,2861 ----
  	/* finally set the selection */ 
  	SetSelection();
  }
+ 
+ 
+ //sam's hack
+ void LyXText::QuickSpellPreviousWord()
+ {
+ 	int wordend = cursor.pos;
+ 	int wordstart = cursor.pos;
+ 
+ 	//find the start of the word
+ 	while (wordstart && cursor.par->IsLetter(wordstart-1)) {
+ 		wordstart--;
+ 	}
+ 	//if we have a word put it in a buffer
+ 	if (wordstart < wordend) {
+ 		char* string = new char [wordend - wordstart + 2];
+ 		char* p = string;
+ 		for (int i=wordstart; i<wordend; i++, p++) {
+ 			*p = cursor.par->GetChar(i);
+ 		}
+ 		*p = '\0';
+ 		//if the word fails the spell check mark it
+ 		if(!SpellCheckWord(string)) {
+ 			cursor.par->InsertChar(wordend, '*');
+ 			cursor.par->InsertChar(wordstart, '*');
+ 			cursor.pos+=2;
+ 		}
+ 		delete[] string;
+ 	}
+ }
+ //endsam
  
  
  /* -------> Delete from cursor up to the end of the current or next word. */
============================================================
end of diff for text.C:
============================================================

============================================================
diff for lyxtext.h:
============================================================
*** klyx-0.9.8a/src/lyxtext.h	Wed Apr 15 02:09:03 1998
--- klyx-0.9.8a.hack/src/lyxtext.h	Fri Nov 13 19:57:50 1998
***************
*** 219,224 ****
--- 219,227 ----
  	 With SelectSelectedWord can this be highlighted really
  	 */ 
  	char* SelectNextWord(float &value);
+ //sam's hack
+ 	void QuickSpellPreviousWord();
+ //endsam
  	///
  	void SelectSelectedWord();
  	///
============================================================
end of diff for lyxtext.h:
============================================================

============================================================
diff for spellchecker.C:
============================================================
*** klyx-0.9.8a/src/spellchecker.C	Wed Jan 28 10:10:16 1998
--- klyx-0.9.8a.hack/src/spellchecker.C	Fri Nov 13 19:59:43 1998
***************
*** 420,429 ****
    klyxdialogs->spellchecker->reset();
    
    (void)klyxdialogs->spellchecker->exec();
!   
    return;
  }
  
  
  // Perform an ispell session
  bool RunSpellChecker(LString const & lang) // Ported to Qt/KDE, Kalle,
--- 420,476 ----
    klyxdialogs->spellchecker->reset();
    
    (void)klyxdialogs->spellchecker->exec();
! 
    return;
  }
  
+ //sam's hack
+ bool StartISpell()
+ {
+   signal(SIGCHLD, sigchldhandler);
+   
+   if (isp_pid == -1) {
+ 	create_ispell_pipe("default");
+ 	if (isp_pid == -1) {
+ 		fclose(out);
+ 		return false;
+ 	} else {
+ 		ispell_terse_mode();
+ 	}
+   }
+   return true;
+ }
+ 
+ void StopISpell()
+ {
+   if (isp_pid==-1) {
+ 	fclose(out);
+   } else {
+ 	ispell_terminate();
+   }
+ }
+ 
+ int SpellCheckWord(char* word)
+ {
+   isp_result *result;
+   int correct = 1;
+ 
+   if(!StartISpell()) {
+ 	//Ispell error
+ 	return -1;
+   }
+ 
+   result = ispell_check_word(word);
+   switch (result->flag) {
+   case ISP_UNKNOWN:
+   case ISP_MISSED:
+ 	correct = 0;
+   default:
+ 	delete result;
+   }
+   return correct;
+ }
+ //endsam
  
  // Perform an ispell session
  bool RunSpellChecker(LString const & lang) // Ported to Qt/KDE, Kalle,
***************
*** 440,451 ****
    oldval = 0;  /* used for updating slider only when needed */
    newval = 0.0;
    
!   /* create ispell process */
!   signal(SIGCHLD, sigchldhandler);
    
!   create_ispell_pipe(tmp);
!   
!   if (isp_pid == -1) {
  	QMessageBox::warning( NULL, klocale->translate( "ispell problem" ),
  						  klocale->translate("The ispell-process has died for some reason. *One* possible reason\n"
  											 "could be that you do not have a dictionary file\n"
--- 487,501 ----
    oldval = 0;  /* used for updating slider only when needed */
    newval = 0.0;
    
! //presam
! //  /* create ispell process */
! //  signal(SIGCHLD, sigchldhandler);
! //  
! //  create_ispell_pipe(tmp);
! //sam's hack
!   if(!StartISpell()) {
    
! //  if (isp_pid == -1) {
  	QMessageBox::warning( NULL, klocale->translate( "ispell problem" ),
  						  klocale->translate("The ispell-process has died for some reason. *One* possible reason\n"
  											 "could be that you do not have a dictionary file\n"
***************
*** 453,465 ****
  											 "Check /usr/lib/ispell or set another\n"
  											 "dictionary in the Spellchecker Options menu."),
  						  klocale->translate( "OK "), 0, 0, 0, 0 );
! 	fclose(out);
  	return true;
    }
    
!   // Put ispell in terse mode to improve speed
!   ispell_terse_mode();
!   
    while (true) {
  	word = NextWord(newval);
  	if (word==NULL) break;
--- 503,518 ----
  											 "Check /usr/lib/ispell or set another\n"
  											 "dictionary in the Spellchecker Options menu."),
  						  klocale->translate( "OK "), 0, 0, 0, 0 );
! //	fclose(out);
  	return true;
    }
+ //endsam
    
! //pre sam's hack
! //  // Put ispell in terse mode to improve speed
! //  ispell_terse_mode();
! //endsam  
! 
    while (true) {
  	word = NextWord(newval);
  	if (word==NULL) break;
***************
*** 542,548 ****
  	    if( klyxdialogs->spellchecker->isClose() ) {
  		  delete result;
  		  delete[] word;
! 		  ispell_terminate();
  		  return false;
  		}
  	  }
--- 595,602 ----
  	    if( klyxdialogs->spellchecker->isClose() ) {
  		  delete result;
  		  delete[] word;
! // pre sam's hack
! //		  ispell_terminate();
  		  return false;
  		}
  	  }
***************
*** 553,559 ****
    }
    
    if(isp_pid!=-1) {
! 	ispell_terminate();
  	LString word_msg;
  	word_msg += int(word_count);
  	if (word_count != 1) {
--- 607,614 ----
    }
    
    if(isp_pid!=-1) {
! // pre sam's hack
! //	ispell_terminate();
  	LString word_msg;
  	word_msg += int(word_count);
  	if (word_count != 1) {
***************
*** 572,578 ****
  	QMessageBox::warning( 0, klocale->translate("The ispell-process has died for some reason.\n" 
  												"Maybe it has been killed."),
  						  klocale->translate( "OK" ), 0, 0, 0, 0 );
! 	fclose(out);
  	return true;
    }
  }
--- 627,634 ----
  	QMessageBox::warning( 0, klocale->translate("The ispell-process has died for some reason.\n" 
  												"Maybe it has been killed."),
  						  klocale->translate( "OK" ), 0, 0, 0, 0 );
! // pre sam's hack
! //	fclose(out);
  	return true;
    }
  }
============================================================
end of diff for spellchecker.C:
============================================================

============================================================
diff for spellchecker.h:
============================================================
*** klyx-0.9.8a/src/spellchecker.h	Mon Jan 19 01:35:14 1998
--- klyx-0.9.8a.hack/src/spellchecker.h	Fri Nov 13 19:58:03 1998
***************
*** 29,33 ****
--- 29,36 ----
  ///
  void SpellCheckerOptions();
  
+ //sam's hack
+ int SpellCheckWord(char* word);
+ //endsam
  bool RunSpellChecker(LString const &);
  #endif
============================================================
end of diff for spellchecker.h:
============================================================



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic