1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2003,2004 Dom Lachowicz
4 * 2006-2007 Harri Pitkänen <hatapitk@iki.fi>
5 * 2006 Anssi Hannula <anssi.hannula@gmail.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02110-1301, USA.
22 * In addition, as a special exception, Dom Lachowicz
23 * gives permission to link the code of this program with
24 * non-LGPL Spelling Provider libraries (eg: a MSFT Office
25 * spell checker backend) and distribute linked combinations including
26 * the two. You must obey the GNU Lesser General Public License in all
27 * respects for all of the code used other than said providers. If you modify
28 * this file, you may extend this exception to your version of the
29 * file, but you are not obligated to do so. If you do not wish to
30 * do so, delete this exception statement from your version.
38 #include <libvoikko/voikko.h>
41 #include "enchant-provider.h"
44 * Voikko is a Finnish spell checker. More information is available from:
46 * http://voikko.sourceforge.net/
48 ENCHANT_PLUGIN_DECLARE("Voikko")
51 voikko_dict_check (EnchantDict * me, const char *const word, size_t len)
56 voikko_handle = (long) me->user_data;
57 result = voikko_spell_cstr(voikko_handle, word);
58 if (result == VOIKKO_SPELL_FAILED)
60 else if (result == VOIKKO_SPELL_OK)
67 voikko_dict_suggest (EnchantDict * me, const char *const word,
68 size_t len, size_t * out_n_suggs)
73 voikko_handle = (long) me->user_data;
74 sugg_arr = voikko_suggest_cstr(voikko_handle, word);
77 for (*out_n_suggs = 0; sugg_arr[*out_n_suggs] != NULL; (*out_n_suggs)++);
82 voikko_provider_request_dict (EnchantProvider * me, const char *const tag)
85 const char * voikko_error;
88 /* Only Finnish is supported at the moment */
89 if (strncmp(tag, "fi_FI", 6) != 0 && strncmp(tag, "fi", 3) != 0)
92 voikko_error = voikko_init(&voikko_handle, "fi_FI", 0);
94 enchant_provider_set_error(me, voikko_error);
98 dict = g_new0 (EnchantDict, 1);
99 dict->user_data = (void *)(long) voikko_handle;
100 dict->check = voikko_dict_check;
101 dict->suggest = voikko_dict_suggest;
107 voikko_provider_dispose_dict (EnchantProvider * me, EnchantDict * dict)
109 voikko_terminate((long) dict->user_data);
114 voikko_provider_dictionary_exists (struct str_enchant_provider * me,
115 const char *const tag)
119 /* Only Finnish is supported */
120 if (strncmp(tag, "fi", 3) != 0)
123 /* Check that a dictionary is actually available */
124 if (voikko_init(&voikko_handle, "fi_FI", 0) == NULL) {
125 voikko_terminate(voikko_handle);
133 voikko_provider_list_dicts (EnchantProvider * me,
134 size_t * out_n_dicts)
136 char ** out_list = NULL;
140 if (voikko_init(&voikko_handle, "fi_FI", 0) == NULL) {
141 voikko_terminate(voikko_handle);
143 out_list = g_new0 (char *, *out_n_dicts + 1);
144 out_list[0] = g_strdup("fi");
151 voikko_provider_free_string_list (EnchantProvider * me, char **str_list)
153 g_strfreev (str_list);
157 voikko_provider_dispose (EnchantProvider * me)
163 voikko_provider_identify (EnchantProvider * me)
169 voikko_provider_describe (EnchantProvider * me)
171 return "Voikko Provider";
178 ENCHANT_MODULE_EXPORT (EnchantProvider *)
179 init_enchant_provider (void);
182 init_enchant_provider (void)
184 EnchantProvider *provider;
186 provider = g_new0 (EnchantProvider, 1);
187 provider->dispose = voikko_provider_dispose;
188 provider->request_dict = voikko_provider_request_dict;
189 provider->dispose_dict = voikko_provider_dispose_dict;
190 provider->dictionary_exists = voikko_provider_dictionary_exists;
191 provider->identify = voikko_provider_identify;
192 provider->describe = voikko_provider_describe;
193 provider->list_dicts = voikko_provider_list_dicts;
194 provider->free_string_list = voikko_provider_free_string_list;