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

📄 routelink_src.c

📁 本程序的功能是对导航数据中的道路情况数据进行整理
💻 C
📖 第 1 页 / 共 3 页
字号:
/*	Outline:															   */
/*		Get result data from current record area.						   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Others:																   */
/*																		   */
/***************************************************************************/
S_LNKDATA_DSP* routelink_src_getrsltdata(
	BYTE*			pbCurRecAdr			/* I/ Route link info data file    */
	)
{

	BYTE			bRoadNameFlg= 0;	/* Road name exist flag			   */
	UWORD			uwNameSize	= 0;	/* Road name size				   */
	UDWORD			udwNodeInf	= 0;	/* Node information				   */
	int				iMallocSize	= 0;	/* Size of result data area		   */
	BYTE*			pbMallocAdr = NULL;	/* Header pointer				   */
	S_LNKDATA_DSP*	pstRsltData	= NULL;	/* Result data info	buffer		   */

	/* Exception prevention				*/
	if( NULL == pbCurRecAdr )
	{
		return (S_LNKDATA_DSP*)NULL;
	}

	/* Route link info data get			*/
	uwNameSize = MC_GET_SHORT( 
					((BYTE*)pbCurRecAdr + RL_OFFSET_NAMESIZE) );

	/* Result data area allocation										   */
	routelink_readrec( pbCurRecAdr, RL_GET_NODEINF, &udwNodeInf );
	bRoadNameFlg = MC_GET_RNFLG( udwNodeInf );
	if( 1 == bRoadNameFlg )
	{
		iMallocSize = sizeof(S_LNKDATA_DSP) + sizeof(S_STRING) + uwNameSize;
	}
	else
	{
		iMallocSize = sizeof(S_LNKDATA_DSP);
	}

	/* Allocate memory for Link Data string displaying			*/
	/* iMallocSize = Recordsize + 1byte(1byte is for '\0')		*/
	pbMallocAdr	= (BYTE*)malloc( iMallocSize + 1 );
	if( NULL == pbMallocAdr )
	{
		return (S_LNKDATA_DSP*)NULL;
	}
	memset( pbMallocAdr, 0, iMallocSize );

	/* Memory split and address set										   */
	/* S_LNKDATA_DSP area set			*/
	pstRsltData	= (S_LNKDATA_DSP*)pbMallocAdr;

	/* Current pointer offset to the end of S_LNKDATA_DSP		*/
	pbMallocAdr	+= sizeof( S_LNKDATA_DSP );

	if( 1 == bRoadNameFlg )
	{
		/* Set the address for S_STRING* field					*/
		pstRsltData->pstRoadName = (S_STRING*)pbMallocAdr;

		/* Current pointe offset to the end of S_STRING			*/
		pbMallocAdr += sizeof( S_STRING );

		/* Set the address for name buffer						*/
		pstRsltData->pstRoadName->pbStr = (BYTE*)pbMallocAdr;
	}

	/* Result info set					*/
	routelink_readrec( pbCurRecAdr, RL_GET_LNKID, &pstRsltData->udwLinkID );
	if( 1 == bRoadNameFlg )
	{
		pstRsltData->pstRoadName->uwSize = uwNameSize;
		routelink_readrec( 
			pbCurRecAdr, RL_GET_ROADNAME, pstRsltData->pstRoadName->pbStr );
		pstRsltData->pstRoadName->pbStr[uwNameSize] = '\0';
	}
	routelink_readrec( pbCurRecAdr, RL_GET_NODEINF, &udwNodeInf );
	pstRsltData->bRoadNameFlg	= bRoadNameFlg;
	pstRsltData->bBranchNum		= MC_GET_BRCH( udwNodeInf );
	pstRsltData->bDspClass		= MC_GET_CLSNO( udwNodeInf );

	return pstRsltData;
}


