mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Support for new GNU aspell library. Final pspell fix ups.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6578 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
bd56331825
commit
99215ea58f
@ -1,3 +1,7 @@
|
||||
2003-03-25 John Levon <levon@movementarian.org>
|
||||
|
||||
* autogen.sh: add aspell.m4
|
||||
|
||||
2003-03-12 Kayvan Sylvan <kayvan@sylvan.com>
|
||||
|
||||
* autogen.sh (ACINCLUDE_FILES): Added cygwin.m4
|
||||
|
@ -4,7 +4,7 @@ ACLOCAL="aclocal"
|
||||
AUTOHEADER="autoheader"
|
||||
AUTOMAKE="automake -a -c --foreign"
|
||||
AUTOCONF="autoconf"
|
||||
ACINCLUDE_FILES="lyxinclude.m4 libtool.m4 codeset.m4 gettext.m4 glibc21.m4 iconv.m4 isc-posix.m4 lcmessage.m4 progtest.m4 xforms.m4 qt.m4 gtk--.m4 gnome--.m4 gnome.m4 pspell.m4 cygwin.m4 pkg.m4"
|
||||
ACINCLUDE_FILES="lyxinclude.m4 libtool.m4 codeset.m4 gettext.m4 glibc21.m4 iconv.m4 isc-posix.m4 lcmessage.m4 progtest.m4 xforms.m4 qt.m4 gtk--.m4 gnome--.m4 gnome.m4 aspell.m4 pspell.m4 cygwin.m4 pkg.m4"
|
||||
|
||||
# Discover what version of autoconf we are using.
|
||||
autoversion=`$AUTOCONF --version | head -n 1`
|
||||
|
@ -1,3 +1,13 @@
|
||||
2003-03-25 John Levon <levon@movementarian.org>
|
||||
|
||||
* Makefile.am:
|
||||
* aspell.m4: add
|
||||
|
||||
* pspell.m4: some more fixes
|
||||
|
||||
* configure.in:
|
||||
* configure.ac: prefer new aspell to pspell
|
||||
|
||||
2003-03-25 John Levon <levon@movementarian.org>
|
||||
|
||||
* pspell.m4: fix up the tests again
|
||||
|
@ -4,4 +4,4 @@ EXTRA_DIST = common.am codeset.m4 libtool.m4 gettext.m4 \
|
||||
lyxinclude.m4 lyxinclude25x.m4 lyxinclude213.m4 \
|
||||
glibc21.m4 iconv.m4 isc-posix.m4 lcmessage.m4 progtest.m4 \
|
||||
qt.m4 gtk--.m4 gnome--.m4 gnome.m4 pkg.m4 xforms.m4 pspell.m4 \
|
||||
relyx_configure.ac relyx_configure.in cygwin.m4
|
||||
aspell.m4 relyx_configure.ac relyx_configure.in cygwin.m4
|
||||
|
30
config/aspell.m4
Normal file
30
config/aspell.m4
Normal file
@ -0,0 +1,30 @@
|
||||
# Macro to add for using aspell spellchecker libraries! -*- sh -*-
|
||||
|
||||
# Only checks for "new" aspell, > 0.50
|
||||
|
||||
AC_DEFUN(CHECK_WITH_ASPELL,
|
||||
[
|
||||
AC_ARG_WITH(aspell,
|
||||
AC_HELP_STRING([--with-aspell],[use ASpell libraries]),
|
||||
[
|
||||
case "$withval" in
|
||||
y*) USING_ASPELL="yes";;
|
||||
*) USING_ASPELL="no";;
|
||||
esac
|
||||
],
|
||||
[
|
||||
USING_ASPELL="yes"
|
||||
])
|
||||
|
||||
if test "$USING_ASPELL" = "yes" ; then
|
||||
AC_CHECK_HEADERS(aspell.h aspell/aspell.h, USING_ASPELL="yes", USING_ASPELL="no")
|
||||
AC_CHECK_LIB(aspell, new_aspell_config, LIBS="-laspell $LIBS"; USING_ASPELL="yes", USING_ASPELL="no")
|
||||
|
||||
if test "$USING_ASPELL" = "yes"; then
|
||||
AC_DEFINE(USE_ASPELL, 1, [Define as 1 to use the aspell library])
|
||||
lyx_flags="$lyx_flags use-aspell"
|
||||
fi
|
||||
fi
|
||||
AC_MSG_CHECKING([whether to use aspell])
|
||||
AC_MSG_RESULT($USING_ASPELL)
|
||||
])
|
@ -128,8 +128,11 @@ AC_LIBTOOL_WIN32_DLL
|
||||
#AM_PROG_LIBTOOL
|
||||
LYX_PROG_LIBTOOL
|
||||
|
||||
### Check if we want pspell libraries
|
||||
CHECK_WITH_PSPELL
|
||||
### Check if we want spell libraries, prefer new aspell
|
||||
CHECK_WITH_ASPELL
|
||||
if test "$USING_ASPELL" != "yes"; then
|
||||
CHECK_WITH_PSPELL
|
||||
fi
|
||||
|
||||
### Check for some Cygwin-specific details.
|
||||
CHECK_WITH_CYGWIN
|
||||
|
@ -131,8 +131,11 @@ AC_LIBTOOL_WIN32_DLL
|
||||
#AM_PROG_LIBTOOL
|
||||
LYX_PROG_LIBTOOL
|
||||
|
||||
### Check if we want pspell libraries
|
||||
CHECK_WITH_PSPELL
|
||||
### Check if we want spell libraries, prefer new aspell
|
||||
CHECK_WITH_ASPELL
|
||||
if test "$USING_ASPELL" != "yes"; then
|
||||
CHECK_WITH_PSPELL
|
||||
fi
|
||||
|
||||
### Check for some Cygwin-specific details.
|
||||
CHECK_WITH_CYGWIN
|
||||
|
@ -7,23 +7,23 @@ AC_DEFUN(CHECK_WITH_PSPELL,
|
||||
AC_HELP_STRING([--with-pspell],[use PSpell libraries]),
|
||||
[
|
||||
case "$withval" in
|
||||
y*) TRY_PSPELL="yes";;
|
||||
*) TRY_PSPELL="no";;
|
||||
y*) USING_PSPELL="yes";;
|
||||
*) USING_PSPELL="no";;
|
||||
esac
|
||||
],
|
||||
[
|
||||
TRY_PSPELL="yes"
|
||||
USING_PSPELL="yes"
|
||||
])
|
||||
|
||||
if test "$TRY_PSPELL" = "yes" ; then
|
||||
AC_CHECK_HEADERS(pspell.h pspell/pspell.h, break, USE_PSPELL=no)
|
||||
AC_CHECK_LIB(pspell, main)
|
||||
if test "$USING_PSPELL" = "yes" ; then
|
||||
AC_CHECK_HEADERS(pspell/pspell.h, USING_PSPELL="yes", USING_PSPELL="no")
|
||||
AC_CHECK_LIB(pspell, main, LIBS="-lpspell $LIBS"; USING_PSPELL="yes", USING_PSPELL="no")
|
||||
|
||||
if test "$TRY_PSPELL" = "yes"; then
|
||||
if test "$USING_PSPELL" = "yes"; then
|
||||
AC_DEFINE(USE_PSPELL, 1, [Define as 1 to use the pspell library])
|
||||
lyx_flags="$lyx_flags use-pspell"
|
||||
fi
|
||||
fi
|
||||
AC_MSG_CHECKING([whether to use pspell])
|
||||
AC_MSG_RESULT($TRY_PSPELL)
|
||||
AC_MSG_RESULT($USING_PSPELL)
|
||||
])
|
||||
|
@ -1,3 +1,13 @@
|
||||
2003-03-25 John Levon <levon@movementarian.org>
|
||||
|
||||
* Makefile.am:
|
||||
* aspell_local.h:
|
||||
* aspell.C: add new aspell support
|
||||
|
||||
* lyxrc.h:
|
||||
* lyxrc.C: Make use_pspell be use_spell_lib. Always
|
||||
have it accessible.
|
||||
|
||||
2003-03-25 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* lfuns.h:
|
||||
|
@ -87,6 +87,8 @@ lyx_SOURCES = \
|
||||
ToolbarDefaults.C \
|
||||
ToolbarDefaults.h \
|
||||
WordLangTuple.h \
|
||||
aspell.C \
|
||||
aspell_local.h \
|
||||
author.C \
|
||||
author.h \
|
||||
boost.C \
|
||||
|
147
src/aspell.C
Normal file
147
src/aspell.C
Normal file
@ -0,0 +1,147 @@
|
||||
/**
|
||||
* \file aspell.C
|
||||
* Copyright 2001 the LyX Team
|
||||
* Read the file COPYING
|
||||
*
|
||||
* \author Kevin Atkinson
|
||||
* \author John Levon <levon@movementarian.org>
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ifdef USE_ASPELL
|
||||
|
||||
#include "support/LAssert.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include <aspell.h>
|
||||
|
||||
#include "aspell_local.h"
|
||||
#include "WordLangTuple.h"
|
||||
|
||||
using std::endl;
|
||||
|
||||
ASpell::ASpell(BufferParams const &, string const & lang)
|
||||
: els(0), spell_error_object(0)
|
||||
{
|
||||
addSpeller(lang);
|
||||
}
|
||||
|
||||
|
||||
ASpell::~ASpell()
|
||||
{
|
||||
if (spell_error_object) {
|
||||
delete_aspell_can_have_error(spell_error_object);
|
||||
spell_error_object = 0;
|
||||
}
|
||||
|
||||
if (els)
|
||||
delete_aspell_string_enumeration(els);
|
||||
|
||||
Spellers::iterator it = spellers_.begin();
|
||||
Spellers::iterator end = spellers_.end();
|
||||
|
||||
for (; it != end; ++it) {
|
||||
aspell_speller_save_all_word_lists(it->second.speller);
|
||||
delete_aspell_speller(it->second.speller);
|
||||
delete_aspell_config(it->second.config);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ASpell::addSpeller(string const & lang)
|
||||
{
|
||||
AspellConfig * config = new_aspell_config();
|
||||
aspell_config_replace(config, "language-tag", lang.c_str());
|
||||
AspellCanHaveError * err = new_aspell_speller(config);
|
||||
if (spell_error_object)
|
||||
delete_aspell_can_have_error(spell_error_object);
|
||||
spell_error_object = 0;
|
||||
|
||||
if (aspell_error_number(err) == 0) {
|
||||
Speller m;
|
||||
m.speller = to_aspell_speller(err);
|
||||
m.config = config;
|
||||
spellers_[lang] = m;
|
||||
} else {
|
||||
spell_error_object = err;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enum ASpell::Result ASpell::check(WordLangTuple const & word)
|
||||
{
|
||||
Result res = UNKNOWN;
|
||||
|
||||
Spellers::iterator it = spellers_.find(word.lang_code());
|
||||
if (it == spellers_.end()) {
|
||||
addSpeller(word.lang_code());
|
||||
it = spellers_.find(word.lang_code());
|
||||
// FIXME
|
||||
if (it == spellers_.end())
|
||||
return res;
|
||||
}
|
||||
|
||||
AspellSpeller * m = it->second.speller;
|
||||
|
||||
int word_ok = aspell_speller_check(m, word.word().c_str(), -1);
|
||||
lyx::Assert(word_ok != -1);
|
||||
|
||||
if (word_ok) {
|
||||
res = OK;
|
||||
} else {
|
||||
AspellWordList const * sugs =
|
||||
aspell_speller_suggest(m, word.word().c_str(), -1);
|
||||
lyx::Assert(sugs != 0);
|
||||
els = aspell_word_list_elements(sugs);
|
||||
if (aspell_word_list_empty(sugs))
|
||||
res = UNKNOWN;
|
||||
else
|
||||
res = MISSED;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void ASpell::insert(WordLangTuple const & word)
|
||||
{
|
||||
Spellers::iterator it = spellers_.find(word.lang_code());
|
||||
if (it != spellers_.end())
|
||||
aspell_speller_add_to_personal(it->second.speller, word.word().c_str(), -1);
|
||||
}
|
||||
|
||||
|
||||
void ASpell::accept(WordLangTuple const & word)
|
||||
{
|
||||
Spellers::iterator it = spellers_.find(word.lang_code());
|
||||
if (it != spellers_.end())
|
||||
aspell_speller_add_to_session(it->second.speller, word.word().c_str(), -1);
|
||||
}
|
||||
|
||||
|
||||
string const ASpell::nextMiss()
|
||||
{
|
||||
char const * str = 0;
|
||||
|
||||
if (els)
|
||||
str = aspell_string_enumeration_next(els);
|
||||
if (str)
|
||||
return str;
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
string const ASpell::error()
|
||||
{
|
||||
char const * err = 0;
|
||||
|
||||
if (spell_error_object && aspell_error_number(spell_error_object) != 0) {
|
||||
err = aspell_error_message(spell_error_object);
|
||||
}
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
return "";
|
||||
}
|
||||
|
||||
#endif // USE_ASPELL
|
75
src/aspell_local.h
Normal file
75
src/aspell_local.h
Normal file
@ -0,0 +1,75 @@
|
||||
/**
|
||||
* \file aspell_local.h
|
||||
* Copyright 2001 the LyX Team
|
||||
* Read the file COPYING
|
||||
*
|
||||
* \author Kevin Atkinson
|
||||
* \author John Levon <levon@movementarian.org>
|
||||
*/
|
||||
|
||||
#ifndef LYX_ASPELL_H
|
||||
#define LYX_ASPELL_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "SpellBase.h"
|
||||
|
||||
class AspellSpeller;
|
||||
class AspellStringEnumeration;
|
||||
class AspellCanHaveError;
|
||||
class AspellConfig;
|
||||
|
||||
class BufferParams;
|
||||
|
||||
|
||||
class ASpell : public SpellBase {
|
||||
public:
|
||||
/**
|
||||
* Initialise the spellchecker with the given buffer params and language.
|
||||
*/
|
||||
ASpell(BufferParams const & params, string const & lang);
|
||||
|
||||
virtual ~ASpell();
|
||||
|
||||
/**
|
||||
* return true if the spellchecker instance still exists
|
||||
* Always true for aspell, since there is no separate process
|
||||
*/
|
||||
virtual bool alive() { return true; }
|
||||
|
||||
/// check the given word and return the result
|
||||
virtual enum Result check(WordLangTuple const &);
|
||||
|
||||
/// insert the given word into the personal dictionary
|
||||
virtual void insert(WordLangTuple const &);
|
||||
|
||||
/// accept the given word temporarily
|
||||
virtual void accept(WordLangTuple const &);
|
||||
|
||||
/// return the next near miss after a MISSED result
|
||||
virtual string const nextMiss();
|
||||
|
||||
/// give an error message on messy exit
|
||||
virtual string const error();
|
||||
|
||||
private:
|
||||
/// add a speller of the given language
|
||||
void addSpeller(string const & lang);
|
||||
|
||||
struct Speller {
|
||||
AspellSpeller * speller;
|
||||
AspellConfig * config;
|
||||
};
|
||||
|
||||
typedef std::map<string, struct Speller> Spellers;
|
||||
|
||||
/// the spellers
|
||||
Spellers spellers_;
|
||||
|
||||
/// FIXME
|
||||
AspellStringEnumeration * els;
|
||||
/// FIXME
|
||||
AspellCanHaveError * spell_error_object;
|
||||
};
|
||||
|
||||
#endif // ASPELL_H
|
@ -1,3 +1,7 @@
|
||||
2003-03-25 John Levon <levon@movementarian.org>
|
||||
|
||||
* ControlSpellchecker.C: support for new aspell
|
||||
|
||||
2003-03-25 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* ControlLog.[Ch]:
|
||||
|
@ -24,6 +24,10 @@
|
||||
#include "ispell.h"
|
||||
#ifdef USE_PSPELL
|
||||
# include "pspell.h"
|
||||
#else
|
||||
#ifdef USE_ASPELL
|
||||
# include "aspell_local.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "frontends/Alert.h"
|
||||
@ -55,6 +59,30 @@ void ControlSpellchecker::clearParams()
|
||||
endSession();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
SpellBase * getSpeller(BufferParams const & bp)
|
||||
{
|
||||
string lang = (lyxrc.isp_use_alt_lang)
|
||||
? lyxrc.isp_alt_lang
|
||||
: bp.language->code();
|
||||
|
||||
#ifdef USE_ASPELL
|
||||
if (lyxrc.use_spell_lib)
|
||||
return new ASpell(bp, lang);
|
||||
#endif
|
||||
#ifdef USE_PSPELL
|
||||
if (lyxrc.use_spell_lib)
|
||||
return new PSpell(bp, lang);
|
||||
#endif
|
||||
|
||||
lang = (lyxrc.isp_use_alt_lang) ?
|
||||
lyxrc.isp_alt_lang : bp.language->lang();
|
||||
|
||||
return new ISpell(bp, lang);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ControlSpellchecker::startSession()
|
||||
{
|
||||
@ -66,23 +94,7 @@ void ControlSpellchecker::startSession()
|
||||
return;
|
||||
}
|
||||
|
||||
// create spell object
|
||||
string tmp;
|
||||
#ifdef USE_PSPELL
|
||||
if (lyxrc.use_pspell) {
|
||||
tmp = (lyxrc.isp_use_alt_lang) ?
|
||||
lyxrc.isp_alt_lang : buffer()->params.language->code();
|
||||
|
||||
speller_.reset(new PSpell(buffer()->params, tmp));
|
||||
} else {
|
||||
#endif
|
||||
tmp = (lyxrc.isp_use_alt_lang) ?
|
||||
lyxrc.isp_alt_lang : buffer()->params.language->lang();
|
||||
|
||||
speller_.reset(new ISpell(buffer()->params, tmp));
|
||||
#ifdef USE_PSPELL
|
||||
}
|
||||
#endif
|
||||
speller_.reset(getSpeller(buffer()->params));
|
||||
|
||||
// reset values to initial
|
||||
newval_ = 0.0;
|
||||
|
24
src/lyxrc.C
24
src/lyxrc.C
@ -141,9 +141,9 @@ keyword_item lyxrcTags[] = {
|
||||
{ "\\use_escape_chars", LyXRC::RC_USE_ESC_CHARS },
|
||||
{ "\\use_input_encoding", LyXRC::RC_USE_INP_ENC },
|
||||
{ "\\use_personal_dictionary", LyXRC::RC_USE_PERS_DICT },
|
||||
#ifdef USE_PSPELL
|
||||
{ "\\use_pspell", LyXRC::RC_USE_PSPELL },
|
||||
#endif
|
||||
// compatibility with versions older than 1.4.0 only
|
||||
{ "\\use_pspell", LyXRC::RC_USE_SPELL_LIB },
|
||||
{ "\\use_spell_lib", LyXRC::RC_USE_SPELL_LIB },
|
||||
{ "\\use_tempdir", LyXRC::RC_USETEMPDIR },
|
||||
{ "\\user_email", LyXRC::RC_USER_EMAIL },
|
||||
{ "\\user_name", LyXRC::RC_USER_NAME },
|
||||
@ -227,9 +227,7 @@ void LyXRC::setDefaults() {
|
||||
backupdir_path.erase();
|
||||
display_graphics = grfx::ColorDisplay;
|
||||
// Spellchecker settings:
|
||||
#ifdef USE_PSPELL
|
||||
use_pspell = true;
|
||||
#endif
|
||||
use_spell_lib = true;
|
||||
isp_command = "ispell";
|
||||
isp_accept_compound = false;
|
||||
isp_use_input_encoding = false;
|
||||
@ -879,13 +877,11 @@ int LyXRC::read(string const & filename)
|
||||
}
|
||||
break;
|
||||
// Spellchecker settings:
|
||||
#ifdef USE_PSPELL
|
||||
case RC_USE_PSPELL:
|
||||
case RC_USE_SPELL_LIB:
|
||||
if (lexrc.next()) {
|
||||
use_pspell = lexrc.getBool();
|
||||
use_spell_lib = lexrc.getBool();
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case RC_SPELL_COMMAND:
|
||||
if (lexrc.next()) {
|
||||
isp_command = lexrc.getString();
|
||||
@ -1628,12 +1624,10 @@ void LyXRC::output(ostream & os) const
|
||||
os << "\n#\n"
|
||||
<< "# SPELLCHECKER SECTION ##############################\n"
|
||||
<< "#\n\n";
|
||||
#ifdef USE_PSPELL
|
||||
case RC_USE_PSPELL:
|
||||
if (use_pspell != system_lyxrc.use_pspell) {
|
||||
os << "\\use_pspell " << tostr(use_pspell) << '\n';
|
||||
case RC_USE_SPELL_LIB:
|
||||
if (use_spell_lib != system_lyxrc.use_spell_lib) {
|
||||
os << "\\use_spell_lib " << tostr(use_spell_lib) << '\n';
|
||||
}
|
||||
#endif
|
||||
case RC_SPELL_COMMAND:
|
||||
if (isp_command != system_lyxrc.isp_command) {
|
||||
os << "\\spell_command \"" << isp_command << "\"\n";
|
||||
|
@ -118,9 +118,7 @@ enum LyXRCTags {
|
||||
RC_PREVIEW,
|
||||
RC_PREVIEW_HASHED_LABELS,
|
||||
RC_PREVIEW_SCALE_FACTOR,
|
||||
#ifdef USE_PSPELL
|
||||
RC_USE_PSPELL,
|
||||
#endif
|
||||
RC_USE_SPELL_LIB,
|
||||
RC_USER_NAME,
|
||||
RC_USER_EMAIL,
|
||||
RC_LAST
|
||||
@ -280,10 +278,9 @@ enum LyXRCTags {
|
||||
string ascii_roff_command;
|
||||
///
|
||||
unsigned int ascii_linelen;
|
||||
/// use library instead of process
|
||||
bool use_spell_lib;
|
||||
/// Ispell command
|
||||
#ifdef USE_PSPELL
|
||||
bool use_pspell;
|
||||
#endif
|
||||
string isp_command;
|
||||
/// Accept compound words in spellchecker?
|
||||
bool isp_accept_compound;
|
||||
|
Loading…
Reference in New Issue
Block a user