diff -ur enchant-1.2.6.orig/configure.in enchant-1.2.6/configure.in --- enchant-1.2.6.orig/configure.in 2006-08-17 01:49:57.000000000 +0300 +++ enchant-1.2.6/configure.in 2006-08-17 01:50:06.000000000 +0300 @@ -131,6 +131,17 @@ AC_SUBST(MYSPELL_CFLAGS) AC_SUBST(MYSPELL_LIBS) +build_zemberek=yes + +AC_ARG_ENABLE(zemberek, [ --disable-zemberek enable the zemberek backend [default=auto]], build_zemberek="$enableval", build_zemberek=yes) + +if test "x$have_cxx" = "xno"; then + build_zemberek=no +fi +AM_CONDITIONAL(WITH_ZEMBEREK, test "x$build_zemberek" = "xyes") + +zemberek_dir=${datadir}/enchant/zemberek + check_aspell=yes build_aspell=no @@ -265,6 +276,7 @@ src/myspell/Makefile src/hspell/Makefile src/applespell/Makefile +src/zemberek/Makefile tests/Makefile tests/ispell doc/Makefile @@ -290,5 +302,6 @@ Build Uspell backend: ${build_uspell} Build Hspell backend: ${build_hspell} Build Myspell/Hunspell backend: ${build_myspell} + Build Zemberek backend: ${build_zemberek} Build a relocatable library: ${relocatable_library} " diff -ur enchant-1.2.6.orig/data/enchant.ordering enchant-1.2.6/data/enchant.ordering --- enchant-1.2.6.orig/data/enchant.ordering 2006-08-17 01:49:57.000000000 +0300 +++ enchant-1.2.6/data/enchant.ordering 2006-08-17 02:21:46.000000000 +0300 @@ -2,3 +2,4 @@ he:hspell,myspell he_IL:hspell,myspell yi:uspell +tr:zemberek diff -ur enchant-1.2.6.orig/src/Makefile.am enchant-1.2.6/src/Makefile.am --- enchant-1.2.6.orig/src/Makefile.am 2006-08-17 01:49:57.000000000 +0300 +++ enchant-1.2.6/src/Makefile.am 2006-08-17 01:50:18.000000000 +0300 @@ -1,4 +1,4 @@ -SUBDIRS=. aspell ispell uspell myspell hspell applespell +SUBDIRS=. aspell ispell uspell myspell hspell applespell zemberek INCLUDES=-I$(top_srcdir) $(ENCHANT_CFLAGS) -DENCHANT_GLOBAL_MODULE_DIR=\"$(libdir)/enchant\" -DENCHANT_GLOBAL_ORDERING=\"$(datadir)/enchant\" -D_ENCHANT_BUILD=1 Yalnızca enchant-1.2.6/src/zemberek'da: .deps diff -ur enchant-1.2.6.orig/src/zemberek/Makefile.am enchant-1.2.6/src/zemberek/Makefile.am --- enchant-1.2.6.orig/src/zemberek/Makefile.am 2006-08-17 01:51:32.000000000 +0300 +++ enchant-1.2.6/src/zemberek/Makefile.am 2006-08-17 01:50:25.000000000 +0300 @@ -0,0 +1,20 @@ +if WITH_ZEMBEREK +target_lib = libenchant_zemberek.la +else +target_lib = +endif + +INCLUDES=-I$(top_srcdir)/src $(ENCHANT_CFLAGS) -D_ENCHANT_BUILD=1 + +zemberek_LTLIBRARIES = $(target_lib) +zemberekdir= $(libdir)/enchant + +libenchant_zemberek_lalibdir=$(libdir)/enchant +libenchant_zemberek_la_LIBADD= $(top_builddir)/src/libenchant.la +libenchant_zemberek_la_LDFLAGS = -avoid-version -no-undefined + +libenchant_zemberek_la_SOURCES =\ + zemberek.cpp \ + zemberek_provider.cpp + + diff -ur enchant-1.2.6.orig/src/zemberek/zemberek.cpp enchant-1.2.6/src/zemberek/zemberek.cpp --- enchant-1.2.6.orig/src/zemberek/zemberek.cpp 2006-08-17 01:51:37.000000000 +0300 +++ enchant-1.2.6/src/zemberek/zemberek.cpp 2006-08-17 01:50:25.000000000 +0300 @@ -0,0 +1,163 @@ +/* Copyright (C) 2006 Barış Metin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include +#include +#include +#include +#include +#include + + +#include "zemberek.h" + +#define HOST "localhost" +#define ZPORT 10444 + + +Zemberek::Zemberek() +{ + struct hostent *he; + struct sockaddr_in saddr; + + if ( ( he = (struct hostent *)gethostbyname(HOST) ) == NULL ) { + perror( "gethostbyname()" ); + } + + if ( ( _conn = socket(AF_INET, SOCK_STREAM, 0) ) == -1 ) { + perror( "socket()" ); + } + + saddr.sin_family = AF_INET; + saddr.sin_port = htons( (uint16_t)ZPORT ); + saddr.sin_addr = *( (struct in_addr *)he->h_addr ); + memset( &(saddr.sin_zero), '\0', 8 ); + + if ( connect(_conn, (struct sockaddr *)&saddr, sizeof(struct sockaddr)) == -1) { + perror("connect()"); + } +} + + +Zemberek::~Zemberek() +{ + if ( _conn ) { + shutdown( _conn, SHUT_RDWR ); + close( _conn ); + } +} + + +bool Zemberek::checkWord( const string& str, size_t len ) const +{ + stringstream strstream; + strstream << str.length()+2 << " * " << str; + string checkStr = strstream.str(); + if ( send(_conn, checkStr.c_str(), checkStr.length(), 0) == -1) { + perror("send()"); + } + + switch ( recvResult()[0] ) { + case '*': + return true; + break; + case '#': + return false; + break; + default: + return false; + break; + } +} + + +vector Zemberek::suggestWord(const string& str, size_t size, size_t *out_n_suggs) +{ + stringstream strstream; + strstream << str.length()+2 << " & " << str; + string checkStr = strstream.str(); + if ( send( _conn, checkStr.c_str(), checkStr.length(), 0 ) == -1 ) { + perror( "send()" ); + } + + vector suggestions; + string result = recvResult(); + + if ( result[0] != '&' ) { + return suggestions; + } + + string::iterator it = result.begin(); + string::iterator end = result.end(); + bool start = false; + string tmp; + for ( ; it != end; ++it ) { + if ( *it == '(' ) { + start = true; + continue; + } + + if ( !start ) continue; + + + if ( *it == ',' ) { + suggestions.push_back( tmp ); + tmp.erase(); + continue; + } else if ( *it == ')' ) { + suggestions.push_back( tmp ); + break; + } + + tmp += *it; + } + + *out_n_suggs = suggestions.size(); + return suggestions; +} + + +string Zemberek::recvResult() const +{ + int numbytes = 0; + string buf(""); + + int size = 0; + while (true) { + char s; + numbytes = recv (_conn, &s, 1, 0); + + // ' ' boşluk karakteri hiç gelmezse??? + if (s == ' ') { + char *endptr; + size = strtol (buf.c_str() , &endptr, 0); + buf.erase(); + break; + } + + buf += s; + } + char *ret = new char[size+1]; + numbytes = recv (_conn, ret, size, 0); + ret[numbytes]='\0'; + + string result = ret; + delete ret; + + return result; +} diff -ur enchant-1.2.6.orig/src/zemberek/zemberek.h enchant-1.2.6/src/zemberek/zemberek.h --- enchant-1.2.6.orig/src/zemberek/zemberek.h 2006-08-17 01:51:38.000000000 +0300 +++ enchant-1.2.6/src/zemberek/zemberek.h 2006-08-17 01:50:25.000000000 +0300 @@ -0,0 +1,41 @@ +/* Copyright (C) 2006 Barış Metin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifndef ZEMBEREK_H +#define ZEMBEREK_H + +#include +#include + + +using namespace std; + +class Zemberek +{ +public: + Zemberek(); + ~Zemberek(); + + bool checkWord(const string& str, size_t len) const; + vector suggestWord(const string& str, size_t len, size_t *out_n_suggs); + +private: + int _conn; + string recvResult() const; +}; +#endif diff -ur enchant-1.2.6.orig/src/zemberek/zemberek_provider.cpp enchant-1.2.6/src/zemberek/zemberek_provider.cpp --- enchant-1.2.6.orig/src/zemberek/zemberek_provider.cpp 2006-08-17 01:51:45.000000000 +0300 +++ enchant-1.2.6/src/zemberek/zemberek_provider.cpp 2006-08-17 02:15:15.000000000 +0300 @@ -0,0 +1,149 @@ +/* Copyright (C) 2006 Barış Metin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include + +#include "enchant.h" +#include "enchant-provider.h" + +#include "zemberek.h" + +ENCHANT_PLUGIN_DECLARE("Zemberek") + + +static int +zemberek_dict_check (EnchantDict * me, const char *const word, size_t len) +{ + Zemberek *checker; + + checker = (Zemberek *) me->user_data; + + if (checker->checkWord(word, len)) + return 0; + return 1; +} + +static char** +zemberek_dict_suggest (EnchantDict * me, const char *const word, + size_t len, size_t * out_n_suggs) +{ + Zemberek *checker; + + checker = (Zemberek *) me->user_data; + vector suggestions = checker->suggestWord (word, len, out_n_suggs); + + vector::const_iterator it = suggestions.begin(); + int suglen = suggestions.size(); + + if (suglen > 0) + { + char **sug; // enchant is oldie C ;) + sug = g_new0(char *, suglen+1); + + for (int i=0 ; i < suglen ; ++i, ++it ) + sug[i] = g_strdup(it->c_str()); + + return sug; + } + return 0; +} + + +static void +zemberek_provider_dispose(EnchantProvider *me) +{ + g_free(me); +} + +static EnchantDict* +zemberek_provider_request_dict(EnchantProvider *me, const char *tag) +{ + Zemberek* checker = new Zemberek(); + + if (!checker) + return NULL; + + EnchantDict* dict = g_new0(EnchantDict, 1); + dict->user_data = (void *) checker; + dict->check = zemberek_dict_check; + dict->suggest = zemberek_dict_suggest; + + return dict; +} + +static void +zemberek_provider_dispose_dict (EnchantProvider * me, EnchantDict * dict) +{ + Zemberek *checker; + checker = (Zemberek *) dict->user_data; + delete checker; + g_free (dict); +} + + +static char * +zemberek_provider_identify (EnchantProvider * me) +{ + return "zemberek"; +} + +static char * +zemberek_provider_describe (EnchantProvider * me) +{ + return "Zemberek Provider"; +} + +static void +zemberek_provider_free_string_list (EnchantProvider * me, char **str_list) +{ + g_strfreev (str_list); +} + +static char ** +zemberek_provider_list_dicts (EnchantProvider * me, + size_t * out_n_dicts) +{ + char ** out_list = NULL; + *out_n_dicts = 1; + out_list = g_new0 (char *, 2); + out_list[0] = g_strdup ("tr"); + + return out_list; +} + + +extern "C" { + +ENCHANT_MODULE_EXPORT(EnchantProvider *) +init_enchant_provider(void) +{ + EnchantProvider *provider; + + provider = g_new0(EnchantProvider, 1); + provider->dispose = zemberek_provider_dispose; + provider->request_dict = zemberek_provider_request_dict; + provider->dispose_dict = zemberek_provider_dispose_dict; + provider->identify = zemberek_provider_identify; + provider->describe = zemberek_provider_describe; + provider->list_dicts = zemberek_provider_list_dicts; + provider->free_string_list = zemberek_provider_free_string_list; + + return provider; +} + +}