int main(int argc, char *argv[]) { char* hanja_table_file = NULL; char buf[256] = { '\0', }; if (argc > 1) hanja_table_file = argv[1]; HanjaTable *table; table = hanja_table_load(hanja_table_file); while (fgets(buf, sizeof(buf), stdin) != NULL) { char* p = strchr(buf, '\n'); if (p != NULL) *p = '\0'; HanjaList *list = hanja_table_match_prefix(table, buf); int i, n; n = hanja_list_get_size(list); for (i = 0; i < n; i++) { const char* key = hanja_list_get_nth_key(list, i); const char* value = hanja_list_get_nth_value(list, i); const char* comment = hanja_list_get_nth_comment(list, i); printf("%s:%s:%s\n", key, value, comment); } hanja_list_delete(list); } hanja_table_delete(table); return 0; }
void HangulInstance::update_candidates () { m_lookup_table.clear (); m_candidate_comments.clear (); HanjaList* list = NULL; // search for symbol character // key string for symbol character is like: // 'ㄱ', 'ㄴ', 'ㄷ', etc WideString preeditw = get_preedit_string(); if (preeditw.length() == 1) { String key = utf8_wcstombs(preeditw); list = hanja_table_match_suffix(m_factory->m_symbol_table, key.c_str()); } // search for hanja if (list == NULL) { String str = get_candidate_string(); SCIM_DEBUG_IMENGINE(1) << "candidate string: " << str << "\n"; if (str.length() > 0) { if (is_hanja_mode() || m_factory->m_commit_by_word) { list = hanja_table_match_prefix(m_factory->m_hanja_table, str.c_str()); } else { list = hanja_table_match_suffix(m_factory->m_hanja_table, str.c_str()); } } } if (list != NULL) { int n = hanja_list_get_size(list); for (int i = 0; i < n; ++i) { const char* value = hanja_list_get_nth_value(list, i); const char* comment = hanja_list_get_nth_comment(list, i); WideString candidate = utf8_mbstowcs(value, -1); m_lookup_table.append_candidate(candidate); m_candidate_comments.push_back(String(comment)); } m_lookup_table.set_page_size (9); m_lookup_table.show_cursor (); update_lookup_table (m_lookup_table); show_lookup_table (); hangul_update_aux_string (); hanja_list_delete(list); } if (m_lookup_table.number_of_candidates() <= 0) { delete_candidates(); } }
static void ibus_hangul_engine_apply_hanja_list (IBusHangulEngine *hangul) { HanjaList* list = hangul->hanja_list; if (list != NULL) { int i, n; n = hanja_list_get_size (list); ibus_lookup_table_clear (hangul->table); for (i = 0; i < n; i++) { const char* value = hanja_list_get_nth_value (list, i); IBusText* text = ibus_text_new_from_string (value); ibus_lookup_table_append_candidate (hangul->table, text); } ibus_lookup_table_set_cursor_pos (hangul->table, 0); ibus_hangul_engine_update_lookup_table_ui (hangul); lookup_table_set_visible (hangul->table, TRUE); } }
static void ibus_hangul_engine_commit_current_candidate (IBusHangulEngine *hangul) { guint cursor_pos; const char* key; const char* value; const ucschar* hic_preedit; glong key_len; glong hic_preedit_len; glong preedit_len; IBusText* text; cursor_pos = ibus_lookup_table_get_cursor_pos (hangul->table); key = hanja_list_get_nth_key (hangul->hanja_list, cursor_pos); value = hanja_list_get_nth_value (hangul->hanja_list, cursor_pos); hic_preedit = hangul_ic_get_preedit_string (hangul->context); key_len = g_utf8_strlen(key, -1); preedit_len = ustring_length(hangul->preedit); hic_preedit_len = ucschar_strlen (hic_preedit); if (hangul->last_lookup_method == LOOKUP_METHOD_PREFIX) { if (preedit_len == 0 && hic_preedit_len == 0) { /* remove surrounding_text */ if (key_len > 0) { ibus_engine_delete_surrounding_text ((IBusEngine *)hangul, -key_len , key_len); } } else { /* remove ibus preedit text */ if (key_len > 0) { glong n = MIN(key_len, preedit_len); ustring_erase (hangul->preedit, 0, n); key_len -= preedit_len; } /* remove hic preedit text */ if (key_len > 0) { hangul_ic_reset (hangul->context); key_len -= hic_preedit_len; } } } else { /* remove hic preedit text */ if (hic_preedit_len > 0) { hangul_ic_reset (hangul->context); key_len -= hic_preedit_len; } /* remove ibus preedit text */ if (key_len > preedit_len) { ustring_erase (hangul->preedit, 0, preedit_len); key_len -= preedit_len; } else if (key_len > 0) { ustring_erase (hangul->preedit, 0, key_len); key_len = 0; } /* remove surrounding_text */ if (key_len > 0) { ibus_engine_delete_surrounding_text ((IBusEngine *)hangul, -key_len , key_len); } } /* clear preedit text before commit */ ibus_hangul_engine_clear_preedit_text (hangul); text = ibus_text_new_from_string (value); ibus_engine_commit_text ((IBusEngine *)hangul, text); ibus_hangul_engine_update_preedit_text (hangul); }