5 * Copyright (c) 2000 by Jean-Claude Batista
19 extern HANDLE RICHED32_hHeap;
21 void CHARLIST_Enqueue( CHARLIST* pCharList, char myChar )
23 CHARLISTENTRY* pNewEntry = HeapAlloc(RICHED32_hHeap, 0,sizeof(CHARLISTENTRY));
24 pNewEntry->pNext = NULL;
25 pNewEntry->myChar = myChar;
27 if(pCharList->pTail == NULL)
29 pCharList->pHead = pCharList->pTail = pNewEntry;
33 CHARLISTENTRY* pCurrent = pCharList->pTail;
34 pCharList->pTail = pCurrent->pNext = pNewEntry;
40 void CHARLIST_Push( CHARLIST* pCharList, char myChar)
42 CHARLISTENTRY* pNewEntry = malloc(sizeof(CHARLISTENTRY));
44 pNewEntry->myChar = myChar;
46 if(pCharList->pHead == NULL)
48 pCharList->pHead = pCharList->pTail = pNewEntry;
49 pNewEntry->pNext = NULL;
54 pNewEntry->pNext = pCharList->pHead;
55 pCharList->pHead = pNewEntry;
61 char CHARLIST_Dequeue(CHARLIST* pCharList)
63 CHARLISTENTRY* pCurrent;
66 if(pCharList->nCount == 0)
70 myChar = pCharList->pHead->myChar;
71 pCurrent = pCharList->pHead->pNext;
72 HeapFree(RICHED32_hHeap, 0,pCharList->pHead);
74 if(pCharList->nCount == 0)
76 pCharList->pHead = pCharList->pTail = NULL;
80 pCharList->pHead = pCurrent;
86 int CHARLIST_GetNbItems(CHARLIST* pCharList)
88 return pCharList->nCount;
91 void CHARLIST_FreeList(CHARLIST* pCharList){
92 while(pCharList->nCount)
93 CHARLIST_Dequeue(pCharList);
96 /* this function count the number of occurences of a caracter */
97 int CHARLIST_CountChar(CHARLIST* pCharList, char myChar)
99 CHARLISTENTRY *pCurrent;
102 for(pCurrent =pCharList->pHead ;pCurrent;pCurrent=pCurrent->pNext)
103 if(pCurrent->myChar == myChar)
109 int CHARLIST_toBuffer(CHARLIST* pCharList, char* pBuffer, int nBufferSize)
112 /* we add one to store a NULL caracter */
113 if(nBufferSize < pCharList->nCount + 1)
114 return pCharList->nCount;
116 for(;pCharList->nCount;pBuffer++)
117 *pBuffer = CHARLIST_Dequeue(pCharList);