/** * Simply dump config. * Not very useful at all. */ static VALUE aspell_dump_config(VALUE self) { AspellSpeller *speller = get_speller(self); AspellConfig *config = aspell_speller_config(speller); AspellKeyInfoEnumeration * key_list = aspell_config_possible_elements( config, 0 ); const AspellKeyInfo * entry; while ( (entry = aspell_key_info_enumeration_next(key_list) ) ) { printf("%20s: %s\n", entry->name, aspell_config_retrieve(config, entry->name) ); } delete_aspell_key_info_enumeration(key_list); return self; }
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); }
/* method:ConfigKeys **********************************************************/ static PyObject* m_configkeys(PyObject* self, PyObject* args) { 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 = aspell_speller_config(Speller(self)); 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("(ssO)", key_info->name, key_type, obj)) == -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); return key_list; config_get_error: PyErr_SetString(_AspellConfigException, aspell_config_error_message(config)); delete_aspell_key_info_enumeration(keys_enumeration); Py_DECREF(key_list); return NULL; }