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

📄 atbpbgi.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:
*******************************************************************************/

T_MFW GI_pb_ReadRecList(UBYTE mode, UBYTE index, UBYTE num_recs, T_MFW_PHB_LIST *entries)
{
	PB_RET result;
	T_MFW ret;
	T_PB_INDEX index_type = GI_index_Convert(mode);
	T_PB_RECORD *record;
	SHORT recs_count;

	tracefunction("GI_pb_ReadRecList");

	/* MFW/ACI indices start at 1, ATB indices start at 0 */
	
	index--;

	/* Allocate memory for record */

	record = ATB_pb_AllocRec(PB_BOOK_DEFAULT);

	for (recs_count = 0; recs_count<(SHORT)num_recs; recs_count++)
	{
		result = ATB_pb_ReadRec(PB_BOOK_DEFAULT, index_type, (SHORT)(index+recs_count), record);
		if (result!=PB_OK)
			break;
		
		entries->entry[recs_count].book = PHB_IPB;
		entries->entry[recs_count].index = GI_pb_ConvIndex(index_type, (UBYTE)(index+recs_count), INDEX_PHYSICAL);
		entries->entry[recs_count].ton = (record->ton_npi & 0xF0)>>4;
		entries->entry[recs_count].npi = record->ton_npi & 0x0F;
		GI_alpha_AlphaToAscii(&entries->entry[recs_count].name, &record->alpha, PB_ALPHATAG_MAX);
		ATB_pb_BCDToChar((char *)entries->entry[recs_count].number, record->number, PB_NUMBER_MAX);
	}

	entries->book = PHB_IPB;

	if (recs_count)
	{
	    entries->result = MFW_ENTRY_EXIST;
	    entries->num_entries = (UBYTE) recs_count;
	    /* SPR#1994 - SH - If at least one record is found, result is a success */
		result = PB_OK;
	}
	else
	{
		entries->result = MFW_NO_ENTRY;
	}

	/* Free allocated record */

	ATB_pb_FreeRec(PB_BOOK_DEFAULT, record);
		
	switch(result)
	{
		case PB_OK:
			ret = MFW_PHB_OK;
			break;
		case PB_RECDOESNOTEXIST:
			ret = MFW_PHB_FAIL;
			break;
		default:
			ret = MFW_PHB_FAIL;
			break;
	}

	return ret;
}

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

 $Function:    	GI_pb_ConvIndex
 
 $Description:	Returns the index in table new_index_type corresponding to the index
 				in table index_type.
 
 $Returns:		The new index

 $Arguments:	index_type		The index table of the original index.
				index			The original logical index.
				new_index_type	The index table required.
				
*******************************************************************************/

UBYTE GI_pb_ConvIndex(T_PB_INDEX index_type, UBYTE index, T_PB_INDEX new_index_type)
{
	SHORT new_index;

	tracefunction("GI_pb_ConvIndex");
	
	ATB_pb_ConvIndex(PB_BOOK_DEFAULT, index_type, (SHORT)index, new_index_type, &new_index);

	/* MFW/ACI indices start at 1, ATB indices start at 0 */

	if (new_index_type==INDEX_PHYSICAL)
	{
		new_index++;
	}
	
	return (UBYTE)new_index;
}


/********************************
 * Functions called by the ATB PB  *
 ********************************/

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

 $Function:    	GI_pb_OK
 
 $Description:	This function is called if the requested command executed successfully.
 				The param parameter is a pointer to command specific information,
 				when such information is required to be passed from the ATB to the GI.
 				See the individual functions for more details.
 
 $Returns:		None.

 $Arguments:	phonebook_id	The phonebook identifier
				command_id		Identifies the command.
				param			Pointer to command-specific information
 
*******************************************************************************/

void GI_pb_OK(SHORT phonebook_id, SHORT command_id, void *param)
{
	trace("GI_pb_OK");

	if (param!=NULL)
	{
		trace_P1("Param is: %d", *((SHORT *)param));
	}
}

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

 $Function:    	GI_pb_Error
 
 $Description:	This function is called if an error was returned while executing the
 				requested command.
 
 $Returns:		None.

 $Arguments:	phonebook_id	The phonebook identifier
				command_id		Identifies the command.
				error_id		Identifies the error that occurred.
 
*******************************************************************************/

