📄 routelink_update.c
字号:
/****************************************************************************
FileName : routelink_update.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_p.h"
#include "routelink_in_c.h"
#include "routelink_in_s.h"
#include "routelink_in_p.h"
/*-------------------------------------------------------------------------*/
/* */
/* Route Link Info update function define */
/* */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
/* routelink_upd_cycupdate */
/* -----------------------------------------------------------------------*/
/* Input: */
/* */
/* -----------------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮Normal乯RET_SUCCESS */
/* 乮Error乯 RET_FAILED */
/* */
/* -----------------------------------------------------------------------*/
/* Outline: */
/* Update link data by cycling. */
/* */
/* -----------------------------------------------------------------------*/
/* Others: */
/* */
/***************************************************************************/
int routelink_upd_cycupdate()
{
int iStrLen = 0; /* Lenth of string from file */
int iRetReadFile= 0; /* Return value for read file */
int iEndFlg = 0;
FILE* pUpdFile = NULL;
FILE* pSourceFile = NULL; /* Soure data file handle */
BYTE* pbLinkData = NULL; /* New Link Data */
BYTE abLinkStr[RL_DSPSTR_MAXLEN];
/* String from source data file */
/* Initialization */
memset( abLinkStr, 0, RL_DSPSTR_MAXLEN );
/* Souce Data file open(sourcelink.txt) */
pSourceFile = fopen( RTL_UPDDAT_FILENAME, "r" );
if( NULL == pSourceFile )
{
printf(
"\nFailed to open the source link data file sourcelink.txt\n" );
return RET_FAILED;
}
/* Prompt info print out */
printf( "Press Enter Key to confirm to update one item of the data.\n" );
printf( "Any other key will quit the process of updating.\n" );
printf( "Continue?(Enter to confirm)>>>>>>>>\n" );
/* Read the info and get the source data */
while( '\n' == getchar() )
{
/* Reach the end of the file */
if( 0 != feof( pSourceFile ) )
{
printf( "\nIt reaches the end of the source data file.\n" );
printf( "Please press any key to exit current process!\n" );
break;
}
/* Read on item from source data file */
memset( abLinkStr, 0, RL_DSPSTR_MAXLEN );
iStrLen = 0;
iEndFlg = 0;
/* Read on item from source data file(byte by byte) */
while( 0 == feof( pSourceFile ) )
{
iRetReadFile = fread( &abLinkStr[iStrLen], sizeof(BYTE), 1, pSourceFile );
if( '#' == abLinkStr[iStrLen] )
{
iEndFlg++;
}
if( (iRetReadFile > 0) && (iStrLen < RL_DSPSTR_MAXLEN - 1) )
{
iStrLen = strlen(abLinkStr);
}
else
{
abLinkStr[iStrLen] = '\0';
}
if( '\n' == abLinkStr[iStrLen - 1] )
{
abLinkStr[iStrLen - 1] = '\0';
break;
}
if( 0 != feof( pSourceFile ) )
{
break;
}
}
/* Terminal char set */
abLinkStr[iStrLen] = '\0';
/* Updated link data print out */
printf(
"\nThe following data will be updated into the file GTBL.dat!\n");
printf( "%s\n", abLinkStr );
/* Sourcefile update prompt */
printf( "\nGTBL.dat is being updated. Please wait......\n" );
/* Convert the displayed string to link data */
pbLinkData = (BYTE*)routelink_dspstr2linkdata( abLinkStr );
/* Insert the link data into the Sing Link */
routelink_upd_updlnkdata( pbLinkData, RTL_ORGDAT_FILENAME );
/* Update the analyse result data file */
pUpdFile = fopen( RTL_ANALYSEDAT_FILENAME, "rb" );
if( NULL == pUpdFile )
{
printf( "\nThe file of analyse result data does not exist!\n" );
printf( "It will now create it.Please wait......\n" );
RouteLink_Analyse();
}
else
{
fclose( pUpdFile );
pUpdFile = NULL;
/* Update the analyse result data file */
routelink_upd_updlnkdata( pbLinkData, RTL_ANALYSEDAT_FILENAME );
}
/* Link data area free */
routelink_linkdatafree( &pbLinkData );
/* Continue confirm */
printf( "Continue?(Enter to confirm)>>>>>>>>\n" );
}
/* Key buffer clear */
while( '\n'!= getchar() )
{
continue;
}
return RET_SUCCESS;
}
/***************************************************************************/
/* routelink_upd_updlnkdata */
/* -----------------------------------------------------------------------*/
/* Input: */
/* BYTE* : New link data[IN] */
/* BYTE* : File to be updated[IN] */
/* */
/* -----------------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮Normal乯RET_SUCCESS */
/* 乮Error乯 RET_FAILED */
/* */
/* -----------------------------------------------------------------------*/
/* Outline: */
/* Update 1 Link Data into the data file. */
/* */
/* -----------------------------------------------------------------------*/
/* Others: */
/* */
/***************************************************************************/
int routelink_upd_updlnkdata(
BYTE* pbLinkData, /* I / New link data */
BYTE* pbUpdFileName /* I / File to be updated */
)
{
UDWORD udwBaseLnkID= 0; /* Link specified by user */
int iInsertFlg = 0; /* Flag for insert or append */
fpos_t stFilePos = 0; /* File read pointer */
/* Exception prevention */
if( NULL == pbLinkData )
{
printf( "\nLink data is NULL.Please check it!\n" );
return RET_FAILED;
}
/* Get link ID */
routelink_readrec( pbLinkData, RL_GET_LNKID, &udwBaseLnkID );
/* Check Route Link node exist or not */
iInsertFlg =
routelink_upd_chklnkid( udwBaseLnkID, &stFilePos, pbUpdFileName );
/* Insert */
if( iInsertFlg > 0 )
{
routelink_upd_insertlnkdata( pbLinkData, &stFilePos, pbUpdFileName );
}
/* Append */
else
{
routelink_upd_appendlnkdata( pbLinkData, pbUpdFileName );
}
return RET_SUCCESS;
}
/***************************************************************************/
/* routelink_upd_appendlnkdata */
/* -----------------------------------------------------------------------*/
/* Input: */
/* BYTE* : New link data[IN] */
/* BYTE* : File to be updated[IN] */
/* */
/* -----------------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮Normal乯RET_SUCCESS */
/* 乮Error乯 RET_FAILED */
/* */
/* -----------------------------------------------------------------------*/
/* Outline: */
/* Append 1 Link Data into the data file. */
/* */
/* -----------------------------------------------------------------------*/
/* Others: */
/* */
/***************************************************************************/
int routelink_upd_appendlnkdata(
BYTE* pbLinkData, /* I / New link data */
BYTE* pbUpdFileName /* I / File to be updated */
)
{
UWORD uwRecSize = 0; /* Current Record size */
FILE* pOrgFile = NULL; /* File Handle */
/* Exception prevention */
if( (NULL == pbLinkData) || (NULL == pbUpdFileName) )
{
return RET_FAILED;
}
/* Route link data file open */
pOrgFile = fopen( pbUpdFileName, "ab+" );
if( NULL == pOrgFile )
{
printf( "\nFailed to open file GTBL.dat while append link data.\n" );
return RET_FAILED;
}
/* Get record size */
routelink_readrec( pbLinkData, RL_GET_RECSIZE, &uwRecSize );
if( uwRecSize <= 0 )
{
/* Close data file */
fclose( pOrgFile );
pOrgFile = NULL;
printf( "\nRecord size of the link data is 0. Please check it!\n" );
return RET_FAILED;
}
/* Write data into file */
fwrite( pbLinkData, uwRecSize, 1, pOrgFile );
/* Close data file */
fclose( pOrgFile );
pOrgFile = NULL;
return RET_SUCCESS;
}
/***************************************************************************/
/* routelink_upd_insertlnkdata */
/* -----------------------------------------------------------------------*/
/* Input: */
/* BYTE* : Link ID for the data updating[IN] */
/* fpos_t* : Position of the link data being updated[IN]*/
/* BYTE* : Name of File to be updated */
/* */
/* -----------------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮Normal乯RET_SUCCESS */
/* 乮Error乯 RET_FAILED */
/* */
/* -----------------------------------------------------------------------*/
/* Outline: */
/* Insert the new link data into the link data file. */
/* */
/* -----------------------------------------------------------------------*/
/* Others: */
/* */
/***************************************************************************/
int routelink_upd_insertlnkdata(
BYTE* pbLinkData, /* I / New link data */
fpos_t* pstFilePos, /* I / Position of Matched link data */
BYTE* pbUpdFileName /* I / File to be updated */
)
{
UWORD uwRecSize; /* Record of original link data */
UWORD uwNewRecSize; /* Record of new link data */
int iReadSize = 0; /* Size of data need to be read */
int iRetReadFile= 0; /* Return value for read file */
int iOrgFileSize= 0; /* Original File size */
int iTmpFileSize= 0; /* Temporary File size */
int iFwrite = 0; /* Result of write file */
BYTE* pbReadBlock = NULL; /* Memory Block for read from file */
fpos_t stFilePntr = 0; /* Current file read pointer */
FILE* pOrgFile = NULL; /* File Handle */
FILE* pTmpFile = NULL; /* Temporary file handle */
BYTE abTmpFileName[RTL_FILENAME_MAXLEN]; /* Temp file name */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -