FreeCalypso > hg > fc-tourmaline
changeset 141:67b91d34f75e
mmiBlkResources.c: bogotab fixes
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 14 Nov 2020 04:29:03 +0000 |
parents | 1c4536a30e32 |
children | ec9f955fc487 |
files | src/ui/bmi/mmiBlkResources.c |
diffstat | 1 files changed, 140 insertions(+), 141 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ui/bmi/mmiBlkResources.c Sat Nov 14 04:27:10 2020 +0000 +++ b/src/ui/bmi/mmiBlkResources.c Sat Nov 14 04:29:03 2020 +0000 @@ -1,6 +1,6 @@ /******************************************************************************* - CONDAT (UK) + CONDAT (UK) ******************************************************************************** @@ -9,27 +9,27 @@ ******************************************************************************** - $Project name: Basic MMI - $Project code: BMI (6349) - $Module: PhoneBook - $File: MmiBlkResources.c - $Revision: 1.0 + $Project name: Basic MMI + $Project code: BMI (6349) + $Module: PhoneBook + $File: MmiBlkResources.c + $Revision: 1.0 - $Author: Condat(UK) - $Date: 25/10/00 + $Author: Condat(UK) + $Date: 25/10/00 ******************************************************************************** Description: This modules provides, in conjunction with the MmiBlkManager module, - the resource management facilities for the MMI. + the resource management facilities for the MMI. ******************************************************************************** $History: MmiBlkResources.c - 25/10/00 Original Condat(UK) BMI version. + 25/10/00 Original Condat(UK) BMI version. $End @@ -78,23 +78,23 @@ /* Define the control structures used to implement the block resource manager */ -#define RESOURCE_MANAGER_KEY 0x00BABE02L -#define RESOURCE_SEARCH_LIMIT 4 +#define RESOURCE_MANAGER_KEY 0x00BABE02L +#define RESOURCE_SEARCH_LIMIT 4 typedef struct _tBlkEntry_ { - tBlkId BlkId; - tBlkHandle BlkHandle; + tBlkId BlkId; + tBlkHandle BlkHandle; } tBlkEntry, *pBlkEntry; typedef struct _tBlkControl_ { - long int BlkKey; - tBlkHandle BlkBase; - int BlkLength; - pBlkEntry BlkStartPtr; - tBlkHandle BlkMinAddress; - tBlkHandle BlkMaxAddress; + long int BlkKey; + tBlkHandle BlkBase; + int BlkLength; + pBlkEntry BlkStartPtr; + tBlkHandle BlkMinAddress; + tBlkHandle BlkMaxAddress; } tBlkControl, *pBlkControl; @@ -106,30 +106,30 @@ /******************************************************************************* - $Function: ValidBlockResource + $Function: ValidBlockResource - $Description: Verifies that the resource indicated by the handle is a valid + $Description: Verifies that the resource indicated by the handle is a valid resource. - $Returns: 0 If invalid, non-zero if valid. + $Returns: 0 If invalid, non-zero if valid. - $Arguments: BlkRsrc, handle of resource + $Arguments: BlkRsrc, handle of resource *******************************************************************************/ static int ValidBlockResource( tBlkHandle BlkRsrc ) { - pBlkControl BlkControl = (pBlkControl) BlkRsrc; + pBlkControl BlkControl = (pBlkControl) BlkRsrc; - /* Check for non-NULL handle - */ - if ( BlkControl == NULL ) - return 0; + /* Check for non-NULL handle + */ + if ( BlkControl == NULL ) + return 0; - /* Check key has been set up correctly - */ - return ( BlkControl->BlkKey == RESOURCE_MANAGER_KEY ); + /* Check key has been set up correctly + */ + return ( BlkControl->BlkKey == RESOURCE_MANAGER_KEY ); } @@ -141,7 +141,7 @@ /******************************************************************************* - $Function: mmibr_Initialise + $Function: mmibr_Initialise $Description: @@ -152,52 +152,52 @@ must be called prior to invocation of any other block resource function - $Returns: Handle to a resource block, NULL if unsuccessful + $Returns: Handle to a resource block, NULL if unsuccessful - $Arguments: BlkBase, Base address of the block of data relating + $Arguments: BlkBase, Base address of the block of data relating to the resource - NumEntries, number of entries associated with the resource + NumEntries, number of entries associated with the resource *******************************************************************************/ tBlkHandle mmibr_Initialise( tBlkHandle BlkBase, int NumEntries ) { - pBlkControl Blk; - int i; + pBlkControl Blk; + int i; - /* As part of the initialisation process, we need to allocate a - block of memory in which to store the control information - associated with this block resource manager - */ - if ( ( Blk = (pBlkControl) ALLOC_MEMORY( sizeof(tBlkControl) ) ) != NULL ) - { - /* Store the things we know straight off - */ - Blk->BlkKey = RESOURCE_MANAGER_KEY; - Blk->BlkBase = BlkBase; - Blk->BlkLength = NumEntries; - Blk->BlkStartPtr = (pBlkEntry) BlkBase; + /* As part of the initialisation process, we need to allocate a + block of memory in which to store the control information + associated with this block resource manager + */ + if ( ( Blk = (pBlkControl) ALLOC_MEMORY( sizeof(tBlkControl) ) ) != NULL ) + { + /* Store the things we know straight off + */ + Blk->BlkKey = RESOURCE_MANAGER_KEY; + Blk->BlkBase = BlkBase; + Blk->BlkLength = NumEntries; + Blk->BlkStartPtr = (pBlkEntry) BlkBase; - /* In order to detect memory allocations, we scan the list - of known entries, storing the maximum and minimum addresses - in the list. This scan allows us to detect when allocated - memory is being returned, since the address will be outside - the contiguous memory block we are managing. - */ - Blk->BlkMinAddress = Blk->BlkMaxAddress = BlkBase; - for ( i = 0; i < NumEntries; i++ ) - { - if ( Blk->BlkMaxAddress < Blk->BlkStartPtr[i].BlkHandle ) - Blk->BlkMaxAddress = Blk->BlkStartPtr[i].BlkHandle; - } - } + /* In order to detect memory allocations, we scan the list + of known entries, storing the maximum and minimum addresses + in the list. This scan allows us to detect when allocated + memory is being returned, since the address will be outside + the contiguous memory block we are managing. + */ + Blk->BlkMinAddress = Blk->BlkMaxAddress = BlkBase; + for ( i = 0; i < NumEntries; i++ ) + { + if ( Blk->BlkMaxAddress < Blk->BlkStartPtr[i].BlkHandle ) + Blk->BlkMaxAddress = Blk->BlkStartPtr[i].BlkHandle; + } + } - return Blk; + return Blk; } /******************************************************************************* - $Function: mmibr_ShutDown + $Function: mmibr_ShutDown $Description: @@ -206,27 +206,27 @@ be called unless a catastrophic error has occurred and the system needs to be restarted. - $Returns: none. + $Returns: none. - $Arguments: Pointer to a block resource handle (ie ptr to ptr) + $Arguments: Pointer to a block resource handle (ie ptr to ptr) *******************************************************************************/ void mmibr_ShutDown( tBlkHandle *BlkRsrc ) { - /* Only allow the resource manager to be shutdown if the provided - handle is consistent - */ - if ( ValidBlockResource( *BlkRsrc ) ) - { - free( *BlkRsrc ); - *BlkRsrc = NULL; - } + /* Only allow the resource manager to be shutdown if the provided + handle is consistent + */ + if ( ValidBlockResource( *BlkRsrc ) ) + { + free( *BlkRsrc ); + *BlkRsrc = NULL; + } } /******************************************************************************* - $Function: mmibr_Fetch + $Function: mmibr_Fetch $Description: @@ -236,84 +236,84 @@ when dealing with data coming from either ROM or dynamically allocated memory. - $Returns: pointer to resource, NULL if unsuccessful + $Returns: pointer to resource, NULL if unsuccessful - $Arguments: BlkRsrc, resource handle created by mmibr_Initialise + $Arguments: BlkRsrc, resource handle created by mmibr_Initialise Id, identifier of the resource to be returned *******************************************************************************/ tBlkHandle mmibr_Fetch( tBlkHandle BlkRsrc, tBlkId Id ) { - int Start, End, Search; - tBlkId CurrentId; - tBlkHandle SearchPtr; + int Start, End, Search; + tBlkId CurrentId; + tBlkHandle SearchPtr; - /* convert the handle and verify it's valid - */ - pBlkControl BlkControl = (pBlkControl) BlkRsrc; - if ( ! ValidBlockResource( BlkRsrc ) ) - return NULL; + /* convert the handle and verify it's valid + */ + pBlkControl BlkControl = (pBlkControl) BlkRsrc; + if ( ! ValidBlockResource( BlkRsrc ) ) + return NULL; - /* When locating a specific entry, we need to search the list of - ids for one matching the input value. Since the Ids will be - organised as an ordered list, very important that bit, we can - perform a simple binary search to locate the items. - */ - Start = 0; - End = BlkControl->BlkLength - 1; - SearchPtr = NULL; - do - { - /* grab the entry midway between the current start and end - */ - Search = Start + ((End - Start) >> 1); - CurrentId = BlkControl->BlkStartPtr[Search].BlkId; + /* When locating a specific entry, we need to search the list of + ids for one matching the input value. Since the Ids will be + organised as an ordered list, very important that bit, we can + perform a simple binary search to locate the items. + */ + Start = 0; + End = BlkControl->BlkLength - 1; + SearchPtr = NULL; + do + { + /* grab the entry midway between the current start and end + */ + Search = Start + ((End - Start) >> 1); + CurrentId = BlkControl->BlkStartPtr[Search].BlkId; - /* Binary chop the search space - */ - if ( CurrentId == Id ) - { - /* Found a match, grab handle and terminate search - */ - SearchPtr = BlkControl->BlkStartPtr[Search].BlkHandle; - Start = End; - } - else if ( CurrentId > Id ) - { - /* Not got a match, but it's not in the top half so move - the End pointer down - */ - End = Search; - } - else - { - /* Not got a match, but it's not in the bottom half so - move the Start pointer up - */ - Start = Search; - } + /* Binary chop the search space + */ + if ( CurrentId == Id ) + { + /* Found a match, grab handle and terminate search + */ + SearchPtr = BlkControl->BlkStartPtr[Search].BlkHandle; + Start = End; + } + else if ( CurrentId > Id ) + { + /* Not got a match, but it's not in the top half so move + the End pointer down + */ + End = Search; + } + else + { + /* Not got a match, but it's not in the bottom half so + move the Start pointer up + */ + Start = Search; + } - /* when we get down to the last three or four entries, just - search linearly to solve it, this is generally quicker for - a small number of entries than continuing the binary chop - */ - if ( ( End - Start ) < RESOURCE_SEARCH_LIMIT ) - { - /* search quickly through the possibles - */ - for ( Search = Start; Search <= End; Search++ ) - if ( Id == BlkControl->BlkStartPtr[Search].BlkId ) - SearchPtr = BlkControl->BlkStartPtr[Search].BlkHandle; + /* when we get down to the last three or four entries, just + search linearly to solve it, this is generally quicker for + a small number of entries than continuing the binary chop + */ + if ( ( End - Start ) < RESOURCE_SEARCH_LIMIT ) + { + /* search quickly through the possibles + */ + for ( Search = Start; Search <= End; Search++ ) + if ( Id == BlkControl->BlkStartPtr[Search].BlkId ) + SearchPtr = BlkControl->BlkStartPtr[Search].BlkHandle; - /* And terminate the binary chop - */ - Start = End; - } + /* And terminate the binary chop + */ + Start = End; + } - } while ( Start != End ); + } while ( Start != End ); - return SearchPtr; + return SearchPtr; } /******************************************************************************* @@ -321,4 +321,3 @@ End of File *******************************************************************************/ -