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

📄 mmibookservices.c

📁 GSM手机设计软件代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    int count; /* Number of matching characters */
    int lenNum;
    int lenNumPB;
    int firstNotMatch=0;
    int match=0;

    TRACE_FUNCTION("bookFindIndexMatchPB()");

#ifdef TRACE_PB_DEBUG
    TRACE_EVENT_P1("numEntries to examine: %d", numEntries);
#endif /* TRACE_PB_DEBUG */

    if ( (listPB == NULL) || (srcNumber == NULL) ) /* Invalid data */
    {
        TRACE_EVENT("Invalid data passed to findIndexMatchPB");
        return (-1);
    }

    if (numEntries <= 0) /* Invalid number of entries */
    {
        TRACE_EVENT_P1("Invalid number of entries passed into findIndexMatchPB: %d", numEntries);
        return (-1);
    }

    /* Calculate length of number */
    lenNum = strlen(srcNumber);

#ifdef TRACE_PB_DEBUG
    TRACE_EVENT_P1("Len of number: %d", lenNum);
#endif /* TRACE_PB_DEBUG */
    
    /* Loop round number of entries */
    for (i=0; i<numEntries; i++)
    {
        char* entryPB = (char*)listPB->entry[i].number;
        
        /* Calculate length of number in PB entry */
        lenNumPB = strlen(entryPB);

#ifdef TRACE_PB_DEBUG
        TRACE_EVENT_P2("Len of PB number for entry %d: %d", i, lenNumPB);
#endif /* TRACE_PB_DEBUG */

        /* Set count and loop-counter to 0 before comparing numbers */
        count = 0;
        j = 0;

        /* Determine number of matching digits
          * Exit loop if digits don't match or if reached end of either number buffer
          */
        while ( (!firstNotMatch) &&  !(j > lenNumPB) && !(j > lenNum) )
        {
            /* Compare digits */
            if (srcNumber[lenNum-j] == entryPB[lenNumPB-j]) /* Matching character */
            {
#ifdef TRACE_PB_DEBUG
                TRACE_EVENT_P1("Found match at pos", j);
#endif /* TRACE_PB_DEBUG */
                count = count + 1;
            }
            else
            {
                /* Digits don't match */
                firstNotMatch=1;
            }
            
            /* Increment index to point at next set of digits */
            j = j + 1;
        }

        /* If better match store count and index */
        /* SPR#1727 - DS - Added numbersMatch() check */
        if ( (count > maxMatchChars) && numbersMatch((char*)srcNumber, entryPB) )
        {
#ifdef TRACE_PB_DEBUG
            TRACE_EVENT_P2("Entry %d is better match. Matches %d chars", i, count);
#endif /* TRACE_PB_DEBUG */
            maxMatchChars = count;
            indexMatch = i;
        }
    }

    /* Return index of best match */
    return indexMatch;
}





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

 $Function:     bookFindNameInPhonebook

 $Description:  SPR#1112 - Modified function to search in alternate phonebook.
 			  Locates the name in the current phonebook.  If the current phonebook is
 			  the internal phonebook and no result is found, the SIM phonebook is also
 			  searched.

 $Returns:      0 if error, 1 if successful

 $Arguments:  p_pszNumber, pointer to pattern to match, p_pEntry, pointer
                to buffer into which to store result.

*******************************************************************************/
//GW-SPR#810-Simplified phonebook entry search based on 1.3.3 code.