/***************************************************************************/
/*	routelink_src_rsltoutput()											   */
/*	-----------------------------------------------------------------------*/
/*	Input:																   */
/*		BYTE*				:	Route link info data file[IN]			   */
/*		int					:	Size of data for being saved[IN]		   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Output:																   */
/*		RETURN				:	乮Normal乯RET_SUCCESS					   */
/*								乮Error乯 RET_FAILED					   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Outline:															   */
/*		Output search result data into file.							   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Others:																   */
/*																		   */
/***************************************************************************/
int routelink_src_rsltoutput(
	BYTE*				pbSrcRslt,		/* I/ Route link info data file	   */
	int					iBufSize		/* I/ Size of data for beging saved*/
	)
{
	int					iSrcCnt	= 0;
	BYTE				abFileName[32];
	FILE*				pFileOutPut	= NULL;

	/* File name buffer clear			*/
	memset( abFileName, 0, sizeof(abFileName) );

	iSrcCnt = routelink_file_getsrccnt();

	if( iBufSize > 0 )
	{
		iSrcCnt++;
		RTL_SRCRSLT_OUTPUT( abFileName, iSrcCnt ); 
		pFileOutPut = fopen( abFileName, "a" );
		if( NULL != pFileOutPut )
		{
			/* Data save					*/
			fwrite( pbSrcRslt, iBufSize, 1, pFileOutPut );

			/* Close file					*/
			fclose( pFileOutPut );
			pFileOutPut = NULL;
		}
	}

	return RET_SUCCESS;
}

/***************************************************************************/
/*	routelink_src_slinknode()											   */
/*	-----------------------------------------------------------------------*/
/*	Input:																   */
/*		BYTE*				:	Current data block head address[IN]		   */
/*		S_LNKTBL_SRC**		:	Header node[IN/OUT]						   */
/*		S_LNKTBL_SRC**		:	Current link node[IN/OUT]				   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Output:																   */
/*		RETURN				:	乮Normal乯RET_SUCCESS					   */
/*								乮Error乯 RET_FAILED					   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Outline:															   */
/*		Sing link node insert.											   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Others:																   */
/*																		   */
/***************************************************************************/
int routelink_src_slinknode(
	BYTE*				pbCurBlock,		/* I / Current data block 		   */
	S_LNKTBL_SRC**		pstHeader,		/* IO/ Header node				   */
	S_LNKTBL_SRC**		pstCurLnk		/* IO/ Curren link node			   */	
	)
{

	BYTE*				pbDspStr	= NULL;	/* Display string buffer	   */
	S_LNKTBL_SRC*		pstSLinkHead= NULL;	/* Header link node			   */
	S_LNKTBL_SRC*		pstSLinkNode= NULL;	/* Curren link node			   */
	S_LNKDATA_DSP*		pstRsltData	= NULL;	/* Search result data		   */

	/* Paramete get							*/
	pstSLinkHead	= *pstHeader;
	pstSLinkNode	= *pstCurLnk;

	/* Header Node NULL, Create it			*/
	if( NULL == pstSLinkHead )
	{
		pstSLinkHead = malloc( sizeof(S_LNKTBL_SRC) );
		if( NULL == pstSLinkHead )
		{
			printf( "\nCreate header node of link table err!\n" );
		}
		else
		{
			memset( pstSLinkHead, 0, sizeof(S_LNKTBL_SRC) );
			pstSLinkNode = pstSLinkHead;
		}

		*pstHeader = pstSLinkHead;
		*pstCurLnk = pstSLinkHead;
	}

	/* Get result data from current record block		*/
	pstRsltData = routelink_src_getrsltdata( pbCurBlock );

	/* Search result convert to string 					*/
	pbDspStr = routelink_linkdata2dspstr( pstRsltData );

	if( NULL != pstRsltData )
	{
		free( pstRsltData );
		pstRsltData = NULL;
	}

	/* Link next node		*/
	if( NULL != pstSLinkNode )
	{
		pstSLinkNode->pNxtNode 
					= (S_LNKTBL_SRC*)malloc( sizeof(S_LNKTBL_SRC) );
		if( NULL != pstSLinkNode->pNxtNode )
		{
			pstSLinkNode->pNxtNode->pbDspStr = pbDspStr;
			pstSLinkNode->pNxtNode->pNxtNode = NULL;
		}
		*pstCurLnk = pstSLinkNode->pNxtNode;
	}

	return RET_SUCCESS;
}

