Don't include windows.h internally.
[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
15 #include "charlist.h"
16 #include "windef.h"
17 #include "winbase.h"
18
19 extern HANDLE RICHED32_hHeap;
20
21 void CHARLIST_Enqueue( CHARLIST* pCharList, char myChar )
22 {   
23     CHARLISTENTRY* pNewEntry = HeapAlloc(RICHED32_hHeap, 0,sizeof(CHARLISTENTRY));
24     pNewEntry->pNext = NULL;
25     pNewEntry->myChar = myChar;
26     
27     if(pCharList->pTail == NULL)
28     {
29          pCharList->pHead = pCharList->pTail = pNewEntry;
30     }
31     else
32     {
33          CHARLISTENTRY* pCurrent = pCharList->pTail;         
34          pCharList->pTail = pCurrent->pNext = pNewEntry;
35     }
36
37     pCharList->nCount++;
38 }
39
40 void CHARLIST_Push( CHARLIST* pCharList, char myChar)
41 {   
42     CHARLISTENTRY* pNewEntry = malloc(sizeof(CHARLISTENTRY));
43     
44     pNewEntry->myChar = myChar;
45     
46     if(pCharList->pHead == NULL)
47     {
48          pCharList->pHead = pCharList->pTail = pNewEntry;
49          pNewEntry->pNext = NULL;
50
51     }
52     else
53     {
54          pNewEntry->pNext = pCharList->pHead;
55          pCharList->pHead = pNewEntry;
56     }
57
58     pCharList->nCount++;
59 }
60
61 char CHARLIST_Dequeue(CHARLIST* pCharList)
62 {
63     CHARLISTENTRY* pCurrent;
64     char myChar;
65
66     if(pCharList->nCount == 0) 
67       return 0;
68     
69     pCharList->nCount--;
70     myChar = pCharList->pHead->myChar;
71     pCurrent = pCharList->pHead->pNext;
72     HeapFree(RICHED32_hHeap, 0,pCharList->pHead);
73  
74     if(pCharList->nCount == 0)
75     {
76         pCharList->pHead = pCharList->pTail = NULL;
77     }
78     else
79     {
80         pCharList->pHead = pCurrent;
81     }
82
83     return myChar;   
84 }
85
86 int CHARLIST_GetNbItems(CHARLIST* pCharList)
87 {
88     return pCharList->nCount;
89 }
90
91 void CHARLIST_FreeList(CHARLIST* pCharList){
92     while(pCharList->nCount)
93         CHARLIST_Dequeue(pCharList);       
94 }
95
96 /* this function count the number of occurences of a caracter */
97 int CHARLIST_CountChar(CHARLIST* pCharList, char myChar)
98 {
99     CHARLISTENTRY *pCurrent;
100     int nCount = 0;
101     
102     for(pCurrent =pCharList->pHead ;pCurrent;pCurrent=pCurrent->pNext)
103         if(pCurrent->myChar == myChar)
104             nCount++;
105     
106     return nCount;
107 }
108
109 int CHARLIST_toBuffer(CHARLIST* pCharList, char* pBuffer, int nBufferSize)
110 {
111    
112    /* we add one to store a NULL caracter */
113    if(nBufferSize < pCharList->nCount + 1) 
114         return pCharList->nCount;
115   
116    for(;pCharList->nCount;pBuffer++)
117        *pBuffer = CHARLIST_Dequeue(pCharList);
118    
119    *pBuffer = '\0';
120
121    return 0;
122 }
123