void GI_pb_Error(SHORT phonebook_id, SHORT command_id, SHORT error_id)
{
	trace("GI_pb_Error");
	trace_P2("***ERROR*** - command %d, error %d", command_id, error_id);

	return;
}


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

 $Function:    	GI_pb_MemAlloc
 
 $Description:	Dynamically allocates memory for the phonebook.
 
 $Returns:		The address of the block of allocated memory, or NULL if failed.

 $Arguments:	size	- Amount of memory to be allocated in bytes
 
*******************************************************************************/

UBYTE *GI_pb_MemAlloc(int size)
{
	return mfwAlloc((U16)size);
}


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

 $Function:    	GI_pb_MemFree
 
 $Description:	Frees dynamically allocated memory.
 
 $Returns:		None
 
 $Arguments:	mem - Pointer to a block of allocated memory
 				size - Size of the block
 
*******************************************************************************/

void GI_pb_MemFree(UBYTE *mem, int size)
{
	mfwFree(mem, (U16)size);
	return;
}


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

 $Function:    	GI_pb_Match
 
 $Description:	This function allows the user to specify the way in which entries are
 				matched during searching.  This provides the capability of searching
 				languages with non-Latin alphabets, or searching through special user
 				fields.
				This function attempts a match between two records based on the
				field appropriate for the index list, specified in index_type.  It returns
				a value indicating whether there is no match (MATCH_NONE),
				a partial match (MAX_START), or an exact match (MATCH_EXACT).
				Note that the contents of the records themselves should not be altered
				by this function.  The sole result should be a return value that specifies
				how the first record matches the second.  If it is preferred that the
				default matching routine is used (i.e match from the start for alpha
				tags, match from the end for phone numbers) then MATCH_DEFAULT
				should be returned.

 $Returns:		MATCH_DEFAULT, MATCH_EXACT, MATCH_START or MATCH_NONE

 $Arguments:	record1		The first record to be compared
				record2		The second record to be compared
				index_type	Indicator of the field which is to be compared
 
*******************************************************************************/

T_PB_MATCH GI_pb_Match(T_PB_RECORD *record1,T_PB_RECORD *record2, T_PB_INDEX index_type)
{
	return MATCH_DEFAULT;
}


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

 $Function:    	GI_pb_Compare
 
 $Description:	This function allows the user to specify the way in which entries are
 				compared during sorting.  This provides the capability of sorting languages
 				with non-Latin alphabets, or sorting to alternative orders (for example,
 				reverse alphabetical).
				This function compares two records based on the field appropriate for the
				index list, specified in index_type.
				It returns a value indicating whether the first record should come before
				or after the second.
				Note that the contents of the records themselves should not be altered by
				this function.  The sole result should be a return value that specifies
				whether or not the positions of the records should be swapped.  If it
				is preferred that the default comparison routine is used (e.g.Latin
				alphabetical ascending) then COMPARE_DEFAULT should be returned.


 $Returns:		COMPARE_DEFAULT		No comparison made - use the default comparison method
				COMPARE_FIRSTBEFORE		The first record should come before the second record
				COMPARE_FIRSTAFTER		The first record should come after the second record

 $Arguments:	record1		The first record to be compared
				record2		The second record to be compared
				index_type	Index list to use
 
*******************************************************************************/

T_PB_COMPARE GI_pb_Compare (T_PB_RECORD *record1,T_PB_RECORD *record2, T_PB_INDEX index_type)
{
	return COMPARE_DEFAULT;
}


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

 $Function:    	GI_pb_GetTable
 
 $Description:	If fields other than name and number are required, then index tables
 				must be provided for each field.  This function is called when access
 				to an index table is required for an unknown index type.

 				The array provided must be a user-allocated array of type SHORT,
 				records_max in size, e.g.

 				static SHORT user_table[RECORDS_MAX];
 				return user_table;

 $Returns:		A pointer to an array of SHORTs records_max in size.

 $Arguments:	index_type	Index list to use
 
*******************************************************************************/

SHORT *GI_pb_GetTable (T_PB_INDEX index_type)
{
	SHORT *user_table = NULL;	/*DUMMY IMPLEMENTATION*/
	return user_table;
}


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

 $Function:    	GI_alpha_AlphaToAscii
 
 $Description:	Convert an alpha tag to an ascii string

 $Returns:		None

 $Arguments:	ascii		The ascii string
 				alpha		The alpha tag
 				max_len		The maximum length of the resulting string
 
