dbt.c
来自「基于nucleus操作系统的GPRS无线数据传输终端全套源文件。包括支持ARM7」· C语言 代码 · 共 462 行 · 第 1/2 页
C
462 行
/***********************************************************************
*
* FUNCTION
*
* DBT_HEX_ASCII_To_Long
*
* DESCRIPTION
*
* This function will attempt to convert the input string into
* an unsigned long location specified in the call.
*
* INPUTS
*
* string String to convert
* num_ptr Pointer to integer dest.
*
* OUTPUTS
*
* return(DB_SUCCESS) If successful conversion
* return(DB_ERROR) If an error exists
* *num_ptr Converted ulong value
*
***********************************************************************/
INT DBT_HEX_ASCII_To_Long(CHAR *string, unsigned long *num_ptr)
{
INT i;
INT status;
unsigned long number;
/* Since there is no sign bit for a HEX number, start making the
conversion immediately. */
/* Check to see if the string contains a valid ASCII representation of
a HEX unsigned long. */
i = 0;
status = DB_SUCCESS;
number = 0;
do
{
/* Check for a valid character. */
if ((string[i] >= '0') && (string[i] <= '9'))
{
/* A normal HEX number is present. */
number = (number << 4) + (string[i] - '0');
}
else if ((string[i] >= 'a') && (string[i] <= 'f'))
{
/* A lower-case HEX digit is present. */
number = (number << 4) + (string[i] - 'a' + 10);
}
else if ((string[i] >= 'A') && (string[i] <= 'F'))
{
/* A lower-case HEX digit is present. */
number = (number << 4) + (string[i] - 'A' + 10);
}
else
{
/* An error is present. */
status = DB_ERROR;
i--;
}
/* Increment the character index in the string. */
i++;
} while ((i <= COL) && (string[i] != NUL) && (status == DB_SUCCESS));
/* See if the digit exceeded the size limit. (8 digits). */
if (i > 8)
{
/* An error is present. */
status = DB_ERROR;
}
/* If the string represented an ASCII HEX number copy the converted
number into the destination. */
if (status == DB_SUCCESS)
/* Copy the converted number into the destination. */
*num_ptr = number;
/* Return status to the caller. */
return(status);
}
/***********************************************************************
*
* FUNCTION
*
* DBT_Name_Compare
*
* DESCRIPTION
*
* This function compares the two supplied strings. If the they
* are equal, a DB_TRUE is returned. Otherwise, a DB_FALSE is
* returned.
*
* INPUTS
*
* string1 First string to compare
* string2 Second string to compare
*
* OUTPUTS
*
* return(DB_TRUE) If the strings are equal
* return(DB_FALSE) If the strings are not equal
*
***********************************************************************/
INT DBT_Name_Compare(CHAR *string1, CHAR *string2)
{
INT j,i,k;
i = 0;
j = 0;
while (string1[i] == ' ')
i++;
while (string2[j] == ' ')
j++;
/* Comapare two strings. */
k = 0;
while (((k < MAX_NAME) && (string1[i] == string2[j])) &&
(string1[i] != NUL))
{
i++;
j++;
k++;
}
if (k == MAX_NAME)
/* Strings are equal, return a DB_TRUE. */
return(DB_TRUE);
else if ((string1[i] == NUL) && (string2[j] == NUL))
/* Strings are equal, return a DB_TRUE. */
return(DB_TRUE);
else if ((string1[i] == ' ') && (string2[j] == NUL))
/* Strings are equal, return a DB_TRUE. */
return(DB_TRUE);
else if ((string2[j] == ' ') && (string1[i] == NUL))
/* Strings are equal, return a DB_TRUE. */
return(DB_TRUE);
else
/* Strings are not equal, return a DB_FALSE. */
return(DB_FALSE);
}
/***********************************************************************
*
* FUNCTION
*
* DBT_String_Compare
*
* DESCRIPTION
*
* This function compares the two supplied strings. If the they
* are equal, a DB_TRUE is returned. Otherwise, a DB_FALSE is
* returned.
*
* INPUTS
*
* string1 First string to compare
* string2 Second string to compare
*
* OUTPUTS
*
* return(DB_TRUE) If the strings are equal
* return(DB_FALSE) If the strings are not equal
*
***********************************************************************/
INT DBT_String_Compare(CHAR *string1, CHAR *string2)
{
/* Comapare two strings. */
if (strncmp(string1, string2, COL) == 0)
/* Strings are equal, return a DB_TRUE. */
return(DB_TRUE);
else
/* Strings are not equal, return a DB_FALSE. */
return(DB_FALSE);
}
/***********************************************************************
*
* FUNCTION
*
* DBT_String_Cat
*
* DESCRIPTION
*
* This function appends the source string to the end of the
* destination string.
*
* INPUTS
*
* dest Destination string
* source String to append
*
* OUTPUTS
*
* None
*
***********************************************************************/
VOID DBT_String_Cat(CHAR *dest, CHAR *source)
{
/* Append source string to destination string. */
strcat(dest,source);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?