multimedia/device/mpp/extdrv/ssp-ili9342h-6bit/strfunc.c

173 lines
4.4 KiB
C
Raw Normal View History

/******************************************************************************
Copyright (C), 2001-2011, Hisilicon Tech. Co., Ltd.
******************************************************************************
File Name : strfunc.c
Version : Initial Draft
Author : Hisilicon multimedia software group
Created : 2005/7/27
Last Modified :
Description : String functions
Function List :
History :
1.Date : 2005/7/27
Author : T41030
Modification: Created file
******************************************************************************/
#include <stdio.h>
#include <ctype.h>
#include "strfunc.h"
static int atoul(char* str, unsigned int* pulValue);
static int atoulx(char* str, unsigned int* pulValue);
/*****************************************************************************
Prototype : StrToNumber
Description : 10/16 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>Ϊ<EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD>
Input args : IN CHAR *str
10<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܷ<EFBFBD><EFBFBD><EFBFBD>
16<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ׺0x. <EFBFBD><EFBFBD>ABCDE
Output args : U32* pulValue, ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Return value : HI_RET HI_SUCCESS ת<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
HI_FAILURE ת<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
Calls : isdigit
Called By :
History :
1.Date : 2005<EFBFBD><EFBFBD>7<EFBFBD><EFBFBD>10<EFBFBD><EFBFBD>
Author : t41030
Modification : Created function
*****************************************************************************/
int StrToNumber(char* str , unsigned int* pulValue)
{
/*<2A>ж<EFBFBD><D0B6>Ƿ<EFBFBD>16<31><36><EFBFBD>Ƶ<EFBFBD><C6B5>ַ<EFBFBD><D6B7><EFBFBD>*/
if ( *str == '0' && (*(str + 1) == 'x' || *(str + 1) == 'X') )
{
if (*(str + 2) == '\0')
{
return -1;
}
else
{
return atoulx(str + 2, pulValue);
}
}
else
{
return atoul(str, pulValue);
}
}
/*****************************************************************************
Prototype : atoul
Description : 10<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>Ϊ<EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD>
Input args : IN CHAR *str 10<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܷ<EFBFBD><EFBFBD><EFBFBD>
Output args : U32* pulValue, ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Return value : HI_RET HI_SUCCESS ת<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
HI_FAILURE ת<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
Calls : isdigit
Called By :
History :
1.Date : 2005<EFBFBD><EFBFBD>7<EFBFBD><EFBFBD>10<EFBFBD><EFBFBD>
Author : t41030
Modification : Created function
*****************************************************************************/
static int atoul(char* str, unsigned int* pulValue)
{
unsigned int ulResult = 0;
while (*str)
{
if (isdigit((int)*str))
{
/*<2A><><EFBFBD><EFBFBD>֧<EFBFBD>ֵ<EFBFBD>0xFFFFFFFF(4294967295),
X * 10 + (*str)-48 <= 4294967295
<EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD> X = 429496729 */
if ((ulResult < 429496729) || ((ulResult == 429496729) && (*str < '6')))
{
ulResult = ulResult * 10 + (*str) - 48;
}
else
{
*pulValue = ulResult;
return -1;
}
}
else
{
*pulValue = ulResult;
return -1;
}
str++;
}
*pulValue = ulResult;
return 0;
}
/*****************************************************************************
Prototype : atoulx
Description : 16<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>Ϊ<EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>16<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ׺0x
Input args : IN CHAR *str 16<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ׺0x. <EFBFBD><EFBFBD>ABCDE
Output args : U32* pulValue, ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Return value : HI_RET HI_SUCCESS ת<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
HI_FAILURE ת<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
Calls : toupper
isdigit
Called By :
History :
1.Date : 2005<EFBFBD><EFBFBD>7<EFBFBD><EFBFBD>10<EFBFBD><EFBFBD>
Author : t41030
Modification : Created function
*****************************************************************************/
#define ASC2NUM(ch) (ch - '0')
#define HEXASC2NUM(ch) (ch - 'A' + 10)
int atoulx(char* str, unsigned int* pulValue)
{
unsigned int ulResult = 0;
unsigned char ch;
while (*str)
{
ch = toupper(*str);
if (isdigit(ch) || ((ch >= 'A') && (ch <= 'F' )))
{
if (ulResult < 0x10000000)
{
ulResult = (ulResult << 4) + ((ch <= '9') ? (ASC2NUM(ch)) : (HEXASC2NUM(ch)));
}
else
{
*pulValue = ulResult;
return -1;
}
}
else
{
*pulValue = ulResult;
return -1;
}
str++;
}
*pulValue = ulResult;
return 0;
}