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

📄 parse.c

📁 telcobridges cas develop
💻 C
📖 第 1 页 / 共 5 页
字号:
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print error message */
		TB640_CAS_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;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640CasParseDoConnConfigurationLine:	Parses the content of a Do connection configuration line and stores them 
 |											into our structure
 |
 |  in_pszLine		:	Pointer to the text line
 |  in_pszOriginalLine:	Pointer to the original text line
 |	in_un32Line		:	Line number in the configuration file
 |	in_un32Index	:	Index of the argument in the original string
 |	out_pfCTBusConn	:	Output flag from the configuration file
 |
 |  Note			:	Line must be converted in CAPS
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640CasParseDoConnConfigurationLine(
  IN		const PTBX_CHAR				in_pszLine,
  IN		const PTBX_CHAR				in_pszOriginalLine,
  IN		TBX_UINT32					in_un32Line,
  IN		TBX_UINT32					in_un32Index,
  IN		PTBX_BOOL					out_pfDoConn)
{
	TBX_CHAR					szLine [TB640_CAS_MAX_CONFIGURATION_LINE_LENGTH];
	TBX_UINT32					un32Setting;
	TBX_UINT32					un32SizeOfEntry;
	PTBX_CHAR					pArg;
	TBX_BOOL					fDoConnConfig;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variable */
		strcpy (szLine, in_pszLine);
		un32Setting = 0;

		/* Begin parsing */
		pArg = strtok (szLine, TB640_CAS_LINE_PARSING_DELIMITERS);
		while (NULL != pArg)
		{
			switch (un32Setting)
			{
			/* First argument is the CTBus config */
			case 0:
				{
					TB640_CAS_PARSE_GET_PARAMETER (									\
					  g_aParseBoolean, 												\
					  &(fDoConnConfig),										\
					  "Invalid value. Expecting CTBus connection enable [TRUE/FALSE]");
						
					*out_pfDoConn = fDoConnConfig;
				}
				break;
		
			default:
				/* Too many argument found */
				TB640_CAS_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "Too many arguments");
				TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				break;
			}

			/* Process the next argument */
			un32Setting++;

			/* Get the next token */
			pArg = strtok (NULL, TB640_CAS_LINE_PARSING_DELIMITERS);
		}

		/* End of the code (skip to cleanup) */
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print error message */
		TB640_CAS_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;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640CasParseCallConfigurationLine:	Parses the content of a call configuration line and stores them into our structure
 |
 |  in_pszLine		:	Pointer to the text line
 |  in_pszOriginalLine:	Pointer to the original text line
 |	in_un32Line		:	Line number in the configuration file
 |	in_un32Index	:	Index of the argument in the original string
 |	in_un32Adapter	:	Adapter index in our internal array
 |	in_un32TrunkNb	:	Trunk number to which the stack is connected
 |
 |  Note			:	Line must be converted in CAPS
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640CasParseCallConfigurationLine(
  IN		const PTBX_CHAR				in_pszLine,
  IN		const PTBX_CHAR				in_pszOriginalLine,
  IN		TBX_UINT32					in_un32Line,
  IN		TBX_UINT32					in_un32Index,
  IN		TBX_UINT32					in_un32Adapter,
  IN		TBX_UINT32					in_un32TrunkNb)
{
	TBX_CHAR					szLine [TB640_CAS_MAX_CONFIGURATION_LINE_LENGTH];
	TBX_UINT32					un32Setting;
	PTBX_CHAR					pArg;
	PTB640_CAS_ADAPTER_INFO		pAdapterInfo;
	PTB640_CAS_TRUNK_INFO		pTrunkInfo;
	PTB640_CAS_CALL_CFG			pCallCfg;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variable */
		strcpy (szLine, in_pszLine);
		un32Setting = 0;
		pAdapterInfo = &(g_AppContext->ahAdapterInfo [in_un32Adapter]);
		pTrunkInfo = &(pAdapterInfo->aTrunkInfo [in_un32TrunkNb]);
		pCallCfg = &(pTrunkInfo->CallConfiguration);

		/* Copy the origin number */
		strncpy (pCallCfg->szCategory, pTrunkInfo->szCategory, sizeof(pCallCfg->szCategory));
		pCallCfg->szCategory[ sizeof(pCallCfg->szCategory - 1) ] = '\0';

		/* Begin parsing */
		pArg = strtok (szLine, TB640_CAS_LINE_PARSING_DELIMITERS);
		while (NULL != pArg)
		{
			switch (un32Setting)
			{
			/* First argument is the calling number */
			case 0:
				strncpy (pCallCfg->szCallingPhoneNb, pArg, sizeof(pCallCfg->szCallingPhoneNb));
				pCallCfg->szCallingPhoneNb[ sizeof(pCallCfg->szCallingPhoneNb) - 1 ] = '\0';
				break;

			/* Second argument is the called number */
			case 1:
				strncpy (pCallCfg->szCalledPhoneNb, pArg, sizeof(pCallCfg->szCalledPhoneNb));
				pCallCfg->szCalledPhoneNb[ sizeof(pCallCfg->szCalledPhoneNb) - 1 ] = '\0';
				break;

			default:
				/* Too many argument found */
				TB640_CAS_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "Too many arguments");
				TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				break;
			}

			/* Process the next argument */
			un32Setting++;

			/* Get the next token */
			pArg = strtok (NULL, TB640_CAS_LINE_PARSING_DELIMITERS);
		}

		/* End of the code (skip to cleanup) */
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print error message */
		TB640_CAS_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;
}


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Utility functions
 *------------------------------------------------------------------------------------------------------------------------------*/



