5 * Copyright (c) 2000 by Jean-Claude Batista
17 extern HANDLE RICHED32_hHeap
;
19 void CHARLIST_Enqueue( CHARLIST
* pCharList
, char myChar
)
21 CHARLISTENTRY
* pNewEntry
= HeapAlloc(RICHED32_hHeap
, 0,sizeof(CHARLISTENTRY
));
22 pNewEntry
->pNext
= NULL
;
23 pNewEntry
->myChar
= myChar
;
25 if(pCharList
->pTail
== NULL
)
27 pCharList
->pHead
= pCharList
->pTail
= pNewEntry
;
31 CHARLISTENTRY
* pCurrent
= pCharList
->pTail
;
32 pCharList
->pTail
= pCurrent
->pNext
= pNewEntry
;
38 void CHARLIST_Push( CHARLIST
* pCharList
, char myChar
)
40 CHARLISTENTRY
* pNewEntry
= malloc(sizeof(CHARLISTENTRY
));
42 pNewEntry
->myChar
= myChar
;
44 if(pCharList
->pHead
== NULL
)
46 pCharList
->pHead
= pCharList
->pTail
= pNewEntry
;
47 pNewEntry
->pNext
= NULL
;
52 pNewEntry
->pNext
= pCharList
->pHead
;
53 pCharList
->pHead
= pNewEntry
;
59 char CHARLIST_Dequeue(CHARLIST
* pCharList
)
61 CHARLISTENTRY
* pCurrent
;
64 if(pCharList
->nCount
== 0)
68 myChar
= pCharList
->pHead
->myChar
;
69 pCurrent
= pCharList
->pHead
->pNext
;
70 HeapFree(RICHED32_hHeap
, 0,pCharList
->pHead
);
72 if(pCharList
->nCount
== 0)
74 pCharList
->pHead
= pCharList
->pTail
= NULL
;
78 pCharList
->pHead
= pCurrent
;
84 int CHARLIST_GetNbItems(CHARLIST
* pCharList
)
86 return pCharList
->nCount
;
89 void CHARLIST_FreeList(CHARLIST
* pCharList
){
90 while(pCharList
->nCount
)
91 CHARLIST_Dequeue(pCharList
);
94 /* this function count the number of occurences of a caracter */
95 int CHARLIST_CountChar(CHARLIST
* pCharList
, char myChar
)
97 CHARLISTENTRY
*pCurrent
;
100 for(pCurrent
=pCharList
->pHead
;pCurrent
;pCurrent
=pCurrent
->pNext
)
101 if(pCurrent
->myChar
== myChar
)
107 int CHARLIST_toBuffer(CHARLIST
* pCharList
, char* pBuffer
, int nBufferSize
)
110 /* we add one to store a NULL caracter */
111 if(nBufferSize
< pCharList
->nCount
+ 1)
112 return pCharList
->nCount
;
114 for(;pCharList
->nCount
;pBuffer
++)
115 *pBuffer
= CHARLIST_Dequeue(pCharList
);