Exemplo n.º 1
0
NJ_EXTERN NJ_INT16 njx_get_stroke(NJ_CLASS *iwnn, NJ_RESULT *result, NJ_CHAR *buf, NJ_UINT16 buf_size) {
    NJ_INT16 ret;


    if (iwnn == NULL) {
        
        return NJ_SET_ERR_VAL(NJ_FUNC_NJ_GET_STROKE, NJ_ERR_PARAM_ENV_NULL);
    }
    if (result == NULL) {
        return NJ_SET_ERR_VAL(NJ_FUNC_NJ_GET_STROKE, NJ_ERR_PARAM_RESULT_NULL);
    }

    if ((buf == NULL) || (buf_size == 0)) {
        return NJ_SET_ERR_VAL(NJ_FUNC_NJ_GET_STROKE, NJ_ERR_BUFFER_NOT_ENOUGH);
    }

    switch (NJ_GET_RESULT_OP(result->operation_id)) {
    case NJ_OP_SEARCH:
        ret = njd_get_stroke(iwnn, result, buf, buf_size);
        break;

    default:
        
        ret = NJ_SET_ERR_VAL(NJ_FUNC_NJ_GET_STROKE, NJ_ERR_INVALID_RESULT); 
        break;
    }
    return ret;
}
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;
}