/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640CasParseToken:	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
TB640CasParseToken(
  IN		const PTBX_CHAR				in_pszLine,
  OUT		PTB640_CAS_PARSING_TOKEN	out_pTokenType,
  OUT		PTBX_CHAR *					out_ppszToken,
  OUT		PTBX_CHAR *					out_ppszArgument)
{
	TBX_CHAR					szLine [TB640_CAS_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_CAS_PARSING_TOKEN_UNKNOWN;
		*out_ppszToken = NULL;
		*out_ppszArgument = NULL;

		/* Found the first text string */
		pszParsePtr = strtok (szLine, TB640_CAS_PARSING_DELIMITERS);
		if (pszParsePtr != NULL)
		{
			/* Check if this is a comment */
			if (pszParsePtr[0] == '#')
			{
				*out_pTokenType = TB640_CAS_PARSING_TOKEN_COMMENT;
				*out_ppszToken = (in_pszLine + (pszParsePtr - szLine));
				*out_ppszArgument = (in_pszLine + (pszParsePtr - szLine)) + 1;
			}
			else
			{
				/* Get the value of the token */
				TB640CasCompareEntries (pszParsePtr, g_aParseMainConfigItems, (PTBX_UINT32)out_pTokenType, &un32SizeOfEntry);
				if (*out_pTokenType != TB640_CAS_PARSING_TOKEN_UNKNOWN)
				{
					*out_ppszToken = (in_pszLine + (pszParsePtr - szLine));
					*out_ppszArgument = (in_pszLine + (pszParsePtr - szLine)) + un32SizeOfEntry;
				}
			}
		}
		else
		{
			/* Empty line */
			*out_pTokenType = TB640_CAS_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_CAS_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;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640CasCompareEntries:	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
TB640CasCompareEntries(
  IN		const PTBX_CHAR				in_pszLine,
  IN		PTB640_CAS_PARSING_ENTRY	in_paParsingEntries,
  OUT		PTBX_UINT32					out_pun32Value,
  OUT		PTBX_UINT32					out_pun32SizeOfEntry)
{
	TBX_UINT32					un32Count;
	PTB640_CAS_PAR

⌨️ 快捷键说明

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