⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phb_se.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 5 页
字号:
#endif /* defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__) */ 


/*****************************************************************************
 * FUNCTION
 *  phb_se_build_index
 * DESCRIPTION
 *  Build index of certain type
 * PARAMETERS
 *  type                [IN]        
 *  record_index        [IN]        
 *  ext_index           [IN]        
 *  phb_entry           [?]         
 * RETURNS
 *  void
 *****************************************************************************/
void phb_se_build_index(phb_type_enum type, kal_uint16 record_index, kal_uint8 ext_index, phb_entry_struct *phb_entry)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /* 20040223 Wilson, temporary solution for PinYin sorting hang problem */
#if defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__)

    kal_uint8 temp_name_length;
    kal_uint8 temp_name[PHB_ALPHA_ID_DEPTH];
    kal_uint8 is_convert = 0;
#endif /* defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__) */ 

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_SE_BUILD_INDEX);
    if (ext_index == 0)
    {
        ext_index = (kal_uint8) PHB_INVALID_VALUE;
    }
    if (type == PHB_PHONEBOOK && ext_index != (kal_uint8) PHB_INVALID_VALUE)
    {
        phb_se_ext_index_set(record_index, ext_index, type);
    }
#ifdef __PHB_SORT_ENABLE__
    if ((type == PHB_PHONEBOOK) || (type == PHB_FDN) || (type == PHB_BDN))
#else 
    if ((type == PHB_FDN) || (type == PHB_BDN))
#endif 
    {
        kal_uint16 data_entry_pos;

        kal_uint8 signature;
        kal_uint8 tel_num;
        name_num_index_type *name_num_index;

        phb_se_get_index_values(type, &phb_entry->tel_number, &signature, &tel_num, &name_num_index);

        /* amanda add, put number in name for sorting */
        if (phb_entry->alpha_id.name_length == 0)
        {
            kal_uint8 fake_name_bcd[15];
            kal_uint8 *temp_ptr;

            kal_mem_cpy(fake_name_bcd, &phb_entry->tel_number.addr_bcd[1], 10);
            fake_name_bcd[10] = 0xff;
            temp_ptr = phb_entry->alpha_id.name;
            phb_entry->alpha_id.name_length = 0;
            if (phb_entry->tel_number.addr_bcd[0] & 0x10)
            {
                *(temp_ptr++) = '+';
                phb_entry->alpha_id.name_length++;
            }
            phb_entry->alpha_id.name_length += convert_to_digit(fake_name_bcd, temp_ptr);
            phb_entry->alpha_id.name_dcs = PHB_ASCII;
        }
        /* Handle 0x81 case for sorting */
    #ifdef __PHB_0x81_SUPPORT__     /* MTK 2004-04-20 Wisoln, support maximum length of 0x81 UCS2 */
        else if (phb_entry->alpha_id.name_dcs == PHB_UCS2_81)
        {
            kal_uint8 offset = 0;
            kal_uint8 specified_decoded_str_len;
            kal_uint16 ch;
            kal_uint16 base_ptr;
            kal_uint8 count;
            kal_uint8 result[PHB_ALPHA_ID_DEPTH];

            ++offset;
            specified_decoded_str_len = phb_entry->alpha_id.name[offset++];
            base_ptr = phb_entry->alpha_id.name[offset++] << 7;

            for (count = 0; offset < phb_entry->alpha_id.name_length;)
            {
                ch = phb_entry->alpha_id.name[offset++];

                /* Exceeds capacity, truncate */
                if ((count + 1) >= PHB_ALPHA_ID_DEPTH)
                {
                    break;
                }

                /* All bytes are docoed */
                if ((count + 1) >= (specified_decoded_str_len * 2))
                {
                    break;
                }

                if (ch < 0x80)
                {
                    result[count++] = 0x0;
                    result[count++] = (kal_uint8) ch;
                }
                else
                {
                    ch &= 0x7F;
                    ch += base_ptr;

                    result[count++] = phb_more_significant_char(ch);
                    result[count++] = phb_less_significant_char(ch);
                }
            }

            phb_entry->alpha_id.name_length = count;
            phb_entry->alpha_id.name_dcs = PHB_UCS2;
            memcpy(phb_entry->alpha_id.name, result, PHB_ALPHA_ID_DEPTH);

        }
        /* Handle 0x82 case for sorting */
        else if (phb_entry->alpha_id.name_dcs == PHB_UCS2_82)
        {
            kal_uint8 offset = 0;
            kal_uint8 specified_decoded_str_len;
            kal_uint16 ch;
            kal_uint16 base_ptr;
            kal_uint8 count;
            kal_uint8 result[PHB_ALPHA_ID_DEPTH];

            ++offset;
            specified_decoded_str_len = phb_entry->alpha_id.name[offset++];
            base_ptr = phb_entry->alpha_id.name[offset++] << 8;
            base_ptr |= phb_entry->alpha_id.name[offset++];

            for (count = 0; offset < phb_entry->alpha_id.name_length;)
            {
                ch = phb_entry->alpha_id.name[offset++];

                /* Exceeds capacity, truncate */
                if ((count + 1) >= PHB_ALPHA_ID_DEPTH)
                {
                    break;
                }

                /* All bytes are docoed */
                if ((count + 1) >= (specified_decoded_str_len * 2))
                {
                    break;
                }

                if (ch < 0x80)
                {
                    result[count++] = 0x0;
                    result[count++] = (kal_uint8) ch;
                }
                else
                {
                    ch &= 0x7F;
                    ch += base_ptr;

                    result[count++] = phb_more_significant_char(ch);
                    result[count++] = phb_less_significant_char(ch);
                }
            }

            phb_entry->alpha_id.name_length = count;
            phb_entry->alpha_id.name_dcs = PHB_UCS2;
            memcpy(phb_entry->alpha_id.name, result, PHB_ALPHA_ID_DEPTH);

        }
    #endif /* __PHB_0x81_SUPPORT__ */ 
        /* 20040223 Wilson, temporary solution for PinYin sorting hang problem */
    #if defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__)

        else if (type == PHB_PHONEBOOK && phb_entry->alpha_id.name_dcs == PHB_UCS2)
        {
            kal_mem_cpy((kal_uint8*) temp_name, (kal_uint8*) phb_entry->alpha_id.name, PHB_ALPHA_ID_DEPTH);
            temp_name_length = phb_entry->alpha_id.name_length;

            phb_se_build_index_convert_name((kal_uint8*) phb_entry->alpha_id.name);
            phb_entry->alpha_id.name_length = strlen((char*)phb_entry->alpha_id.name);
            phb_entry->alpha_id.name_dcs = PHB_ASCII;

            is_convert = 1;
        }
    #endif /* defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__) */ 

        data_entry_pos = phb_det_append(
                            &name_num_index->data_entry_table,
                            (alpha_id_type*) & phb_entry->alpha_id,
                            phb_entry->storage,
                            record_index,
                            signature,
                            tel_num,
                            ext_index);
        if (data_entry_pos == (kal_uint16) PHB_INVALID_VALUE)
        {
            return;
        }

        phb_pindex_append(&name_num_index->name_index, data_entry_pos);
        phb_pindex_append(&name_num_index->num_index, data_entry_pos);

        /* 20040223 Wilson, temporary solution for PinYin sorting hang problem */
    #if defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__)

        if (is_convert)
        {
            alpha_id_pinyin_PHB[data_entry_pos].charset = PHB_UCS2;

            if (temp_name_length < PHB_ALPHA_ID_DEPTH)
            {
                alpha_id_pinyin_PHB[data_entry_pos].length = temp_name_length;
            }
            else
            {
                alpha_id_pinyin_PHB[data_entry_pos].length = PHB_ALPHA_ID_DEPTH;
            }

            kal_mem_cpy(
                (kal_uint8*) alpha_id_pinyin_PHB[data_entry_pos].data,
                (kal_uint8*) temp_name,
                PHB_ALPHA_ID_DEPTH);
        }
        else
        {
            alpha_id_pinyin_PHB[data_entry_pos].charset = PHB_ASCII;
        }
    #endif /* defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__) */ 

    }
}   /* end of phb_se_build_index */