/***************************************************************************/
/*	routelink_src_slinknode()											   */
/*	-----------------------------------------------------------------------*/
/*	Input:																   */
/*		S_LNKTBL_SRC*		:	Header node[IN]							   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Output:																   */
/*		RETURN				:	乮Normal乯RET_SUCCESS					   */
/*								乮Error乯 RET_FAILED					   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Outline:															   */
/*		Output search result data into file.							   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Others:																   */
/*																		   */
/***************************************************************************/
int routelink_src_blocksave(
	S_LNKTBL_SRC*		pstSLinkHead	/* I/ Header node				   */
	)
{
	int					iWriteSize		= 0;	/* Current saved data size */
	BYTE*				pbWriteBuf		= NULL;	/* Current saved data buf  */
	BYTE*				pbCurWriteBuf	= NULL;	/* Current pointer in buf  */
	S_LNKTBL_SRC*		pstSLinkNode	= NULL; /* Current link Node	   */

	/* Exception prevention				*/
	if( NULL == pstSLinkHead )
	{
		return RET_SUCCESS;
	}

	/* Calculate the size of data writting into file						*/
	pstSLinkNode = pstSLinkHead->pNxtNode;
	iWriteSize	 = 0;
	while( NULL != pstSLinkNode )
	{
		if( NULL != pstSLinkNode->pbDspStr )
		{
			iWriteSize += ( strlen( pstSLinkNode->pbDspStr ) + 1 );
		}
		pstSLinkNode = pstSLinkNode->pNxtNode;
	}

	/* Allocate the buffer for data write					*/
	pbWriteBuf = malloc( iWriteSize );
	memset( pbWriteBuf, 0, iWriteSize );
	pbCurWriteBuf = pbWriteBuf;

	/* Save Search result data into continuous memory		*/
	if( NULL != pbWriteBuf )
	{
		pstSLinkNode = pstSLinkHead->pNxtNode;
		while( NULL != pstSLinkNode )
		{
			if( NULL != pstSLinkNode->pbDspStr )
			{
				memcpy( pbCurWriteBuf, pstSLinkNode->pbDspStr, 
									strlen(pstSLinkNode->pbDspStr) );
				pbCurWriteBuf += strlen(pstSLinkNode->pbDspStr);
				*pbCurWriteBuf = '\0';
				pbCurWriteBuf++;
			}
			pstSLinkNode = pstSLinkNode->pNxtNode;
		}

		/* Display string output							*/
		routelink_src_rsltoutput( pbWriteBuf, iWriteSize );

		/* Write buffer free			*/
		free( pbWriteBuf );
		pbWriteBuf = NULL;
	}

	return RET_SUCCESS;
}

/***************************************************************************/
/*	routelink_src_slinkfree()											   */
/*	-----------------------------------------------------------------------*/
/*	Input:																   */
/*		S_LNKTBL_SRC**		:	Header Node[IN/OUT]						   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Output:																   */
/*		RETURN				:	乮Normal乯RET_SUCCESS					   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Outline:															   */
/*		Single link free.												   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Others:																   */
/*																		   */
/***************************************************************************/
int routelink_src_slinkfree(
	S_LNKTBL_SRC**			pstHeader	/* IO/ Header Node				   */
	)
{
	S_LNKTBL_SRC*			pstSLinkHead = NULL;	
							/* Header Node for Single Link table	*/
	S_LNKTBL_SRC*			pstSLinkNode = NULL;	
							/* Current Node for Single Link table	*/


	/* Exception prevention							*/
	if( (NULL == pstHeader) || (NULL == *pstHeader) )
	{
		return RET_SUCCESS;
	}

	/* Header Node get		*/
	pstSLinkHead = *pstHeader;

	/* Single Link table Free						*/
	pstSLinkNode = pstSLinkHead;
	while( NULL != pstSLinkNode )
	{
		pstSLinkNode = pstSLinkHead->pNxtNode;

		/* Data area free					*/
		if( NULL != pstSLinkHead->pbDspStr )
		{
			free( pstSLinkHead->pbDspStr );
			pstSLinkHead->pbDspStr = NULL;
		}
		free( pstSLinkHead );
		pstSLinkHead = pstSLinkNode;
	}

	*pstHeader = NULL;

	return RET_SUCCESS;
}

⌨️ 快捷键说明

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