--- mstools/samples/deb/linklist.h 2018/08/09 18:20:39 1.1 +++ mstools/samples/deb/linklist.h 2018/08/09 18:23:35 1.1.1.3 @@ -1,91 +1,72 @@ -// ************************************************************************ -// LinkList.H - (Ordered) Double Linked List Header -// ************************************************************************ -// PURPOSE: Provide a generalized sorted double linked list package -// -// FUNCTIONS: -// InitList - initialize/clear list -// CreateNode - allocate a new node that can be put into list -// InsertNode - insert a new node into the list -// DeleteCurrentNode - remove a node from the list -// GetNextNode - get the next (right) node from the CurrentNode -// GetPreviousNode - get the previous (left) node from the -// CurrentNode -// GetNode - get nth Occurence of a node that matches a -// key(s) -// GetListError - get the error value -// -// COMMENTS: The application must serialize access to the linked list -// -// Format of the Ordering and Matching functions is as follows: -// -// int OrderFunc( PNODE pNodeOne, PNODE pNodeTwo ) -// { -// if( (pNodeOne->NodeData).Key < (pNodeTwo->NodeData).Key ) -// return( LEFT_OF ); -// if( (pNodeOne->NodeData).Key == (pNodeTwo->NodeData).Key ) -// return( MATCH ); -// if( (pNodeOne->NodeData).Key > (pNodeTwo->NodeData).Key ) -// return( RIGHT_OF ); -// } -// -// ************************************************************************ -#include // for DWORD definition only - -#define NO_ERROR_FOUND 1 -#define NO_FREE_MEM_ERROR -1 -#define NO_NODE_ERROR -2 -#define NO_MATCH_ERROR -3 -#define NO_NEXT_NODE_ERROR -4 -#define NO_PREV_NODE_ERROR -5 - -#define DEREFERENCE_NULL_ERROR -99 - -#define LEFT_OF -1 -#define MATCH 0 -#define OVERWRITE 0 -#define RIGHT_OF 1 - -// ************************************************************************ -// the NODE_DATA type should be modified to suit needs - -typedef struct NODE_DATA_STRUCT { - DWORD dwThreadId; - HANDLE hThread; - } NODE_DATA; - -//* End of custom NODE_DATA definition -// ************************************************************************ - -typedef struct NODE_STRUCT* PNODE; - -//-- definition of a node -typedef struct NODE_STRUCT { - NODE_DATA NodeData; - PNODE pLeftLink; - PNODE pRightLink; - } NODE; - -//-- definition of a list -typedef struct LIST_STRUCT* PLIST; - -typedef struct LIST_STRUCT { - int ListError; - PNODE pFirstNode; - PNODE pCurrentNode; - PNODE pLastNode; - int (*OrderFunction)(PNODE, PNODE); - } LIST; - -//-- prototypes -int GetListError( PLIST pList ); -int InitList( PLIST pList, int (*OrderingFunction)( PNODE pNodeOne, PNODE pNodeTwo ) ); -int CreateNode( PLIST pList, PNODE* pNewNode ); -int InsertNode( PLIST pList, PNODE pNewNode ); -int DestroyNode( PNODE pNode ); -int DeleteCurrentNode( PLIST pList ); -int GetNextNode( PLIST pList, PNODE* ppNode ); -int GetPreviousNode( PLIST pList, PNODE* ppNode ); -int GetNode( PLIST pList, PNODE* pKeyNode, - int (*MatchingFunction)( PNODE pNodeOne, PNODE pNodeTwo ), - int Occurence ); + +/******************************************************************************\ +* This is a part of the Microsoft Source Code Samples. +* Copyright (C) 1993 Microsoft Corporation. +* All rights reserved. +* This source code is only intended as a supplement to +* Microsoft Development Tools and/or WinHelp documentation. +* See these sources for detailed information regarding the +* Microsoft samples programs. +\******************************************************************************/ + +#ifndef LINKLIST_H + + #define LINKLIST_H + + // public typedefs and defines + // ----------------------------------------------------------------------- + #define LIST_NO_ERROR 1 + #define LIST_ERROR_NO_NODE -1 + #define LIST_ERROR_NO_MATCH -2 + #define LIST_ERROR_NO_FREE_MEM -3 + #define LIST_ERROR_DEREFERENCE_NULL -99 + + #define LIST_LEFT_OF -1 + #define LIST_MATCH 0 + #define LIST_RIGHT_OF 1 + + #ifndef TRUE + #define TRUE 1 + #define FALSE 0 + typedef int BOOL; + #endif + + typedef void* PVOID; + + //-- definition of a node + typedef struct NODE_STRUCT* PNODE; + typedef struct NODE_STRUCT { + PVOID pNodeData; + PNODE pLeftLink; + PNODE pRightLink; + } NODE; + + //-- definition of a list + typedef struct LIST_STRUCT* PLIST; + typedef struct LIST_STRUCT { + PVOID pListData; + PNODE pFirstNode; + PNODE pCurrentNode; + PNODE pLastNode; + int (*OrderFunction)(PNODE, PNODE); + int ListError; + } LIST; + + // public function prototypes + // ----------------------------------------------------------------------- + BOOL CreateList( PLIST* ppList, int (*OrderFunction)( PNODE pNodeOne, PNODE pNodeTwo ) ); + BOOL CreateNode( PNODE* ppNewNode ); + BOOL InsertNode( PLIST pList, PNODE pNewNode ); + BOOL SetCurrentNode( PLIST pList, PNODE pKeyNode, int (*MatchFunction)( PNODE pNodeOne, PNODE pNodeTwo ) ); + BOOL SetCurrentNodeEx( PLIST pList, PNODE pKeyNode, int (*MatchFunction)( PNODE pNodeOne, PNODE pNodeTwo ), int Occurence ); + BOOL GetCurrentNode( PLIST pList, PNODE* ppNode ); + BOOL GetFirstNode( PLIST pList, PNODE* ppNode ); + BOOL GetLastNode( PLIST pList, PNODE* ppNode ); + BOOL GetNextNode( PLIST pList, PNODE* ppNode ); + BOOL GetPrevNode( PLIST pList, PNODE* ppNode ); + BOOL DeleteCurrentNode( PLIST pList ); + BOOL DestroyNode( PNODE pNode ); + BOOL DestroyList( PLIST pList ); + int GetListError( PLIST pList ); + +#endif // LINKLIST_H