5 * Copyright (c) 2000 by Jean-Claude Batista
18 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(richedit);
22 extern HANDLE RICHED32_hHeap;
24 void CHARLIST_Enqueue( CHARLIST* pCharList, char myChar )
26 CHARLISTENTRY* pNewEntry = HeapAlloc(RICHED32_hHeap, 0,sizeof(CHARLISTENTRY));
27 pNewEntry->pNext = NULL;
28 pNewEntry->myChar = myChar;
32 if(pCharList->pTail == NULL)
34 pCharList->pHead = pCharList->pTail = pNewEntry;
38 CHARLISTENTRY* pCurrent = pCharList->pTail;
39 pCharList->pTail = pCurrent->pNext = pNewEntry;
45 void CHARLIST_Push( CHARLIST* pCharList, char myChar)
47 CHARLISTENTRY* pNewEntry = malloc(sizeof(CHARLISTENTRY));
51 pNewEntry->myChar = myChar;
53 if(pCharList->pHead == NULL)
55 pCharList->pHead = pCharList->pTail = pNewEntry;
56 pNewEntry->pNext = NULL;
61 pNewEntry->pNext = pCharList->pHead;
62 pCharList->pHead = pNewEntry;
68 char CHARLIST_Dequeue(CHARLIST* pCharList)
70 CHARLISTENTRY* pCurrent;
75 if(pCharList->nCount == 0)
79 myChar = pCharList->pHead->myChar;
80 pCurrent = pCharList->pHead->pNext;
81 HeapFree(RICHED32_hHeap, 0,pCharList->pHead);
83 if(pCharList->nCount == 0)
85 pCharList->pHead = pCharList->pTail = NULL;
89 pCharList->pHead = pCurrent;
95 int CHARLIST_GetNbItems(CHARLIST* pCharList)
99 return pCharList->nCount;
102 void CHARLIST_FreeList(CHARLIST* pCharList){
105 while(pCharList->nCount)
106 CHARLIST_Dequeue(pCharList);
109 /* this function counts the number of occurrences of a caracter */
110 int CHARLIST_CountChar(CHARLIST* pCharList, char myChar)
112 CHARLISTENTRY *pCurrent;
117 for(pCurrent =pCharList->pHead ;pCurrent;pCurrent=pCurrent->pNext)
118 if(pCurrent->myChar == myChar)
124 int CHARLIST_toBuffer(CHARLIST* pCharList, char* pBuffer, int nBufferSize)
129 /* we add one to store a NULL caracter */
130 if(nBufferSize < pCharList->nCount + 1)
131 return pCharList->nCount;
133 for(;pCharList->nCount;pBuffer++)
134 *pBuffer = CHARLIST_Dequeue(pCharList);