示例#1
0
int get_word_lang(const char *word, int cur_lang)
{
	int len = strlen(word);

	char *low_word = lower_word(word, len);
	len = trim_word(low_word, len);

	if (len == 0)
	{
		free(low_word);
		return NO_LANGUAGE;
	}

	log_message(DEBUG, "Processing word '%s'", low_word);

	// Check by regexp
	int lang = get_regexp_lang(low_word);
	
	// Check by dictionary
	if (lang == NO_LANGUAGE)
		lang = get_dict_lang(low_word);

	// Check by aspell
#ifdef WITH_ASPELL 
	if (lang == NO_LANGUAGE)
		lang = get_aspell_hits(low_word, len);
#endif
	
	// If not found lang by proto, try to find in all letter order
	if (lang == NO_LANGUAGE)
		lang = get_letter_order_lang(low_word, len, cur_lang);
	
	// Try to find in no first symbol
	if (lang == NO_LANGUAGE)
		lang = get_nofirst_letter_lang(low_word, cur_lang);
	
	// If not found in dictionary, try to find in proto
	if (lang == NO_LANGUAGE)
		lang = get_proto_lang(low_word, len, cur_lang, BIG_PROTO_LEN);

	if (lang == NO_LANGUAGE)
		lang = get_proto_lang(low_word, len, cur_lang, PROTO_LEN);
	
	log_message(DEBUG, "End word processing");

	free(low_word);
	return lang;
}
示例#2
0
int handle_word(char buf[], FILE *files[], struct sc_config const *config)
{
    int ret = -1;
    char tmp[strlen(buf)];
    char inp[MAX_WORD_LENGTH];
    trim_word(buf, tmp);
    if (is_number(tmp))
        goto NEXT;
    if (word_exists(files[FILE_DIC], tmp)) {
        fprintf(files[FILE_OUT], "%s", buf);
    } else {
        printf(CLSCRN);
        print_header(config->file[FILE_DOC]);
        print_hr();
        print_preview(files[FILE_DOC], buf);
        print_hr();
        printf("word \"%s\" not found in dict\n", tmp);
        print_progress(files[FILE_DOC]);
        switch (show_menu()) {
        case 'a':
            fprintf(files[FILE_DIC], "%s\n", tmp);
            fprintf(files[FILE_OUT], "%s", tmp);
            break;
        case 's':
            printf("substitute %s: ", buf);
            input_line(inp, sizeof(inp));
            fprintf(files[FILE_OUT], "%s", inp);
            break;
        case 'c':
            fprintf(files[FILE_OUT], "%s", buf);
            break;
        case 'q':
            goto ERROR;
        }
    }

NEXT:
    ret = 0;

ERROR:
    return ret;
}