aspell-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pspell] (no subject)


From: a a
Subject: Re: [pspell] (no subject)
Date: Thu, 12 Oct 2000 10:53:17 GMT

Hi,

This is the application that shows the bug.
It is a application in which you can make one or more managers which will be stored, so you can simulate multiple documents with different langauges and other settings. The errors occur after you try to set the language from english (aspell) to French (ispell) to German (ispell). It doesn't recognise that language anymore. Also core dump occur after entering wrong language codes (like xy), maybe not the first time, but keep trying in different documents and it will occur sooner or later. I spend only 2 days writing this program, so it might be a bug on my side, but I think I do understand the api calls of pspell.

Alain Dufour

===========================================================
This is the header file of the MySpell class. (MySpell.hh)
===========================================================
#ifndef _MYSPELL_H_
#define _MYSPELL_H_

#include <vector>
#include <string>

class PspellConfig;
class PspellCanHaveError;
class PspellManager;
class PspellStringEmulation;
class PspellWordList;

class MySpell {
       public:
               static MySpell* Instance(void);
               static MySpell* Instance(char const *lang);
               ~MySpell(void);
               bool Init(void);
               bool SetSpellCheckMode(char const *mode);
               bool CheckWord(char const *word) const;
bool GetSuggestions(vector<string> &v, char const *word) const;
               bool ClearSessionWordlist(void) const;
               bool AddToSessionWordlist(char const *word);
               bool AddToPersonalWordlist(char const *word);
               bool GetSessionWordlist(vector<string> &v) const;
               bool GetPersonalWordlist(vector<string> &v) const;
               bool SetLanguage(char const *lang);
               char const *GetLanguage(void) const;
               bool CreateNewDocument(void);
               bool SetActiveDocument(int const docNr);
               int const GetActiveDocument(void) const;
               int const GetNrOfDocuments(void) const;
       private:
               MySpell(void);
               MySpell(char const *lang);
               bool CheckForError(void) const;
vector<string> const GetWordList(PspellWordList const *wordList) const;
               void PrintConfigDetails(void) const;
               static MySpell*                 _instance;
               PspellConfig*                   config;
               PspellCanHaveError*             ret;
               PspellManager*                  manager;
               vector<PspellManager*>*         vManager;
               char*                           language;
               int                             activeDocument;
               int                             nrOfDocuments;
};
#endif

