Added assembly wrapper for calling window procedures.
[wine.git] / dlls / richedit / charlist.c
blobaab292920ff3507d913cbf97b3b464338b418b81
1 /*
2 *
3 * Character List
4 *
5 * Copyright (c) 2000 by Jean-Claude Batista
6 *
7 */
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"
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;
29 else
31 CHARLISTENTRY* pCurrent = pCharList->pTail;
32 pCharList->pTail = pCurrent->pNext = pNewEntry;
35 pCharList->nCount++;
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;
50 else
52 pNewEntry->pNext = pCharList->pHead;
53 pCharList->pHead = pNewEntry;
56 pCharList->nCount++;
59 char CHARLIST_Dequeue(CHARLIST* pCharList)
61 CHARLISTENTRY* pCurrent;
62 char myChar;
64 if(pCharList->nCount == 0)
65 return 0;
67 pCharList->nCount--;
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;
76 else
78 pCharList->pHead = pCurrent;
81 return myChar;
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;
98 int nCount = 0;
100 for(pCurrent =pCharList->pHead ;pCurrent;pCurrent=pCurrent->pNext)
101 if(pCurrent->myChar == myChar)
102 nCount++;
104 return nCount;
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);
117 *pBuffer = '\0';
119 return 0;