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