int bookFindNameInPhonebook( const char *p_pszNumber, T_MFW_PHB_ENTRY *p_pEntry )
{
  int result;
  
  TRACE_FUNCTION( "bookFindNameInPhonebook()" );

  if(p_pszNumber == 0 || p_pEntry == 0)
    return (0);

  if (strlen(p_pszNumber) < 1)
    return (0);
  
  result = bookFindNameInSpecificPhonebook(p_pszNumber, p_pEntry);

  #ifdef INT_PHONEBOOK
  /* If not found in internal phonebook, try SIM */

  if (!result && bookGetBookAvailable() && bookGetBookSelected())
  {
  	bookSetBookSelected(FALSE);
  	result = bookFindNameInSpecificPhonebook(p_pszNumber, p_pEntry);
  	bookSetBookSelected(TRUE);
  }
  #endif
  
  return result;
}


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

 $Function:     bookFindNameInSpecificPhonebook

 $Description:  Locates the name in a specified phone book
			  SPR#1112 - SH - Separate this part of function, so we can call it twice
 $Returns:      0 if error, 1 if successful

 $Arguments:  p_pszNumber, pointer to pattern to match, p_pEntry, pointer
                to buffer into which to store result.

 SPR#1727 - Modified to use bookFindIndexMatchPB.

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

int bookFindNameInSpecificPhonebook( const char *p_pszNumber, T_MFW_PHB_ENTRY *p_pEntry )
{
#ifdef NO_ASCIIZ
	T_MFW_PHB_TEXT p_pszNumberText;
#endif
  
  T_MFW_PHB_LIST  phb_list, new_list;
  UBYTE     phb_index = 0;
  UBYTE     l_name[MAX_ALPHA_LEN];
  T_MFW_PHB_ENTRY temp_pEntry[4];
  int i;
  int result;
/*MC SPR 1319*/
  char debug[MAX_ALPHA_LEN];
  int k;
  int ret;
  int indexMatch;
  
  if(p_pszNumber == 0 || p_pEntry == 0)
    return (0);
  
  if (strlen(p_pszNumber) < 1)
	return (0);
  
  memset( p_pEntry,  0, sizeof(T_MFW_PHB_ENTRY) );
  memset( &phb_list, 0, sizeof(phb_list) );
  phb_list.entry = temp_pEntry;
  phb_list.num_entries = 4;
  
  /* Search phonebook for up to 4 entries with the last 6 digits matching number */

#ifdef NO_ASCIIZ
	/* GW Set up data structure for NO_ASCIIZ */
	p_pszNumberText.dcs = MFW_DCS_8bits;
	p_pszNumberText.len = strlen(p_pszNumber);
	strcpy((char*)p_pszNumberText.data, p_pszNumber);

    ret = phb_find_entries(
    bookActiveBook(READ),   /* phonebook                */
		&phb_index,				/* returns index in phb     */
		MFW_PHB_NUMBER,			/* searching for number     */
		4,						/* return max. four entry    */
	    &p_pszNumberText,  /* search this pattern      */
		&phb_list				/* return structure         */
		);

#else

    ret = phb_find_entries(
    bookActiveBook(READ),   /* phonebook                */
		&phb_index,				/* returns index in phb     */
		MFW_PHB_NUMBER,			/* searching for number     */
		4,						/* return max. four entry    */
		(char *)p_pszNumber,  /* search this pattern      */
             &phb_list       /* return structure         */
    );
#endif //NO_ASCIIZ

    //Check return from phb_find_entries
    if (ret == MFW_PHB_FAIL)
    {
        return (0);
    }

    result = 0;	/* SPR#1112 - SH */
    /* GW-SPR#762-Simplified phonebook entry */

    memset( p_pEntry,  0, sizeof(T_MFW_PHB_ENTRY) );

    /* SPR#1727 - DS - Examine returned PB entries and find best match */
    indexMatch = bookFindIndexMatchPB(&phb_list, phb_list.num_entries, p_pszNumber);

    if (indexMatch == -1) /* No match found */
    {
        TRACE_EVENT("No match found in findIndexMatchPB !");
        return (0);
    }

#ifdef TRACE_PB_DEBUG
    TRACE_EVENT_P1("Match found in findIndexMatchPB. Pb entry %d", indexMatch);
#endif /* TRACE_PB_DEBUG */

    /* Copy matched phonebook entry details */
    memcpy( p_pEntry, &temp_pEntry[indexMatch] , sizeof(T_MFW_PHB_ENTRY) );

    if (p_pEntry == NULL)
    {
        return (0);
    }

    /* Convert name into appropriate format */
#ifdef NO_ASCIIZ
	/*MC SPR 1319*/
#ifdef EASY_TEXT_ENABLED
	for (k=0;k<p_pEntry->name.len; k++)
	{	
	    if (p_pEntry->name.data[k]==0 )
	    {
		  debug[k] = '0';
	    }
	    else
	    {
	        debug[k] = p_pEntry->name.data[k];
	    }
	}
	TRACE_EVENT_P1("BFNIP: %s ", debug);	
	
	/*MC SPR 1257, replacing PHB_MAX_LEN with MAX_ALPHA_LEN for name strings*/	
	if (p_pEntry->name.data[0] == 0x80) /* Unicode 0x80 style */
	{
	       /*MC, removed var "actual_length*/
		
             for (i=1; i<MAX_ALPHA_LEN; i+=1)
        	{
        		l_name[i+1] = p_pEntry->name.data[i];
        		
        	}
	       l_name[0] =	p_pEntry->name.data[0]; 
	       l_name[1] = MAX_ALPHA_LEN;
			
		memcpy( p_pEntry->name.data, (char*)l_name, MAX_ALPHA_LEN );
		
	      if (p_pEntry->name.len%2 == 1)/*if length of string odd*/
	      {
   		    p_pEntry->name.len++; /*MC we have to increase the length by one as we've shifted the string up*/
	      }

   	      /*MC, ensure all the chars in the string after string length are 0*/
  	     for (i=p_pEntry->name.len; i<MAX_ALPHA_LEN; i++)	 		
  	     {
   	          p_pEntry->name.data[i]= 0;
  	     }
  	     
	     for (k=0;k<p_pEntry->name.len; k++)
	     {
                if (p_pEntry->name.data[k]==0 )
                {
                    debug[k] = '0';
                }
                else
                {
                    debug[k] = p_pEntry->name.data[k];
                }
	     }

            TRACE_EVENT_P1("BNFIP conv: %s", debug);

	      sprintf(debug, "Length of phonebook entry:%d", p_pEntry->name.len);

	
	}
       else
#endif /* EASY_TEXT_ENABLED */
	/* Marcus: Issue 963: 11/09/2002: Start */
	{
	    /*
	     * bookGsm2Alpha requires ASCIIZ string - make sure it is.
	     * This also will help calling functions that may assume ASCIIZ.
	     */
	    if (sizeof(p_pEntry->name.data) > p_pEntry->name.len)
	    {
	        p_pEntry->name.data[p_pEntry->name.len] = '\0';
	    }
	    bookGsm2Alpha( (UBYTE *) p_pEntry->name.data );
	}
	/* Marcus: Issue 963: 11/09/2002: End */
/*MC end*/
#else
  	bookGsm2Alpha( (UBYTE *) p_pEntry->name );
#endif /* NO_ASCIIZ */
  
  return (1);
}




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

 $Function:    	bookFindNumberByPosition

 $Description:	locate a number given the index
 
 $Returns:		0 if failure, 1 otherwise

 $Arguments:	index of the number to find, p_pentry, return structure
 
