Removed a few dependencies on kernel32 functions.
[wine] / dlls / richedit / charlist.c
1 /*
2  * 
3  *  Character List
4  * 
5  *  Copyright (c) 2000 by Jean-Claude Batista
6  *  
7  */
8
9 #include <stdio.h>
10 #include <string.h>
11 #include <stddef.h>
12 #include <ctype.h>
13 #include <stdlib.h>
14 #include "charlist.h"
15 #include "windows.h"
16
17 extern HANDLE RICHED32_hHeap;
18
19 void CHARLIST_Enqueue( CHARLIST* pCharList, char myChar )
20 {   
21     CHARLISTENTRY* pNewEntry = HeapAlloc(RICHED32_hHeap, 0,sizeof(CHARLISTENTRY));
22     pNewEntry->pNext = NULL;
23     pNewEntry->myChar = myChar;
24     
25     if(pCharList->pTail == NULL)
26     {
27          pCharList->pHead = pCharList->pTail = pNewEntry;
28     }
29     else
30     {
31          CHARLISTENTRY* pCurrent = pCharList->pTail;         
32          pCharList->pTail = pCurrent->pNext = pNewEntry;
33     }
34
35     pCharList->nCount++;
36 }
37
38 void CHARLIST_Push( CHARLIST* pCharList, char myChar)
39 {   
40     CHARLISTENTRY* pNewEntry = malloc(sizeof(CHARLISTENTRY));
41     
42     pNewEntry->myChar = myChar;
43     
44     if(pCharList->pHead == NULL)
45     {
46          pCharList->pHead = pCharList->pTail = pNewEntry;
47          pNewEntry->pNext = NULL;
48
49     }
50     else
51     {
52          pNewEntry->pNext = pCharList->pHead;
53          pCharList->pHead = pNewEntry;
54     }
55
56     pCharList->nCount++;
57 }
58
59 char CHARLIST_Dequeue(CHARLIST* pCharList)
60 {
61     CHARLISTENTRY* pCurrent;
62     char myChar;
63
64     if(pCharList->nCount == 0) 
65       return 0;
66     
67     pCharList->nCount--;
68     myChar = pCharList->pHead->myChar;
69     pCurrent = pCharList->pHead->pNext;
70     HeapFree(RICHED32_hHeap, 0,pCharList->pHead);
71  
72     if(pCharList->nCount == 0)
73     {
74         pCharList->pHead = pCharList->pTail = NULL;
75     }
76     else
77     {
78         pCharList->pHead = pCurrent;
79     }
80
81     return myChar;   
82 }
83
84 int CHARLIST_GetNbItems(CHARLIST* pCharList)
85 {
86     return pCharList->nCount;
87 }
88
89 void CHARLIST_FreeList(CHARLIST* pCharList){
90     while(pCharList->nCount)
91         CHARLIST_Dequeue(pCharList);       
92 }
93
94 /* this function count the number of occurences of a caracter */
95 int CHARLIST_CountChar(CHARLIST* pCharList, char myChar)
96 {
97     CHARLISTENTRY *pCurrent;
98     int nCount = 0;
99     
100     for(pCurrent =pCharList->pHead ;pCurrent;pCurrent=pCurrent->pNext)
101         if(pCurrent->myChar == myChar)
102             nCount++;
103     
104     return nCount;
105 }
106
107 int CHARLIST_toBuffer(CHARLIST* pCharList, char* pBuffer, int nBufferSize)
108 {
109    
110    /* we add one to store a NULL caracter */
111    if(nBufferSize < pCharList->nCount + 1) 
112         return pCharList->nCount;
113   
114    for(;pCharList->nCount;pBuffer++)
115        *pBuffer = CHARLIST_Dequeue(pCharList);
116    
117    *pBuffer = '\0';
118
119    return 0;
120 }
121