예제 #1
0
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;
}
예제 #2
0
파일: list.c 프로젝트: Vechnoya/Aspell
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);
}
예제 #3
0
파일: raspell.c 프로젝트: stuart/raspell
/**
 * Retrieve the value of a specific option.
 * The options are listed inside 
 * Aspell::[DictionaryOptions|CheckerOptions|FilterOptions|RunTogetherOptions|MiscOptions|UtilityOptions]
 * @param word the option as string.
 */
static VALUE aspell_conf_retrieve(VALUE self, VALUE key) {
    AspellSpeller *speller = get_speller(self);
    AspellConfig *config = aspell_speller_config(speller);
    VALUE result = rb_str_new2(aspell_config_retrieve(config, STR2CSTR(key)));
    if (aspell_config_error(config) != 0) {
        rb_raise(cAspellError, "%s", aspell_config_error_message(config));
    }
    return result;
}
예제 #4
0
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);
}
예제 #5
0
파일: raspell.c 프로젝트: stuart/raspell
/**
 * 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;
}
예제 #6
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;
}
예제 #7
0
파일: suggest.cpp 프로젝트: moceap/scribus
//__________________________________________________________________________
std::string Speller::Aspell::Suggest::getConfigOpt(const std::string& opt)
{
	return std::string( aspell_config_retrieve( fconfig, opt.c_str() ) );
}
예제 #8
0
int main(int argc, const char *argv[]) 
{
  AspellCanHaveError * ret;
  AspellSpeller * speller;
  int have;
  char word[81];
  char * p;
  char * word_end;
  AspellConfig * config;

  if (argc < 2) {
    printf("Usage: %s <language> [<size>|- [[<jargon>|- [<encoding>]]]\n", argv[0]);
    return 1;
  }

  config = new_aspell_config();

  aspell_config_replace(config, "lang", argv[1]);

  if (argc >= 3 && argv[2][0] != '-' && argv[2][1] != '\0')
    aspell_config_replace(config, "size", argv[2]);

  if (argc >= 4 && argv[3][0] != '-')
    aspell_config_replace(config, "jargon", argv[3]);

  if (argc >= 5 && argv[4][0] != '-')
    aspell_config_replace(config, "encoding", argv[4]);

  ret = new_aspell_speller(config);

  delete_aspell_config(config);

  if (aspell_error(ret) != 0) {
    printf("Error: %s\n",aspell_error_message(ret));
    delete_aspell_can_have_error(ret);
    return 2;
  }
  speller = to_aspell_speller(ret);
  config = aspell_speller_config(speller);

  fputs("Using: ",                                      stdout);
  fputs(aspell_config_retrieve(config, "lang"),         stdout);
  fputs("-",                                            stdout);
  fputs(aspell_config_retrieve(config, "jargon"),       stdout);
  fputs("-",                                            stdout);
  fputs(aspell_config_retrieve(config, "size"),         stdout);
  fputs("-",                                            stdout);
  fputs(aspell_config_retrieve(config, "module"),       stdout);
  fputs("\n\n",                                         stdout);

  puts("Type \"h\" for help.\n");

  while (fgets(word, 80, stdin) != 0) {

    /* remove trailing spaces */

    word_end = strchr(word, '\0') - 1;
    while (word_end != word && (*word_end == '\n' || *word_end == ' ')) 
      --word_end;
    ++word_end;
    *word_end = '\0';
    
    putchar('\n');
    switch (word[0]) {
    case '\0':
      break;
    case 'h':
      puts(
	"Usage: \n"
	"  h(elp)      help\n"
	"  c <word>    check if a word is the correct spelling\n"
	"  s <word>    print out a list of suggestions for a word\n"
	"  a <word>    add a word to the personal word list\n"
	"  i <word>    ignore a word for the rest of the session\n"
        "  d <file>    spell checks a document\n"
	"  p           dumps the personal word list\n"
	"  P           dumps the session word list\n"
	"  m           dumps the main  word list\n"
        "  o <option> <value> sets a config option\n"
	"  r <option>         retrieves a config option\n"
        "  l <option>         retrieves a config option as a list\n"
	"  S           saves all word lists\n"
	"  C           clear the curent sesstion word list\n"
	"  x           quite\n"	);
      break;
    case 'p':
      print_word_list(speller, 
		      aspell_speller_personal_word_list(speller), '\n');
      break;
    case 'P':
      print_word_list(speller, 
		      aspell_speller_session_word_list(speller), '\n');
      break;
    case 'm':
      print_word_list(speller, 
		      aspell_speller_main_word_list(speller), '\n');
      break;
    case 'S':
      aspell_speller_save_all_word_lists(speller);
      check_for_error(speller);
      break;
    case 'C': 
      aspell_speller_clear_session(speller);
      check_for_error(speller);
      break;
    case 'x':
      goto END;
    case 'c':
      if (strlen(word) < 3) {
	printf("Usage: %c <word>\n", word[0]);
      } else {
	have = aspell_speller_check(speller, word + 2, -1);
	if (have == 1) 
	  puts("correct");
	else if (have == 0)
	  puts("incorrect");
	else
	  printf("Error: %s\n", aspell_speller_error_message(speller));
      }
      break;
    case 's':
      if (strlen(word) < 3) {
	printf("Usage: %c <word>\n", word[0]);
      } else {
	print_word_list(speller, 
			aspell_speller_suggest(speller, word + 2, -1), '\n');
      }
      break;
    case 'a':
      if (strlen(word) < 3) {
	printf("Usage: %c <word>\n", word[0]);
      } else {
	aspell_speller_add_to_personal(speller, word + 2, -1);
	check_for_error(speller);
      }
      break;
    case 'i':
      if (strlen(word) < 3) {
	printf("Usage: %c <word>\n", word[0]);
      } else {
	aspell_speller_add_to_session(speller, word + 2, -1);
	check_for_error(speller);
      }
      break;
    case 'o':
      word[80] = '\0'; /* to make sure strchr doesn't run off end of string */
      p = strchr(word + 3, ' ');
      if (strlen(word) < 3 || p == 0) {
	printf("Usage: %c <option> <value>\n", word[0]);
      } else {
	*p = '\0';
	++p;
	aspell_config_replace(config, word + 2, p);
	check_for_config_error(config);
      }
      break;
    case 'r':
      if (strlen(word) < 3) {
	printf("Usage: %c <option>\n", word[0]);
      } else {
	const char * val = aspell_config_retrieve(config, word + 2);
	check_for_config_error(config);
	if (val)
	  printf("%s = \"%s\"\n", word + 2, val);
      }
      break;
    case 'l':
      if (strlen(word) < 3) {
	printf("Usage: %c <option>\n", word[0]);
      } else {
	AspellStringList * lst = new_aspell_string_list();
	AspellMutableContainer * lst0 
	  = aspell_string_list_to_mutable_container(lst);
	AspellStringEnumeration * els;
	const char * val;
	aspell_config_retrieve_list(config, word + 2, lst0);
	check_for_config_error(config);
	els = aspell_string_list_elements(lst);
	printf("%s:\n", word + 2);
	while ( (val = aspell_string_enumeration_next(els)) != 0)
	  printf("  %s\n", val);
	delete_aspell_string_enumeration(els);
	delete_aspell_string_list(lst);
      }
      break;
    case 'd':
      if (strlen(word) < 3) {
	printf("Usage: %c <file>\n", word[0]);
      } else {
	check_document(speller, word + 2);
	printf("\n");
      }
      break;
    default:
      printf("Unknown Command: %s\n", word);
    }
    putchar('\n');
  }
 END:
  delete_aspell_speller(speller);
  return 0;
}