*******************************************************************************/

void GI_alpha_AlphaToAscii(T_MFW_PHB_TEXT *ascii, T_PB_ALPHA *alpha, SHORT max_len)
{
	SHORT asciiIndex;
	SHORT alphaIndex;

	/* Unicode entry - swap the low and high bytes, add in 0x80 at start*/

	ascii->dcs = alpha->dcs;
	
	if (alpha->dcs == MFW_DCS_UCS2)
	{
		ascii->data[0] = 0x80;
		asciiIndex = 1;
		alphaIndex = 0;
		
		while (alphaIndex<alpha->length && asciiIndex<max_len)
		{
			ascii->data[asciiIndex++] = (char) (alpha->data[alphaIndex]>>8);
			ascii->data[asciiIndex++] = (char) (alpha->data[alphaIndex] & 0xFF);
			alphaIndex++;
		}

		/* Put two NULLs at the end, if there is space */
		
		if (asciiIndex<max_len)
			ascii->data[asciiIndex++] = NULL;
		if (asciiIndex<max_len)
			ascii->data[asciiIndex] = NULL;

		ascii->len = asciiIndex;
	}

	/* Ascii entry - convert from unicode */
	
	else
	{
		asciiIndex = 0;
		alphaIndex = 0;
		
		while (alphaIndex<alpha->length && asciiIndex<max_len)
		{
			ascii->data[asciiIndex++] = (char) (alpha->data[alphaIndex++]);
		}

		/* Put a NULL at the end, if there is space */

		if (asciiIndex<max_len)
			ascii->data[asciiIndex] = NULL;

		ascii->len = asciiIndex;
	}
	
	return;
}


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

 $Function:    	GI_alpha_AsciiToAlpha
 
 $Description:	Convert an ascii string to an alpha tag

 $Returns:		None

 $Arguments:	alpha		The alpha tag
 				ascii		The ascii string
 				max_len		The maximum length of the resulting string
 
*******************************************************************************/

void GI_alpha_AsciiToAlpha(T_PB_ALPHA *alpha, T_MFW_PHB_TEXT *ascii, SHORT max_len)
{
	SHORT asciiIndex;
	SHORT alphaIndex;

	alpha->dcs = ascii->dcs;
	
	/* Unicode entry - swap the low and high bytes, ignore first '0x80' character */
	
	if (ascii->dcs == MFW_DCS_UCS2)
	{
		asciiIndex = 1;
		alphaIndex = 0;
	
		while (asciiIndex<ascii->len && alphaIndex<max_len)
		{
			alpha->data[alphaIndex++] = (USHORT) ((ascii->data[asciiIndex++]<<8) | ascii->data[asciiIndex++]);
		}

		/* Put a NULL at the end, if there is space */
		
		if (alphaIndex<max_len)
			alpha->data[alphaIndex] = NULL;
	}

	/* Ascii entry - convert to unicode */
	
	else
	{
		asciiIndex = 0;
		alphaIndex = 0;
	
		while (asciiIndex<ascii->len && alphaIndex<max_len)
		{
			alpha->data[alphaIndex++] = (USHORT)ascii->data[asciiIndex++];
		}
		
		/* Put a NULL at the end, if there is space */
		
		if (alphaIndex<max_len)
			alpha->data[alphaIndex] = NULL;
	}
	
	alpha->length = alphaIndex;

	return;
}


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

 $Function:    	GI_index_Convert
 
 $Description:	Convert indexing types from MFW to ATB.

 $Returns:		The ATB indexing type

 $Arguments:	mode		The MFW sort mode
 
*******************************************************************************/

T_PB_INDEX GI_index_Convert(UBYTE mode)
{
	T_PB_INDEX index_type;
	
	switch(mode)
	{
		case MFW_PHB_ALPHA:
			index_type = INDEX_NAME;
			break;
		case MFW_PHB_NUMBER:
			index_type = INDEX_NUMBER;
			break;
		case MFW_PHB_INDEX:
			index_type = INDEX_PHYSICAL;	/* NOTE - may not work quite as intended */
			break;
		case MFW_PHB_PHYSICAL:
			index_type = INDEX_PHYSICAL;
			break;
	}

	return index_type;
}

⌨️ 快捷键说明

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