NJ_INT16 njd_f_search_word(NJ_SEARCH_CONDITION *con, NJ_SEARCH_LOCATION_SET *loctset) { NJ_UINT16 ret; switch (con->operation) { case NJ_CUR_OP_LINK: if ((con->hinsi.yominasi_fore == NULL) || (con->hinsi.foreSize == 0)) { loctset->loct.status = NJ_ST_SEARCH_END; return 0; } break; case NJ_CUR_OP_FORE: if (NJ_CHAR_STRLEN_IS_0(con->yomi)) { loctset->loct.status = NJ_ST_SEARCH_END; return 0; } if ((con->hinsi.yominasi_fore == NULL) || (con->hinsi.foreSize == 0)) { loctset->loct.status = NJ_ST_SEARCH_END; return 0; } break; default: loctset->loct.status = NJ_ST_SEARCH_END; return 0; } if (con->mode != NJ_CUR_MODE_FREQ) { loctset->loct.status = NJ_ST_SEARCH_END; return 0; } if ((GET_LOCATION_STATUS(loctset->loct.status) == NJ_ST_SEARCH_NO_INIT) || (GET_LOCATION_STATUS(loctset->loct.status) == NJ_ST_SEARCH_READY)) { ret = search_data(con, loctset); if (ret < 1) { loctset->loct.status = NJ_ST_SEARCH_END; } return ret; } else { loctset->loct.status = NJ_ST_SEARCH_END; return 0; } }
NJ_INT16 njd_f_get_word(NJ_SEARCH_LOCATION_SET *loctset, NJ_WORD *word) { NJ_UINT8 *data; NJ_CHAR stroke[NJ_MAX_LEN + NJ_TERM_LEN]; NJ_INT16 yomilen, kouholen; if (GET_LOCATION_STATUS(loctset->loct.status) == NJ_ST_SEARCH_END) { return 0; } data = STEM_AREA_TOP_ADDR(loctset->loct.handle) + loctset->loct.current; NJ_SET_YLEN_TO_STEM(word, 1); word->stem.loc = loctset->loct; yomilen = njd_f_get_stroke(word, stroke, sizeof(stroke)); if (yomilen <= 0) { return NJ_SET_ERR_VAL(NJ_FUNC_NJD_F_GET_WORD, NJ_ERR_INVALID_RESULT); } word->stem.info1 = yomilen; word->stem.info1 |= (NJ_UINT16)(DATA_FHINSI(data) << HINSI_OFFSET); word->stem.info2 = (NJ_UINT16)(DATA_BHINSI(data) << HINSI_OFFSET); kouholen = (NJ_UINT16)DATA_CANDIDATE_SIZE(data)/sizeof(NJ_CHAR); if (kouholen == 0) { kouholen = yomilen; } word->stem.info2 |= kouholen; word->stem.hindo = CALCULATE_HINDO(DATA_HINDO(data), loctset->dic_freq.base, loctset->dic_freq.high, YOMINASI_DIC_FREQ_DIV); word->stem.type = 0; return 1; }
NJ_INT16 njd_get_word_data(NJ_CLASS *iwnn, NJ_DIC_SET *dicset, NJ_SEARCH_LOCATION_SET *loctset, NJ_UINT16 dic_idx, NJ_WORD *word) { NJ_INT16 ret = 0; NJ_UINT32 dic_type; if (GET_LOCATION_STATUS(loctset->loct.status) == NJ_ST_SEARCH_END) { return 0; } if (loctset->loct.handle == NULL) { return NJ_SET_ERR_VAL(NJ_FUNC_NJD_GET_WORD_DATA, NJ_ERR_DIC_TYPE_INVALID); } dic_type = NJ_GET_DIC_TYPE_EX(loctset->loct.type, loctset->loct.handle); switch (dic_type) { case NJ_DIC_TYPE_JIRITSU: case NJ_DIC_TYPE_FZK: case NJ_DIC_TYPE_TANKANJI: case NJ_DIC_TYPE_STDFORE: case NJ_DIC_TYPE_CUSTOM_COMPRESS: case NJ_DIC_TYPE_FORECONV: ret = njd_b_get_word(loctset, word); break; case NJ_DIC_TYPE_USER: case NJ_DIC_TYPE_CUSTOM_INCOMPRESS: ret = njd_l_get_word(iwnn, loctset, word); break; case NJ_DIC_TYPE_YOMINASHI: ret = njd_f_get_word(loctset, word); break; default: return NJ_SET_ERR_VAL(NJ_FUNC_NJD_GET_WORD_DATA, NJ_ERR_DIC_TYPE_INVALID); } return ret; }
static NJ_UINT16 search_data(NJ_SEARCH_CONDITION *condition, NJ_SEARCH_LOCATION_SET *loctset) { NJ_UINT32 offset; NJ_UINT8 *data; NJ_UINT16 i, j; NJ_UINT16 hindo; NJ_UINT8 hit_flg; NJ_UINT8 *tmp_hinsi = NULL; offset = loctset->loct.current; data = STEM_AREA_TOP_ADDR(loctset->loct.handle) + offset; if (GET_LOCATION_STATUS(loctset->loct.status) != NJ_ST_SEARCH_NO_INIT) { data += DATA_SIZE; offset += DATA_SIZE; if (data >= STRS_AREA_TOP_ADDR(loctset->loct.handle)) { loctset->loct.status = NJ_ST_SEARCH_END; return 0; } } tmp_hinsi = condition->hinsi.fore; condition->hinsi.fore = condition->hinsi.yominasi_fore; i = (STRS_AREA_TOP_ADDR(loctset->loct.handle) - data) / DATA_SIZE; for (j = 0; j < i; j++) { if (njd_connect_test(condition, DATA_FHINSI(data), DATA_BHINSI(data))) { hit_flg = 0; if (condition->operation == NJ_CUR_OP_LINK) { hit_flg = 1; } else { if (yomi_strcmp_forward(loctset->loct.handle, data, condition->yomi)) { hit_flg = 1; } } if (hit_flg) { loctset->loct.current_info = CURRENT_INFO_SET; loctset->loct.current = offset; loctset->loct.status = NJ_ST_SEARCH_READY; hindo = DATA_HINDO(STEM_AREA_TOP_ADDR(loctset->loct.handle) + loctset->loct.current); loctset->cache_freq = CALCULATE_HINDO(hindo, loctset->dic_freq.base, loctset->dic_freq.high, YOMINASI_DIC_FREQ_DIV); condition->hinsi.fore = tmp_hinsi; return 1; } } data += DATA_SIZE; offset += DATA_SIZE; } loctset->loct.status = NJ_ST_SEARCH_END; condition->hinsi.fore = tmp_hinsi; return 0; }
static NJ_INT16 get_word_and_search_next_word(NJ_CLASS *iwnn, NJ_CURSOR *cursor, NJ_RESULT *result, NJ_UINT8 comp_flg) { NJ_INT16 ret = -1; NJ_INT32 i, next, first; NJ_WORD tmp_word; NJ_RESULT tmp_result; NJ_CHAR tmp_stroke[NJ_MAX_LEN + NJ_TERM_LEN]; NJ_CHAR result_stroke[NJ_MAX_LEN + NJ_TERM_LEN]; NJ_INT32 j, max_len = 0; NJ_UINT32 dic_type; NJ_SEARCH_LOCATION_SET *loctset; next = -1; first= 0; njd_init_word(&tmp_word); result->word = tmp_word; tmp_result.word = tmp_word; for (i = 0; i < NJ_MAX_DIC; i++) { loctset = &(cursor->loctset[i]); if ((loctset->loct.handle == NULL) || (GET_LOCATION_STATUS(loctset->loct.status) == NJ_ST_SEARCH_END) || (GET_LOCATION_STATUS(loctset->loct.status) == NJ_ST_SEARCH_END_EXT)) { continue; } dic_type = NJ_GET_DIC_TYPE_EX(loctset->loct.type, loctset->loct.handle); switch (dic_type) { case NJ_DIC_TYPE_JIRITSU: case NJ_DIC_TYPE_FZK: case NJ_DIC_TYPE_TANKANJI: case NJ_DIC_TYPE_STDFORE: case NJ_DIC_TYPE_CUSTOM_COMPRESS: case NJ_DIC_TYPE_FORECONV: tmp_word.yomi = cursor->cond.yomi; tmp_word.stem.info1 = cursor->cond.ylen; tmp_result.word.yomi = cursor->cond.yomi; tmp_result.word.stem.info1 = cursor->cond.ylen; break; default: break; } loctset->loct.status |= SET_LOCATION_OPERATION(cursor->cond.operation); if (cursor->cond.mode == NJ_CUR_MODE_FREQ) { if ((cursor->cond.ds->mode & (NJ_CACHE_MODE_VALID)) && (cursor->cond.ds->dic[i].srhCache != NULL) && (NJ_GET_AIMAI_FROM_SCACHE(cursor->cond.ds->dic[i].srhCache)) && (cursor->cond.operation == NJ_CUR_OP_FORE)) { first = 1; ret = njd_get_word_data(iwnn, cursor->cond.ds, loctset, (NJ_UINT16)i, &tmp_result.word); if (ret < 0) { return ret; } ret = njd_get_stroke(iwnn, &tmp_result, tmp_stroke, sizeof(tmp_stroke)); if (ret <= 0) { if ((ret == 0) || (NJ_GET_ERR_CODE(ret) == NJ_ERR_BUFFER_NOT_ENOUGH)) { return NJ_SET_ERR_VAL(NJ_FUNC_GET_WORD_AND_SEARCH_NEXT_WORD, NJ_ERR_INVALID_RESULT); } else { return ret; } } for (j = 0; j < cursor->cond.ylen; j++) { if (cursor->cond.yomi[j] != tmp_stroke[j]) { break; } } switch (dic_type) { case NJ_DIC_TYPE_JIRITSU: case NJ_DIC_TYPE_FZK: case NJ_DIC_TYPE_TANKANJI: case NJ_DIC_TYPE_STDFORE: case NJ_DIC_TYPE_CUSTOM_COMPRESS: case NJ_DIC_TYPE_FORECONV: ret = njd_b_search_word(&cursor->cond, loctset); break; case NJ_DIC_TYPE_USER: case NJ_DIC_TYPE_CUSTOM_INCOMPRESS: ret = njd_l_search_word(iwnn, &cursor->cond, loctset, comp_flg); break; default: return NJ_SET_ERR_VAL(NJ_FUNC_GET_WORD_AND_SEARCH_NEXT_WORD, NJ_ERR_DIC_TYPE_INVALID); } if (ret < 0) { return ret; } } else { ret = njd_get_word_data(iwnn, cursor->cond.ds, loctset, (NJ_UINT16)i, &tmp_result.word); if (ret < 0) { return ret; } j = cursor->cond.ylen; } if ((j > max_len) || ((j == max_len) && (loctset->cache_freq > result->word.stem.hindo)) || (next == -1)) { set_operation_id(&(loctset->loct), 0, result); result->word = tmp_result.word; next = i; max_len = j; } } else { ret = njd_get_word_data(iwnn, cursor->cond.ds, loctset, (NJ_UINT16)i, &(tmp_result.word)); if (ret < 0) { return ret; } ret = njd_get_stroke(iwnn, &tmp_result, tmp_stroke, sizeof(tmp_stroke)); if (ret <= 0) { if ((ret == 0) || (NJ_GET_ERR_CODE(ret) == NJ_ERR_BUFFER_NOT_ENOUGH)) { return NJ_SET_ERR_VAL(NJ_FUNC_GET_WORD_AND_SEARCH_NEXT_WORD, NJ_ERR_INVALID_RESULT); } else { return ret; } } if ((next == -1) || (nj_strcmp(result_stroke, tmp_stroke) > 0)) { set_operation_id(&(loctset->loct), 0, result); result->word = tmp_result.word; next = i; nj_strcpy(result_stroke, tmp_stroke); } } } if (next == -1) { return 0; } loctset = &(cursor->loctset[next]); if ((!first) || ((loctset->loct.handle != NULL) && (cursor->cond.ds->dic[next].srhCache == NULL))) { dic_type = NJ_GET_DIC_TYPE_EX(loctset->loct.type, loctset->loct.handle); switch (dic_type) { case NJ_DIC_TYPE_JIRITSU: case NJ_DIC_TYPE_FZK: case NJ_DIC_TYPE_TANKANJI: case NJ_DIC_TYPE_STDFORE: case NJ_DIC_TYPE_CUSTOM_COMPRESS: case NJ_DIC_TYPE_FORECONV: ret = njd_b_search_word(&cursor->cond, loctset); break; case NJ_DIC_TYPE_USER: case NJ_DIC_TYPE_CUSTOM_INCOMPRESS: ret = njd_l_search_word(iwnn, &cursor->cond, loctset, comp_flg); break; case NJ_DIC_TYPE_YOMINASHI: ret = njd_f_search_word(&cursor->cond, loctset); break; default: return NJ_SET_ERR_VAL(NJ_FUNC_GET_WORD_AND_SEARCH_NEXT_WORD, NJ_ERR_DIC_TYPE_INVALID); } } if (ret < 0) { return ret; } return 1; }
static NJ_INT16 search_word(NJ_CLASS *iwnn, NJ_CURSOR *cursor, NJ_UINT8 comp_flg, NJ_UINT8 *exit_flag) { NJ_UINT32 dic_type; NJ_INT16 i; NJ_INT16 ret = 0; NJ_INT16 flag = 0; NJ_SEARCH_LOCATION_SET *loctset; *exit_flag = 1; for (i = 0; i < NJ_MAX_DIC; i++) { loctset = &(cursor->loctset[i]); if (loctset->loct.handle == NULL) { continue; } dic_type = NJ_GET_DIC_TYPE_EX(loctset->loct.type, loctset->loct.handle); #ifdef IWNN_ERR_CHECK if (iwnn->err_check_flg == 12) { dic_type = 0x11111111; } #endif switch (dic_type) { case NJ_DIC_TYPE_JIRITSU: case NJ_DIC_TYPE_FZK: case NJ_DIC_TYPE_TANKANJI: case NJ_DIC_TYPE_STDFORE: case NJ_DIC_TYPE_CUSTOM_COMPRESS: case NJ_DIC_TYPE_FORECONV: ret = njd_b_search_word(&cursor->cond, loctset); break; case NJ_DIC_TYPE_USER: case NJ_DIC_TYPE_CUSTOM_INCOMPRESS: ret = njd_l_search_word(iwnn, &cursor->cond, loctset, comp_flg); break; case NJ_DIC_TYPE_YOMINASHI: ret = njd_f_search_word(&cursor->cond, loctset); break; default: return NJ_SET_ERR_VAL(NJ_FUNC_SEARCH_WORD, NJ_ERR_DIC_TYPE_INVALID); } if (ret < 0) { return ret; } if (ret == 0) { if ((GET_LOCATION_STATUS(loctset->loct.status) == NJ_ST_SEARCH_END) && (*exit_flag == 1)) { *exit_flag = 0; } loctset->loct.status = NJ_ST_SEARCH_END; } else { flag = 1; *exit_flag = 0; } } return flag; }