📄 parse.c
字号:
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*--------------------------------------------------------------------------------------------------------------------------------
| Utility functions
*------------------------------------------------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640IsdnParseToken: Parses the current line and returns the token type if known
|
| in_pszLine : Pointer to the text line
| out_pTokenType : Pointer to a variable that will contain the token type
| out_ppszToken : Pointer to a variable that will contain a pointer to the token after the found token
| (of NULL if no token is discovered)
| out_ppszArgument: Pointer to a variable that will contain a pointer to the argument following the token after the found
| token (of NULL if no token is discovered).
|
| Note : Line must be converted in CAPS
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640IsdnParseToken(
IN const PTBX_CHAR in_pszLine,
OUT PTB640_ISDN_PARSING_TOKEN out_pTokenType,
OUT PTBX_CHAR * out_ppszToken,
OUT PTBX_CHAR * out_ppszArgument)
{
TBX_CHAR szLine [TB640_ISDN_MAX_CONFIGURATION_LINE_LENGTH];
TBX_UINT32 un32SizeOfEntry;
PTBX_CHAR pszParsePtr;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variable */
strcpy (szLine, in_pszLine);
/* Initialize output arguments */
*out_pTokenType = TB640_ISDN_PARSING_TOKEN_UNKNOWN;
*out_ppszToken = NULL;
*out_ppszArgument = NULL;
/* Found the first text string */
pszParsePtr = strtok (szLine, TB640_ISDN_PARSING_DELIMITERS);
if (pszParsePtr != NULL)
{
/* Check if this is a comment */
if (pszParsePtr[0] == '#')
{
*out_pTokenType = TB640_ISDN_PARSING_TOKEN_COMMENT;
*out_ppszToken = (in_pszLine + (pszParsePtr - szLine));
*out_ppszArgument = (in_pszLine + (pszParsePtr - szLine)) + 1;
}
else
{
/* Get the value of the token */
TB640IsdnCompareEntries (pszParsePtr, g_aParseMainConfigItems, (PTBX_UINT32)out_pTokenType, &un32SizeOfEntry);
if (*out_pTokenType != TB640_ISDN_PARSING_TOKEN_UNKNOWN)
{
*out_ppszToken = (in_pszLine + (pszParsePtr - szLine));
*out_ppszArgument = (in_pszLine + (pszParsePtr - szLine)) + un32SizeOfEntry;
}
}
}
else
{
/* Empty line */
*out_pTokenType = TB640_ISDN_PARSING_TOKEN_COMMENT;
*out_ppszToken = "";
*out_ppszArgument = "";
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print error message */
TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640IsdnCompareEntries: Compare a string with a number of entries to find a specific value
|
| in_pszLine : Pointer to the text line
| in_paParsingEntries: Pointer to an array of parsing entries
| out_pun32Value : Pointer to a variable that will contain the value of the compared string
| (does nothing if it isn't found)
| out_pun32SizeOfEntry: Pointer to a variable that will contain the size of the found token (0 otherwise)
|
| Note : Line must be converted in CAPS
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640IsdnCompareEntries(
IN const PTBX_CHAR in_pszLine,
IN PTB640_ISDN_PARSING_ENTRY in_paParsingEntries,
OUT PTBX_UINT32 out_pun32Value,
OUT PTBX_UINT32 out_pun32SizeOfEntry)
{
TBX_UINT32 un32Count;
PTB640_ISDN_PARSING_ENTRY pParsingEntry;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize output arguments */
*out_pun32SizeOfEntry = 0;
/* Check for other tokens */
un32Count = 0;
do
{
/* Get the parsing entry pointer */
pParsingEntry = &(in_paParsingEntries [un32Count++]);
/* See if this token corresponds to what we have */
if (pParsingEntry->pszIdentifier != NULL)
{
if (strncmp(pParsingEntry->pszIdentifier, in_pszLine, strlen(pParsingEntry->pszIdentifier)) == 0)
{
*out_pun32Value = pParsingEntry->un32Value;
*out_pun32SizeOfEntry = strlen (pParsingEntry->pszIdentifier);
break;
}
}
} while (pParsingEntry->pszIdentifier != NULL);
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print error message */
TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640IsdnGetTokenString: Search in an array of parsing token entries and return the first matching token string with the
| given token value.
|
| in_paParsingEntries : Pointer to an array of token parsing entries
| in_un32Value : Searching token value
|
| Note :
|
| Return : The string pointer or NULL if not found.
|
*------------------------------------------------------------------------------------------------------------------------------*/
PTBX_CHAR TB640IsdnGetTokenString(
IN PTB640_ISDN_PARSING_ENTRY in_paParsingEntries,
IN TBX_UINT32 in_un32Value )
{
PTB640_ISDN_PARSING_ENTRY pParsingEntry;
PTBX_CHAR pszToken = NULL;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Check for tokens value */
pParsingEntry = in_paParsingEntries;
while( pParsingEntry->pszIdentifier != NULL )
{
/* See if this token value corresponds to what we have */
if( pParsingEntry->un32Value == in_un32Value )
{
pszToken = pParsingEntry->pszIdentifier;
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS(TBX_RESULT_OK);
}
pParsingEntry++;
};
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS(TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print error message */
TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
return pszToken;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640IsdnToUpper: Converts a string to uppercase and remove trailing 0x0D and 0x0A.
|
| in_pszLine : Pointer to the text line
|
| Note : ~
|
| Return : No return value
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID
TB640IsdnToUpper(
IN PTBX_CHAR in_pszLine)
{
TBX_UINT32 un32Dst;
TBX_UINT32 un32Count;
TBX_UINT32 un32Size;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variable */
un32Size = strlen (in_pszLine);
un32Dst = 0;
/* Convert each character to upper case */
for (un32Count=0; un32Count<un32Size; un32Count++)
{
if ((in_pszLine [un32Count] != 0x0A) && (in_pszLine [un32Count] != 0x0D))
in_pszLine [un32Dst++] = toupper (in_pszLine [un32Count]);
}
in_pszLine [un32Dst++] = 0x0;
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS_VOID;
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print error message */
TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN_VOID;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640IsdnToLower: Converts a string to lowercase and remove trailing 0x0D and 0x0A.
|
| in_pszLine : Pointer to the text line
|
| Note : ~
|
| Return : No return value
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID
TB640IsdnToLower(
IN PTBX_CHAR in_pszLine)
{
TBX_UINT32 un32Dst;
TBX_UINT32 un32Count;
TBX_UINT32 un32Size;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variable */
un32Size = strlen (in_pszLine);
un32Dst = 0;
/* Convert each character to upper case */
for (un32Count=0; un32Count<un32Size; un32Count++)
{
if ((in_pszLine [un32Count] != 0x0A) && (in_pszLine [un32Count] != 0x0D))
in_pszLine [un32Dst++] = tolower (in_pszLine [un32Count]);
}
in_pszLine [un32Dst++] = 0x0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -