source: trunk/src/riched32/charlist.c

Last change on this file was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 3.4 KB
Line 
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 <stdio.h>
23#include <string.h>
24#include <stddef.h>
25#include <ctype.h>
26#include <stdlib.h>
27
28#include "charlist.h"
29#include "windef.h"
30#include "winbase.h"
31#include "wine/debug.h"
32
33WINE_DEFAULT_DEBUG_CHANNEL(richedit);
34
35#ifdef __WIN32OS2__ /* no useful trace in this file! */
36#undef TRACE
37#define TRACE(a) do {} while (0)
38#endif
39
40extern HANDLE RICHED32_hHeap;
41
42void CHARLIST_Enqueue( CHARLIST* pCharList, char myChar )
43{
44 CHARLISTENTRY* pNewEntry = HeapAlloc(RICHED32_hHeap, 0,sizeof(CHARLISTENTRY));
45 pNewEntry->pNext = NULL;
46 pNewEntry->myChar = myChar;
47
48 TRACE("\n");
49
50 if(pCharList->pTail == NULL)
51 {
52 pCharList->pHead = pCharList->pTail = pNewEntry;
53 }
54 else
55 {
56 CHARLISTENTRY* pCurrent = pCharList->pTail;
57 pCharList->pTail = pCurrent->pNext = pNewEntry;
58 }
59
60 pCharList->nCount++;
61}
62
63void CHARLIST_Push( CHARLIST* pCharList, char myChar)
64{
65 CHARLISTENTRY* pNewEntry = malloc(sizeof(CHARLISTENTRY));
66
67 TRACE("\n");
68
69 pNewEntry->myChar = myChar;
70
71 if(pCharList->pHead == NULL)
72 {
73 pCharList->pHead = pCharList->pTail = pNewEntry;
74 pNewEntry->pNext = NULL;
75
76 }
77 else
78 {
79 pNewEntry->pNext = pCharList->pHead;
80 pCharList->pHead = pNewEntry;
81 }
82
83 pCharList->nCount++;
84}
85
86char CHARLIST_Dequeue(CHARLIST* pCharList)
87{
88 CHARLISTENTRY* pCurrent;
89 char myChar;
90
91 TRACE("\n");
92
93 if(pCharList->nCount == 0)
94 return 0;
95
96 pCharList->nCount--;
97 myChar = pCharList->pHead->myChar;
98 pCurrent = pCharList->pHead->pNext;
99 HeapFree(RICHED32_hHeap, 0,pCharList->pHead);
100
101 if(pCharList->nCount == 0)
102 {
103 pCharList->pHead = pCharList->pTail = NULL;
104 }
105 else
106 {
107 pCharList->pHead = pCurrent;
108 }
109
110 return myChar;
111}
112
113int CHARLIST_GetNbItems(CHARLIST* pCharList)
114{
115 TRACE("\n");
116
117 return pCharList->nCount;
118}
119
120void CHARLIST_FreeList(CHARLIST* pCharList){
121 TRACE("\n");
122
123 while(pCharList->nCount)
124 CHARLIST_Dequeue(pCharList);
125}
126
127/* this function counts the number of occurrences of a caracter */
128int CHARLIST_CountChar(CHARLIST* pCharList, char myChar)
129{
130 CHARLISTENTRY *pCurrent;
131 int nCount = 0;
132
133 TRACE("\n");
134
135 for(pCurrent =pCharList->pHead ;pCurrent;pCurrent=pCurrent->pNext)
136 if(pCurrent->myChar == myChar)
137 nCount++;
138
139 return nCount;
140}
141
142int CHARLIST_toBuffer(CHARLIST* pCharList, char* pBuffer, int nBufferSize)
143{
144
145 TRACE("\n");
146
147 /* we add one to store a NULL caracter */
148 if(nBufferSize < pCharList->nCount + 1)
149 return pCharList->nCount;
150
151 for(;pCharList->nCount;pBuffer++)
152 *pBuffer = CHARLIST_Dequeue(pCharList);
153
154 *pBuffer = '\0';
155
156 return 0;
157}
158
Note: See TracBrowser for help on using the repository browser.