/* The example is cooked from aspell.cpp program. */ #include #include "iostream.hpp" #include "posib_err.hpp" #include "speller.hpp" #include "aspell.h" #include "gettext.h" using namespace aspell; void print_error(ParmString msg) { CERR.printf(_("Error: %s\n"), msg.str()); } void print_error(ParmString msg, ParmString str) { CERR.put(_("Error: ")); CERR.printf(msg.str(), str.str()); CERR.put('\n'); } static void test_word_spelling(AspellSpeller * speller, char* word); static char* words [] = { "Christmas", "christmas", "USA", "usa", NULL }; int main(int argc, char **argv) { aspell_gettext_init(); AspellConfig * config = new_aspell_config(); aspell_config_replace(config, "lang", "en"); AspellCanHaveError * ret = new_aspell_speller(config); if (aspell_error(ret)) { print_error (aspell_error_message(ret)); exit(1); } AspellSpeller * speller = to_aspell_speller(ret); int i = 0; char* w = NULL; while ((w = words[i++])) test_word_spelling (speller, w); return 0; } static void test_word_spelling(AspellSpeller * speller, char* word) { int result = -1; result = aspell_speller_check(speller, word, -1); if (result == 1) { printf("word \"%s\" - is correct\n", word); } else if (result == 0) { printf("word \"%s\" - is out of dictionary\n", word); } else { printf(" aspell_speller_check error, msg %s, word %s\n", aspell_speller_error_message(speller), word); } return; }