//__________________________________________________________________________ void Speller::Aspell::Suggest::resetConfig() throw( std::invalid_argument, std::runtime_error ) { delete_aspell_config( fconfig ); fconfig = new_aspell_config(); try { setConfig(); } catch( const std::invalid_argument& err ) { throw err; } AspellCanHaveError* ret = new_aspell_speller( fconfig ); if( aspell_error_number( ret ) != 0 ) { delete_aspell_can_have_error( ret ); throw std::runtime_error( "(Aspell::Speller::Suggest::Reset" "Config): Error in creating " "speller." ); } else { // Following statement causes a crash, hence commented out //delete_aspell_speller( fspeller ); fspeller = to_aspell_speller( ret ); delete_aspell_config( fconfig ); fconfig = aspell_speller_config( fspeller ); } }
SpellChecker::~SpellChecker() { delete_aspell_speller(m_spell_checker_ru); delete_aspell_config(m_spell_config_ru); delete_aspell_speller(m_spell_checker_en); delete_aspell_config(m_spell_config_en); }
AspellSpeller * weechat_aspell_speller_new (const char *lang) { AspellConfig *config; AspellCanHaveError *ret; AspellSpeller *new_speller; struct t_infolist *infolist; if (!lang) return NULL; if (weechat_aspell_plugin->debug) { weechat_printf (NULL, "%s: creating new speller for lang \"%s\"", ASPELL_PLUGIN_NAME, lang); } /* create a speller instance for the newly created cell */ config = new_aspell_config(); aspell_config_replace (config, "lang", lang); /* apply all options on speller */ infolist = weechat_infolist_get ("option", NULL, "aspell.option.*"); if (infolist) { while (weechat_infolist_next (infolist)) { aspell_config_replace (config, weechat_infolist_string (infolist, "option_name"), weechat_infolist_string (infolist, "value")); } weechat_infolist_free (infolist); } ret = new_aspell_speller (config); if (aspell_error (ret) != 0) { weechat_printf (NULL, "%s%s: error: %s", weechat_prefix ("error"), ASPELL_PLUGIN_NAME, aspell_error_message (ret)); delete_aspell_config (config); delete_aspell_can_have_error (ret); return NULL; } new_speller = to_aspell_speller (ret); weechat_hashtable_set (weechat_aspell_spellers, lang, new_speller); /* free configuration */ delete_aspell_config (config); return new_speller; }
SpellChecker::~SpellChecker() { delete m_regExp; delete m_map; delete_aspell_speller(spell_checker1); delete_aspell_speller(spell_checker2); delete_aspell_config(spell_config1); delete_aspell_config(spell_config2); delete dictList; }
struct spelling * spelling_init(char *lang) { AspellConfig *config; AspellCanHaveError *ret; struct spelling *spelling = malloc(sizeof(struct spelling)); if (spelling == NULL) { warn("malloc(spelling)"); return NULL; } config = new_aspell_config(); aspell_config_replace(config, "lang", spelling_lookup_lang(lang)); aspell_config_replace(config, "dict-dir", bfile("data/dict/")); aspell_config_replace(config, "encoding", "iso-8859-1"); ret = new_aspell_speller(config); delete_aspell_config(config); spelling->speller = to_aspell_speller(ret); if (aspell_error(ret) != 0) { printf("Error: %s\n", aspell_speller_error_message(spelling->speller)); delete_aspell_can_have_error(ret); return NULL; } spelling->conv = iconv_open("iso-8859-1", "utf-8"); spelling->conv_out = iconv_open("utf-8", "iso-8859-1"); return spelling; }
bool KAspellChecker::init() { QString locale = QString(QLocale::system().name()).left(2); if (locale.length() < 2) locale = "en"; AspellConfig * config = new_aspell_config(); aspell_config_replace(config, "lang", locale.toLocal8Bit().data()); AspellCanHaveError * ret = new_aspell_speller(config); delete_aspell_config(config); if (aspell_error(ret) != 0) { qDebug("Error: %s\n",aspell_error_message(ret)); delete_aspell_can_have_error(ret); return false; } m_speller = to_aspell_speller(ret); config = aspell_speller_config(m_speller); qDebug() << "USING LANG= " << aspell_config_retrieve(config, "lang"); return true; }
/** * Ctor for aspell objects. * This is a custom constructor and takes a hash of config options: key, value pairs. * Common use: * * a = Aspell.new({"lang"=>"de", "jargon"=>"berlin"}) * * For a list of config options, see aspell manual. * @param options hash of options */ static VALUE aspell_s_new1(VALUE klass, VALUE options) { //aspell values AspellCanHaveError * ret; AspellSpeller * speller; AspellConfig * config; //create new config config = new_aspell_config(); //set options set_options(config, options); //create speller: ret = new_aspell_speller(config); delete_aspell_config(config); if (aspell_error(ret) != 0) { const char *tmp = strdup(aspell_error_message(ret)); delete_aspell_can_have_error(ret); rb_raise(cAspellError, "%s", tmp); } speller = to_aspell_speller(ret); //wrap pointer return Data_Wrap_Struct(klass, 0, aspell_free, speller); }
int weechat_aspell_speller_dict_supported (const char *lang) { #ifdef USE_ENCHANT return enchant_broker_dict_exists (broker, lang); #else struct AspellConfig *config; AspellDictInfoList *list; AspellDictInfoEnumeration *elements; const AspellDictInfo *dict; int rc; rc = 0; config = new_aspell_config (); list = get_aspell_dict_info_list (config); elements = aspell_dict_info_list_elements (list); while ((dict = aspell_dict_info_enumeration_next (elements)) != NULL) { if (strcmp (dict->name, lang) == 0) { rc = 1; break; } } delete_aspell_dict_info_enumeration (elements); delete_aspell_config (config); return rc; #endif /* USE_ENCHANT */ }
SpellCheck::SpellCheck(QObject *parent) : QObject(parent), config(NULL), spell_checker(NULL) { config = new_aspell_config(); aspell_config_replace(config, "encoding", "utf-8"); aspell_config_replace(config, "personal", (dcpp::Util::getPath(dcpp::Util::PATH_USER_CONFIG)+"dict").c_str()); #if defined(Q_WS_WIN) aspell_config_replace(config, "data-dir", "./aspell/data"); aspell_config_replace(config, "dict-dir", "./aspell/dict"); #endif if (config) { AspellCanHaveError *error = new_aspell_speller(config); if (aspell_error(error)) { delete_aspell_config(config); printf("%s\n", aspell_error_message(error)); config = NULL; } else spell_checker = to_aspell_speller(error); } }
SpellCheck::~SpellCheck(){ if (spell_checker) aspell_speller_save_all_word_lists(spell_checker); delete_aspell_config(config); delete_aspell_speller(spell_checker); }
//__________________________________________________________________________ void Speller::Aspell::Suggest::init(const std::string& lang, const std::string& jargon, const std::string& encoding) throw( std::invalid_argument, std::runtime_error ) { // Save aspell configuration values flang = lang; fjargon = jargon; fencoding = encoding; fconfig = new_aspell_config(); try { setConfig(); } catch( const std::invalid_argument& err ) { throw err; } AspellCanHaveError* ret = new_aspell_speller( fconfig ); delete_aspell_config( fconfig ); if( aspell_error_number( ret ) != 0 ) { delete_aspell_can_have_error( ret ); throw std::runtime_error( "(Aspell::Speller::Suggest::init" "): Error in creating speller." ); } else { fspeller = to_aspell_speller( ret ); fconfig = aspell_speller_config( fspeller ); } }
SpellChecker::~SpellChecker() { disconnect(ChatWidgetManager::instance(), SIGNAL(chatWidgetCreated(ChatWidget *)), this, SLOT(chatCreated(ChatWidget *))); delete_aspell_config(spellConfig); foreach(AspellSpeller *speller, checkers.values()) delete_aspell_speller(speller); }
ASpellChecker::~ASpellChecker() { if(config_) { delete_aspell_config(config_); config_ = NULL; } clearSpellers(); }
AspellAdapterImpl::~AspellAdapterImpl() { if (NULL != aspellSpeller_) { delete_aspell_speller(aspellSpeller_); } if (NULL != aspellConfig_) { delete_aspell_config(aspellConfig_); } }
static void checker_dispose( checker *c ) { if ( c->spell_config != NULL ) delete_aspell_config(c->spell_config); if ( c->spell_checker != NULL ) delete_aspell_speller(c->spell_checker); if ( c->next != NULL ) checker_dispose( c->next ); free( c ); }
SpellCheck::~SpellCheck() { if (spell_checker) aspell_speller_save_all_word_lists(spell_checker); if (config) WSSET(WS_APP_ASPELL_LANG, aspell_config_retrieve(config, "lang")); delete_aspell_config(config); delete_aspell_speller(spell_checker); }
/** * Free memory structures used wiith spell-checker 'chk' */ void spellcheck_destroy(void * chk) { struct linkgrammar_aspell *aspell = (struct linkgrammar_aspell *)chk; if (aspell) { delete_aspell_speller(aspell->speller); delete_aspell_config(aspell->config); free(aspell); aspell = NULL; } }
ASpellChecker::~ASpellChecker() { if(config_) { delete_aspell_config(config_); config_ = NULL; } if(speller_) { delete_aspell_speller(speller_); speller_ = NULL; } }
/** * create a neew spell-checker for the language 'lang' */ void * spellcheck_create(const char * lang) { struct linkgrammar_aspell *aspell = NULL; size_t i = 0; AspellCanHaveError *spell_err = NULL; for (i = 0; i < sizeof(spellcheck_lang_mapping)/sizeof(char *); i += 2) { if (0 != strcmp(lang, spellcheck_lang_mapping[i])) continue; aspell = (struct linkgrammar_aspell *)malloc(sizeof(struct linkgrammar_aspell)); if (!aspell) { prt_error("Error: out of memory. Aspell not used.\n"); aspell = NULL; break; } aspell->config = NULL; aspell->speller = NULL; aspell->config = new_aspell_config(); if (aspell_config_replace(aspell->config, ASPELL_LANG_KEY, spellcheck_lang_mapping[i]) == 0) { prt_error("Error: failed to set language in aspell: %s\n", lang); delete_aspell_config(aspell->config); free(aspell); aspell = NULL; break; } spell_err = new_aspell_speller(aspell->config); if (aspell_error_number(spell_err) != 0) { prt_error("Error: Aspell: %s\n", aspell_error_message(spell_err)); delete_aspell_can_have_error(spell_err); delete_aspell_config(aspell->config); free(aspell); aspell = NULL; break; } aspell->speller = to_aspell_speller(spell_err); break; } return aspell; }
bool AspellAdapterImpl::isDictionaryAvailable(const std::string & langCode) { AspellConfig * tempAspellConfig = new_aspell_config(); aspell_config_replace(tempAspellConfig, "lang", langCode.c_str()); AspellCanHaveError * possibleError = new_aspell_speller(tempAspellConfig); bool result = true; if (aspell_error_number(possibleError) != 0) { result = false; } else { AspellSpeller * tempSpeller = to_aspell_speller(possibleError); delete_aspell_speller(tempSpeller); } delete_aspell_config(tempAspellConfig); return result; }
void ASpellChecker::setActiveLanguages(const QList<QString>& langs) { clearSpellers(); foreach(const QString& lang, langs) { AspellConfig* conf = aspell_config_clone(config_); aspell_config_replace(conf, "lang", lang.toUtf8().constData()); AspellCanHaveError* ret = new_aspell_speller(conf); if (aspell_error_number(ret) == 0) { spellers_.append(to_aspell_speller(ret)); } else { qDebug() << QString("Aspell error: %1").arg(aspell_error_message(ret)); } delete_aspell_config(conf); }
SpellCheck::SpellCheck(QObject *parent) : QObject(parent), config(NULL), spell_checker(NULL) { config = new_aspell_config(); aspell_config_replace(config, "encoding", "utf-8"); aspell_config_replace(config, "personal", (QDir::homePath()+QDir::separator()+".eiskaltdc++"+QDir::separator()+"dict").toAscii().constData()); if (config){ /*const AspellDictInfoList *dicts = get_aspell_dict_info_list(config); AspellDictInfoEnumeration *enumer = aspell_dict_info_list_elements(dicts); const AspellDictInfo *info = NULL; QStringList all; while ((info = aspell_dict_info_enumeration_next(enumer)) != NULL) all.append(QString::fromUtf8(info->code, strlen(info->code))); if (WSGET(WS_APP_ASPELL_LANG).isEmpty()){ QString lc_prefix = QLocale::system().name(); if (all.contains(lc_prefix))//Loading dictionary from system locale aspell_config_replace(config, "lang", lc_prefix.toAscii().constData()); else if (all.contains(lc_prefix.left(lc_prefix.indexOf("_")))) { aspell_config_replace(config, "lang", lc_prefix.left(lc_prefix.indexOf("_")).toAscii().constData()); } } else aspell_config_replace(config, "lang", WSGET(WS_APP_ASPELL_LANG).toAscii().constData());*/ AspellCanHaveError *error = new_aspell_speller(config); if (aspell_error(error) != 0){ delete_aspell_config(config); printf("%s\n", aspell_error_message(error)); config = NULL; } else spell_checker = to_aspell_speller(error); } }
void ASpellChecker::setActiveLanguages(const QSet<LanguageManager::LangId>& langs) { clearSpellers(); for(auto const &lang: langs) { AspellConfig* conf = aspell_config_clone(config_); aspell_config_replace(conf, "lang", LanguageManager::toString(lang) .replace(QLatin1Char('-'),QLatin1Char('_')).toUtf8().constData()); AspellCanHaveError* ret = new_aspell_speller(conf); if (aspell_error_number(ret) == 0) { spellers_.append(to_aspell_speller(ret)); } else { qDebug() << QString("Aspell error: %1").arg(aspell_error_message(ret)); } delete_aspell_config(conf); } }
/** * List all available dictionaries. * @param class object * @return array of AspellDictInfo objects. */ static VALUE aspell_s_list_dicts(VALUE klass) { AspellConfig * config; AspellDictInfoList * dlist; AspellDictInfoEnumeration * dels; const AspellDictInfo * entry; VALUE result = rb_ary_new(); //get a list of dictionaries config = new_aspell_config(); dlist = get_aspell_dict_info_list(config); delete_aspell_config(config); //iterate over list - fill ruby array dels = aspell_dict_info_list_elements(dlist); while ( (entry = aspell_dict_info_enumeration_next(dels)) != 0) { rb_ary_push(result, Data_Wrap_Struct(cDictInfo, 0, 0, (AspellDictInfo *)entry)); } delete_aspell_dict_info_enumeration(dels); return result; }
int weechat_aspell_completion_dicts_cb (const void *pointer, void *data, const char *completion_item, struct t_gui_buffer *buffer, struct t_gui_completion *completion) { #ifndef USE_ENCHANT struct AspellConfig *config; AspellDictInfoList *list; AspellDictInfoEnumeration *elements; const AspellDictInfo *dict; #endif /* USE_ENCHANT */ /* make C compiler happy */ (void) pointer; (void) data; (void) completion_item; (void) buffer; #ifdef USE_ENCHANT enchant_broker_list_dicts (broker, weechat_aspell_completion_enchant_add_dict_cb, completion); #else config = new_aspell_config (); list = get_aspell_dict_info_list (config); elements = aspell_dict_info_list_elements (list); while ((dict = aspell_dict_info_enumeration_next (elements)) != NULL) { weechat_hook_completion_list_add (completion, dict->name, 0, WEECHAT_LIST_POS_SORT); } delete_aspell_dict_info_enumeration (elements); delete_aspell_config (config); #endif /* USE_ENCHANT */ return WEECHAT_RC_OK; }
/** * Dispose of a userdata * @param u the object to dispose */ void userdata_dispose( userdata *u ) { if ( u != NULL ) { if ( u->rules != NULL ) u->rules = recipe_dispose( u->rules ); if ( u->ignoring != NULL ) stack_delete( u->ignoring ); if ( u->range_stack != NULL ) stack_delete( u->range_stack ); if ( u->spell_config != NULL ) delete_aspell_config(u->spell_config); if ( u->spell_checker != NULL ) delete_aspell_speller(u->spell_checker); if ( u->last_word != NULL ) free( u->last_word ); if ( u->dest_map != NULL ) hashmap_dispose( u->dest_map ); // we don't own the hh_exceptions free( u ); } }
static gboolean gtkspell_set_language_internal(GtkSpell *spell, const gchar *lang, GError **error) { AspellConfig *config; AspellCanHaveError *err; if (lang == NULL) { lang = g_getenv("LANG"); if (lang) { if (g_strncasecmp(lang, "C", 1) == 0) lang = NULL; else if (lang[0] == 0) lang = NULL; } } config = new_aspell_config(); if (lang) aspell_config_replace(config, "language-tag", lang); aspell_config_replace(config, "encoding", "utf-8"); err = new_aspell_speller(config); delete_aspell_config(config); if (aspell_error_number(err) != 0) { #ifdef USING_ASPELL g_set_error(error, GTKSPELL_ERROR, GTKSPELL_ERROR_BACKEND, "aspell: %s", aspell_error_message(err)); #elif defined USING_PSPELL g_set_error(error, GTKSPELL_ERROR, GTKSPELL_ERROR_BACKEND, "pspell: %s", aspell_error_message(err)); #endif return FALSE; } if (spell->speller) delete_aspell_speller(spell->speller); spell->speller = to_aspell_speller(err); return TRUE; }
/** * Ctor for aspell objects: * Aspell.new(language, jargon, size, encoding) * Please note: All parameters are optional. If a parameter is omitted, a default value is assumed from * the environment (eg lang from $LANG). To retain default values, you can use nil * as value: to set only size: Aspell.new(nil, nil, "80") * @param language ISO639 language code plus optional ISO 3166 counry code as string (eg: "de" or "us_US") * @param jargon a special jargon of the selected language * @param size the size of the dictionary to chose (if there are options) * @param encoding the encoding to use * @exception Exception if the specified dictionary is not found. */ static VALUE aspell_s_new(int argc, VALUE *argv, VALUE klass) { VALUE vlang, vjargon, vsize, vencoding; const char *tmp; //aspell values AspellCanHaveError * ret; AspellSpeller * speller; AspellConfig * config; //create new config config = new_aspell_config(); //extract values rb_scan_args(argc, argv, "04", &vlang, &vjargon, &vsize, &vencoding); //language: if (RTEST(vlang)) set_option(config, "lang", STR2CSTR(vlang)); //jargon: if (RTEST(vjargon)) set_option(config, "jargon", STR2CSTR(vjargon)); //size: if (RTEST(vsize)) set_option(config, "size", STR2CSTR(vsize)); //encoding: if (RTEST(vencoding)) set_option(config, "encoding", STR2CSTR(vencoding)); //create speller: ret = new_aspell_speller(config); delete_aspell_config(config); if (aspell_error(ret) != 0) { tmp = strdup(aspell_error_message(ret)); delete_aspell_can_have_error(ret); rb_raise(cAspellError, "%s", tmp); } speller = to_aspell_speller(ret); //wrap pointer return Data_Wrap_Struct(klass, 0, aspell_free, speller); }
void SpellChecker::enumerateDicts() { AspellConfig *config; AspellDictInfoList *dlist; AspellDictInfoEnumeration *dels; const AspellDictInfo *entry; config = new_aspell_config(); /* the returned pointer should _not_ need to be deleted */ dlist = get_aspell_dict_info_list(config); /* config is no longer needed */ delete_aspell_config(config); dels = aspell_dict_info_list_elements(dlist); while ((entry = aspell_dict_info_enumeration_next(dels)) != 0) { dictList->append(entry->code); } delete_aspell_dict_info_enumeration(dels); }
/* ConfigKeys *****************************************************************/ static PyObject* configkeys(PyObject* _) { AspellConfig* config; AspellKeyInfoEnumeration *keys_enumeration; AspellStringList* lst; AspellMutableContainer* amc; const AspellKeyInfo *key_info; PyObject *key_list, *obj; const char* string; unsigned int integer; unsigned int boolean; char *key_type = 0; config = new_aspell_config(); if (config == NULL) { PyErr_SetString(_AspellModuleException, "can't create config"); return NULL; } keys_enumeration = aspell_config_possible_elements(config, 1); if (!keys_enumeration) { PyErr_SetString(_AspellConfigException, "can't get list of config keys"); return NULL; } key_list = PyList_New(0); while ((key_info = aspell_key_info_enumeration_next(keys_enumeration))) { /* key type -> string */ switch (key_info->type) { case AspellKeyInfoString: key_type = "string"; string = aspell_config_retrieve(config, key_info->name); if (aspell_config_error(config) != NULL) goto config_get_error; obj = PyString_FromString( string ); break; case AspellKeyInfoInt: key_type = "integer"; integer = aspell_config_retrieve_int(config, key_info->name); if (aspell_config_error(config) != NULL) goto config_get_error; obj = PyInt_FromLong( integer ); break; case AspellKeyInfoBool: key_type = "boolean"; boolean = aspell_config_retrieve_bool(config, key_info->name); if (aspell_config_error(config) != NULL) goto config_get_error; obj = PyBool_FromLong( boolean ); break; case AspellKeyInfoList: key_type = "list"; lst = new_aspell_string_list(); amc = aspell_string_list_to_mutable_container(lst); aspell_config_retrieve_list(config, key_info->name, amc); if (aspell_config_error(config) != NULL) goto config_get_error; obj = AspellStringList2PythonList(lst); delete_aspell_string_list(lst); break; default: obj = NULL; break; } if (obj == NULL) { continue; } if (PyList_Append(key_list, Py_BuildValue("(ssOs)", key_info->name, key_type, obj, key_info->desc ? key_info->desc : "internal")) == -1) { PyErr_SetString(PyExc_Exception, "It is almost impossible, but happend! Can't append element to the list."); delete_aspell_key_info_enumeration(keys_enumeration); Py_DECREF(key_list); return NULL; } } delete_aspell_key_info_enumeration(keys_enumeration); delete_aspell_config(config); return key_list; config_get_error: PyErr_SetString(_AspellConfigException, aspell_config_error_message(config)); delete_aspell_key_info_enumeration(keys_enumeration); delete_aspell_config(config); Py_DECREF(key_list); return NULL; }