=================================================================
2. This is the implemantation of the MySpell class. (MySpell.cc)
=================================================================
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <string>
#include "MySpell.hh"
#include "pspell/pspell.h"
MySpell::MySpell() {
       config = new_pspell_config();
       vManager = new vector< PspellManager* >;
       language = new char[3];
       strcpy(language, "en");
       activeDocument = 0;
       nrOfDocuments = 0;
}
MySpell::MySpell(char const *lang) {
       config = new_pspell_config();
       vManager = new vector< PspellManager* >;
       language = new char[3];
       strcpy(language, lang);
       activeDocument = 0;
       nrOfDocuments = 0;
}
MySpell::~MySpell() {
       delete_pspell_manager(manager);
       delete vManager;
       delete language;
}
MySpell* MySpell::_instance = 0;
MySpell* MySpell::Instance() {
       if (_instance == 0) {
               _instance = new MySpell;
       }
       return _instance;
}
MySpell* MySpell::Instance(char const *lang) {
       if (_instance == 0) {
               _instance = new MySpell(lang);
       }
       return _instance;
}
bool MySpell::Init() {
       bool status = false;
       config->replace("language-tag", language);
       ret = new_pspell_manager(config);
       if (ret->error_number() != 0) {
               // Handle error...
               cout << ret->error_message() << endl;
               delete_pspell_can_have_error(ret);
               status = false;
       } else {
               manager = (PspellManager *) ret;
               vManager->push_back(manager);
               nrOfDocuments++;
               PrintConfigDetails();
               status = true;
       }
       return(status);
}
bool MySpell::SetSpellCheckMode(char const *mode) {
       bool status = false;
       if (strcmp(mode, "fast") != 0 &&
            strcmp(mode, "normal") != 0 &&
            strcmp(mode, "bad-spellers") != 0) {
               goto END;
       }
       delete_pspell_config(config);
       delete_pspell_manager(manager);
       config = new_pspell_config();
       config->replace("language-tag", language);
       config->replace("sug-mode", mode);
       ret = new_pspell_manager(config);
       if (ret->error_number() != 0) {
               // Handle error...
               cout << ret->error_message() << endl;
               delete_pspell_can_have_error(ret);
               goto END;
       } else {
               manager = (PspellManager *) ret;
               (*vManager)[activeDocument] = manager;
               PrintConfigDetails();
               status = true;
       }
       END:
       return(status);
}
bool MySpell::CheckWord(char const *word) const {
       bool correct = false;
       correct = manager->check(word);
       return(correct);
}
bool MySpell::GetSuggestions(vector< string > &v, char const *word) const {
       bool status = false;
       v = GetWordList(manager->suggest(word));
       //!!! This method to be changed !!!
       status = true;
       return(status);
}
bool MySpell::ClearSessionWordlist() const {
       bool status = false;
       manager->clear_session();
       status = CheckForError();
       return(status);
}
bool MySpell::AddToSessionWordlist(char const *word) {
       bool status = false;
       manager->add_to_session(word);
       status = CheckForError();
       return(status);
}
bool MySpell::AddToPersonalWordlist(char const *word) {
       bool status = false;
       manager->add_to_personal(word);
       status = CheckForError();
       return(status);
}
bool MySpell::GetSessionWordlist(vector< string > &v) const {
       bool status = false;
       v = GetWordList(manager->session_word_list());
       //!!! This method to be changed !!!
       status = true;
       return(status);
}
bool MySpell::GetPersonalWordlist(vector< string > &v) const {
       bool status = false;
       v = GetWordList(manager->personal_word_list());
       //!!! This method to be changed !!!
       status = true;
       return(status);
}
bool MySpell::SetLanguage(char const *lang) {
       bool status = false;
       strcpy(language, lang);
       delete_pspell_config(config);
       delete_pspell_manager(manager);
       config = new_pspell_config();
       config->replace("language-tag", language);
       ret = new_pspell_manager(config);
       if (ret->error_number() != 0) {
               // Handle error...
               cout << ret->error_message() << endl;
               delete_pspell_can_have_error(ret);
               status = false;
       } else {
               manager = (PspellManager *) ret;
               (*vManager)[activeDocument] = manager;
               PrintConfigDetails();
               status = true;
       }
       return(status);
}
char const *MySpell::GetLanguage() const {
       return(language);
}
bool MySpell::CreateNewDocument() {
       PspellConfig* newConfig = config->clone();
       PspellCanHaveError* newRet = new_pspell_manager(newConfig);
       PspellManager* newManager = (PspellManager *) newRet;
       vManager->push_back(newManager);
       delete_pspell_config(config);
       activeDocument = nrOfDocuments;
       nrOfDocuments++;
       config = newConfig;
       manager = (*vManager)[activeDocument];
       PrintConfigDetails();
}
bool MySpell::SetActiveDocument(int const docNr) {
       bool status = false;
       if (docNr < 0 || docNr > nrOfDocuments) {
               // docNr is NOT within range!
               goto END;
       }
       if (activeDocument != docNr) {
               manager = (*vManager)[docNr];
               activeDocument = docNr;
       }
       PrintConfigDetails();
       status = true;
       END:
       return(status);
}
int const MySpell::GetActiveDocument() const {
       return(activeDocument);
}
int const MySpell::GetNrOfDocuments() const {
       return(nrOfDocuments);
}
bool MySpell::CheckForError() const {
       bool status = false;
       if (manager->error_number() == 0) {
               status = true;
       }
       return(status);
}
vector< string > const MySpell::GetWordList(PspellWordList const *wordList) const {
       char const *word;
       vector< string > list;
       PspellStringEmulation* els = wordList->elements();
       if(wordList == 0) {
               goto END;
       } else {
               while((word = els->next()) != 0) {
                       list.push_back((string) word);
               }
       }
       END:
       return(list);
}
void MySpell::PrintConfigDetails() const {
       cout << "Using: ";
       cout << manager->config().retrieve("language-tag");
       cout << "-";
       cout << manager->config().retrieve("jargon");
       cout << "-";
       cout << manager->config().retrieve("module");
       cout << "-";
       cout << manager->config().retrieve("sug-mode");
       cout << "\n\n";
}
// The End
========================================
3. This is the test program. (ptest.cc)
========================================
#include <iostream>
#include <string>
#include <vector>
#include "pspell/pspell.h"
#include "MySpell.hh"