*******************************************************************************/

UBYTE bookFindNumberByPosition (UBYTE index,T_MFW_PHB_ENTRY* p_pEntry)
{
  T_MFW_PHB_LIST  phb_list;
  /*MC SPR 1257, replacing PHB_MAX_LEN with MAX_ALPHA_LEN for name strings*/
  UBYTE l_name[MAX_ALPHA_LEN];

  TRACE_FUNCTION( "bookFindNumberByPosition()" );

    /* only search if we have valid input information
    */
  if( index == 0 || p_pEntry == 0 )
    return 0;

    /* Clear the output buffers
    */
  memset( p_pEntry,  0, sizeof( T_MFW_PHB_ENTRY ) );
  memset( &phb_list, 0, sizeof( phb_list ) );

    /* searc for the selected entry
    */
  phb_list.entry          = p_pEntry;
  phb_list.num_entries    = 1;
  phb_read_entries( bookActiveBook(READ), index, MFW_PHB_INDEX, 1, &phb_list );

    /* if we haven't found the entry return 0
    */
    if ( phb_list.result == MFW_ENTRY_EXIST )
        return 0;

    /* otherwise copy the located information to the output structure
    */
#ifdef NO_ASCIIZ

	{
	#ifdef EASY_TEXT_ENABLED
		/*MC SPR 1257, name strings should use MAX_ALPHA_LEN*/
		int i;
		if (p_pEntry->name.data[0] == 0x80 ||p_pEntry->name.data[0]== 0x00)
			{	for (i=1; i<MAX_ALPHA_LEN; i+=1)
				{
					l_name[i+1] = p_pEntry->name.data[i];
					
				}
	       	 	l_name[0] =	p_pEntry->name.data[0]; 
	       		l_name[1] = MAX_ALPHA_LEN;
			
				memcpy( p_pEntry->name.data, (char*)l_name, MAX_ALPHA_LEN );

   		 		p_pEntry->name.len++;/* = actual_length;*/
				
			}
		else
	#endif
			bookGsm2Alpha( (UBYTE *) p_pEntry->name.data );
	}

#else

  bookGsm2Alpha( (UBYTE *) p_pEntry->name );

#endif

    /* successful return status
    */
  return 1;

}








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

 $Function:     bookCallIndex

 $Description:  Calls the number in the physical index

 $Returns:    status from the phb_read_entries routine

 $Arguments:  index, of the number to call

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

