5 * Copyright (c) 2000 by Jean-Claude Batista
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.
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.
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
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
43 extern HANDLE RICHED32_hHeap;
45 void CHARLIST_Enqueue( CHARLIST* pCharList, char myChar )
47 CHARLISTENTRY* pNewEntry = HeapAlloc(RICHED32_hHeap, 0,sizeof(CHARLISTENTRY));
48 pNewEntry->pNext = NULL;
49 pNewEntry->myChar = myChar;
53 if(pCharList->pTail == NULL)
55 pCharList->pHead = pCharList->pTail = pNewEntry;
59 CHARLISTENTRY* pCurrent = pCharList->pTail;
60 pCharList->pTail = pCurrent->pNext = pNewEntry;
66 void CHARLIST_Push( CHARLIST* pCharList, char myChar)
68 CHARLISTENTRY* pNewEntry = malloc(sizeof(CHARLISTENTRY));
72 pNewEntry->myChar = myChar;
74 if(pCharList->pHead == NULL)
76 pCharList->pHead = pCharList->pTail = pNewEntry;
77 pNewEntry->pNext = NULL;
82 pNewEntry->pNext = pCharList->pHead;
83 pCharList->pHead = pNewEntry;
89 char CHARLIST_Dequeue(CHARLIST* pCharList)
91 CHARLISTENTRY* pCurrent;
96 if(pCharList->nCount == 0)
100 myChar = pCharList->pHead->myChar;
101 pCurrent = pCharList->pHead->pNext;
102 HeapFree(RICHED32_hHeap, 0,pCharList->pHead);
104 if(pCharList->nCount == 0)
106 pCharList->pHead = pCharList->pTail = NULL;
110 pCharList->pHead = pCurrent;
116 int CHARLIST_GetNbItems(CHARLIST* pCharList)
120 return pCharList->nCount;
123 void CHARLIST_FreeList(CHARLIST* pCharList){
126 while(pCharList->nCount)
127 CHARLIST_Dequeue(pCharList);
130 /* this function counts the number of occurrences of a caracter */
131 int CHARLIST_CountChar(CHARLIST* pCharList, char myChar)
133 CHARLISTENTRY *pCurrent;
138 for(pCurrent =pCharList->pHead ;pCurrent;pCurrent=pCurrent->pNext)
139 if(pCurrent->myChar == myChar)
145 int CHARLIST_toBuffer(CHARLIST* pCharList, char* pBuffer, int nBufferSize)
150 /* we add one to store a NULL caracter */
151 if(nBufferSize < pCharList->nCount + 1)
152 return pCharList->nCount;
154 for(;pCharList->nCount;pBuffer++)
155 *pBuffer = CHARLIST_Dequeue(pCharList);