void ShowOptions() {
       cout << endl;
       cout << "l to change the language in the current document." << endl;
cout << "m to change the spellcheck mode (speed) in the current document." << endl;
       cout << "n to simulate a new document." << endl;
       cout << "s to select a document." << endl;
       cout << "c to clear the sessions wordlist." << endl;
       cout << "a to add a word to the sessions wordlist." << endl;
       cout << "p to add a word to your personal wordlist." << endl;
       cout << "ps to print out the session wordlist." << endl;
       cout << "pp to print out your personal wordlist." << endl;
       cout << "q to quit" << endl << endl;
}
int main() {
       char prevWordToCheck[81];
       char wordToCheck[81];
       MySpell* sp = MySpell::Instance();
       //MySpell* sp = MySpell::Instance("fr");
       sp->Init();
       cout << "This is the MySpell spell checker." << endl << endl;
       while (strcmp(wordToCheck, "q") != 0) {
               ShowOptions();
               cout << "[Document:" << sp->GetActiveDocument() << "]"
                                   << " Enter a word to check: ";
               cin >> wordToCheck;
               if (strcmp(wordToCheck, "q") == 0) {
                       delete sp;
                       exit(1);
               }
               if (strcmp(wordToCheck, "l") == 0) {
                       char language[81];
                       cout << "Enter the language code: ";
                       cin >> language;
                       if (sp->SetLanguage(language) == false) {
                               cout << "Unknown language code." << endl;
                       }
                       continue;
               }
               if (strcmp(wordToCheck, "m") == 0) {
                       char mode[81];
                       cout << "Availlable modes: " << endl;
                       cout << "fast" << endl;
                       cout << "normal" << endl;
                       cout << "bad-spellers" << endl;
                       cout << "Enter the mode: ";
                       cin >> mode;
                       if (sp->SetSpellCheckMode(mode) == false) {
                               cout << "Unknown mode." << endl;
                       }
                       continue;
               }
               if (strcmp(wordToCheck, "n") == 0) {
                       sp->CreateNewDocument();
                       continue;
               }
               if (strcmp(wordToCheck, "s") == 0) {
                       cout << "Which document? [0-" <<
                               sp->GetNrOfDocuments() - 1 << "]: ";
                       int docNr;
                       cin >> docNr;
                       sp->SetActiveDocument(docNr);
                       continue;
               }
               if (strcmp(wordToCheck, "c") == 0) {
                       cout << "Clearing this sessions wordlist." << endl;
                       // Basically this is an ignore(word) command.
                       sp->ClearSessionWordlist();
                       continue;
               }
               if (strcmp(wordToCheck, "a") == 0) {
                       cout << "Adding [" << prevWordToCheck <<
                               "] to the sessions wordlist." << endl;
                       // Basically this is an ignore(word) command.
                       sp->AddToSessionWordlist(prevWordToCheck);
                       continue;
               }
               if (strcmp(wordToCheck, "p") == 0) {
                       cout << "Adding [" << prevWordToCheck <<
                               "] to your personal wordlist." << endl;
                       sp->AddToPersonalWordlist(prevWordToCheck);
                       continue;
               }
               if (strcmp(wordToCheck, "ps") == 0) {
                       cout << "Session wordlist:" << endl;
                       vector<string> v;
                       if (sp->GetSessionWordlist(v) == false) {
                               continue;
                       } else {
                               for(vector<string>::iterator i = v.begin();
i != v.end(); ++i) {
                                       cout << *i << endl;
                               }
                               continue;
                       }
               }
               if (strcmp(wordToCheck, "pp") == 0) {
                       cout << "Personal wordlist:" << endl;
                       vector<string> v;
                       if (sp->GetPersonalWordlist(v) == false) {
                               for(vector<string>::iterator i = v.begin();
i != v.end(); ++i) {
                                       cout << *i << endl;
                               }
                               continue;
                       }
               }
               // Checking.
               if (sp->CheckWord(wordToCheck) == true) {
                       cout << "Correct!" << endl;
               } else {
                       cout << "Incorrect!" << endl << endl;
                       vector<string> v;
                       if (sp->GetSuggestions(v, wordToCheck) == false) {
                               continue;
                       } else {
                               for(vector<string>::iterator i = v.begin();
i != v.end(); ++i) {
                                       cout << *i << endl;
                               }
                       }
               }
               strcpy(prevWordToCheck, wordToCheck);
       }
       return 0;
}
====================================
4. This is the makefile. (Makefile)
====================================
#
# AD
# Test makefile for pspell application.
#
#.SILENT:
libdir = /usr/local/lib
srcdir =.
includedir = /usr/local/include
top_builddir = ../..
SHELL = /bin/sh
LIBTOOL = $(SHELL) $(top_builddir)/libtool
TARGET = ptest
PROG_OBJS = ptest.o MySpell.o
AM_CPPFLAGS =
CPPFLAGS =
AM_CXXFLAGS =
LIBS =
DEFS =  -DPACKAGE=\"pspell\" -DVERSION=\".11.2\"  -I. -I$(srcdir)
INCLUDES = -I$(includedir)
CXX = c++
CXXLD = $(CXX)
CXXFLAGS = -g -O2
CXX_LIBS = -L/usr/lib/gcc-lib/i386-redhat-linux/2.95.2  -lstdc++
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
LDFLAGS =
PROG_LDFLAGS =
PROG_DEPENDENCIES =
PROG_LDADD = -L$(libdir) -lpspell
CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@

ptest: $(PROG_OBJS) $(PROG_DEPENDENCIES)
       @rm -f $(TARGET)
       $(CXXLINK) $(PROG_LDFLAGS) $(PROG_OBJS) $(PROG_LDADD) $(LIBS)
       @echo "make: complete"
#.cc.o:
#       $(CXXCOMPILE) -c $<
ptest.o : ptest.cc
       $(CXXCOMPILE) -c ptest.cc
       @echo "ptest.cc compiled"
MySpell.o : MySpell.cc
       $(CXXCOMPILE) -c MySpell.cc
       @echo "MySpell.cc compiled"
clear:
       @rm *.o $(TARGET)
       @echo "make: clear"



From: Kevin Atkinson <address@hidden>
To: a a <address@hidden>
CC: address@hidden
Subject: Re: [pspell] (no subject)
Date: Wed, 11 Oct 2000 22:38:47 -0400 (EDT)


Could you please send me a complete program.  I will then try it out for my
self and get back to you.  Everything seams OK from what you posted so it
could be a bug in Pspell.

---
Kevin Atkinson
kevina at users sourceforge net
http://metalab.unc.edu/kevina/



_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at http://profiles.msn.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]