int bookCallIndex( UBYTE index )
{
  T_MFW_PHB_LIST  phb_list;
  T_MFW_PHB_ENTRY entry;
  UBYTE           status;

  TRACE_FUNCTION( "bookCallIndex()" );

  memset( &entry,    0, sizeof( T_MFW_PHB_ENTRY ) );
  memset( &phb_list, 0, sizeof( phb_list ) );

  phb_list.entry          = &entry;
  phb_list.num_entries    = 1;
  if ( ( status = phb_read_entries( bookActiveBook(READ), index, MFW_PHB_PHYSICAL, 1, &phb_list ) ) == MFW_PHB_OK )
    callNumber( entry.number );
    return status;
}











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

 $Function:     bookGsm2Alpha

 $Description:  Convert a string from it's GSM to alpha characters

 $Returns:    none

 $Arguments:  alpha, pointer to string to be converted (Must be null
                terminated string)

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


void bookGsm2Alpha( UBYTE *alpha )
{
  int index;
  int length=0;

  if (alpha != NULL)
  {
    length = strlen( (char *) alpha );
  }
  
  for ( index = 0; index < length; index++ )
    alpha[index] = alpha[index] & 0x7F;
}








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

 $Function:     bookActiveBook

 $Description:  Determine if the current active book is restricted or not

 $Returns:    PHB_FDN if restricted, PHB_ADN otherwise

 $Arguments:  None

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

UBYTE bookActiveBook( int process )
{
  TRACE_FUNCTION( "bookActiveBook()" );

/* SPR#1112 - SH - Return internal phonebook ID when appropriate */
#ifdef INT_PHONEBOOK
  if (bookGetBookAvailable() && bookGetBookSelected())
  	return PHB_IPB;
#endif

  if(process == READ)
    return ( phb_get_mode() == PHB_RESTRICTED ) ? PHB_FDN : PHB_ADN_FDN;
  else if(process == WRITE)
  	return ( phb_get_mode() == PHB_RESTRICTED ) ? PHB_FDN : PHB_ADN;
}




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

 $Function:     bookMemoryView

 $Description:  Display the memory status

 $Returns:    None

 $Arguments:  None

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

void bookMemoryView( void )
{
    T_MFW_HND       win         = mfwParent( mfw_header() );
    T_MFW_WIN       *win_data   = ( (T_MFW_HDR *) win )->data;
    tBookStandard   *data       = (tBookStandard *) win_data->user;
  char            Buffer[16];
  int TxtToShow;

	
    /* Determine which book we are currently using
    */

⌨️ 快捷键说明

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