Changed the CreateDC driver entry point to use an HDC instead of a DC
[wine] / dlls / richedit / charlist.c
1 /*
2  *
3  *  Character List
4  *
5  *  Copyright (c) 2000 by Jean-Claude Batista
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <stddef.h>
26 #include <ctype.h>
27 #include <stdlib.h>
28
29 #include "charlist.h"
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wine/debug.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
35
36 extern HANDLE RICHED32_hHeap;
37
38 void CHARLIST_Enqueue( CHARLIST* pCharList, char myChar )
39 {
40     CHARLISTENTRY* pNewEntry = HeapAlloc(RICHED32_hHeap, 0,sizeof(CHARLISTENTRY));
41     pNewEntry->pNext = NULL;
42     pNewEntry->myChar = myChar;
43
44     TRACE("\n");
45
46     if(pCharList->pTail == NULL)
47     {
48          pCharList->pHead = pCharList->pTail = pNewEntry;
49     }
50     else
51     {
52          CHARLISTENTRY* pCurrent = pCharList->pTail;
53          pCharList->pTail = pCurrent->pNext = pNewEntry;
54     }
55
56     pCharList->nCount++;
57 }
58
59 void CHARLIST_Push( CHARLIST* pCharList, char myChar)
60 {
61     CHARLISTENTRY* pNewEntry = malloc(sizeof(CHARLISTENTRY));
62
63     TRACE("\n");
64
65     pNewEntry->myChar = myChar;
66
67     if(pCharList->pHead == NULL)
68     {
69          pCharList->pHead = pCharList->pTail = pNewEntry;
70          pNewEntry->pNext = NULL;
71
72     }
73     else
74     {
75          pNewEntry->pNext = pCharList->pHead;
76          pCharList->pHead = pNewEntry;
77     }
78
79     pCharList->nCount++;
80 }
81
82 char CHARLIST_Dequeue(CHARLIST* pCharList)
83 {
84     CHARLISTENTRY* pCurrent;
85     char myChar;
86
87     TRACE("\n");
88
89     if(pCharList->nCount == 0)
90       return 0;
91
92     pCharList->nCount--;
93     myChar = pCharList->pHead->myChar;
94     pCurrent = pCharList->pHead->pNext;
95     HeapFree(RICHED32_hHeap, 0,pCharList->pHead);
96
97     if(pCharList->nCount == 0)
98     {
99         pCharList->pHead = pCharList->pTail = NULL;
100     }
101     else
102     {
103         pCharList->pHead = pCurrent;
104     }
105
106     return myChar;
107 }
108
109 int CHARLIST_GetNbItems(CHARLIST* pCharList)
110 {
111     TRACE("\n");
112
113     return pCharList->nCount;
114 }
115
116 void CHARLIST_FreeList(CHARLIST* pCharList){
117     TRACE("\n");
118
119     while(pCharList->nCount)
120         CHARLIST_Dequeue(pCharList);
121 }
122
123 /* this function counts the number of occurrences of a caracter */
124 int CHARLIST_CountChar(CHARLIST* pCharList, char myChar)
125 {
126     CHARLISTENTRY *pCurrent;
127     int nCount = 0;
128
129     TRACE("\n");
130
131     for(pCurrent =pCharList->pHead ;pCurrent;pCurrent=pCurrent->pNext)
132         if(pCurrent->myChar == myChar)
133             nCount++;
134
135     return nCount;
136 }
137
138 int CHARLIST_toBuffer(CHARLIST* pCharList, char* pBuffer, int nBufferSize)
139 {
140
141    TRACE("\n");
142
143    /* we add one to store a NULL caracter */
144    if(nBufferSize < pCharList->nCount + 1)
145         return pCharList->nCount;
146
147    for(;pCharList->nCount;pBuffer++)
148        *pBuffer = CHARLIST_Dequeue(pCharList);
149
150    *pBuffer = '\0';
151
152    return 0;
153 }
154