1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2003 Dom Lachowicz
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02110-1301, USA.
20 * In addition, as a special exception, Dom Lachowicz
21 * gives permission to link the code of this program with
22 * the non-LGPL Spelling Provider libraries (eg: a MSFT Office
23 * spell checker backend) and distribute linked combinations including
24 * the two. You must obey the GNU Lesser General Public License in all
25 * respects for all of the code used other than said providers. If you modify
26 * this file, you may extend this exception to your version of the
27 * file, but you are not obligated to do so. If you do not wish to
28 * do so, delete this exception statement from your version.
37 enumerate_providers_fn (const char * const name,
38 const char * const desc,
39 const char * const file,
42 printf ("%s: '%s' (%s)\n", name, desc, file);
46 describe_dict_fn (const char * const lang,
47 const char * const name,
48 const char * const desc,
49 const char * const file,
52 printf ("%s: %s '%s' (%s)\n", lang, name, desc, file);
55 static const char * print_found(EnchantDict *dict, const char * word)
57 if (enchant_dict_check (dict, word, -1) == 0)
63 run_dict_tests (EnchantDict * dict)
69 const char *check_checks[] = { "hello", "helllo" };
70 const char *sugg_checks[] = { "helllo", "taag" };
72 for (i = 0; i < (sizeof (check_checks) / sizeof (check_checks[0])); i++)
74 printf ("enchant_dict_check (%s): %s\n", check_checks[i],
75 print_found(dict, check_checks[i]));
78 for (i = 0; i < (sizeof (sugg_checks) / sizeof (sugg_checks[0])); i++)
81 enchant_dict_suggest (dict, sugg_checks[i], strlen (sugg_checks[i]),
84 printf ("enchant_dict_suggest(%s): %d\n", sugg_checks[i], n_suggs);
85 for (j = 0; j < n_suggs; j++)
87 printf ("\t=>%s\n", suggs[j]);
91 enchant_dict_free_string_list (dict, suggs);
94 printf ("Adding 'helllo' to session\n");
95 enchant_dict_add_to_session (dict, "helllo", 6);
96 for (i = 0; i < (sizeof (check_checks) / sizeof (check_checks[0])); i++)
98 printf ("enchant_dict_check (%s): %s\n", check_checks[i],
99 print_found(dict, check_checks[i]));
102 printf ("Adding 'helllo' to personal\n");
103 enchant_dict_add (dict, "helllo", 6);
104 for (i = 0; i < (sizeof (check_checks) / sizeof (check_checks[0])); i++)
106 printf ("enchant_dict_check (%s): %s\n", check_checks[i],
107 print_found(dict, check_checks[i]));
112 main (int argc, char **argv)
114 EnchantBroker *broker;
118 broker = enchant_broker_init ();
120 dict = enchant_broker_request_dict (broker, "en_US");
124 err = enchant_broker_get_error (broker);
126 fprintf (stderr, "Couldn't create dictionary for en_US: %s\n", err);
128 fprintf (stderr, "Couldn't create dictionary for en_US\n");
132 enchant_dict_describe (dict, describe_dict_fn, NULL);
133 run_dict_tests (dict);
134 enchant_broker_free_dict (broker, dict);
137 dict = enchant_broker_request_pwl_dict (broker, "test.pwl");
140 err = enchant_broker_get_error (broker);
142 fprintf (stderr, "Couldn't create personal wordlist dictionary: %s\n", err);
144 fprintf (stderr, "Couldn't create personal wordlist dictionary\n");
148 enchant_dict_describe (dict, describe_dict_fn, NULL);
149 run_dict_tests (dict);
150 enchant_broker_free_dict (broker, dict);
153 enchant_broker_describe (broker, enumerate_providers_fn, NULL);
154 enchant_broker_free (broker);