📄 routelink_src.c
字号:
/****************************************************************************
FileName : routelink_src.c
Date : 2006.07.22
Author :
Copyright :
-----------------------------------------------------------------------------
Modify History
NO Date Modifier Modified Contet
****************************************************************************/
/*-------------------------------------------------------------------------*/
/* */
/* Include File Section */
/* */
/*-------------------------------------------------------------------------*/
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include "routelink_c.h"
#include "routelink_in_c.h"
#include "routelink_in_s.h"
#include "routelink_in_p.h"
/* Record field ID definition */
#define RL_GET_RECSIZE ( 0 ) /* Record size get */
#define RL_GET_LNKID ( 1 ) /* Link ID */
#define RL_GET_NAMESIZE ( 2 ) /* Road name size get */
#define RL_GET_NODEINF ( 3 ) /* Node info get */
#define RL_GET_ROADNAME ( 4 ) /* Road name get */
/*-------------------------------------------------------------------------*/
/* */
/* Route link search process function define */
/* */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
/* routelink_src_lnkid() */
/* -----------------------------------------------------------------------*/
/* Input: */
/* FILE* : Route link info data file[IN] */
/* */
/* -----------------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮Normal乯RET_SUCCESS */
/* 乮Error乯 RET_FAILED */
/* */
/* -----------------------------------------------------------------------*/
/* Outline: */
/* Create single link table for data analysing using. */
/* */
/* -----------------------------------------------------------------------*/
/* Others: */
/* */
/***************************************************************************/
int routelink_src_lnkid(
FILE* pOrgFile /* I/ Route link info data file */
)
{
UDWORD udwBaseLnkID= 0; /* Link specified by user */
UWORD uwRecSize = 0; /* Current Record size */
UDWORD udwLinkID = 0; /* Link ID */
int iRetReadFile= 0; /* Return of read file */
int iGetChrNum = 0; /* Number of char from key buf */
int iSrcRsltNum = 0; /* Search result */
int iMovSize = 0; /* Size of memory move */
int iSrcCnt = 0; /* Search times counter */
int iReadSize = 0; /* Size of block to be read */
int iFileSize = 0; /* Size of the file */
BYTE* pbMemBlock = NULL; /* Memory Block for read from file */
BYTE* pbCurBlock = NULL; /* Current pointer to Memory Block */
BYTE* pbCatPos = NULL; /* The position of a record cut */
S_LNKTBL_SRC* pstSLinkNode= NULL; /* Sing link table */
S_LNKTBL_SRC* pstSLinkHead= NULL; /* Sing link table */
fpos_t stFilePntr = 0; /* Current file read pointer */
/* Exception prevention */
if( NULL == pOrgFile )
{
return RET_FAILED;
}
/* Get file size */
iFileSize = routelink_getfsize( RTL_ORGDAT_FILENAME );
while( iGetChrNum <= 0 )
{
/* Prompt user to specify the Link ID for searching */
printf( "\nPlease input the Link ID you want to search!>>>>>>>>\n" );
/* Read from key buffer */
iGetChrNum = scanf( "%8d", &udwBaseLnkID );
if( iGetChrNum <= 0 )
{
printf( "\nInvalid input!\n" );
}
/* Buffer clear */
while( 10 != getchar() )
{
continue;
}
}
/* Memory block allocation */
pbMemBlock = malloc( FILEREAD_BLOCKSIZE );
if( NULL == pbMemBlock )
{
return RET_FAILED;
}
else
{
memset( pbMemBlock, 0, FILEREAD_BLOCKSIZE );
pbCatPos = pbMemBlock;
}
printf( "\nRoute link searching. Please be waitting..." );
while( 0 == feof( pOrgFile ) )
{
printf( "." );
/* Memory clear */
memset( pbCatPos, 0, (FILEREAD_BLOCKSIZE - iMovSize) );
/* Get current file read position */
fgetpos( pOrgFile, &stFilePntr );
/* Get the size of block to be read */
if( (iFileSize - stFilePntr) < (FILEREAD_BLOCKSIZE - iMovSize) )
{
iReadSize = (int)(iFileSize - stFilePntr);
}
else
{
iReadSize = FILEREAD_BLOCKSIZE - iMovSize;
}
iRetReadFile = fread( pbCatPos, iReadSize, 1, pOrgFile );
pbCurBlock = pbMemBlock;
if( iRetReadFile > 0 )
{
while( (pbCurBlock + RL_SIZE_RECSIZE) <
(pbMemBlock + iReadSize + iMovSize ) )
{
/* Get Record size and Link ID */
uwRecSize = MC_GET_SHORT( pbCurBlock );
if( (pbCurBlock + uwRecSize) >
(pbMemBlock + iReadSize + iMovSize ) )
{
break;
}
udwLinkID = MC_GET_LONG( (pbCurBlock + RL_OFFSET_LNKID) );
if( udwLinkID == udwBaseLnkID )
{
iSrcRsltNum++;
routelink_src_slinknode(
pbCurBlock, &pstSLinkHead, &pstSLinkNode );
}
/* Next record header address get */
pbCurBlock += uwRecSize;
}
iMovSize = (pbMemBlock + (FILEREAD_BLOCKSIZE) - pbCurBlock);
memcpy( pbMemBlock, pbCurBlock, iMovSize );
pbCatPos = pbMemBlock + iMovSize;
/* Current search result saved(into file) */
routelink_src_blocksave( pstSLinkHead );
/* Single Link table Free */
routelink_src_slinkfree( &pstSLinkHead );
}
else
{
break;
}
}
printf( "\n" );
/* Search result prompt */
if( iSrcRsltNum > 0 )
{
/* Search Ok, search times counter update */
iSrcCnt = routelink_file_updsrccnt();
printf( "\nSearch Ok! %d route link is matched!\n", iSrcRsltNum );
printf(
"Search result has been output into file searchresult%03d.txt\n",
iSrcCnt );
}
else
{
printf( "\nSearch NG! No matched route link is found!\n" );
}
/* Memory block free */
if( NULL != pbMemBlock )
{
free( pbMemBlock );
pbMemBlock = NULL;
}
return RET_SUCCESS;
}
/***************************************************************************/
/* routelink_src_clsno() */
/* -----------------------------------------------------------------------*/
/* Input: */
/* FILE* : Route link info data file[IN] */
/* */
/* -----------------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮Normal乯RET_SUCCESS */
/* 乮Error乯 RET_FAILED */
/* */
/* -----------------------------------------------------------------------*/
/* Outline: */
/* Search by class no. */
/* */
/* -----------------------------------------------------------------------*/
/* Others: */
/* */
/***************************************************************************/
int routelink_src_clsno(
FILE* pOrgFile /* I/ Route link info data file */
)
{
BYTE bBaseClsNo = 0; /* Class No input by user */
BYTE bClsNo = 0; /* Class No by searching */
UWORD uwRecSize = 0; /* Current Record size */
UDWORD udwNodeInf = 0; /* Node information */
int iRetReadFile= 0; /* Return of read file */
int iGetChrNum = 0; /* Number of char from key buf */
int iSrcRsltNum = 0; /* Search result number */
int iMovSize = 0; /* Size of memory move */
int iSrcCnt = 0; /* Search times counter */
BYTE* pbMemBlock = NULL; /* Memory Block for read from file */
BYTE* pbCurBlock = NULL; /* Current pointer to Memory Block */
BYTE* pbCatPos = NULL; /* The position of a record cut */
S_LNKTBL_SRC* pstSLinkNode= NULL; /* Sing link table */
S_LNKTBL_SRC* pstSLinkHead= NULL; /* Sing link table */
/* Exception prevention */
if( NULL == pOrgFile )
{
return RET_FAILED;
}
while( iGetChrNum <= 0 )
{
/* Prompt user to specify the Link ID for searching */
printf( "\nPlease input the Class No. you want to search!>>>>>>>>\n" );
/* Read from key buffer */
iGetChrNum = scanf( "%8d", &bBaseClsNo );
if( iGetChrNum <= 0 )
{
printf( "\nInvalid input!\n" );
}
/* Buffer clear */
while( 10 != getchar() )
{
continue;
}
}
/* Memory block allocation */
pbMemBlock = malloc( FILEREAD_BLOCKSIZE );
if( NULL == pbMemBlock )
{
return RET_FAILED;
}
else
{
memset( pbMemBlock, 0, FILEREAD_BLOCKSIZE );
pbCatPos = pbMemBlock;
}
printf( "\nRoute link searching. Please be waitting..." );
while( 0 == feof( pOrgFile ) )
{
printf( "." );
memset( pbCatPos, 0, (FILEREAD_BLOCKSIZE - iMovSize) );
iRetReadFile = fread( pbCatPos,
(FILEREAD_BLOCKSIZE - iMovSize), 1, pOrgFile );
pbCurBlock = pbMemBlock;
if( iRetReadFile > 0 )
{
while( (pbCurBlock + RL_SIZE_RECSIZE) <
(pbMemBlock + FILEREAD_BLOCKSIZE) )
{
/* Get Record size and Link ID */
uwRecSize = MC_GET_SHORT( pbCurBlock );
if( (pbCurBlock + uwRecSize) >
(pbMemBlock + FILEREAD_BLOCKSIZE) )
{
break;
}
/* Get start node info */
udwNodeInf = MC_GET_LONG( (pbCurBlock + RL_OFFSET_NODEINF) );
/* Get class No. */
bClsNo = MC_GET_CLSNO( udwNodeInf );
if( bClsNo == bBaseClsNo )
{
iSrcRsltNum++;
routelink_src_slinknode(
pbCurBlock, &pstSLinkHead, &pstSLinkNode );
}
/* Next Record header address get */
pbCurBlock += uwRecSize;
}
iMovSize = (pbMemBlock + (FILEREAD_BLOCKSIZE) - pbCurBlock);
memcpy( pbMemBlock, pbCurBlock, iMovSize );
pbCatPos = pbMemBlock + iMovSize;
/* Current search result saved(into file) */
routelink_src_blocksave( pstSLinkHead );
/* Single Link table Free */
routelink_src_slinkfree( &pstSLinkHead );
}
else
{
break;
}
}
printf( "\n" );
/* Search result prompt */
if( iSrcRsltNum > 0 )
{
/* Search Ok, search times counter update */
iSrcCnt = routelink_file_updsrccnt();
printf( "\nSearch Ok! %d route link is matched!\n", iSrcRsltNum );
printf(
"Search result has been output into file searchresult%03d.txt\n",
iSrcCnt );
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -