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

📄 routelink_cmn.c

📁 本程序的功能是对导航数据中的道路情况数据进行整理
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
	FileName    :	routelink_cmn.c

	Date        :	2006.07.22

	Author      :	

	Copyright   :	
-----------------------------------------------------------------------------
	Modify History
	NO       Date           Modifier         Modified Contet

****************************************************************************/

/*-------------------------------------------------------------------------*/
/*																		   */
/*   Include File Section                                                  */
/*																		   */
/*-------------------------------------------------------------------------*/
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <fcntl.h>
#include <io.h>
#include <sys/stat.h>
#include "routelink_c.h"
#include "routelink_in_c.h"
#include "routelink_in_s.h"

/*-------------------------------------------------------------------------*/
/*																		   */
/*   Function definition section                                           */
/*																		   */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
/*	routelink_readrec													   */
/*	-----------------------------------------------------------------------*/
/*	Input:																   */
/*		void*				:	Current record head address[IN]			   */
/*		WORD				:	Data field ID[IN]						   */
/*		void*				:	Output data area[OUT]					   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Output:																   */
/*		RETURN				:	乮Normal乯RET_SUCCESS					   */
/*								乮Error乯 RET_FAILED					   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Outline:															   */
/*		Read 1 field from current record.								   */
/*		Which field will be read is decided by the parameter 2.			   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Others:																   */
/*																		   */
/***************************************************************************/
int	routelink_readrec(
	void*			pvCurRecAdr,		/* I / Current record head address */
	WORD			wID,				/* I / Data field ID			   */
	void*			pvGetValue			/* O / Output data area			   */
	)
{
	UWORD			uwNameLen	= 0;	/* Road name size				   */
	UWORD*			puwRecSize	= NULL;	/* Current Record size			   */
	UDWORD*			pudwLinkID	= NULL;	/* Link ID						   */
	UWORD*			puwNameSize	= NULL;	/* Road name size				   */
	UDWORD*			pudwNodeInf	= NULL;	/* Node information				   */
	BYTE*			pbRoadName	= NULL;	/* Road name					   */

	/* Exception prevention								*/
	if( (NULL == pvCurRecAdr) || (NULL == pvGetValue) )
	{
		return RET_FAILED;
	}

	/* Read different field from the data file			*/
	switch( wID )
	{
	case RL_GET_RECSIZE:	/* Read record size			*/
		puwRecSize	= (UWORD*)pvGetValue;
		*puwRecSize = MC_GET_SHORT( pvCurRecAdr );
		break;

	case RL_GET_LNKID:		/* Read Link ID				*/
		pudwLinkID	= (UDWORD*)pvGetValue;
		*pudwLinkID = MC_GET_LONG( 
					((BYTE*)pvCurRecAdr + RL_OFFSET_LNKID) );
		break;

	case RL_GET_NAMESIZE:	/* Read Name size			*/
		puwNameSize	 = (UWORD*)pvGetValue;
		*puwNameSize = MC_GET_SHORT( 
					((BYTE*)pvCurRecAdr + RL_OFFSET_NAMESIZE) );
		break;

	case RL_GET_NODEINF:	/* Read start node info		*/
		pudwNodeInf	 = (UDWORD*)pvGetValue;
		*pudwNodeInf = MC_GET_LONG( 
					((BYTE*)pvCurRecAdr + RL_OFFSET_NODEINF) );
		break;

	case RL_GET_ROADNAME:	/* Read Road name			*/
		uwNameLen	= MC_GET_SHORT( 
					((BYTE*)pvCurRecAdr + RL_OFFSET_NAMESIZE) );
		/* There is error in data file, exception prevention	*/
		if( uwNameLen > 0x8000 )
		{
			break;
		}
		pbRoadName = (BYTE*)pvGetValue;
		if( uwNameLen >= 1 )
		{
			memcpy( pbRoadName, 
					((BYTE*)pvCurRecAdr + RL_OFFSET_ROADNAME), uwNameLen );
			pbRoadName[uwNameLen] = '\0';
		}
		break;

	default:
		break;
	}

	return RET_SUCCESS;
}

/***************************************************************************/
/*	routelink_getfsize													   */
/*	-----------------------------------------------------------------------*/
/*	Input:																   */
/*		char*				:	File name[IN]							   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Output:																   */
/*		RETURN				:	乮Normal乯File size						   */
/*								乮Error乯 0								   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Outline:															   */
/*		Get the size of file.											   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Others:																   */
/*																		   */
/***************************************************************************/
int	routelink_getfsize(
	char*			pFileName
	)
{
	int				iSize	= 0;	/* File size			*/
	int				iFileNo = 0;	/* File handle			*/
	struct _stat	stBuf;			/* File info buffer		*/
	

	/* Initialization				*/
	memset( &stBuf, 0, sizeof(stBuf) );

	/* File open					*/
	iFileNo = _open( pFileName, _O_RDONLY );
	if( -1 == iFileNo )
	{
		return 0;
	}

	/* File information get			*/
	_fstat( iFileNo, &stBuf );
	iSize = (int)stBuf.st_size;

	/* File close					*/
	_close( iFileNo );

	return iSize;
}

/***************************************************************************/
/*	routelink_file_getsrccnt											   */
/*	-----------------------------------------------------------------------*/
/*	Input:																   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Output:																   */
/*		RETURN				:	乮Normal乯Search times					   */
/*								乮Error乯 0								   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Outline:															   */
/*		Get search counter.												   */
/*		This function will get the counter that the data had been searched.*/
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Others:																   */
/*																		   */
/***************************************************************************/
int	routelink_file_getsrccnt()
{
	int				iSrcCnt		= 0;	/* Search times coutner			   */
	int				iRetReadFile= 0;	/* Return value for read file	   */
	FILE*			pFileSrcCnt	= NULL;	/* Search times record file handle */

	/* File srctimesrec.dat open					*/
	pFileSrcCnt = fopen( RTL_SRCCNT_FILENAME, "r" );
	if( NULL == pFileSrcCnt )
	{
		/* File does not exist, create.(Means the first time to search )   */
		pFileSrcCnt = fopen( RTL_SRCCNT_FILENAME, "w" );
		if( NULL == pFileSrcCnt )
		{
			iSrcCnt = 0;
			printf( "\nFailed to Open file srctimesrec.dat!\n" );
			return iSrcCnt;
		}
	}

	/* Read current search times from file						*/
	iRetReadFile = fread( &iSrcCnt, sizeof(int), 1, pFileSrcCnt );
	if( iRetReadFile <= 0 )
	{
		iSrcCnt = 0;
	}

	/* File close				*/
	fclose( pFileSrcCnt );
	pFileSrcCnt = NULL;

	return iSrcCnt;
}

/***************************************************************************/
/*	routelink_file_updsrccnt											   */
/*	-----------------------------------------------------------------------*/
/*	Input:																   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Output:																   */
/*		RETURN				:	乮Normal乯Search times					   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Outline:															   */
/*		Update search times.											   */
/*		This function will update the times of file be searched.		   */
/*		Whenever the data be searched, this function should be called.	   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Others:																   */
/*																		   */
/***************************************************************************/
int	routelink_file_updsrccnt()
{
	int				iSrcCnt		= 0;	/* Search times counter			   */
	FILE*			pFileSrcCnt	= NULL;	/* Search times record file handle */

	/* Current search times counter get */
	iSrcCnt = routelink_file_getsrccnt();

	/* Current search times counter plus */
	iSrcCnt ++;

	/* File srctimesrec.txt open					*/
	pFileSrcCnt = fopen( RTL_SRCCNT_FILENAME, "w" );
	if( NULL == pFileSrcCnt )
	{
		printf( "\nFailed to Open file srctimesrec.txt!\n" );
		return iSrcCnt;
	}

	if( iSrcCnt > 999 )
	{
		iSrcCnt = 0;
	}

	/* Write current search counter into the file	*/
	fwrite( &iSrcCnt, sizeof(int), 1, pFileSrcCnt );

	/* File close				*/
	fclose( pFileSrcCnt );
	pFileSrcCnt = NULL;

	return iSrcCnt;
}

/***************************************************************************/
/*	routelink_cmn_str2num()												   */
/*	-----------------------------------------------------------------------*/
/*	Input:																   */
/*		BYTE*				:	String to be converted[IN]				   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Output:																   */
/*		RETURN				:	乮Normal乯Number after converting		   */
/*								乮Error乯 0								   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Outline:															   */
/*		Convert string to number(with the data type int).				   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Others:																   */
/*																		   */
/***************************************************************************/
int	routelink_cmn_str2num(
	BYTE*			pbStr			/* I/ String to convert				   */
	)
{
	int				iStrLen = 0;	/* Lenth of string			*/
	int				iDigit	= 0;	/* Current Digit			*/
	int				iNumber	= 0;	/* Convertion result		*/

	/* Exception prevention				*/
	if( NULL == pbStr )
	{
		return 0;
	}

	/* Get the lenth of string			*/
	iStrLen = strlen( pbStr );

	/* Convert to number						*/
	for( iDigit = 0; iDigit < iStrLen; iDigit ++ )
	{
		iNumber = iNumber * 10 + (pbStr[iDigit] - '0');
	}

	return iNumber;
}


/***************************************************************************/
/*	routelink_linkdata2dspstr()											   */

⌨️ 快捷键说明

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