📄 telsrc_memsrc.c
字号:
/********************************************************************
挊嶌尃強桳幰 丗 WangHongjun@neusoft.com
僜乕僗僼傽僀儖柤 丗 telsrc_memsrc.c
撪梕 丗 Tel No. search(Memory search IF)
嶌惉擔丒幰 丗 2005.07.08 Wang Hongjun
廋惓擔丒幰 丗
*********************************************************************/
/*------------------------------------------------------------------*/
/* */
/* 僀儞僋儖乕僪僼傽僀儖晹暘 */
/* */
/*------------------------------------------------------------------*/
#include "telsrc_in.h"
/*------------------------------------------------------------------*/
/* */
/* 娭悢掕媊晹暘 */
/* */
/*------------------------------------------------------------------*/
/********************************************************************/
/* telsrc_crehandle_mem */
/* ----------------------------------------------------------------*/
/* Input: */
/* int : Search condition[IN] */
/* */
/* ----------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮惓忢乯Telphone search handle */
/* 乮堎忢乯NULL */
/* */
/* ----------------------------------------------------------------*/
/* Outline: */
/* Create telphone search handle (Data saved in memory). */
/* ----------------------------------------------------------------*/
/* Others: */
/* */
/********************************************************************/
H_TELSRC telsrc_crehandle_mem(
S_TELSRC_COND* pstTelSrcCond /* I/ Search condition */
)
{
int iMallocSize = 0;
/* Memory size */
S_TELSRC* pstTelSrc = NULL;
/* Telsearch struct */
H_TELSRC hTelSrc = NULL;
/* Telsearch class handle */
void* pvMallocAdr = NULL;
/* Temp address */
/* Exception prevention */
if( NULL == pstTelSrcCond )
{
return (H_TELSRC)NULL;
}
/* Search data area and search class area allocation */
iMallocSize
= ( sizeof(S_TELSRC_DATA) * (pstTelSrcCond->iMaxDataNum) )+
sizeof(S_TELSRC);
pvMallocAdr = malloc( iMallocSize );
/* Exception prevention */
if( NULL == pvMallocAdr )
{
return (H_TELSRC)NULL;
}
/* Initialization */
memset( pvMallocAdr, 0, iMallocSize );
/* Memory split and addres set */
telsrc_crehandle_mem_adrset( pstTelSrc, pvMallocAdr );
if( NULL != pstTelSrc )
{
/* Search condition copy */
memcpy( &pstTelSrc->stTelSrcCond, pstTelSrcCond,
(WORD)sizeof(S_TELSRC_COND) );
}
hTelSrc = (H_TELSRC)pstTelSrc;
return hTelSrc;
}
/********************************************************************/
/* telsrc_datareg_mem */
/* ----------------------------------------------------------------*/
/* Input: */
/* S_TELSRC* : Telphone search data area[IN] */
/* S_TELSRC_DATA* : The Tel No. Data for searching[IN] */
/* */
/* ----------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮惓忢乯RET_SUCCESS */
/* 乮堎忢乯RET_FAILED */
/* */
/* ----------------------------------------------------------------*/
/* Outline: */
/* Regist new Tel No. */
/* ----------------------------------------------------------------*/
/* Others: */
/* */
/********************************************************************/
int telsrc_datareg_mem(
S_TELSRC* pstTelSrc, /* I/ Telphone search data area */
S_TELSRC_DATA* pstSrcData /* I/ The Tel No. Data for searching*/
)
{
int iRet = 0;
/* Return value save */
S_TELSRC_DATA* pstDestSrcData = NULL;
/* Dest data area for saving the Tel to register*/
/* Exception prevention */
if( (NULL == pstSrcData) || (NULL == pstTelSrc) )
{
return RET_FAILED;
}
/* Current data ID set */
pstSrcData->iNo = pstTelSrc->iDataNum;
/* Dest data area get */
pstDestSrcData =
(S_TELSRC_DATA*)( pstTelSrc->pstTelSrcData +
( sizeof( S_TELSRC_DATA ) * (pstTelSrc->iDataNum) ) );
memset( pstDestSrcData, 0, (WORD)sizeof(S_TELSRC_DATA) );
/* Save the data info input by user */
memcpy( pstDestSrcData, pstSrcData, (WORD)sizeof(pstDestSrcData) );
(pstTelSrc->iDataNum)++;
return iRet;
}
/********************************************************************/
/* telsrc_datasrc_mem */
/* ----------------------------------------------------------------*/
/* Input: */
/* S_TELSRC* : Telphone search data area[IN] */
/* char* : The Tel No. for searching[IN] */
/* */
/* ----------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮惓忢乯RET_SUCCESS */
/* 乮堎忢乯RET_FAILED */
/* */
/* ----------------------------------------------------------------*/
/* Outline: */
/* Tel No. search. */
/* ----------------------------------------------------------------*/
/* Others: */
/* */
/********************************************************************/
int telsrc_datasrc_mem(
S_TELSRC* pstTelSrc, /* I/ Telphone search data area */
char* pcTelNo /* I/ The Tel No. for searching */
)
{
int iLoopCnt= 0; /* Loop counter */
int iSrcRslt= TELSRC_RESULT_NG; /* Search result */
int iRet = TELSRC_RESULT_NG; /* Return value */
int iCmpCnt = 0; /* Times for compare*/
int iCurPos = 0; /* Current char pos */
S_TELSRC_DATA* pstTelSrcData = NULL; /* Tel No. data info*/
/* Exception prevention */
if( NULL == pstTelSrc )
{
return TELSRC_RESULT_NG;
}
/* Data area get */
pstTelSrcData = (S_TELSRC_DATA*)pstTelSrc->pstTelSrcData;
/* Searching */
for( iLoopCnt = 0; iLoopCnt < pstTelSrc->iDataNum; iLoopCnt++ )
{
/* Compare, output the result */
iCmpCnt = strlen( pstTelSrcData->acTelNo ) - strlen(pcTelNo);
for( iCurPos = 0; iCurPos <= iCmpCnt; iCurPos++ )
{
iSrcRslt = strncmp(
pstTelSrcData->acTelNo, pcTelNo, strlen(pcTelNo) );
if( TELSRC_RESULT_OK == iSrcRslt )
{
if( (0 == iCurPos) && (0 == iCmpCnt) )
{
printf( "\nSearch OK(Complete match)!\n" );
printf( "Tel No: %s\n", pstTelSrcData->acTelNo );
printf( "Address: %s\n", pstTelSrcData->acName );
iRet = iSrcRslt;
}
else
{
printf( "\nSearch OK(Part match)!\n" );
printf( "Tel No: %s\n", pstTelSrcData->acTelNo );
printf( "Address: %s\n", pstTelSrcData->acName );
iRet = iSrcRslt;
}
break;
}
}
/* Data area pointer get */
pstTelSrcData ++;
}
/* Search NG, ouput the result */
if( TELSRC_RESULT_NG == iRet )
{
printf( "\nSearch NG! No corresponding Tel No.\n" );
}
return iRet;
}
/********************************************************************/
/* telsrc_datasrc_mem */
/* ----------------------------------------------------------------*/
/* Input: */
/* S_TELSRC* : Telphone search data area[IN] */
/* char* : The Tel No. for searching[IN] */
/* */
/* ----------------------------------------------------------------*/
/* Output: */
/* RETURN : RET_SUCCESS */
/* */
/* ----------------------------------------------------------------*/
/* Outline: */
/* Tel No. search class handle free. */
/* ----------------------------------------------------------------*/
/* Others: */
/* */
/********************************************************************/
int telsrc_freehandle_mem(
S_TELSRC* pstTelSrc /* I/ Telphone search data area */
)
{
/* Exception prevention */
if( NULL == pstTelSrc )
{
return RET_SUCCESS;
}
/* Tel No. search class handle area free */
free( pstTelSrc );
pstTelSrc = NULL;
return RET_SUCCESS;
}
/********************************************************************/
/* telsrc_datasrc_mem */
/* ----------------------------------------------------------------*/
/* Input: */
/* S_TELSRC* : Telphone search data area[OUT] */
/* void* : Current memory pointer[IN] */
/* */
/* ----------------------------------------------------------------*/
/* Output: */
/* RETURN : RET_SUCCESS */
/* RET_FAILED */
/* */
/* ----------------------------------------------------------------*/
/* Outline: */
/* Memory split and address set. */
/* ----------------------------------------------------------------*/
/* Others: */
/* */
/********************************************************************/
int telsrc_crehandle_mem_adrset(
S_TELSRC* pstTelSrc, /* O / Telphone search data area */
void* pvMallocAdr /* I / Current memory address */
)
{
/* Exception prevention */
if( NULL == pvMallocAdr )
{
return RET_FAILED;
}
pstTelSrc = (S_TELSRC*)pvMallocAdr;
/*==============================================================*/
/* Memory split and address set */
/*==============================================================*/
/* Current pointer offset to the end of S_TELSRC */
pvMallocAdr =(void*)((char*)pvMallocAdr + sizeof(S_TELSRC));
pstTelSrc->pstTelSrcData
= (S_TELSRC_DATA*)pvMallocAdr;
return RET_SUCCESS;
}
/* End of file-----------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -