📄 telsrc_main.c
字号:
/* TelSrc_DataReg娭悢 */
/* ----------------------------------------------------------------*/
/* Input: */
/* H_TELSRC : Tel No. search handle[IN] */
/* */
/* ----------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮惓忢乯RET_SUCCESS */
/* 乮堎忢乯RET_FAILED */
/* */
/* ----------------------------------------------------------------*/
/* Outline: */
/* Regist new tel no. */
/* ----------------------------------------------------------------*/
/* Others: */
/* */
/********************************************************************/
int TelSrc_DataReg(
H_TELSRC hTelSrc /* I/ Telphone search handle */
)
{
int iRet = RET_SUCCESS;
/* Return value */
int iLoopCnt = 0;
/* Loop counter */
int iOkFlg = TELSRC_ILLEGAL;
/* The No. input illegal flag */
int iTelStrLen = 0;
/* The lenth of Tel No. input */
int iReadBuf = 0;
/* Read form key buffer */
S_TELSRC* pstTelSrc = NULL;
/* Tel No. search class data struct */
S_TELSRC_COND* pstTelSrcCond = NULL;
/* Tel No. search class condition */
S_TELSRC_DATA stTelSrcData;
char acTelNo[TELSRC_NO_MAXLEN];
char acName[TELSRC_NAME_MAXLEN];
/* Exception prevention */
if( NULL == hTelSrc )
{
return RET_FAILED;
}
/* Initialization */
memset( &stTelSrcData, 0, (WORD)sizeof(stTelSrcData) );
/* Tel No. search class data area adress get */
pstTelSrc = (S_TELSRC*)hTelSrc;
pstTelSrcCond = &pstTelSrc->stTelSrcCond;
/* Max number reaches on, exception prevention */
if( pstTelSrcCond->iMaxDataNum <= pstTelSrc->iDataNum )
{
printf( "\nIt cannt be registerd any more.\n" );
printf( "\nPlease delete part of the data.\n" );
}
/* Tel No. input prompt */
printf( "\nPlease input the Tel No. you want to register.\n" );
printf( "\nNotice: Only the No. 0~9 is legal.\n" );
/*==============================================================*/
/* Read the Tel No. input by user. */
/* Notice: */
/* 1.If the Tel No. input is illeagal, user must input the */
/* correct one. */
/* 2.If the Tel No. input is over 11 digit, the No. after */
/* the 11st digit will be cut autometically. */
/*==============================================================*/
while( TELSRC_ILLEGAL == iOkFlg )
{
iReadBuf = getchar();
while( 10 != iReadBuf )
{
if( strlen(acTelNo) <= (TELSRC_NO_MAXLEN -1) )
{
acTelNo[strlen(acTelNo)] = (char)iReadBuf;
}
iReadBuf = getchar();
}
/* Get the No. lenth input by user */
iTelStrLen = strlen( acTelNo );
for( iLoopCnt = 0; iLoopCnt < iTelStrLen; iLoopCnt ++ )
{
/* Illegal, prompt the user to correct it */
if( (0x30 > acTelNo[iLoopCnt]) || (0x39 < acTelNo[iLoopCnt]) )
{
printf( "\nIllegal No. was input. Please input the correct one.\n" );
iOkFlg = TELSRC_ILLEGAL;
memset( acTelNo, 0, TELSRC_NO_MAXLEN );
break;
}
/* Input complete */
else
{
iOkFlg = TELSRC_LEGAL;
}
}
}
/* Save the new Tel No. input by user */
strncpy( stTelSrcData.acTelNo, acTelNo,
((WORD)sizeof(stTelSrcData.acTelNo) - 1) );
/* Name input prompt */
printf( "\nPlease input the point name for the Tel No.\n" );
printf( "\nNotice: Should be less than 64 characters.\n" );
/*==============================================================*/
/* Read the Tel No. input by user. */
/* Notice: */
/* If the Point Name input is over 64 characters, the */
/* characters after the 64th will be cut autometically. */
/*==============================================================*/
/* Read the Name input by user */
iReadBuf = getchar();
while( 10 != iReadBuf )
{
if( strlen(acName) <= (TELSRC_NAME_MAXLEN -1) )
{
acName[strlen(acName)] = (char)iReadBuf;
}
iReadBuf = getchar();
}
/* Save the name input by user */
strncpy( stTelSrcData.acName, acName,
((WORD)sizeof(stTelSrcData.acName) - 1) );
/* New data regist by different data source */
if( TELSRC_DATASRC_FILE == pstTelSrcCond->iDataSource )
{
iRet = telsrc_datareg_file( pstTelSrc, &stTelSrcData );
}
else
{
iRet = telsrc_datareg_mem( pstTelSrc, &stTelSrcData );
}
/* Result print */
if( RET_SUCCESS == iRet )
{
printf( "\nNew Tel No. has been registered successfully!\n" );
}
return iRet;
}
/********************************************************************/
/* TelSrc_DataSrc娭悢 */
/* ----------------------------------------------------------------*/
/* Input: */
/* H_TELSRC : Telphone search handle[IN] */
/* */
/* ----------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮惓忢乯RET_SUCCESS */
/* 乮堎忢乯RET_FAILED */
/* */
/* ----------------------------------------------------------------*/
/* Outline: */
/* Tel No. search. */
/* ----------------------------------------------------------------*/
/* Others: */
/* */
/********************************************************************/
int TelSrc_DataSrc(
H_TELSRC hTelSrc /* I/ Telphone search handle */
)
{
int iRet = RET_SUCCESS;
/* Return value */
S_TELSRC* pstTelSrc = NULL;
/* Tel No. search class data struct */
S_TELSRC_COND* pstTelSrcCond = NULL;
/* Tel No. search class condition */
char acTelNo[TELSRC_NO_MAXLEN];
/* Exception prevention */
if( NULL == hTelSrc )
{
return RET_FAILED;
}
/* Tel No. search class data area adress get */
pstTelSrc = (S_TELSRC*)hTelSrc;
pstTelSrcCond = &pstTelSrc->stTelSrcCond;
/* Tel No. input prompt */
printf( "\nPlease input the Tel No. you want to search.\n" );
printf( "\nNotice: Only the No. 0~9 is legal.\n" );
printf( "\nPart match is possiable.\n" );
/*==============================================================*/
/* Read the Tel No. input by user. */
/* Notice: */
/* If the Tel No. input is over 11 digit, the No. after */
/* the 11st digit will be cut autometically. */
/*==============================================================*/
/* Read the Tel No. input by user */
memset( acTelNo, 0, (WORD)sizeof(acTelNo) );
scanf( "%11s", acTelNo );
/* More than 11 digit was input, cut autometically */
if( 0 != acTelNo[TELSRC_NO_MAXLEN -1] )
{
printf( "\nYou have input more than 11 digit Tel No.\n" );
printf( "\nThe No. after 11 digit will be cut.\n" );
acTelNo[TELSRC_NO_MAXLEN -1] = '\0';
}
/* New data regist by different data source */
if( TELSRC_DATASRC_FILE == pstTelSrcCond->iDataSource )
{
iRet = telsrc_datasrc_file( pstTelSrc, acTelNo );
}
else
{
iRet = telsrc_datasrc_mem( pstTelSrc, acTelNo );
}
return iRet;
}
/********************************************************************/
/* TelSrc_DataDel娭悢 */
/* ----------------------------------------------------------------*/
/* Input: */
/* H_TELSRC : Telphone search handle[IN] */
/* */
/* ----------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮惓忢乯RET_SUCCESS */
/* 乮堎忢乯RET_FAILED */
/* */
/* ----------------------------------------------------------------*/
/* Outline: */
/* Tel No. search. */
/* ----------------------------------------------------------------*/
/* Others: */
/* */
/********************************************************************/
int TelSrc_DataDel(
H_TELSRC hTelSrc /* I/ Telphone search handle */
)
{
int iRet = RET_SUCCESS;
/* Return value */
if( NULL == hTelSrc )
{
return RET_FAILED;
}
/* DUMMY */
printf( "\nDelete funciton is not completed yet!\n" );
return iRet;
}
/********************************************************************/
/* TelSrc_FreeHandle娭悢 */
/* ----------------------------------------------------------------*/
/* Input: */
/* H_TELSRC : Telphone search handle[IN] */
/* */
/* ----------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮惓忢乯RET_SUCCESS */
/* 乮堎忢乯RET_FAILED */
/* */
/* ----------------------------------------------------------------*/
/* Outline: */
/* Tel No. search class handle free. */
/* ----------------------------------------------------------------*/
/* Others: */
/* */
/********************************************************************/
int TelSrc_FreeHandle(
H_TELSRC hTelSrc /* I/ Telphone search handle */
)
{
int iRet = RET_SUCCESS;
/* Return value */
S_TELSRC* pstTelSrc = NULL;
/* Tel No. search class data struct */
S_TELSRC_COND* pstTelSrcCond = NULL;
/* Tel No. search class condition */
/* Exception prevention */
if( NULL == hTelSrc )
{
return RET_FAILED;
}
/* Tel No. search class data area adress get */
pstTelSrc = (S_TELSRC*)hTelSrc;
pstTelSrcCond = &pstTelSrc->stTelSrcCond;
/* New data regist by different data source */
if( TELSRC_DATASRC_FILE == pstTelSrcCond->iDataSource )
{
iRet = telsrc_freehandle_file( pstTelSrc );
}
else
{
iRet = telsrc_freehandle_mem( pstTelSrc );
}
/* Pointer NULL */
if( RET_SUCCESS == iRet )
{
pstTelSrc = (S_TELSRC*)NULL;
hTelSrc = (H_TELSRC)NULL;
}
return iRet;
}
/* End of file-----------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -