SpellChecker::SpellChecker( QObject * parent ) : QObject(parent) { m_spell_config_ru = new_aspell_config(); aspell_config_replace(m_spell_config_ru, "dict-dir", "./dict"); aspell_config_replace(m_spell_config_ru, "encoding", "utf-8"); aspell_config_replace(m_spell_config_ru, "lang", "ru"); AspellCanHaveError * possible_err = new_aspell_speller(m_spell_config_ru); m_spell_checker_ru = 0; if (aspell_error_number(possible_err) != 0){ puts(aspell_error_message(possible_err)); } else{ m_spell_checker_ru = to_aspell_speller(possible_err); } m_spell_config_en = new_aspell_config(); aspell_config_replace(m_spell_config_en, "dict-dir", "./dict"); aspell_config_replace(m_spell_config_en, "encoding", "utf-8"); aspell_config_replace(m_spell_config_en, "lang", "en"); possible_err = new_aspell_speller(m_spell_config_en); m_spell_checker_en = 0; if (aspell_error_number(possible_err) != 0){ puts(aspell_error_message(possible_err)); } else{ m_spell_checker_en = to_aspell_speller(possible_err); } m_codec = QTextCodec::codecForName("UTF-8"); }
SpellChecker::SpellChecker(QTextEdit *textEdit): m_textEdit(textEdit) { m_regExp = new QRegExp("[^\\s]*"); //m_cursor= new QTextCursor(m_textEdit->document()); spell_config1 = new_aspell_config(); spell_config2 = new_aspell_config(); aspell_config_replace(spell_config1, "lang", m_lang1.toAscii()); aspell_config_replace(spell_config2, "lang", m_lang2.toAscii()); aspell_config_replace(spell_config1, "encoding", "utf-8"); aspell_config_replace(spell_config2, "encoding", "utf-8"); m_map = new StringMap(); m_map->insert("ara", "ar"); m_map->insert("ruseng", "ru"); m_map->insert("rus", "ru"); m_map->insert("bul", "bg"); m_map->insert("cze", "cs"); m_map->insert("dan", "da"); m_map->insert("dut", "nl"); m_map->insert("nld", "nl"); m_map->insert("ell", "el"); m_map->insert("eng", "en"); m_map->insert("est", "et"); m_map->insert("fin", "fi"); m_map->insert("fra", "fr"); m_map->insert("ger", "de"); m_map->insert("deu", "de"); m_map->insert("deu-frak", "de-alt"); m_map->insert("heb", "he"); m_map->insert("hin", "hi"); m_map->insert("hrv", "hr"); m_map->insert("hun", "hu"); m_map->insert("ind", "in"); m_map->insert("isl", "is"); m_map->insert("ita", "it"); m_map->insert("lav", "lv"); m_map->insert("lit", "lt"); m_map->insert("mkd", "mk"); m_map->insert("msa", "ms"); m_map->insert("nor", "no"); m_map->insert("pol", "pl"); m_map->insert("por", "pt_PT"); m_map->insert("rum", "ro"); //m_map->insert("rus", "ru"); m_map->insert("ron", "ro"); m_map->insert("slo", "sl"); m_map->insert("slk", "sk"); m_map->insert("spa", "es"); m_map->insert("srp", "sr"); m_map->insert("swa", "sw"); m_map->insert("swe", "sv"); m_map->insert("swef", "sv"); m_map->insert("tur", "tr"); m_map->insert("ukr", "uk"); m_map->insert("vie", "vi"); spell_checker1 = 0; spell_checker2 = 0; setLanguage("ruseng"); dictList = new QStringList(); }
SpellerConfig::SpellerConfig(SpellerBase &base) : m_base(base) { #ifdef WIN32 cfg = NULL; if (m_base._new_aspell_config) cfg = new_aspell_config(); #else cfg = new_aspell_config(); #endif }
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 */ }
//__________________________________________________________________________ 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 ); } }
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; }
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); } }
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; }
//__________________________________________________________________________ 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 ); } }
/** * 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 main(int argc,char **argv) { #ifdef _USEQT5_ QApplication app(argc,argv); #endif AspellCanHaveError* possible_err; aspellConfig=new_aspell_config(); possible_err=new_aspell_speller(aspellConfig); if(aspell_error_number(possible_err)!= 0) puts(aspell_error_message(possible_err)); else spellChecker=to_aspell_speller(possible_err); #ifndef _USEQT5_ gtk_init(&argc,&argv); buildMainGuiGtk(); gtk_window_stick(GTK_WINDOW(window)); gtk_window_set_keep_above((GtkWindow*)window,true); gtk_widget_show_all(window); gtk_main(); #else holdapp=&app; buildMainGuiQt(); window->show(); app.exec(); #endif }
int main(int argc, char *argv[]) { AspellConfig *conf; const char *tmp; char *option = "extra-dicts"; AspellStringList * lst = new_aspell_string_list(); AspellMutableContainer * lst0 = aspell_string_list_to_mutable_container(lst); AspellStringEnumeration *els; if(argc > 1) option = argv[1]; conf = new_aspell_config(); tmp = aspell_config_retrieve(conf, option); fprintf(stderr, "%s = %s\n", option, tmp); aspell_config_retrieve_list(conf, option, lst0); els = aspell_string_list_elements(lst); while( (tmp = aspell_string_enumeration_next(els) ) ) { fprintf(stderr, "%s\n", tmp); } return(0); }
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; }
ASpellChecker::ASpellChecker() : config_(new_aspell_config()) { aspell_config_replace(config_, "encoding", "utf-8"); #ifdef Q_OS_WIN aspell_config_replace(config_, "conf-dir", QDir::homePath().toLocal8Bit().data()); aspell_config_replace(config_, "data-dir", QString("%1/aspell").arg(QCoreApplication::applicationDirPath()).toLocal8Bit().data()); aspell_config_replace(config_, "dict-dir", QString("%1/aspell").arg(QCoreApplication::applicationDirPath()).toLocal8Bit().data()); #endif setActiveLanguages(getAllLanguages()); }
SpellChecker::SpellChecker() { connect(ChatWidgetManager::instance(), SIGNAL(chatWidgetCreated(ChatWidget *)), this, SLOT(chatCreated(ChatWidget *))); // prepare configuration of spellchecker spellConfig = new_aspell_config(); aspell_config_replace(spellConfig, "encoding", "utf-8"); createDefaultConfiguration(); // load mark settings buildMarkTag(); }
void initAspell() { spell_config = new_aspell_config(); aspell_config_replace(spell_config, "lang", "en_US"); //set language possible_err = new_aspell_speller(spell_config); spell_checker = 0; if (aspell_error_number(possible_err) != 0) { printf("%s ", aspell_error_message(possible_err)); } else { printf("Unscrambled words:\n"); spell_checker = to_aspell_speller(possible_err); } }
int main(int argc, char *argv[]) { AspellConfig *conf; AspellKeyInfoEnumeration *els; const AspellKeyInfo *info; conf = new_aspell_config(); els = aspell_config_possible_elements(conf, 1); while( (info = aspell_key_info_enumeration_next(els) ) ) { fprintf(stderr, "%s\n", info->name); } return(0); }
void init(void) { char* filename; #ifdef _ASPELL_ AspellCanHaveError* possible_err; #endif lineWrap=true; highLight=true; useUnderline=true; tabWidth=4; fontAndSize=strdup("mono 10"); terminalCommand=strdup("xterm -e"); windowWidth=800; windowHeight=400; windowX=-1; windowY=-1; wrapSearch=true; insensitiveSearch=true; replaceAll=false; showLiveSearch=true; gzipPages=false; asprintf(&filename,"%s/.ManPageEditor",getenv("HOME")); g_mkdir_with_parents(filename,493); g_free(filename); readConfig(); tmpGzipPages=gzipPages; tmpHighLight=highLight; tmpLineWrap=lineWrap; tmpTabWidth=tabWidth; tmpUseUnderline=useUnderline; tmpShowLiveSearch=showLiveSearch; #ifdef _ASPELL_ aspellConfig=new_aspell_config(); possible_err=new_aspell_speller(aspellConfig); if(aspell_error_number(possible_err)!= 0) puts(aspell_error_message(possible_err)); else spellChecker=to_aspell_speller(possible_err); #endif }
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; }
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); } }
ASpellChecker::ASpellChecker() { config_ = NULL; speller_ = NULL; config_ = new_aspell_config(); aspell_config_replace(config_, "encoding", "utf-8"); #ifdef Q_WS_WIN aspell_config_replace(config_, "conf-dir", QDir::homeDirPath()); aspell_config_replace(config_, "data-dir", QString("%1/aspell/data").arg(QCoreApplication::applicationDirPath())); aspell_config_replace(config_, "dict-dir", QString("%1/aspell/dict").arg(QCoreApplication::applicationDirPath())); #endif AspellCanHaveError* ret = new_aspell_speller(config_); if (aspell_error_number(ret) == 0) { speller_ = to_aspell_speller(ret); } else { qWarning(QString("Aspell error: %1").arg(aspell_error_message(ret)).toAscii()); } }
/** * 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; }
/** * Create a spell checker for a language * @param language the language code e.g. en_GB or it * @return a checker or NULL */ static checker *checker_create( const char *language ) { int err = 0; checker *c = calloc( 1, sizeof(checker) ); if ( c != NULL ) { strncpy(c->lang,language,24); c->spell_config = new_aspell_config(); if ( c->spell_config != NULL ) { aspell_config_replace( c->spell_config, "lang", language ); AspellCanHaveError *possible_err = new_aspell_speller(c->spell_config); c->spell_checker = 0; if (aspell_error_number(possible_err) != 0) { fprintf(stderr,"%s\n",aspell_error_message(possible_err)); err = 1; } else { c->spell_checker = to_aspell_speller(possible_err); if ( c->spell_checker == NULL ) { fprintf(stderr,"checker: failed to initialise speller\n"); err = 1; } } if ( err ) { checker_dispose( c ); c = NULL; } } else fprintf(stderr,"checker: failed to create speller\n"); } else fprintf(stderr,"checker: failed to create object\n"); return c; }
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; }
/** * 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; }
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; }
/* Create a new speller *******************************************************/ static PyObject* new_speller(PyObject* self, PyObject* args) { aspell_AspellObject* newobj; AspellSpeller* speller = 0; AspellConfig* config; AspellCanHaveError* possible_error; int i; int n; /* arg count */ char *key, *value; config = new_aspell_config(); if (config == NULL) { PyErr_SetString(_AspellModuleException, "can't create config"); return NULL; } /* check constructor arguments */ n = PyTuple_Size(args); switch (n) { case 0: /* no arguments passed */ break; case 2: /* constructor is called with single pair: key & value */ if (PyArg_ParseTuple(args, "ss", &key, &value)) { if (!aspell_config_replace(config, key, value)) { PyErr_SetString(_AspellConfigException, aspell_config_error_message(config)); goto arg_error; } break; } PyErr_Clear(); default: /* list of tuples key&value */ for (i=0; i<n; i++) { if (!PyArg_ParseTuple(PyTuple_GetItem(args, i), "ss", &key, &value)) { PyErr_Format(PyExc_TypeError, "argument %d: tuple of two strings (key, value) expeced", i); goto arg_error; } if (!aspell_config_replace(config, key, value)) { PyErr_SetString(_AspellConfigException, aspell_config_error_message(config)); goto arg_error; } } Py_DECREF(args); break; } /* try to create a new speller */ possible_error = new_aspell_speller(config); delete_aspell_config(config); if (aspell_error_number(possible_error) == 0) /* save a speller */ speller = to_aspell_speller(possible_error); else { /* or raise an exception */ PyErr_SetString(_AspellSpellerException, aspell_error_message(possible_error)); delete_aspell_can_have_error(possible_error); return NULL; } /* create a new py-object */ newobj = (aspell_AspellObject*)PyObject_New(aspell_AspellObject, &aspell_AspellType); newobj->speller = speller; return (PyObject*)newobj; /* argument error: before return NULL we need to delete speller's config we've created */ arg_error: delete_aspell_config(config); return NULL; }