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

📄 telsrc_main.c

📁 这是东软嵌入式课件
💻 C
📖 第 1 页 / 共 2 页
字号:
/********************************************************************


	挊嶌尃強桳幰		丗	WangHongjun@neusoft.com

	僜乕僗僼傽僀儖柤	丗	telsrc_main.c

	撪梕				丗	揹榖斣崋専嶕儊僀儞IF娭悢掕媊

	嶌惉擔丒幰			丗	2005.07.08		Wang Hongjun


	廋惓擔丒幰			丗




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

/*------------------------------------------------------------------*/
/*																	*/
/*	僀儞僋儖乕僪僼傽僀儖晹暘										*/
/*																	*/
/*------------------------------------------------------------------*/
#include "telsrc.h"

/*------------------------------------------------------------------*/
/*																	*/
/*	娭悢掕媊晹暘													*/
/*																	*/
/*------------------------------------------------------------------*/

/********************************************************************/
/*	TelSrc_Main娭悢													*/
/*	----------------------------------------------------------------*/
/*	Input:															*/
/*																	*/
/*	----------------------------------------------------------------*/
/*	Output:															*/
/*		RETURN				:	乮惓忢乯RET_SUCCESS					*/
/*								乮堎忢乯RET_FAILED					*/
/*																	*/
/*	----------------------------------------------------------------*/
/*	Outline:														*/
/*		Tel No. search main funciton.								*/
/*																	*/
/*	----------------------------------------------------------------*/
/*	Others:															*/
/*																	*/
/********************************************************************/
int TelSrc_Main()
{
	int				iRet		= RET_SUCCESS;
							 		/* Return value					*/
	int				iDataSource	= TELSRC_DATASRC_FILE;	
									/* Data Source					*/
	int				iReadRslt	= 0;
					/* Result of read from key buffer				*/
	int				iMaxDataNum = 0;/* Number of data for search	*/
	H_TELSRC		hTelSrc	 = NULL;/* Tel search handle			*/
	S_TELSRC_COND	stTelSrcCond;	/* Tel search conditon struct	*/

	/* Welcome information											*/
	printf( "\n************************************************\n" );
	printf( "*This is a Tel No. register and search program!*\n" );
	printf( "************************************************\n" );

	/* Initialization												*/
	memset( &stTelSrcCond, 0, (WORD)sizeof(stTelSrcCond) );

	/* Prompt user to input the number of data for searching		*/
	printf( "\nHow many Tel No. can be saved!\n" );
	iReadRslt = scanf( "%8d", iMaxDataNum );
	while( ( 0 >= iMaxDataNum ) || ( 0 >= iReadRslt ) )
	{
		if( 0 >= iReadRslt )
		{
			while( 10 != getchar() )
			{
				continue;
			}
		}
		
		printf( "Invalid number, please input the correct one." );
		printf( "\nHow many Tel No. can be saved!\n" );
		iReadRslt = scanf( "%8d", &iMaxDataNum );		
	}

	/* Key buffer clear				*/
	while( 10 != getchar() )
	{
		continue;
	}

	/* Max Data num limited (1000)									*/
	if( TELSRC_MAXDATANUM < iMaxDataNum )
	{
		iMaxDataNum = TELSRC_MAXDATANUM;
	}

	/* Prompt user to select the type of set data					*/
	printf( "Please select the Type of data saved!\n" );
	printf( "(0	: File;	1	: Memory)!\n" );
	iReadRslt = scanf( "%8d", &iDataSource );
	while( ( ( TELSRC_DATASRC_FILE != iDataSource ) && 
		     ( TELSRC_DATASRC_MEM != iDataSource ) ) || 
		   ( 0 >= iReadRslt ) )
	{
		/* In the case that string is input, clear the key buffer	*/
		if( 0 >= iReadRslt )
		{
			while( 10 != getchar() )
			{
				continue;
			}
		}
		
		/* Prompt the user to select the correct type				*/
		printf( "Invalid type, please input the correct one.\n" );
		iReadRslt = scanf( "%8d", &iDataSource );		
	}

	/* Key buffer clear				*/
	while( 10 != getchar() )
	{
		continue;
	}

	/* Tel No. search condition set									*/
	stTelSrcCond.iMaxDataNum	= iMaxDataNum;
	stTelSrcCond.iDataSource	= iDataSource;

	/* Handle create												*/
	hTelSrc = TelSrc_CreHandle( &stTelSrcCond );
	if( NULL == hTelSrc )
	{
		printf( "\nHandle create failed!!\n" );
		return RET_FAILED;
	}

	/* Execute different operation by the type user specified		*/
	iRet = TelSrc_UserSel( hTelSrc );

	/* Handle free				*/
	iRet = TelSrc_FreeHandle( hTelSrc );
	
	return iRet;			
}