/*****************************************************************************
 * FUNCTION
 *  phb_se_finish_build
 * DESCRIPTION
 *  Calculate signature of a telephone number
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void phb_se_finish_build()
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    /* 20040223 Wilson, temporary solution for PinYin sorting hang problem */
#if defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__)
    data_entry_struct *table;
    kal_uint16 i;
#endif /* defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__) */ 

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_SE_FINISH_BUILD);

    /* FDN index is not build here, since it is built when FDN is scanned */

    /* 20050408 Jo, If MMI providing sorting mechanism, it does not need to sort in L4 */
#ifdef __PHB_SORT_ENABLE__
    phb_name_num_index_sort(&phb_ptr->indices.phb_index);
#endif /* __PHB_SORT_NAME__ */
    phb_name_num_index_sort(&phb_ptr->indices.bdn_index);

    /* 20040223 Wilson, temporary solution for PinYin sorting hang problem */
#if defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__)

    table = phb_ptr->indices.phb_index.data_entry_table.table;

    for (i = 0; i < phb_ptr->indices.phb_index.data_entry_table.used_count; i++)
    {
        if (alpha_id_pinyin_PHB[i].charset == PHB_UCS2)
        {
            table[i].alpha_id.charset = PHB_UCS2;
            table[i].alpha_id.length = alpha_id_pinyin_PHB[i].length;

            kal_mem_cpy(
                (kal_uint8*) table[i].alpha_id.data,
                (kal_uint8*) alpha_id_pinyin_PHB[i].data,
                PHB_ALPHA_ID_DEPTH);
        }
    }

#endif /* defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__) */ 

}   /* end of phb_se_finish_build */


/*****************************************************************************
 * FUNCTION
 *  phb_se_append
 * DESCRIPTION
 *  Build index of certain type
 * PARAMETERS
 *  type                [IN]        
 *  record_index        [IN]        
 *  ext_index           [IN]        
 *  phb_entry           [?]         
 * RETURNS
 *  index inserted to internal index
 *****************************************************************************/
kal_uint16 phb_se_append(phb_type_enum type, kal_uint16 record_index, kal_uint8 ext_index, phb_entry_struct *phb_entry)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_SE_APPEND);

    if ((type == PHB_PHONEBOOK) || (type == PHB_FDN) || (type == PHB_BDN))
    {
        kal_bool fake_name = KAL_FALSE;
        kal_uint8 signature;
        kal_uint8 tel_num;
        kal_uint16 index;
        name_num_index_type *name_num_index;

    #ifdef __PHB_0x81_SUPPORT__     /* MTK 2004-04-20 Wisoln, support maximum length of 0x81 UCS2 */
        l4_name_struct temp_name;

        temp_name.name_dcs = 0;
    #endif /* __PHB_0x81_SUPPORT__ */ 

        phb_se_get_index_values(type, &phb_entry->tel_number, &signature, &tel_num, &name_num_index);

        /* amanda add, put number in name for sorting */
        if (phb_entry->alpha_id.name_length == 0)
        {
            kal_uint8 fake_name_bcd[15];
            kal_uint8 *temp_ptr;

            fake_name = KAL_TRUE;
            kal_mem_cpy(fake_name_bcd, &phb_entry->tel_number.addr_bcd[1], 10);
            fake_name_bcd[10] = 0xff;
            temp_ptr = phb_entry->alpha_id.name;
            phb_entry->alpha_id.name_length = 0;
            if (phb_entry->tel_number.addr_bcd[0] & 0x10)
            {
                *(temp_ptr++) = '+';
                phb_entry->alpha_id.name_length++;
            }
            phb_entry->alpha_id.name_length += convert_to_digit(fake_name_bcd, temp_ptr);
            phb_entry->alpha_id.name_dcs = PHB_ASCII;
        }
        /* Convert 0x81 to 0x80 in L4 for sorting. */
    #ifdef __PHB_0x81_SUPPORT__     /* MTK 2004-04-20 Wisoln, support maximum length of 0x81 UCS2 */
        else if (phb_entry->alpha_id.name_dcs == PHB_UCS2_81)
        {
            kal_uint8 offset = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -