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

📄 phb_utils.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 4 页
字号:
    /*----------------------------------------------------------------*/
    for (len = 0; n > 0; --n)
    {
        if (phb_less_significant_nibble(*bcd_array) != 0x0F)
        {
            ++len;
        }
        else
        {
            return len;
        }

        if (phb_more_significant_nibble(*bcd_array) != 0x0F)
        {
            ++len;
        }
        else
        {
           return len;
        }

        ++bcd_array;
    }
    return len;
}


/*****************************************************************************
 * FUNCTION
 *  is_empty
 * DESCRIPTION
 *  Tests for a sequence of bytes is empty.
 *  For empty means that all bytes are 0x0F.
 * PARAMETERS
 *  ptr     [IN]        The byte sequence to test
 *  len     [IN]        Length of ptr
 * RETURNS
 *  KAL_TRUE if empty, KAL_FALSE otherwise.
 *****************************************************************************/
kal_bool is_empty(kal_uint8 *ptr, kal_uint16 len)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint16 i;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (i = 0; i < len; ++i)
        if (*ptr++ != 0xFF)
        {
            return KAL_FALSE;
        }

    return KAL_TRUE;
}   /* end of is_empty */


/*****************************************************************************
 * FUNCTION
 *  phb_abs
 * DESCRIPTION
 *  Returns absolute value
 * PARAMETERS
 *  val     [IN]        The value to calculate its absolute value.
 * RETURNS
 *  Absolute value
 *****************************************************************************/
kal_uint32 phb_abs(kal_int32 val)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return (val < 0) ? ~val + 1 : val;
}   /* end of phb_abs */


/*****************************************************************************
 * FUNCTION
 *  binary_search
 * DESCRIPTION
 *  The generic binary search function.
 * PARAMETERS
 *  collection          [?]         
 *  low                 [IN]        
 *  high                [IN]        
 *  key                 [?]         
 *  compare_func        [IN]        
 * RETURNS
 *  If found, hit index to collection is returned;
 *  otherwise -1 is returned.
 *****************************************************************************/
int binary_search(void *collection[], int low, int high, void *key, bin_search_cmp_func_type compare_func)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int8 i;
    int mid;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    ASSERT(compare_func != NULL);

    while (low <= high)
    {
        mid = (low + high) / 2;
        i = compare_func(collection, mid, key);
        if (i < 0)
        {
            low = mid + 1;
        }
        else if (i > 0)
        {
            high = mid - 1;
        }
        else
        {
            return (kal_uint16) mid;
        }
    }
    return -1;
}


/*****************************************************************************
 * FUNCTION
 *  phb_shift_ln
 * DESCRIPTION
 *  
 * PARAMETERS
 *  end_index       [IN]        
 *  data            [?]         
 * RETURNS
 *  void
 *****************************************************************************/
void phb_shift_ln(kal_uint8 end_index, void *data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int8 i;
    nvram_ef_phb_ln_struct *record;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    record = (nvram_ef_phb_ln_struct*) data;

    /* handle the last entry */
    if (end_index + 1 < PHB_MAX_LN_ENTRIES)
    {
        kal_mem_cpy(&record->array[end_index + 1], &record->array[end_index], sizeof(phb_ln_entry_struct));
    }
    for (i = end_index - 1; i >= 0; i--)
    {
        kal_mem_cpy(&record->array[i + 1], &record->array[i], sizeof(phb_ln_entry_struct));
    }
}


/*****************************************************************************
 * FUNCTION
 *  find_pinying_str_for_ucs2
 * DESCRIPTION
 *  
 * PARAMETERS
 *  ucs2_code       [IN]        
 * RETURNS
 *  
 *****************************************************************************/
char *find_pinying_str_for_ucs2(kal_uint16 ucs2_code)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return NULL;
    if (ucs2_code == 0x4e67)
    {
        return "LI";
    }
    return NULL;
}

/* MTK 2003-12-30 Wilson, For PinYin Sort and Search */


/*****************************************************************************
 * FUNCTION
 *  find_pinyin_str_for_ucs2_with_tone
 * DESCRIPTION
 *  Convert input Chinese Character to PinYin spelling, including tone.
 * PARAMETERS
 *  inputString         [?]     
 *  outputString        [?]     
 * RETURNS
 *  Return True if converted, else False.
 *****************************************************************************/
kal_bool find_pinyin_str_for_ucs2_with_tone(kal_uint8 *inputString, kal_uint8 *outputString)
{
#if defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__)
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int8 in, out, i, flag;

#if defined(__PINYIN_SORTING_ZI__)
    kal_uint16 code;
    kal_uint8 pCharInfoBuffer[PHB_ALPHA_ID_DEPTH * 2];
#elif defined(__PINYIN_SORTING_KA__)
    kal_uint8 code[2];
    const kal_int8 *pCharInfoBuffer;
#endif 

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    memset(outputString, 0, PHB_ALPHA_ID_DEPTH);
    flag = in = out = 0;

    while ((out < PHB_ALPHA_ID_DEPTH) && (in < PHB_ALPHA_ID_DEPTH) &&
           !((*inputString == 0) && (*(inputString + 1) == 0)))
    {
    #if defined(__PINYIN_SORTING_ZI__)
        code = *((kal_uint16*) inputString);
        code = (code << 8) | (code >> 8);

        if ((code >= 0x4e00) && (code <= 0x9fa5) &&
            Zi8GetCharInfo(code, (kal_uint16*) pCharInfoBuffer, PHB_ALPHA_ID_DEPTH * 2, 1))
    #elif defined(__PINYIN_SORTING_KA__)

        code[0] = inputString[1];
        code[1] = inputString[0];

        if ((pCharInfoBuffer = GetPYString(code)) != NULL)
    #endif 

        {
            i = 0;
            while ((pCharInfoBuffer[i] != 0x00) && (out < PHB_ALPHA_ID_DEPTH) && (i < PHB_ALPHA_ID_DEPTH * 2))
            {
                outputString[out] = pCharInfoBuffer[i];
                out++;
            #if defined(__PINYIN_SORTING_ZI__)
                i = i + 2;
            #elif defined(__PINYIN_SORTING_KA__)
                i = i + 1;
            #endif 
            }
            /* Add space between convert result for KA */
        #if defined(__PINYIN_SORTING_KA__)
            outputString[out++] = 0x20;
        #endif 
            flag = 1;
        }
        else    // if(*inputString == 0)    /*NOT a Chinese character, Is a ASCII character. Ex. 'A' "0x0041"*/
        {
            outputString[out] = *(inputString + 1);
            out++;
            /* Add space between convert result for KA */
        #if defined(__PINYIN_SORTING_KA__)
            outputString[out++] = 0x20;
        #endif 
        }

        in += 2;
        inputString += 2;

    }

    if (flag)
    {
        return 1;
    }
#endif /* defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__) */ 
    return 0;

}


/*****************************************************************************
 * FUNCTION
 *  find_pinyin_str_for_ucs2_without_tone
 * DESCRIPTION
 *  Convert input Chinese Character to PinYin spelling, ignore tone.
 * PARAMETERS
 *  inputString         [?]     
 *  outputString        [?]     
 * RETURNS
 *  Return True if converted, else False.
 *****************************************************************************/
kal_bool find_pinyin_str_for_ucs2_without_tone(kal_uint8 *inputString, kal_uint8 *outputString)
{
#if defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__)
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int8 in, out, i, flag;

#if defined(__PINYIN_SORTING_ZI__)
    kal_uint16 code;
    kal_uint8 pCharInfoBuffer[PHB_ALPHA_ID_DEPTH * 2];
#elif defined(__PINYIN_SORTING_KA__)
    kal_uint8 code[2];
    const kal_int8 *pCharInfoBuffer;
#endif 

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    memset(outputString, 0, PHB_ALPHA_ID_DEPTH);
    flag = in = out = 0;

    while ((out < PHB_ALPHA_ID_DEPTH) && (in < PHB_ALPHA_ID_DEPTH) &&
           !((*inputString == 0) && (*(inputString + 1) == 0)))
    {
    #if defined(__PINYIN_SORTING_ZI__)
        code = *((kal_uint16*) inputString);
        code = (code << 8) | (code >> 8);

        if ((code >= 0x4e00) && (code <= 0x9fa5) &&
            Zi8GetCharInfo(code, (kal_uint16*) pCharInfoBuffer, PHB_ALPHA_ID_DEPTH * 2, 1))
    #elif defined(__PINYIN_SORTING_KA__)

        code[0] = inputString[1];
        code[1] = inputString[0];

        if ((pCharInfoBuffer = GetPYString(code)) != NULL)
    #endif 
        {
            i = 0;
            while ((pCharInfoBuffer[i] != 0x00) && (out < PHB_ALPHA_ID_DEPTH) &&
                   (i < PHB_ALPHA_ID_DEPTH * 2) &&
                   pCharInfoBuffer[i] != '1' && pCharInfoBuffer[i] != '2' &&
                   pCharInfoBuffer[i] != '3' && pCharInfoBuffer[i] != '4' && pCharInfoBuffer[i] != '5')
            {
                outputString[out] = pCharInfoBuffer[i];
                out++;
            #if defined(__PINYIN_SORTING_ZI__)
                i = i + 2;
            #elif defined(__PINYIN_SORTING_KA__)
                i = i + 1;
            #endif 
            }
            /* Add space between convert result for KA */
        #if defined(__PINYIN_SORTING_KA__)
            outputString[out++] = 0x20;
        #endif 
            flag = 1;
        }
        else    // if(*inputString == 0)    /*NOT a Chinese character, Is a ASCII character. Ex. 'A' "0x0041"*/
        {
            outputString[out] = *(inputString + 1);
            out++;
            /* Add space between convert result for KA */
        #if defined(__PINYIN_SORTING_KA__)
            outputString[out++] = 0x20;
        #endif 
        }

        in += 2;
        inputString += 2;
    }

    if (flag)
    {
        return 1;
    }
#endif /* defined(__PINYIN_SORTING_ZI__) || defined(__PINYIN_SORTING_KA__) */ 
    return 0;

}

/* END of MTK 2003-12-30 Wilson */


/*****************************************************************************
 * FUNCTION
 *  phb_is_prefix
 * DESCRIPTION
 *  
 * PARAMETERS
 *  target          [?]     
 *  candidate       [?]     
 * RETURNS
 *  
 *****************************************************************************/
kal_bool phb_is_prefix(alpha_id_type *target, alpha_id_type *candidate)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint8 i;
    kal_uint8 compare_length;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (target->length > candidate->length)
    {
        compare_length = candidate->length; /* candidate->length should be 1 */
    }
    else
    {
        compare_length = target->length;
    }
    for (i = 0; i < compare_length; i++)
        if (target->data[i] != candidate->data[i])
        {
            return KAL_FALSE;
        }
    return KAL_TRUE;
}

⌨️ 快捷键说明

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