/********************************************************************/
/*	TelSrc_UserSel													*/
/*	----------------------------------------------------------------*/
/*	Input:															*/
/*		int					:	Tel No. search class handle[IN]		*/
/*																	*/
/*	----------------------------------------------------------------*/
/*	Output:															*/
/*		RETURN				:	乮惓忢乯RET_SUCCESS					*/
/*								乮堎忢乯RET_FAILED					*/
/*																	*/
/*	----------------------------------------------------------------*/
/*	Outline:														*/
/*		Excute the different program by user select.				*/
/*																	*/
/*	----------------------------------------------------------------*/
/*	Others:															*/
/*																	*/
/********************************************************************/
int TelSrc_UserSel(
	H_TELSRC		hTelSrc			/* Tel No. search class handle	*/
	)
{
	char			cQuitConf		= 'Y';
									/* Confirm to exit or not		*/
	char			cDelConf		= 'N';
									/* Confirm to delete or not		*/
	int				iRet			= RET_SUCCESS;
							 		/* Return value					*/
	int				iGetChrNum		= 0;
									/* Number of char  from Key Buf */
	int				iOperFlg		= TELSRC_INIT;
									/* User operation type			*/
	S_TELSRC*		pstTelSrc		= NULL;
									/* Telsearch struct				*/
	S_TELSRC_COND*	pstTelSrcCond	= NULL;
									/* Tel search conditon struct	*/

	/* Exception prevention											*/
	if( NULL == hTelSrc )
	{
		return RET_FAILED;
	}

	/* Data area get				*/
	pstTelSrc		= (S_TELSRC*)hTelSrc;
	pstTelSrcCond	= &pstTelSrc->stTelSrcCond;

	/* Execute different operation by the type user specified		*/
	while( (TELSRC_INIT  <= iOperFlg) && (TELSRC_DATADEL  >= iOperFlg) )
	{
		iOperFlg = TELSRC_INIT;

		printf( "\nPlease select your operation!\n" );
		printf( "( 1		: Tel No. Regist.)\n" );
		printf( "( 2		: Tel No. Search.)\n" );
		printf( "( 3		: Tel No. Delete.)\n" );
		printf( "( Other	: Exit. )\n" );

		/* Read user's selection									*/
		iGetChrNum = scanf( "%8d", &iOperFlg );
		if( 0 >= iGetChrNum )
		{
			scanf( "%8s", &iOperFlg );
		}

		/* Key buffer clear				*/
		while( 10 != getchar() )
		{
			continue;
		}

		switch( iOperFlg )
		{
		case TELSRC_DATAREG:	/* New data register				*/
			if( pstTelSrc->iDataNum >= pstTelSrcCond->iMaxDataNum )
			{
				printf( "\nIt cannt be registerd any more.\n" );
				printf( "Delete part of the data?\n" );				
				printf( "Y(y): Delete;	N(n): Select another\n" );
				scanf( "%1s", &cDelConf );
				if( ( 'Y' == cDelConf ) || ( 'y' == cDelConf ) )
				{
					iRet = TelSrc_DataDel( hTelSrc );
				}

				/* Key buffer clear				*/
				while( 10 != getchar() )
				{
					continue;
				}
			}
			else
			{
				iRet = TelSrc_DataReg( hTelSrc );
			}
			break;

		case TELSRC_DATASRC:	/* Tel No. search					*/
			iRet = TelSrc_DataSrc( hTelSrc );
			break;

		case TELSRC_DATADEL:	/* Delete an item					*/
			iRet = TelSrc_DataDel( hTelSrc );
			break;

		default:				/* Quit								*/
			printf( "\nAre you sure that you want to quit the program?\n" );
			printf( "\n(Y(y)/N(n))\n" );
			scanf( "%1s", &cQuitConf );
			if( ( 'Y' == cQuitConf ) || ( 'y' == cQuitConf ) )
			{
				iOperFlg = TELSRC_QUIT;
			}
			else
			{
				iOperFlg = TELSRC_INIT;
			}

			/* Key buffer clear				*/
			while( 10 != getchar() )
			{
				continue;
			}
		}

	}

	return iRet;			
}

/********************************************************************/
/*	TelSrc_CreHandle娭悢											*/
/*	----------------------------------------------------------------*/
/*	Input:															*/
/*		int					:	Search condition[IN]				*/
/*																	*/
/*	----------------------------------------------------------------*/
/*	Output:															*/
/*		RETURN				:	乮惓忢乯Telphone search handle		*/
/*								乮堎忢乯NULL						*/
/*																	*/
/*	----------------------------------------------------------------*/
/*	Outline:														*/
/*		Create telphone search handle.								*/
/*	----------------------------------------------------------------*/
/*	Others:															*/
/*																	*/
/********************************************************************/
H_TELSRC TelSrc_CreHandle(
	S_TELSRC_COND*	pstTelSrcCond
					/* I/ Search condition							*/
	)
{
	H_TELSRC		hTelSrc			= NULL;
					/* Telsearch class handle						*/


	/* Exception prevention											*/
	if( NULL == pstTelSrcCond )
	{
		return (H_TELSRC)NULL;
	}

	/* Create TelSrc handle by conditons user specified				*/
	if( TELSRC_DATASRC_FILE == (pstTelSrcCond->iDataSource) )
	{
		hTelSrc = telsrc_crehandle_file( pstTelSrcCond );
	}
	else
	{
		hTelSrc = telsrc_crehandle_mem( pstTelSrcCond );
	}
	
	return hTelSrc;
}

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

⌨️ 快捷键说明

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