# HG changeset patch # User Mikael Berthe # Date 1254677618 -7200 # Node ID 8d1bcc83ae326f3a98844786552ed416fa2482f8 # Parent 23c08d4f1d1ea8251061ad8509c7a3cdd6dbe361 Add support for spellchecking with Enchant (caolan) Patch from the issue tracker: http://bitbucket.org/McKael/mcabber-crew/issue/36/patch-to-spell-checking-using-enchant diff -r 23c08d4f1d1e -r 8d1bcc83ae32 mcabber/configure.ac --- a/mcabber/configure.ac Sun Oct 04 18:39:08 2009 +0200 +++ b/mcabber/configure.ac Sun Oct 04 19:33:38 2009 +0200 @@ -204,10 +204,19 @@ fi fi +# Check for Enchant stuff +AC_ARG_ENABLE(enchant, [ --enable-enchant enable enchant support], + enable_enchant=$enableval, enchant="") # Check for Aspell stuff AC_ARG_ENABLE(aspell, [ --enable-aspell enable aspell support], enable_aspell=$enableval, aspell="") -if test "x$enable_aspell" = "xyes"; then + +if test "x$enable_enchant" = "xyes"; then + PKG_CHECK_MODULES(ENCHANT, [enchant], + AC_DEFINE(WITH_ENCHANT, 1, [define if you want enchant support]) + ) +else + if test "x$enable_aspell" = "xyes"; then AC_CHECK_HEADERS(aspell.h, [ have_aspell_includes=yes ]) if test "x$have_aspell_includes" = "xyes"; then AC_CHECK_LIB(aspell, new_aspell_config, [ have_aspell_libs=yes ]) @@ -220,6 +229,7 @@ else enable_aspell=no fi + fi fi AC_DEFINE([BUILD_JABBER], 1, [build with jabber support]) diff -r 23c08d4f1d1e -r 8d1bcc83ae32 mcabber/mcabberrc.example --- a/mcabber/mcabberrc.example Sun Oct 04 18:39:08 2009 +0200 +++ b/mcabber/mcabberrc.example Sun Oct 04 19:33:38 2009 +0200 @@ -102,10 +102,10 @@ # If your mcabber has been built with Aspell support, you can enable spell # checking with the following options (you can't change them once mcabber is # running). -#set aspell_enable = 1 -#set aspell_lang = en_EN -#set aspell_encoding = iso8859-1 -#set aspell_encoding = UTF-8 +#set spell_enable = 1 +#set spell_lang = en_US +#set spell_encoding = iso8859-1 +#set spell_encoding = UTF-8 # History # Number of lines to remember for the command line history diff -r 23c08d4f1d1e -r 8d1bcc83ae32 mcabber/src/Makefile.am --- a/mcabber/src/Makefile.am Sun Oct 04 18:39:08 2009 +0200 +++ b/mcabber/src/Makefile.am Sun Oct 04 19:33:38 2009 +0200 @@ -11,10 +11,10 @@ mcabber_SOURCES += otr.c otr.h nohtml.c nohtml.h endif -LDADD = $(GLIB_LIBS) $(GPGME_LIBS) $(LIBOTR_LIBS) \ +LDADD = $(GLIB_LIBS) $(GPGME_LIBS) $(LIBOTR_LIBS) $(ENCHANT_LIBS) \ ../libjabber/liblibjabber.a ../connwrap/libconnwrap.a -AM_CPPFLAGS = $(GLIB_CFLAGS) $(GPGME_CFLAGS) $(LIBOTR_CFLAGS) +AM_CPPFLAGS = $(GLIB_CFLAGS) $(GPGME_CFLAGS) $(LIBOTR_CFLAGS) $(ENCHANT_CFLAGS) CLEANFILES = hgcset.h diff -r 23c08d4f1d1e -r 8d1bcc83ae32 mcabber/src/main.c --- a/mcabber/src/main.c Sun Oct 04 18:39:08 2009 +0200 +++ b/mcabber/src/main.c Sun Oct 04 19:33:38 2009 +0200 @@ -300,6 +300,9 @@ #ifdef HAVE_LIBOTR puts("Compiled with OTR support."); #endif +#ifdef WITH_ENCHANT + puts("Compiled with Enchant support."); +#endif #ifdef WITH_ASPELL puts("Compiled with Aspell support."); #endif @@ -470,9 +473,9 @@ if (optval || optval2) hlog_enable(optval, settings_opt_get("logging_dir"), optval2); -#ifdef HAVE_ASPELL_H - /* Initialize aspell */ - if (settings_opt_get_int("aspell_enable")) { +#if defined(WITH_ENCHANT) || defined(WITH_ASPELL) + /* Initialize spelling */ + if (settings_opt_get_int("spell_enable")) { spellcheck_init(); } #endif @@ -544,9 +547,9 @@ #ifdef HAVE_GPGME gpg_terminate(); #endif -#ifdef HAVE_ASPELL_H - /* Deinitialize aspell */ - if (settings_opt_get_int("aspell_enable")) +#if defined(WITH_ENCHANT) || defined(WITH_ASPELL) + /* Deinitialize spelling */ + if (settings_opt_get_int("spell_enable")) spellcheck_deinit(); #endif /* Save pending message state */ diff -r 23c08d4f1d1e -r 8d1bcc83ae32 mcabber/src/screen.c --- a/mcabber/src/screen.c Sun Oct 04 18:39:08 2009 +0200 +++ b/mcabber/src/screen.c Sun Oct 04 19:33:38 2009 +0200 @@ -41,7 +41,11 @@ # include #endif -#ifdef HAVE_ASPELL_H +#ifdef WITH_ENCHANT +# include +#endif + +#ifdef WITH_ASPELL # include #endif @@ -73,7 +77,7 @@ static void scr_insert_text(const char*); static void scr_handle_tab(void); -#ifdef HAVE_ASPELL_H +#if defined(WITH_ENCHANT) || defined(WITH_ASPELL) static void spellcheck(char *, char *); #endif @@ -120,7 +124,7 @@ static time_t LastActivity; static char inputLine[INPUTLINE_LENGTH+1]; -#ifdef HAVE_ASPELL_H +#if defined(WITH_ENCHANT) || defined(WITH_ASPELL) static char maskLine[INPUTLINE_LENGTH+1]; #endif static char *ptr_inputline; @@ -161,8 +165,14 @@ inline void scr_UpdateBuddyWindow(void); inline void scr_set_chatmode(int enable); -#ifdef HAVE_ASPELL_H -#define ASPELLBADCHAR 5 +#define SPELLBADCHAR 5 + +#ifdef WITH_ENCHANT +EnchantBroker *spell_broker; +EnchantDict *spell_checker; +#endif + +#ifdef WITH_ASPELL AspellConfig *spell_config; AspellSpeller *spell_checker; #endif @@ -3580,7 +3590,7 @@ inputline_offset = c - inputLine; } -#ifdef HAVE_ASPELL_H +#if defined(WITH_ENCHANT) || defined(WITH_ASPELL) // prints inputLine with underlined words when misspelled static inline void print_checked_line(void) { @@ -3610,8 +3620,8 @@ static inline void refresh_inputline(void) { -#ifdef HAVE_ASPELL_H - if (settings_opt_get_int("aspell_enable")) { +#if defined(WITH_ENCHANT) || defined(WITH_ASPELL) + if (settings_opt_get_int("spell_enable")) { memset(maskLine, 0, INPUTLINE_LENGTH+1); spellcheck(inputLine, maskLine); } @@ -3977,18 +3987,32 @@ return; } -#ifdef HAVE_ASPELL_H -// Aspell initialization +#if defined(WITH_ENCHANT) || defined(WITH_ASPELL) +// initialization void spellcheck_init(void) { - int aspell_enable = settings_opt_get_int("aspell_enable"); - const char *aspell_lang = settings_opt_get("aspell_lang"); - const char *aspell_encoding = settings_opt_get("aspell_encoding"); + int spell_enable = settings_opt_get_int("spell_enable"); + const char *spell_lang = settings_opt_get("spell_lang"); +#ifdef WITH_ASPELL + const char *spell_encoding = settings_opt_get("spell_encoding"); AspellCanHaveError *possible_err; - - if (!aspell_enable) +#endif + + if (!spell_enable) return; +#ifdef WITH_ENCHANT + if (spell_checker) { + enchant_broker_free_dict(spell_broker, spell_checker); + enchant_broker_free(spell_broker); + spell_checker = NULL; + spell_broker = NULL; + } + + spell_broker = enchant_broker_init(); + spell_checker = enchant_broker_request_dict(spell_broker, spell_lang); +#endif +#ifdef WITH_ASPELL if (spell_checker) { delete_aspell_speller(spell_checker); delete_aspell_config(spell_config); @@ -3997,8 +4021,8 @@ } spell_config = new_aspell_config(); - aspell_config_replace(spell_config, "encoding", aspell_encoding); - aspell_config_replace(spell_config, "lang", aspell_lang); + aspell_config_replace(spell_config, "encoding", spell_encoding); + aspell_config_replace(spell_config, "lang", spell_lang); possible_err = new_aspell_speller(spell_config); if (aspell_error_number(possible_err) != 0) { @@ -4008,23 +4032,37 @@ } else { spell_checker = to_aspell_speller(possible_err); } +#endif } -// Deinitialization of Aspell spellchecker +// Deinitialization of spellchecker void spellcheck_deinit(void) { if (spell_checker) { +#ifdef WITH_ENCHANT + enchant_broker_free_dict(spell_broker, spell_checker); +#endif +#ifdef WITH_ASPELL delete_aspell_speller(spell_checker); +#endif spell_checker = NULL; } +#ifdef WITH_ENCHANT + if (spell_broker) { + enchant_broker_free(spell_broker); + spell_broker = NULL; + } +#endif +#ifdef WITH_ASPELL if (spell_config) { delete_aspell_config(spell_config); spell_config = NULL; } +#endif } -#define aspell_isalpha(c) (utf8_mode ? iswalpha(get_char(c)) : isalpha(*c)) +#define spell_isalpha(c) (utf8_mode ? iswalpha(get_char(c)) : isalpha(*c)) // Spell checking function static void spellcheck(char *line, char *checked) @@ -4038,7 +4076,7 @@ while (*line) { - if (!aspell_isalpha(line)) { + if (!spell_isalpha(line)) { line = next_char(line); continue; } @@ -4063,12 +4101,18 @@ start = line; - while (aspell_isalpha(line)) + while (spell_isalpha(line)) line = next_char(line); if (spell_checker && - aspell_speller_check(spell_checker, start, line - start) == 0) - memset(&checked[start - line_start], ASPELLBADCHAR, line - start); +#ifdef WITH_ENCHANT + enchant_dict_check(spell_checker, start, line - start) != 0 +#endif +#ifdef WITH_ASPELL + aspell_speller_check(spell_checker, start, line - start) == 0 +#endif + ) + memset(&checked[start - line_start], SPELLBADCHAR, line - start); } } #endif diff -r 23c08d4f1d1e -r 8d1bcc83ae32 mcabber/src/screen.h --- a/mcabber/src/screen.h Sun Oct 04 18:39:08 2009 +0200 +++ b/mcabber/src/screen.h Sun Oct 04 19:33:38 2009 +0200 @@ -14,7 +14,7 @@ # include #endif -#ifdef WITH_ASPELL +#if defined(WITH_ENCHANT) || defined(WITH_ASPELL) void spellcheck_init(void); void spellcheck_deinit(void); //static void spellcheck(char*, char*);