Re: hspell-0.7 provider for enchant.

From: Dom Lachowicz (domlachowicz_at_yahoo.com)
Date: Mon Dec 22 2003 - 09:17:40 EST

  • Next message: Dom Lachowicz: "Commit: fix win32 crash on startup"

    Hi Yaacov,

    Thanks for this patch. I've cleaned it up a bit and
    committed it to Enchant's CVS. It's great that Enchant
    (and all of the Enchant-using applications) will have
    great Hebrew support, thanks you and the Hspell guys
    (hi Dan, Nadav).

    One small nit-pick - please send patches in "cvs diff
    -u" format in the future. Thanks.

    Happy New Year.

    Best regards,
    Dom

    --- Yaacov Zamir <zamiry1_at_macs.biu.ac.il> wrote:
    > hello,
    >
    > 1. Happy new year.
    >
    > 2. the next release of Hspell is near ( "which
    > should hopefully be out
    > tomorrow" - Nadav wrote ).
    >
    > 3. attached is the hspell_provider for Hspell ver.
    > 0.7. ( as is, no nead
    > to touch hspell code )
    >
    > 4. i changed the configure.in file for the new api:
    > ( attached is the patched version )
    > if test "x$check_hspell" != "xno"; then
    >
    >
    AC_CHECK_LIB(hspell,hspell_check_word,build_hspell=yes,
    > build_hspell=no)
    > fi
    >
    > 5. by,
    >
    > Thanks,
    > Kobi Zamir.
    >
    > p.s.
    > this provider is based on a beta hspell 0.7 but
    > i think it will work
    > on the real thing.
    > (the api is the same).
    > > /* vim: set sw=8: -*- Mode: C; tab-width: 8;
    > indent-tabs-mode: t; c-basic-offset: 8 -*- */
    > /* enchant
    > * Copyright (C) 2003 Yaacov Zamir
    > *
    > * This library is free software; you can
    > redistribute it and/or
    > * modify it under the terms of the GNU Lesser
    > General Public
    > * License as published by the Free Software
    > Foundation; either
    > * version 2.1 of the License, or (at your option)
    > any later version.
    > *
    > * This library 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
    > * Lesser General Public License for more details.
    > *
    > * You should have received a copy of the GNU Lesser
    > General Public
    > * License along with this library; if not, write to
    > the
    > * Free Software Foundation, Inc., 59 Temple Place -
    > Suite 330,
    > * Boston, MA 02111-1307, USA.
    > *
    > * In addition, as a special exception, Dom
    > Lachowicz
    > * gives permission to link the code of this program
    > with
    > * non-LGPL Spelling Provider libraries (eg: a MSFT
    > Office
    > * spell checker backend) and distribute linked
    > combinations including
    > * the two. You must obey the GNU Lesser General
    > Public License in all
    > * respects for all of the code used other than said
    > providers. If you modify
    > * this file, you may extend this exception to your
    > version of the
    > * file, but you are not obligated to do so. If you
    > do not wish to
    > * do so, delete this exception statement from your
    > version.
    > */
    >
    > #include <stdio.h>
    > #include <stdlib.h>
    > #include <string.h>
    >
    > #include <glib.h>
    > #include <hspell.h>
    >
    > #include "enchant.h"
    > #include "enchant-provider.h"
    >
    > ENCHANT_PLUGIN_DECLARE("Hspell")
    >
    > /**
    > * hspell helper functions
    > */
    >
    > /**
    > * is hebrew
    > * return TRUE if iso hebrew ( must be null
    > terminated )
    > */
    > int
    > is_hebrew( const char *const iso_word )
    > {
    > if ( iso_word[0] < 'à' || iso_word[0] > 'ú' )
    > return FALSE;
    > return TRUE;
    > }
    >
    > /**
    > * convert struct corlist to **char
    > * the **char must be g_freed
    > */
    > gchar**
    > corlist2strv ( struct corlist *cl )
    > {
    > int i;
    > gsize len;
    > char **sugg_arr = NULL;
    > const char *sugg;
    >
    > if (corlist_n(cl) > 0)
    > {
    > sugg_arr = g_new0 (char *, corlist_n(cl) + 1);
    > for (i = 0; i < corlist_n(cl); i++)
    > {
    > sugg = corlist_str(cl, i);
    > if (sugg)
    > sugg_arr[i] = g_convert (sugg,
    > strlen(sugg),
    > "utf-8",
    > "iso8859-8",
    > NULL,
    > &len,
    > NULL);
    > }
    > }
    >
    > return sugg_arr;
    > }
    >
    > /**
    > * end of helper functions
    > */
    >
    > /**
    > * this is global !??
    > */
    > static struct dict_radix *hspell_common_dict=NULL;
    >
    > static int
    > hspell_dict_check (EnchantDict * me, const char
    > *const word, size_t len)
    > {
    > int res;
    > char *iso_word;
    > gsize length;
    > int preflen;
    >
    > // convert to iso 8859-8
    > iso_word = g_convert (word,
    > len,
    > "iso8859-8",
    > "utf-8",
    > NULL,
    > &length,
    > NULL);
    >
    > // check if hebrew ( if not hebrew give it the
    > benefit of a doubt )
    > if (!is_hebrew( iso_word ))
    > return TRUE;
    >
    > // check
    > res = hspell_check_word( hspell_common_dict ,
    > iso_word , &preflen );
    >
    > // if not correct try gimatria
    > if ( res!=1 )
    > {
    > res=hspell_is_canonic_gimatria( iso_word );
    > if ( res !=0 ) res = 1;
    > }
    >
    > // free the word
    > g_free ( iso_word );
    >
    > return (res!=1);
    > }
    >
    > static char **
    > hspell_dict_suggest (EnchantDict * me, const char
    > *const word,
    > size_t len, size_t * out_n_suggs)
    > {
    >
    > int res;
    > gsize length;
    > char *iso_word;
    > char **sugg_arr = NULL;
    > struct corlist cl;
    >
    > // convert to iso 8859-8
    > iso_word = g_convert (word,
    > len,
    > "iso8859-8",
    > "utf-8",
    > NULL,
    > &length,
    > NULL);
    >
    > // check if hebrew ( if not hebrew cant do anything
    > )
    > if (!is_hebrew( iso_word ))
    > return NULL;
    >
    > // get suggestions
    > corlist_init (&cl);
    > hspell_trycorrect (hspell_common_dict, iso_word,
    > &cl);
    >
    > // set size of list
    > *out_n_suggs = corlist_n(&cl);
    >
    > // convert suggestion list to strv list
    > sugg_arr = corlist2strv (&cl);
    >
    > // free the list
    > corlist_free(&cl);
    >
    > // free the word
    >
    === message truncated ===> AC_INIT(src/enchant.h)
    >
    > dnl Set release number
    > dnl This is derived from "Versioning" chapter of
    > info libtool documentation.
    > PACKAGE=enchant
    > dnl 4a) Increment when removing or changing
    > interfaces.
    > ENCHANT_MAJOR_VERSION=1
    > dnl 4a) 5) Increment when adding interfaces.
    > dnl 6) Set to zero when removing or changing
    > interfaces.
    > ENCHANT_MINOR_VERSION=1
    > dnl 3) Increment when interfaces not changed at
    > all,
    > dnl only bug fixes or internal changes
    > made.
    > dnl 4b) Set to zero when adding, removing or
    > changing interfaces.
    > ENCHANT_MICRO_VERSION=2
    > dnl
    > dnl Set this too
    > MAJOR_VERSION_PLUS_MINOR_VERSION=`expr
    > $ENCHANT_MAJOR_VERSION + $ENCHANT_MINOR_VERSION`
    > dnl
    >
    VERSION=$ENCHANT_MAJOR_VERSION.$ENCHANT_MINOR_VERSION.$ENCHANT_MICRO_VERSION
    > dnl Version info for libraries =
    > CURRENT:REVISION:AGE
    >
    VERSION_INFO=$MAJOR_VERSION_PLUS_MINOR_VERSION:$ENCHANT_MICRO_VERSION:$ENCHANT_MINOR_VERSION
    > AC_SUBST(VERSION_INFO)
    > AC_SUBST(ENCHANT_MAJOR_VERSION)
    > AC_SUBST(ENCHANT_MINOR_VERSION)
    > AC_SUBST(ENCHANT_MICRO_VERSION)
    >
    > AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
    > AM_MAINTAINER_MODE
    >
    > dnl Checks for programs.
    > AC_ISC_POSIX
    > AC_PROG_CC
    > AC_PROG_CPP
    > AC_PROG_INSTALL
    > AC_PROG_LN_S
    > AC_PROG_MAKE_SET
    > AC_STDC_HEADERS
    > AC_LIBTOOL_WIN32_DLL
    > AM_PROG_LIBTOOL
    >
    > AC_C_CONST
    >
    > AC_CHECK_FUNCS(flock lockf)
    >
    > have_cxx=yes
    > AC_PROG_CXX(,have_cxx=no)
    > AM_CONDITIONAL(WITH_CXX, test "x$have_cxx" = "xyes")
    >
    > AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
    >
    > PKG_CHECK_MODULES(ENCHANT, [glib-2.0 gmodule-2.0])
    >
    > AC_SUBST(ENCHANT_CFLAGS)
    > AC_SUBST(ENCHANT_LIBS)
    >
    > AC_MSG_CHECKING([for native Win32])
    > case "$host" in
    > *-*-mingw*)
    > native_win32=yes
    > ;;
    > *)
    > native_win32=no
    > ;;
    > esac
    > AC_MSG_RESULT([$native_win32])
    > AM_CONDITIONAL(OS_WIN32, test "x$native_win32" =
    > "xyes")
    >
    > build_ispell=yes
    >
    > AC_ARG_ENABLE(ispell, [ --disable-ispell enable
    > the ispell backend [default=auto]],
    > build_ispell="$enableval", build_ispell=yes)
    >
    > if test "x$have_cxx" = "xno"; then
    > build_ispell=no
    > fi
    > AM_CONDITIONAL(WITH_ISPELL, test "x$build_ispell" =
    > "xyes")
    >
    > ispell_dir=${datadir}/enchant/ispell
    > AC_ARG_WITH(ispell-dir, [ --with-ispell-dir=PATH
    > path to installed ispell dicts ])
    >
    > if test "x$with_ispell_dir" != "x" ; then
    > ispell_dir=$with_ispell_dir
    > fi
    >
    >
    ISPELL_CFLAGS="-DENCHANT_ISPELL_DICT_DIR='\"$ispell_dir\"'"
    > AC_SUBST(ISPELL_CFLAGS)
    >
    > build_myspell=yes
    >
    > AC_ARG_ENABLE(myspell, [ --disable-myspell
    > enable the myspell backend [default=auto]],
    > build_myspell="$enableval", build_myspell=yes)
    >
    > if test "x$have_cxx" = "xno"; then
    > build_myspell=no
    > fi
    > AM_CONDITIONAL(WITH_MYSPELL, test "x$build_myspell"
    > = "xyes")
    >
    > myspell_dir=${datadir}/enchant/myspell
    > AC_ARG_WITH(myspell-dir, [ --with-myspell-dir=PATH
    > path to installed myspell dicts ])
    >
    > if test "x$with_myspell_dir" != "x" ; then
    > myspell_dir=$with_myspell_dir
    > fi
    >
    >
    MYSPELL_CFLAGS="-DENCHANT_MYSPELL_DICT_DIR='\"$myspell_dir\"'"
    > AC_SUBST(MYSPELL_CFLAGS)
    >
    > check_aspell=yes
    > build_aspell=no
    >
    > AC_ARG_ENABLE(aspell, [ --disable-aspell enable
    > the aspell backend [default=auto]],
    > check_aspell="$enableval", check_aspell=yes)
    >
    > AC_ARG_WITH(aspell-prefix, [
    > --with-aspell-prefix=DIR
    > specify under which prefix
    > aspell is installed.],
    > with_aspell_prefix="$withval", )
    >
    > if test "x$check_aspell" != "xno"; then
    > saved_LDFLAGS=$LDFLAGS
    >
    > if test "x$with_aspell_prefix" != "x"; then
    >
    > LDFLAGS="-L$with_aspell_prefix/lib "$LDFLAGS
    > ASPELL_INC="-I$with_aspell_prefix/include"
    > ASPELL_LIBS="-L$with_aspell_prefix/lib
    > -laspell"
    >
    >
    ASPELL_DICT_DIR="'\"$with_aspell_prefix/lib/aspell\"'"
    > else
    > aspell_prefix=${prefix}
    > if test "x$prefix" = "xNONE"; then
    > aspell_prefix="/usr/local"
    > fi
    >
    > AC_CHECK_PROG(HAVE_ASPELL, aspell, yes, no)
    > if test "x$HAVE_ASPELL" = "xyes"; then
    > #perl -e 'if (<STDIN> =~ /(.*) Aspell
    > 0\.(.*)\.(.*)/) { print "$2\n"; } else { print
    > "0\n"; }'`;
    > AC_MSG_CHECKING([For Aspell >= 0.50.0])
    > aspell_major=`aspell -v | awk -F. '{print $4;}'`
    > if test "$aspell_major" -ge "50"; then
    > LDFLAGS="-L`aspell config prefix`/lib
    > "$LDFLAGS
    > ASPELL_INC="-I`aspell config prefix`/include"
    > ASPELL_LIBS="-L`aspell config prefix`/lib
    > -laspell"
    > ASPELL_DICT_DIR="'\"`aspell config
    > dict-dir`\"'"
    >
    > AC_MSG_RESULT([yes])
    > else
    > AC_MSG_RESULT([no])
    > fi
    > fi
    >
    > if test "x$ASPELL_DICT_DIR" = "x"; then
    > AC_MSG_WARN([Didn't find aspell >= 0.50.0 and
    > no explicit path aspell specified. Guessing at
    > $aspell_prefix])
    > ASPELL_LIBS="-L$aspell_prefix/lib -laspell"
    >
    > ASPELL_DICT_DIR="'\"$aspell_prefix/lib/aspell\"'"
    > fi
    > fi
    >
    >
    >
    AC_CHECK_LIB(aspell,new_aspell_config,build_aspell=yes,
    > [AC_CHECK_LIB(pspell, new_pspell_config,
    > build_aspell=yes, AC_MSG_WARN([Enchant building
    > without the aspell library]))]
    > ,)
    > LDFLAGS=$saved_LDFLAGS
    >
    > AC_SUBST(ASPELL_INC)
    > AC_SUBST(ASPELL_LIBS)
    > AC_SUBST(ASPELL_DICT_DIR)
    > fi
    >
    > AM_CONDITIONAL(WITH_ASPELL, test "$build_aspell" =
    > yes)
    >
    > build_uspell=no
    >
    === message truncated ===

    __________________________________
    Do you Yahoo!?
    Protect your identity with Yahoo! Mail AddressGuard
    http://antispam.yahoo.com/whatsnewfree



    This archive was generated by hypermail 2.1.4 : Mon Dec 22 2003 - 09:17:54 EST