home *** CD-ROM | disk | FTP | other *** search
- ////////////////////////////////////////////////////////////////////////
- //+
- // Module Name: cmemlib.cpp
- //
- // Description: MEM specific routines
- //
- // Include Modules Referenced: cmemlib.hpp
- //
- // Written by: John Tal
- //
- //
- // Modification history:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //-
- ////////////////////////////////////////////////////////////////////////
-
- #include <mem.h>
-
- #include "cmemlib.h"
-
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: HEAP_C
- //
- // Class: HEAP_C
- //
- // Security: Public Constructor
- //
- // Description: Initializes a heap
- //
- // Parameters
- // In: SHORT = Number of heap elements to create
- // Out: NONE
- //
- // Return Codes: VOID
- //
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- HEAP_C::HEAP_C(SHORT sElms)
- {
- C_DEF_VMODULE("HEAP_C::HEAP_C")
-
- sMaxElms = sElms;
-
- sBottom = C_HEAP_EMPTY;
-
- pstHeapData = (HEAP_DATA_P) new HEAP_DATA_T[sElms];
-
- pCompareFunc = NULL;
-
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Enq
- //
- // Class: HEAP_C
- //
- // Security: Public
- //
- // Description: Queues and item to the heap
- //
- // Parameters
- // In: SHORT = Priority of Item
- // PVOID = Data to store
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK = Queued Item
- // = C_NOTOK = Queue Full
- //
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT HEAP_C::Enq(SHORT sPriority, PVOID pvData)
- {
- C_DEF_MODULE("HEAP_C::Enq")
-
- if(sBottom > sMaxElms)
- C_LEAVE(C_NOTOK)
-
- sBottom++;
-
- pstHeapData[sBottom].sPriority = sPriority;
- pstHeapData[sBottom].pvData = pvData;
-
- Up();
-
- C_MODULE_EXIT:
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Deq
- //
- // Class: HEAP_C
- //
- // Security: Public
- //
- // Description: Removes an entry from the heap
- //
- // Parameters
- // In: SHORT = Priority of Item
- // Out: PPVOID = Returned address of item
- //
- // Return Codes: SHORT = C_OK = Got an item
- // = C_NOTOK = Heap empty
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT HEAP_C::Deq(PSHORT pPriority, PPVOID ppvData)
- {
- C_DEF_MODULE("HEAP_C::Deq")
-
- if(sBottom == C_HEAP_EMPTY)
- C_LEAVE(C_NOTOK)
-
- *pPriority = pstHeapData[C_HEAP_TOP].sPriority;
- *ppvData = pstHeapData[C_HEAP_TOP].pvData;
-
- memcpy(&pstHeapData[C_HEAP_TOP],
- &pstHeapData[sBottom],
- sizeof(HEAP_DATA_T));
-
- memset(&pstHeapData[sBottom],
- C_NOTHING,
- sizeof(HEAP_DATA_T));
-
- sBottom--;
-
- Down();
-
- C_MODULE_EXIT:
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Down
- //
- // Class: HEAP_C
- //
- // Security: Protected
- //
- // Description: Adjusts the heap after a deque
- //
- // Parameters: VOID
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT HEAP_C::Down(VOID)
- {
- C_DEF_MODULE("HEAP_C::Down")
-
- BOOL fHeapOk = C_FALSE;
- SHORT sRoot2;
- SHORT sMaxChild;
- SHORT sRoot = C_HEAP_TOP;
-
- sRoot2 = sRoot << 1;
-
- //
- // Process until the root value is in its correct place
- //
-
- while(
- (sRoot2 <= sBottom) &&
- (!fHeapOk)
- )
- {
-
- //
- // Calculate index of the child with the larger value
- //
-
- if(sRoot2 == sBottom)
- sMaxChild = sRoot2; // only one child
- else
- {
-
- //
- // Select the greater of the 2 children
- //
-
- if(pstHeapData[sRoot2].sPriority > // left child
- pstHeapData[sRoot2 + 1].sPriority) // right child
- sMaxChild = sRoot2;
- else
- sMaxChild = (sRoot2) + 1;
-
- }
-
-
- //
- // If heap property violated, swap values
- //
-
- if(pstHeapData[sRoot].sPriority <
- pstHeapData[sMaxChild].sPriority)
- {
- Swap(&pstHeapData[sRoot],
- &pstHeapData[sMaxChild]);
-
- sRoot = sMaxChild;
- sRoot2 = sRoot << 1;
-
-
- }
- else
- fHeapOk = C_TRUE;
- }
-
- C_RETURN
-
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Up
- //
- // Class: HEAP_C
- //
- // Security: Protected
- //
- // Description: Adjusts the heap after an enq
- //
- // Parameters: VOID
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT HEAP_C::Up(VOID)
- {
- C_DEF_MODULE("HEAP_C::Up")
-
- SHORT sCur;
- SHORT sParent;
- SHORT sHeapOk;
-
- sHeapOk = C_FALSE;
- sCur = sBottom;
- sParent = sCur >> 1;
-
-
- //
- // move last element up in heap till in correct place
- //
-
- while((sCur > (C_HEAP_EMPTY + 1)) && !sHeapOk)
- {
-
- //
- // compare current and parent
- //
-
- if(pstHeapData[sParent].sPriority >=
- pstHeapData[sCur].sPriority)
- {
- sHeapOk = C_TRUE;
- }
- else
- {
- Swap(&pstHeapData[sParent],
- &pstHeapData[sCur]);
- sCur = sParent;
- sParent = sParent >> 1;
- }
- }
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Swap
- //
- // Class: HEAP_C
- //
- // Security: Protected
- //
- // Description: Swaps two HEAP_DATA_T elements
- //
- // Parameters
- // In: HEAP_DATA_P = one heap data element
- // HEAP_DATA_P = another heap data element
- // Out: SAME
- //
- // Return Codes: VOID
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- VOID HEAP_C::Swap(HEAP_DATA_P pstHeap1,
- HEAP_DATA_P pstHeap2)
- {
- C_DEF_VMODULE("HEAP_C::Swap")
-
- HEAP_DATA_T stHeapTemp;
-
- memcpy(&stHeapTemp,pstHeap1,sizeof(HEAP_DATA_T));
- memcpy(pstHeap1,pstHeap2,sizeof(HEAP_DATA_T));
- memcpy(pstHeap2,&stHeapTemp,sizeof(HEAP_DATA_T));
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Find
- //
- // Class: HEAP_C
- //
- // Security: Public
- //
- // Description: Searches a heap for pvData/key
- //
- // Parameters
- // In: PVOID = Address of key data to search for
- // Out: PPVOID = Address of returned data (NULL if not found)
- //
- // Return Codes: VOID
- //
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT HEAP_C::Find(PVOID pvData,PPVOID ppVoid)
- {
- C_DEF_MODULE("HEAP_C::Find")
-
- SHORT sCnt;
-
- (*ppVoid) = NULL;
-
- if(sBottom != C_HEAP_EMPTY)
- {
- for(sCnt = C_HEAP_EMPTY + 1; sCnt <= sBottom; sCnt++)
- {
- if(pstHeapData[sCnt].pvData != NULL)
- {
- if( ((*pCompareFunc)(pstHeapData[sCnt].pvData,pvData)) == 0)
- (*ppVoid) = pstHeapData[sCnt].pvData;
- }
- }
- }
-
- C_RETURN
-
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: GetEntries
- //
- // Class: HEAP_C
- //
- // Security: Public
- //
- // Description: Returns current number of entries in heap
- //
- // Parameters
- // In: SAME
- // Out: PSHORT = Number of entries
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT HEAP_C::GetEntries(PSHORT psEntries)
- {
- C_DEF_MODULE("HEAP_C::GetEntries")
-
- *psEntries = sBottom;
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Vacate
- //
- // Class: HEAP_C
- //
- // Security: Public
- //
- // Description: Removes all items from heap
- //
- // Parameters
- // In: BOOL = Whether or not to free data pointed to
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT HEAP_C::Vacate(BOOL fFreeData)
- {
- C_DEF_MODULE("HEAP_C::Vacate")
-
- SHORT sCnt;
-
- //
- // If freeing data, check every [].pvData ptr and free()
- //
-
- if(fFreeData)
- {
- for(sCnt = C_HEAP_EMPTY + 1; sCnt <= sBottom; sCnt++)
- {
- if(pstHeapData[sCnt].pvData != NULL)
- {
- free(pstHeapData[sCnt].pvData);
- pstHeapData[sCnt].pvData = NULL;
- }
- }
- }
-
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: SetCompareFunc
- //
- // Class: HEAP_C
- //
- // Security Public
- //
- // Description: Set the compare function for link list data
- //
- // Parameters
- // In: SHORT (*)(PVOID,PVOID)
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT HEAP_C::SetCompareFunc(SHORT (*pFunc)(PVOID,PVOID))
- {
- C_DEF_MODULE("HEAP_C::SetCompareFunc")
-
- pCompareFunc = pFunc;
-
- C_RETURN
- }
-
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: QUEUE_C
- //
- // Class: QUEUE_C
- //
- // Security: Public
- //
- // Description: Public Constructor
- //
- // Parameters: VOID
- //
- // Return Codes: VOID
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- QUEUE_C::QUEUE_C(VOID)
- {
- C_DEF_VMODULE("QUEUE_C::QUEUE_C")
-
- pstTail = NULL;
-
- lEntries = 0;
-
- pCompareFunc = NULL;
-
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: SetCompareFunc
- //
- // Class: QUEUE_C
- //
- // Security Public
- //
- // Description: Set the compare function for link list data
- //
- // Parameters
- // In: SHORT (*)(PVOID,PVOID)
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT QUEUE_C::SetCompareFunc(SHORT (*pFunc)(PVOID,PVOID))
- {
- C_DEF_MODULE("QUEUE_C::SetCompareFunc")
-
- pCompareFunc = pFunc;
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: GetEntries
- //
- // Class: QUEUE_C
- //
- // Security: Public
- //
- // Description: Returns current number of entries in queue
- //
- // Parameters
- // In: SAME
- // Out: PLONG = Number of entries
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT QUEUE_C::GetEntries(PLONG plEntries)
- {
- C_DEF_MODULE("QUEUE_C::GetEntries")
-
- *plEntries = lEntries;
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Vacate
- //
- // Class: QUEUE_C
- //
- // Security: Public
- //
- // Description: Removes all items from a queue
- //
- // Parameters
- // In: BOOL = C_TRUE = free data pointed to
- // = C_FALSE = do not free data pointed to, only
- // list itself
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT QUEUE_C::Vacate(BOOL fFreeData)
- {
- C_DEF_MODULE("QUEUE_C::Vacate")
-
- C_STATUS = LLIST_C::Vacate(fFreeData);
-
- C_RETURN
- }
-
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Find
- //
- // Class: QUEUE_C
- //
- // Security: Public
- //
- // Description: Find an entry
- //
- // Parameters
- // In: PVOID = Address of key data to search for
- // Out: PPVOID = Address of returned data (NULL if not found)
- //
- // Return Codes: VOID
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT QUEUE_C::Find(PVOID pvData,PPVOID ppVoid)
- {
- C_DEF_MODULE("QUEUE_C:Find")
-
- C_STATUS = LLIST_C::Find(pvData,ppVoid);
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Enq
- //
- // Class: QUEUE_C
- //
- // Security: Public
- //
- // Description: Adds an item to a queue
- //
- // Parameters
- // In: PVOID = Address/item to add
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT QUEUE_C::Enq(PVOID pvData)
- {
- C_DEF_MODULE("QUEUE_C::Enq")
-
- LLIST_P pstNew;
-
- C_STATUS = Alloc(pvData,&pstNew);
-
- if(C_STATUS)
- C_LEAVE(C_STATUS);
-
- if(pstHead == NULL)
- {
- pstHead = pstNew;
- pstTail = pstNew;
- }
- else
- {
- AddAfterNode(pstTail,pstNew);
- pstTail = pstNew;
- }
-
- lEntries++;
-
- C_MODULE_EXIT:
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Deq
- //
- // Class: QUEUE_C
- //
- // Security: Public
- //
- // Description: Removes an entry from a queue
- //
- // Parameters
- // In: SAME
- // Out: PPVOID = Address/item retrieved from queue
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT QUEUE_C::Deq(PPVOID ppvData)
- {
- C_DEF_MODULE("QUEUE_C::Deq")
-
- if(pstHead != NULL)
- *ppvData = pstHead -> pvData;
-
- DeleteNode(pstHead);
-
- if(pstHead == NULL)
- pstTail = NULL;
-
-
- lEntries--;
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: LLIST_C
- //
- // Class: LLIST_C
- //
- // Security: Public Constructor
- //
- // Description: Initializes a link list object
- //
- // Parameters
- // In: SHORT = Number of Tracks to keep
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- LLIST_C::LLIST_C(SHORT sTracks)
- {
- C_DEF_VMODULE("LLIST_C::LLIST_C")
-
- SHORT sCnt;
-
-
- pstTrack = NULL;
- sTrackSize = 0;
-
- pstHead = NULL;
- pstCurNode = NULL;
-
-
- if(sTracks > 0)
- {
- pstTrack = (TRACK_P) new TRACK_T[sTracks];
-
- for(sCnt = 0; sCnt < sTracks; sCnt++)
- pstTrack[sCnt].sState = TRACK_AVAIL;
-
- sTrackSize = sTracks;
- }
-
- pCompareFunc = NULL;
-
-
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: ~LLIST_C
- //
- // Class: LLIST_C
- //
- // Security: Public Destructor
- //
- // Description: Link list termination
- //
- // Parameters: VOID
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- LLIST_C::~LLIST_C(VOID)
- {
- C_DEF_VMODULE("LLIST_C::~LLIST_C")
-
- free(pstTrack);
-
- if(pstHead)
- Vacate(C_FALSE);
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: SetCompareFunc
- //
- // Class: LLIST_C
- //
- // Security Public
- //
- // Description: Set the compare function for link list data
- //
- // Parameters
- // In: SHORT (*)(PVOID,PVOID)
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::SetCompareFunc(SHORT (*pFunc)(PVOID,PVOID))
- {
- C_DEF_MODULE("LLIST_C::SetCompareFunc")
-
- pCompareFunc = pFunc;
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: SetMark
- //
- // Class: LLIST_C
- //
- // Security: Public
- //
- // Description: Set a link list marker, return to caller
- //
- // A mark is like a bookmark, it allows to to leave
- // a mark at the current member, to go elsewhere
- // in the list for processing, and then to return
- // to the marked member.
- //
- // Marks are provided because the LLIST_C objects
- // isolate the application from the internals of
- // the link list nodes (no address, all private).
- //
- // Multiple marks may be set. The limit is defined
- // by the LLIST_C constructor.
- //
- // The mark returned is like a handle since it
- // indicates the array of the marking track where
- // the address is stored within the LLIST_C class
- // and not the address itself. The application
- // passes back the mark handle via LLIST_C::GoMark.
- // After GoMark, the current position in the list
- // is reset and data accessible via:
- //
- // GetCur()
- // AddAfterCur()
- // AddBeforeCur()
- // DeleteCur()
- //
- //
- // Parameters
- // In: SAME
- // Out: PSHORT = marker handle
- // = C_UNAVAIL = no marker slots left
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::SetMark(PSHORT psTrack)
- {
- C_DEF_MODULE("LLIST_C::SetMark")
-
- *psTrack = C_UNAVAIL;
-
- for(SHORT sCnt = 0; sCnt < sTrackSize; sCnt++)
- if(pstTrack[sCnt].sState == TRACK_AVAIL)
- break;
-
- if(sCnt < sTrackSize)
- {
- pstTrack[sCnt].pstNode = pstCurNode;
- pstTrack[sCnt].sState = TRACK_USED;
- *psTrack = sCnt;
- }
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: GoMark
- //
- // Class: LLIST_C
- //
- // Security: Public
- //
- // Description: Set current link list node to previous mark
- //
- // Parameters
- // In: Marker/track handle to set to
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK = Success
- // = C_NOTOK = bad handle
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::GoMark(SHORT sTrack)
- {
- C_DEF_MODULE("LLIST_C::GoMark")
-
- if(
- (sTrack > C_UNAVAIL) &&
- (sTrack < sTrackSize) &&
- (pstTrack[sTrack].sState = TRACK_USED)
- )
- {
-
- pstCurNode = pstTrack[sTrack].pstNode;
- }
- else
- C_SET_STATUS(C_NOTOK);
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: ReleaseMark
- //
- // Class: LLIST_C
- //
- // Security: Public
- //
- // Description: Release/Free a Mark for re-use
- //
- // Parameters
- // In: Marker/track handle to set to
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK = Success
- // = C_NOTOK = bad handle
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::ReleaseMark(SHORT sTrack)
- {
- C_DEF_MODULE("LLIST_C::ReleaseMark")
-
- if(
- (sTrack > C_UNAVAIL) &&
- (sTrack < sTrackSize) &&
- (pstTrack[sTrack].sState = TRACK_USED)
- )
- {
-
- pstTrack[sTrack].pstNode = NULL;
- pstTrack[sTrack].sState = TRACK_AVAIL;
- }
- else
- C_SET_STATUS(C_NOTOK);
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: GetCur
- //
- // Class: LLIST_C
- //
- // Security: Public
- //
- // Description: Get the data for the current link list member/node
- // Usefull after call to GoMark
- //
- // Parameters
- // In: SAME
- // Out: PPVOID = address of current item in list, does not
- // remove item from list
- //
- // Return Codes: SHORT = C_OK = Item was returned
- // = C_NOTOK = No item to return
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::GetCur(PPVOID ppVoid)
- {
- C_DEF_MODULE("LLIST_C::GetCur")
-
- if(pstCurNode != NULL)
- {
- (*ppVoid) = pstCurNode -> pvData;
- }
- else
- {
- (*ppVoid) = NULL;
- C_SET_STATUS(C_NOTOK);
- }
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: AddAfterNode
- //
- // Class: LLIST_C
- //
- // Security: Protected
- //
- // Description: Add node after another node, for use by derived
- // classes, not applications
- //
- // Parameters
- // In: LLIST_P = node to add after
- // LLIST_P = node to add
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK = Success
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- // 16-Feb-1992 Tal v 1.0-002 Support for empty lists
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::AddAfterNode(LLIST_P pstPrev, LLIST_P pstNew)
- {
- C_DEF_MODULE("LLIST_C::AddAfterNode")
-
- LLIST_P pstTemp = NULL;
-
- if(pstPrev != NULL) // fixed 16-Feb-92 Tal
- pstNew -> pstNext = pstPrev -> pstNext;
- pstNew -> pstPrev = pstPrev;
-
- if(pstPrev != NULL) // fixed 16-Feb-92 Tal
- {
- pstTemp = pstPrev -> pstNext;
- pstPrev -> pstNext = pstNew;
- }
-
- if(pstTemp != NULL)
- pstTemp -> pstPrev = pstNew;
-
- pstCurNode = pstNew;
-
- if(pstHead == NULL) // fixed 16-Feb-92 Tal
- pstHead = pstCurNode;
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: AddBeforeNode
- //
- // Class: LLIST_C
- //
- // Security: Protected
- //
- // Description: Add node directly before another one. For use by
- // derived classes.
- //
- // Parameters
- // In: LLIST_P = Node to add before
- // LLIST_P = Node to add
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::AddBeforeNode(LLIST_P pstPrev, LLIST_P pstNew)
- {
- C_DEF_MODULE("LLIST_C::AddBeforeNode")
-
- LLIST_P pstTemp;
-
- if(pstPrev == pstHead)
- {
- pstHead = pstNew;
- pstPrev -> pstPrev = pstNew;
- pstNew -> pstNext = pstPrev;
- }
- else
- {
- pstTemp = pstPrev -> pstPrev;
- pstTemp -> pstNext = pstNew;
- pstPrev -> pstPrev = pstNew;
- pstNew -> pstNext = pstPrev;
- }
-
- pstCurNode = pstNew;
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: AddAfterCur
- //
- // Class: LLIST_C
- //
- // Security: Public
- //
- // Description: Call Find before this to set the current node
- // internally, then call this function
- //
- // Parameters
- // In: PVOID = Data to add
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK = Added
- // = C_NOTOK = Not Added
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::AddAfterCur(PVOID pvData)
- {
- C_DEF_MODULE("LLIST_C::AddAfterCur")
-
- LLIST_P pstNew;
-
-
- C_STATUS = Alloc(pvData,&pstNew);
-
- if(C_STATUS)
- C_LEAVE(C_STATUS);
-
- C_STATUS = AddAfterNode(pstCurNode,pstNew);
-
- C_MODULE_EXIT:
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: AddBeforeCur
- //
- // Class: LLIST_C
- //
- // Security: Public
- //
- // Description: Call Find before this to set the current node
- // internally, then call this function.
- //
- // Parameters
- // In: PVOID = Address/data to add
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK = Added
- // = C_NOTOK = Not added
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::AddBeforeCur(PVOID pvData)
- {
- C_DEF_MODULE("LLIST_C::AddBeforeCur")
-
- LLIST_P pstNew;
-
- C_STATUS = Alloc(pvData,&pstNew);
-
- if(C_STATUS)
- C_LEAVE(C_STATUS);
-
- C_STATUS = AddBeforeNode(pstCurNode,pstNew);
-
- C_MODULE_EXIT:
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: DeleteNode
- //
- // Class: LLIST_C
- //
- // Security: Protected
- //
- // Description: Explicitly delete a node, for use by derived classes.
- //
- // Parameters
- // In: LLIST_P = Node to delete
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::DeleteNode(LLIST_P pstNode)
- {
- C_DEF_MODULE("LLIST_C::DeleteNode")
-
- LLIST_P pstTemp;
-
- if(pstNode == pstHead)
- {
- pstHead = pstHead -> pstNext;
- if(pstHead != NULL)
- pstHead -> pstPrev = NULL;
- }
- else
- {
- pstTemp = pstNode -> pstNext;
- if(pstTemp != NULL)
- pstTemp -> pstPrev = pstNode -> pstPrev;
- pstTemp = pstNode -> pstPrev;
- pstTemp -> pstNext = pstNode -> pstNext;
- }
-
- delete pstNode;
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: DeleteCur
- //
- // Class: LLIST_C
- //
- // Security: Public
- //
- // Description: Delete current member/node
- // See GoMark,
- // Find,
- // FindFirst,
- // FindLast
- //
- // Parameters: VOID
- //
- // Return Codes: SHORT = C_OK = Deleted
- // = C_NOTOK = Not deleted
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::DeleteCur(VOID)
- {
- C_DEF_MODULE("LLIST_C::DeleteCur")
-
- LLIST_P pstTemp;
-
- if(pstCurNode != NULL)
- {
- C_STATUS = DeleteNode(pstCurNode);
- pstCurNode = NULL;
- }
- else
- C_SET_STATUS(C_NOTOK);
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: FindNode
- //
- // Class: LLIST_C
- //
- // Security: Protected
- //
- // Description: Search for entry in list by key, returns node
- //
- // Parameters
- // In: PVOID = Pointer to key
- // Out: LLIST_PP = Pointer to node found or NULL
- //
- // Return Codes: SHORT = C_OK = Data Found
- // = C_NOTOK = Data not found
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
-
- SHORT LLIST_C::FindNode(PVOID pvData, LLIST_PP ppstNode)
- {
- C_DEF_MODULE("LLIST_C::FindNode")
-
- LLIST_P pstNode = NULL;
- SHORT sTemp;
-
- (*ppstNode) = NULL;
-
- pstCurNode = NULL; // fixup object global
-
-
- pstNode = pstHead;
-
- if(pstNode != NULL)
- {
- while ( (sTemp=((*pCompareFunc)(pvData,pstNode -> pvData)) ) != 0)
- {
- pstNode = pstNode -> pstNext;
-
- if(pstNode == NULL)
- break;
- }
- }
-
- if(pstNode != NULL)
- if( ((*pCompareFunc)(pvData,pstNode -> pvData)) != 0)
- pstNode = NULL;
- else
- pstCurNode = pstNode; // set as found node
-
- *ppstNode = pstNode;
-
- C_MODULE_EXIT:
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Find
- //
- // Class: LLIST_C
- //
- // Security: Public
- //
- // Description: Search for entry in list by key
- //
- // Parameters
- // In: PVOID = Pointer to key
- // Out: PPVOID = Pointer to data found or NULL
- //
- // Return Codes: SHORT = C_OK = Data Found
- // = C_NOTOK = Data not found
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
-
- SHORT LLIST_C::Find(PVOID pvData, PPVOID ppVoid)
- {
- C_DEF_MODULE("LLIST_C::Find")
-
- LLIST_P pstNode = NULL;
-
- (*ppVoid) = NULL;
-
-
- C_STATUS = FindNode(pvData,&pstNode);
-
- C_IF_STATUS
-
- C_STATUS = GetCur(ppVoid);
-
- C_MODULE_EXIT:
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: FindLast
- //
- // Class: LLIST_C
- //
- // Security: Public
- //
- // Description: Find data for last member in list
- //
- // Parameters
- // In: SAME
- // Out: PPVOID = Returned address of data found or NULL
- //
- // Return Codes: SHORT = C_OK = Data found
- // = C_NOTOK = No data in list
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::FindLast(PPVOID ppVoid)
- {
- C_DEF_MODULE("LLIST_C::FindLast")
-
- LLIST_P pstNode;
-
- *ppVoid = NULL;
-
- C_STATUS = FindLastNode(&pstNode);
-
- if(pstNode != NULL)
- (*ppVoid) = pstNode -> pvData;
- else
- (*ppVoid) = NULL;
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: FindLastNode
- //
- // Class: LLIST_C
- //
- // Security: Protected
- //
- // Description: Searches for last member in list, returns node
- // For use by derived functions, not applications
- //
- // Parameters
- // In: SAME
- // Out: LLIST_PP = Pointer to Node returned or NULL if none
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::FindLastNode(LLIST_PP ppstNode)
- {
- C_DEF_MODULE("LLIST_C::FindLastNode")
-
- LLIST_P pstNode = NULL;
- LLIST_P pstPrev = NULL;
-
- pstNode = pstHead;
-
- while(pstNode != NULL)
- {
- pstPrev = pstNode;
- pstNode = pstNode -> pstNext;
- }
-
- pstNode = pstPrev;
-
- pstCurNode = pstNode;
-
- (*ppstNode) = pstNode;
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: FindFirst
- //
- // Class: LLIST_C
- //
- // Security: Public
- //
- // Description: Returns data/address of first member pointed to in
- // list.
- //
- // Parameters
- // In: SAME
- // Out: PPVOID = Address of first item tracked or NULL
- //
- // Return Codes: SHORT = C_OK = Item returned
- // = C_NOTOK = No data found
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::FindFirst(PPVOID ppvVoid)
- {
- C_DEF_MODULE("LLIST_C::FindFirst")
-
- (*ppvVoid) = NULL;
-
- if(pstHead != NULL)
- {
- (*ppvVoid) = (PVOID) pstHead -> pvData;
-
- pstCurNode = pstHead;
-
- }
- else
- C_SET_STATUS(C_NOTOK)
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: GetNext
- //
- // Class: LLIST_C
- //
- // Security: Public
- //
- // Description: Returns data/address of next member pointed to in
- // list.
- //
- // Parameters
- // In: SAME
- // Out: PPVOID = Address of next item tracked or NULL
- //
- // Return Codes: SHORT = C_OK = Item returned
- // = C_NOTOK = No data found
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::GetNext(PPVOID ppvVoid)
- {
- C_DEF_MODULE("LLIST_C::GetNext")
-
- (*ppvVoid) = NULL;
-
- if(pstCurNode != NULL)
- {
- pstCurNode = pstCurNode -> pstNext;
-
- (*ppvVoid) = pstCurNode;
- }
- else
- C_SET_STATUS(C_NOTOK)
-
- C_RETURN
- }
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: GetPrev
- //
- // Class: LLIST_C
- //
- // Security: Public
- //
- // Description: Returns data/address of Previous member pointed to in
- // list.
- //
- // Parameters
- // In: SAME
- // Out: PPVOID = Address of previous item tracked or NULL
- //
- // Return Codes: SHORT = C_OK = Item returned
- // = C_NOTOK = No data found
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::GetPrev(PPVOID ppvVoid)
- {
- C_DEF_MODULE("LLIST_C::GetPrev")
-
- (*ppvVoid) = NULL;
-
- if(pstCurNode != NULL)
- {
- if(pstCurNode -> pstPrev != NULL)
- {
- pstCurNode = pstCurNode -> pstPrev;
-
- (*ppvVoid) = pstCurNode;
- }
- else
- C_SET_STATUS(C_NOTOK);
- }
- else
- C_SET_STATUS(C_NOTOK)
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Alloc
- //
- // Class: LLIST_C
- //
- // Security: Protected
- //
- // Description: Allocates a new member
- //
- // Parameters
- // In: PVDATA = Key to insert
- // Out: LLIST_PP = New Node address
- //
- // Return Codes: SHORT = C_OK = Allocated
- // = C_NOTOK = Not allocated
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::Alloc(PVOID pvData, LLIST_PP ppstNode)
- {
- C_DEF_MODULE("LLIST_C::Alloc")
-
- (*ppstNode) = new LLIST_T;
-
- (*ppstNode) -> pstPrev = NULL;
- (*ppstNode) -> pstNext = NULL;
-
- if(*ppstNode != NULL)
- (*ppstNode) -> pvData = pvData;
- else
- C_SET_STATUS(C_NOTOK)
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Insert
- //
- // Class: LLIST_C
- //
- // Security: Public
- //
- // Description: Insert an item into the list
- //
- // Parameters
- // In: PVOID = Address of data to insert
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::Insert(PVOID pvData)
- {
- C_DEF_MODULE("LLIST_C::Insert")
-
- LLIST_P pstPrev = NULL;
- LLIST_P pstNode;
-
- LLIST_P pstNew;
-
-
- C_STATUS = Alloc(pvData,&pstNew);
-
- if(C_STATUS)
- C_LEAVE(C_STATUS);
-
- pstCurNode = pstNew;
-
-
- if(pstHead == NULL)
- {
- pstHead = pstNew;
- }
- else
- {
- pstNode = pstHead;
-
- while( ((*pCompareFunc)(pstNode -> pvData, pstNew -> pvData)) < 0)
- {
- pstPrev = pstNode;
- pstNode = pstNode -> pstNext;
- if(pstNode == NULL)
- break;
- }
-
- if(pstPrev == NULL)
- AddBeforeNode(pstNode,pstNew);
- else
- AddAfterNode(pstPrev,pstNew); // big change from binary, uses
- // prev ptr found here
-
- } // if node != NULL
-
- C_MODULE_EXIT:
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: UnlinkNode
- //
- // Class: LLIST_C
- //
- // Security: Protected
- //
- // Description: Unlinks a node from the list, does not free()
- // Function was in C libraries, must evaluate
- // existing benefits for derived or public.
- //
- // Parameters
- // In: LLIST_P = Node to unlink
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::UnlinkNode(LLIST_P pstNode)
- {
- C_DEF_MODULE("LLIST_C::UnlinkNode")
-
- LLIST_P pstTemp;
-
- if(pstNode == pstHead)
- {
- pstHead = pstHead -> pstNext;
- if(pstHead != NULL)
- pstHead -> pstPrev = NULL;
- }
- else
- {
- pstTemp = pstNode -> pstNext;
- if(pstTemp != NULL)
- pstTemp -> pstPrev = pstNode -> pstPrev;
- pstTemp = pstNode -> pstPrev;
- pstTemp -> pstNext = pstNode -> pstNext;
- }
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Vacate
- //
- // Class: LLIST_C
- //
- // Security: Public
- //
- // Description: Removes all items from a list
- //
- // Parameters
- // In: BOOL = C_TRUE = free data pointed to
- // = C_FALSE = do not free data pointed to, only
- // list itself
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT LLIST_C::Vacate(BOOL fFreeData)
- {
- C_DEF_MODULE("LLIST_C::Vacate")
-
- LLIST_P pstTemp; // working pointer
- LLIST_P pstFree;
-
- pstTemp = pstHead;
-
- //
- // Spin through list from head to end
- //
-
- while(pstTemp != NULL)
- {
- //
- // If free the data and data to free then free
- //
-
- if(fFreeData)
- if(pstTemp -> pvData != NULL)
- delete pstTemp -> pvData;
-
-
- //
- // Delete the member itself
- //
-
- pstFree = pstTemp;
- pstTemp = pstTemp -> pstNext;
-
- DeleteNode(pstFree);
-
- }
-
- //
- // Reset the pointer sent in, should be NULL now
- //
-
- pstHead = pstTemp;
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: TREE_C
- //
- // Class: TREE_C
- //
- // Security: Public Constructor
- //
- // Description: Initializes a tree
- //
- // Parameters: VOID
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- TREE_C::TREE_C(VOID)
- {
- C_DEF_VMODULE("TREE_C::TREE_C")
-
- pstHead = NULL;
- pstNode = NULL;
- pCompareFunc = NULL;
-
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: ~TREE_C
- //
- // Class: TREE_C
- //
- // Security Public Destructor
- //
- // Description: Removes all items from a tree
- //
- // Parameters
- // In: BOOL = C_TRUE = free data pointed to
- // = C_FALSE = free only tree itself
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- TREE_C::~TREE_C(VOID)
- {
- C_DEF_VMODULE("TREE_C::~TNODE_C")
-
- Vacate(C_FALSE);
-
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: SetCompareFunc
- //
- // Class: TREE_C
- //
- // Security Public
- //
- // Description: Set the compare function for tree data
- //
- // Parameters
- // In: SHORT (*)(PVOID,PVOID)
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT TREE_C::SetCompareFunc(SHORT (*pFunc)(PVOID,PVOID))
- {
- C_DEF_MODULE("TREE_C::SetCompareFunc")
-
- pCompareFunc = pFunc;
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Vacate
- //
- // Class: TREE_C
- //
- // Security Public
- //
- // Description: Called by ~TREE_C or application
- //
- // Performs non-recursive removal of all a node and all its
- // children. If used on the root of a tree, the entire
- // tree is removed.
- //
- // Recursion is great, BUT, recursion relies heavily on
- // the stack. Large amounts of recursion and stack pushing
- // will result in stack-overflow or core dump.
- //
- // Dymnamic memory from heap (or system memory) is generally
- // more abundant than stack bytes. So here we use the
- // STACK_C routines which alloc from the compiler heap.
- //
- //
- // Parameters
- // In: BOOL = C_TRUE = free data pointed to
- // = C_FALSE = free only tree itself
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT TREE_C::Vacate(BOOL fFreeData)
- {
- C_DEF_MODULE("TREE_C::Vacate")
-
- TNODE_P pstNode; // main working TNODE_P var
- BOOL bEmpty; // whether stack is empty or not
- TNODE_P pstDeleteNode; // working TNODE_P for delete
- PVOID pvWork; // hold area for TNODE_P after pop
-
- STACK_C clStack; // Stack object
-
-
-
- pstNode = pstHead;
-
- do
- {
- while( pstNode != NULL )
- {
-
- // For non-recursive delete on a binary tree,
- // follow left-size of tree and find left-most node.
- // Drop a marker of the trail down by pushing addresses
- // of the nodes as we go down. Then we can pop them
- // to go back up the tree.
-
- clStack.Push((PVOID) pstNode);
- pstNode = pstNode -> pstLeft;
-
- }
-
- clStack.IsEmpty(&bEmpty);
-
- if( !bEmpty )
- {
-
- // As far left as we can go, we are currently at a NULL
- // so pop off the last node (furthest left)
-
- clStack.Pop(&pvWork);
-
- pstNode = (TNODE_P) pvWork;
-
-
- // Got a node to delete, check if also free pvData;
-
- if(fFreeData && (pstNode -> pvData != NULL))
- {
- free(pstNode -> pvData);
- pstNode -> pvData = NULL;
- }
-
- pstDeleteNode = pstNode;
-
-
- // Now try and go to the right. We would then follow the
- // same logic above by now falling down to the left-most
- // node of our right sibling
-
-
- pstNode = pstNode -> pstRight;
-
- // Free the node we were just at (left-most parent)
-
- free(pstDeleteNode);
-
- }
-
- clStack.IsEmpty(&bEmpty);
-
- } while ( (pstNode != NULL) && (! bEmpty) );
-
-
- // Reset tree head pointer
-
- pstHead = NULL;
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Insert
- //
- // Class: TREE_C
- //
- // Security: Public
- //
- // Description: Insert a node/data into tree. It calls Ins()
- // which then performs recursive walk down the tree.
- //
- // Parameters
- // In: PVOID = data to insert
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- // C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT TREE_C::Insert(PVOID pvDataParm)
- {
- C_DEF_MODULE("TREE_C::Insert")
-
- TNODE_P pstNewNode;
-
- pstNewNode = new TNODE_T;
- pstNewNode -> pstLeft = NULL;
- pstNewNode -> pstRight = NULL;
-
- pstNewNode -> pvData = pvDataParm;
-
- Ins(&pstHead,pstNewNode);
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Ins
- //
- // Class: TREE_C
- //
- // Security: Private
- //
- // Description: Workhorse recursive function for insert
- //
- // Parameters
- // In: TNODE_P = Working head node
- // TNODE_P = Node to insert
- // Out: NONE
- //
- // Return Codes: VOID
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- VOID TREE_C::Ins(TNODE_PP ppstWorkHead, TNODE_P pstNewNode)
- {
- C_DEF_VMODULE("TREE_C::Ins")
-
- if((*ppstWorkHead) == NULL)
- {
- (*ppstWorkHead) = pstNewNode;
- }
- else
- {
- if( ((*pCompareFunc)((*ppstWorkHead) -> pvData,pstNewNode -> pvData)) >= 0)
- Ins(&(*ppstWorkHead) -> pstLeft, pstNewNode);
- else
- Ins(&(*ppstWorkHead) -> pstRight, pstNewNode);
-
- }
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Leaf
- //
- // Class: TREE_C
- //
- // Security: Private
- //
- // Description: Determines if a node is terminal
- // (no left or right children)
- //
- // Parameters
- // In: TNODE_P = node to check
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT TREE_C::Leaf(TNODE_P pstNode)
- {
- C_DEF_MODULE("TREE_C::Leaf")
-
- if(
- (pstNode -> pstLeft == NULL) &&
- (pstNode -> pstRight == NULL)
- )
- C_SET_STATUS(C_TRUE)
- else
- C_SET_STATUS(C_FALSE)
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: RotateLeft
- //
- // Class: TREE_C
- //
- // Security: Private
- //
- // Description: Rotates a node to the left.
- // Called during node deletion
- //
- // Parameters:
- // In: TNODE_P = Node to rotate
- // Out: TNODE_PP = New node address
- //
- // Return Codes: VOID
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- VOID TREE_C::RotateLeft(TNODE_P pstNode, TNODE_PP ppstNode)
- {
- C_DEF_VMODULE("TREE_C::RotateLeft")
-
- TNODE_P pstTempNode = pstNode;
-
- if(pstNode != NULL)
- {
- pstNode = pstNode -> pstRight;
- pstTempNode -> pstRight = pstNode -> pstLeft;
- pstNode -> pstLeft = pstTempNode;
- }
-
- (*ppstNode) = pstNode;
-
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: RotateRight
- //
- // Class: TREE_C
- //
- // Security: Private
- //
- // Description: Rotates a node to the right.
- // Called during node deletion
- //
- // Parameters:
- // In: TNODE_P = Node to rotate
- // Out: TNODE_PP = New node address
- //
- // Return Codes: VOID
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- VOID TREE_C::RotateRight(TNODE_P pstNode, TNODE_PP ppstNode)
- {
- C_DEF_VMODULE("TREE_C::RotateRight")
-
- TNODE_P pTempNode = pstNode;
-
- if(pstNode != NULL)
- {
- pstNode = pstNode -> pstLeft;
- pTempNode -> pstLeft = pstNode -> pstRight;
- pstNode -> pstRight = pTempNode;
- }
-
- (*ppstNode) = pstNode;
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Delete
- //
- // Class: TREE_C
- //
- // Security: Public
- //
- // Description: Node deletion based on key/data.
- // Calls Del()
- //
- // Parameters
- // In: PVOID = data to remove
- // Out: NONE
- //
- // Return Codes: VOID
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT TREE_C::Delete(PVOID pvData)
- {
- C_DEF_MODULE("TREE_C::Delete")
-
- C_STATUS = Del(pvData,pstHead,&pstHead);
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Del
- //
- // Class: TREE_C
- //
- // Security: Private
- //
- // Description: Performs recursive node deletion
- //
- // Parameters
- // In: PVOID = data to remove
- // TNODE_P = Current node/head
- // Out: TNODE_PP = New node/head
- //
- // Return Codes: SHORT = C_OK = success
- // = C_NOTOK = failed, key not in tree
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT TREE_C::Del(PVOID pvData,TNODE_P pstNode, TNODE_PP ppstNode )
- {
- C_DEF_MODULE("TREE_C::Del")
-
- if(pstNode == NULL)
- {
- (*ppstNode) = NULL;
- return C_NOTOK;
- }
-
- if( ((*pCompareFunc)(pvData,pstNode -> pvData)) == 0)
- {
- if(Leaf(pstNode))
- {
- delete pstNode;
- (*ppstNode) = NULL;
-
- return C_OK;
- }
- else
- {
- if(pstNode -> pstLeft != NULL)
- {
- RotateRight(pstNode,&pstNode);
- Del(pvData,pstNode,&pstNode);
- }
- else
- {
- RotateLeft(pstNode,&pstNode);
- Del(pvData,pstNode,&pstNode);
- }
-
- }
- }
- else
- {
- if( ((*pCompareFunc)(pvData, pstNode -> pvData)) < 0)
- Del(pvData, pstNode -> pstLeft,&pstNode -> pstLeft);
- else
- Del(pvData, pstNode -> pstRight,&pstNode -> pstRight);
- }
-
- (*ppstNode) = pstNode;
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Find
- //
- // Class: TREE_C
- //
- // Security: Private
- //
- // Description: Finds a node based on key
- //
- // Parameters
- // In: PVOID = Key of Data to find
- // Out: PPVOID = Pointed to data returned
- //
- // Return Codes: VOID
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT TREE_C::Find(PVOID pvData,PPVOID ppvData)
- {
- C_DEF_MODULE("TREE_C::Find")
-
- TNODE_P pstNode;
- SHORT sCmp;
-
- (*ppvData) = NULL; // 16-Feb-92 Tal, support empty tree
-
- pstNode = pstHead;
-
- if(pstNode != NULL)
- {
- while(pstNode != NULL)
- {
- sCmp = (*pCompareFunc)(pvData,pstNode -> pvData);
-
- if( sCmp == 0 )
- break;
- else if( sCmp > 0 )
- pstNode = pstNode -> pstRight;
- else
- pstNode = pstNode -> pstLeft;
- }
- }
-
- if(pstNode != NULL) // 16-Feb-92 Tal, support empty tree
- (*ppvData) = pstNode -> pvData;
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: IsEmpty
- //
- // Class: STACK_C
- //
- // Security: Public
- //
- // Description: Checks if the stack is empty
- //
- // Parameters
- // In: SAME
- // Out: PBOOL = C_TRUE = Is Empty
- // = C_FALSE = Not Empty
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT STACK_C::IsEmpty(PBOOL fIsEmpty)
- {
- C_DEF_MODULE("STACK_C::IsEmpty")
-
- if(pstHead == NULL)
- *fIsEmpty = C_TRUE;
- else
- *fIsEmpty = C_FALSE;
-
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Pop
- //
- // Class: STACK_C
- //
- // Security: Public
- //
- // Description: Removes an element from stack
- //
- // Parameters
- // In: SAME
- // Out: PPVOID = Address of returned item or NULL
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT STACK_C::Pop(PPVOID ppvData)
- {
- C_DEF_MODULE("STACK_C::Pop")
-
- LLIST_P pstOldHead;
-
-
- if( pstHead != NULL )
- {
- // To modify a pointer inside of a function requires
- // sending in the address of the pointer.
-
- *ppvData = pstHead -> pvData;
-
-
- // Reset to new stack head pointer
-
- pstOldHead = pstHead;
-
- pstHead = pstHead -> pstNext;
-
-
- // Free the old stack head pointer
-
- free(pstOldHead);
-
- }
- else
- {
- // Stack is empty, return NULL
-
- *ppvData = NULL;
- }
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Push
- //
- // Class: STACK_C
- //
- // Security: Public
- //
- // Description: Places an item on the stack
- //
- // Parameters
- // In: PVOID = Address of data to store
- // Out: SAME
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT STACK_C::Push(PVOID pvData)
- {
- C_DEF_MODULE("STACK_C::Push")
-
- LLIST_P pstNew;
-
- C_STATUS = Alloc(pvData,&pstNew); // allocate new member
-
- if(C_STATUS)
- C_LEAVE(C_STATUS);
-
- pstNew -> pstNext = pstHead;
-
- pstHead = pstNew;
-
- C_MODULE_EXIT:
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Vacate
- //
- // Class: STACK_C
- //
- // Security: Public
- //
- // Description: Removes all items from stack
- //
- // Parameters
- // In: BOOL = C_FALSE = Free only stack, not pointed to data
- // = C_TRUE = Free stack and pointed to data
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT STACK_C::Vacate(BOOL fFreeData)
- {
- C_DEF_MODULE("STACK_C::Vacate")
-
- PVOID pvData;
-
- while(pstHead != NULL)
- {
- Pop(&pvData);
-
- if(fFreeData)
- if(pvData != NULL)
- free(pvData);
- }
-
- pstHead = NULL;
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: Find
- //
- // Class: STACK_C
- //
- // Security: Public
- //
- // Description: Find an entry
- //
- // Parameters
- // In: PVOID = Address of key data to search for
- // Out: PPVOID = Address of returned data (NULL if not found)
- //
- // Return Codes: VOID
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT STACK_C::Find(PVOID pvData,PPVOID ppVoid)
- {
- C_DEF_MODULE("STACK_C:Find")
-
- C_STATUS = LLIST_C::Find(pvData,ppVoid);
-
- C_RETURN
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //+
- // Function Name: SetCompareFunc
- //
- // Class: STACK_C
- //
- // Security Public
- //
- // Description: Set the compare function for link list data
- //
- // Parameters
- // In: SHORT (*)(PVOID,PVOID)
- // Out: NONE
- //
- // Return Codes: SHORT = C_OK
- //
- // Written by: John Tal
- //
- //
- // Modification History:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- //
- //-
- ////////////////////////////////////////////////////////////////////////
-
- SHORT STACK_C::SetCompareFunc(SHORT (*pFunc)(PVOID,PVOID))
- {
- C_DEF_MODULE("STACK_C::SetCompareFunc")
-
- pCompareFunc = pFunc;
-
- C_RETURN
- }
-