ReactOS 0.4.15-dev-8058-ga7cbb60
ftcmru.c
Go to the documentation of this file.
1/***************************************************************************/
2/* */
3/* ftcmru.c */
4/* */
5/* FreeType MRU support (body). */
6/* */
7/* Copyright 2003-2018 by */
8/* David Turner, Robert Wilhelm, and Werner Lemberg. */
9/* */
10/* This file is part of the FreeType project, and may only be used, */
11/* modified, and distributed under the terms of the FreeType project */
12/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13/* this file you indicate that you have read the license and */
14/* understand and accept it fully. */
15/* */
16/***************************************************************************/
17
18
19#include <ft2build.h>
20#include FT_CACHE_H
21#include "ftcmru.h"
22#include FT_INTERNAL_OBJECTS_H
23#include FT_INTERNAL_DEBUG_H
24
25#include "ftcerror.h"
26
27
28 FT_LOCAL_DEF( void )
31 {
33
34
35 if ( first )
36 {
37 FTC_MruNode last = first->prev;
38
39
40#ifdef FT_DEBUG_ERROR
41 {
42 FTC_MruNode cnode = first;
43
44
45 do
46 {
47 if ( cnode == node )
48 {
49 fprintf( stderr, "FTC_MruNode_Prepend: invalid action\n" );
50 exit( 2 );
51 }
52 cnode = cnode->next;
53
54 } while ( cnode != first );
55 }
56#endif
57
58 first->prev = node;
59 last->next = node;
60 node->next = first;
61 node->prev = last;
62 }
63 else
64 {
65 node->next = node;
66 node->prev = node;
67 }
68 *plist = node;
69 }
70
71
72 FT_LOCAL_DEF( void )
75 {
77
78
80
81 if ( first != node )
82 {
83 FTC_MruNode prev, next, last;
84
85
86#ifdef FT_DEBUG_ERROR
87 {
88 FTC_MruNode cnode = first;
89 do
90 {
91 if ( cnode == node )
92 goto Ok;
93 cnode = cnode->next;
94
95 } while ( cnode != first );
96
97 fprintf( stderr, "FTC_MruNode_Up: invalid action\n" );
98 exit( 2 );
99 Ok:
100 }
101#endif
102 prev = node->prev;
103 next = node->next;
104
105 prev->next = next;
106 next->prev = prev;
107
108 last = first->prev;
109
110 last->next = node;
111 first->prev = node;
112
113 node->next = first;
114 node->prev = last;
115
116 *plist = node;
117 }
118 }
119
120
121 FT_LOCAL_DEF( void )
124 {
126 FTC_MruNode prev, next;
127
128
129 FT_ASSERT( first );
130
131#ifdef FT_DEBUG_ERROR
132 {
133 FTC_MruNode cnode = first;
134
135
136 do
137 {
138 if ( cnode == node )
139 goto Ok;
140 cnode = cnode->next;
141
142 } while ( cnode != first );
143
144 fprintf( stderr, "FTC_MruNode_Remove: invalid action\n" );
145 exit( 2 );
146 Ok:
147 }
148#endif
149
150 prev = node->prev;
151 next = node->next;
152
153 prev->next = next;
154 next->prev = prev;
155
156 if ( node == next )
157 {
158 FT_ASSERT( first == node );
159 FT_ASSERT( prev == node );
160
161 *plist = NULL;
162 }
163 else if ( node == first )
164 *plist = next;
165 }
166
167
168 FT_LOCAL_DEF( void )
170 FTC_MruListClass clazz,
171 FT_UInt max_nodes,
174 {
175 list->num_nodes = 0;
176 list->max_nodes = max_nodes;
177 list->nodes = NULL;
178 list->clazz = *clazz;
179 list->data = data;
180 list->memory = memory;
181 }
182
183
184 FT_LOCAL_DEF( void )
186 {
187 while ( list->nodes )
188 FTC_MruList_Remove( list, list->nodes );
189
190 FT_ASSERT( list->num_nodes == 0 );
191 }
192
193
194 FT_LOCAL_DEF( void )
196 {
198 }
199
200
201#ifndef FTC_INLINE
203 FTC_MruList_Find( FTC_MruList list,
205 {
206 FTC_MruNode_CompareFunc compare = list->clazz.node_compare;
208
209
210 first = list->nodes;
211 node = NULL;
212
213 if ( first )
214 {
215 node = first;
216 do
217 {
218 if ( compare( node, key ) )
219 {
220 if ( node != first )
221 FTC_MruNode_Up( &list->nodes, node );
222
223 return node;
224 }
225
226 node = node->next;
227
228 } while ( node != first);
229 }
230
231 return NULL;
232 }
233#endif
234
238 FTC_MruNode *anode )
239 {
242 FT_Memory memory = list->memory;
243
244
245 if ( list->num_nodes >= list->max_nodes && list->max_nodes > 0 )
246 {
247 node = list->nodes->prev;
248
249 FT_ASSERT( node );
250
251 if ( list->clazz.node_reset )
252 {
253 FTC_MruNode_Up( &list->nodes, node );
254
255 error = list->clazz.node_reset( node, key, list->data );
256 if ( !error )
257 goto Exit;
258 }
259
260 FTC_MruNode_Remove( &list->nodes, node );
261 list->num_nodes--;
262
263 if ( list->clazz.node_done )
264 list->clazz.node_done( node, list->data );
265 }
266 else if ( FT_ALLOC( node, list->clazz.node_size ) )
267 goto Exit;
268
269 error = list->clazz.node_init( node, key, list->data );
270 if ( error )
271 goto Fail;
272
273 FTC_MruNode_Prepend( &list->nodes, node );
274 list->num_nodes++;
275
276 Exit:
277 *anode = node;
278 return error;
279
280 Fail:
281 if ( list->clazz.node_done )
282 list->clazz.node_done( node, list->data );
283
284 FT_FREE( node );
285 goto Exit;
286 }
287
288
289#ifndef FTC_INLINE
291 FTC_MruList_Lookup( FTC_MruList list,
293 FTC_MruNode *anode )
294 {
296
297
298 node = FTC_MruList_Find( list, key );
299 if ( !node )
300 return FTC_MruList_New( list, key, anode );
301
302 *anode = node;
303 return 0;
304 }
305#endif /* FTC_INLINE */
306
307 FT_LOCAL_DEF( void )
310 {
311 FTC_MruNode_Remove( &list->nodes, node );
312 list->num_nodes--;
313
314 {
315 FT_Memory memory = list->memory;
316
317
318 if ( list->clazz.node_done )
319 list->clazz.node_done( node, list->data );
320
321 FT_FREE( node );
322 }
323 }
324
325
326 FT_LOCAL_DEF( void )
330 {
332
333
334 first = list->nodes;
335 while ( first && ( !selection || selection( first, key ) ) )
336 {
338 first = list->nodes;
339 }
340
341 if ( first )
342 {
343 node = first->next;
344 while ( node != first )
345 {
346 next = node->next;
347
348 if ( selection( node, key ) )
350
351 node = next;
352 }
353 }
354 }
355
356
357/* END */
#define compare
Definition: list.h:37
struct list * prev
Definition: list.h:39
int selection
Definition: ctm.c:92
#define NULL
Definition: types.h:112
int Fail
Definition: ehthrow.cxx:24
FTC_MruList_New(FTC_MruList list, FT_Pointer key, FTC_MruNode *anode)
Definition: ftcmru.c:236
FTC_MruList_Remove(FTC_MruList list, FTC_MruNode node)
Definition: ftcmru.c:308
FTC_MruNode_Up(FTC_MruNode *plist, FTC_MruNode node)
Definition: ftcmru.c:73
FTC_MruList_Reset(FTC_MruList list)
Definition: ftcmru.c:185
FTC_MruNode_Prepend(FTC_MruNode *plist, FTC_MruNode node)
Definition: ftcmru.c:29
FTC_MruNode_Remove(FTC_MruNode *plist, FTC_MruNode node)
Definition: ftcmru.c:122
FTC_MruList_Done(FTC_MruList list)
Definition: ftcmru.c:195
FTC_MruList_Init(FTC_MruList list, FTC_MruListClass clazz, FT_UInt max_nodes, FT_Pointer data, FT_Memory memory)
Definition: ftcmru.c:169
FTC_MruList_RemoveSelection(FTC_MruList list, FTC_MruNode_CompareFunc selection, FT_Pointer key)
Definition: ftcmru.c:327
struct FTC_MruListClassRec_ const * FTC_MruListClass
Definition: ftcmru.h:86
FT_Bool(* FTC_MruNode_CompareFunc)(FTC_MruNode node, FT_Pointer key)
Definition: ftcmru.h:90
typedefFT_BEGIN_HEADER struct FTC_MruNodeRec_ * FTC_MruNode
Definition: ftcmru.h:61
#define FT_LOCAL_DEF(x)
Definition: ftconfig.h:388
#define FT_ASSERT(condition)
Definition: ftdebug.h:211
#define FT_ALLOC(ptr, size)
Definition: ftmemory.h:303
#define FT_FREE(ptr)
Definition: ftmemory.h:329
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:66
int FT_Error
Definition: fttypes.h:300
unsigned int FT_UInt
Definition: fttypes.h:231
@ Ok
Definition: gdiplustypes.h:26
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
const GLint * first
Definition: glext.h:5794
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define error(str)
Definition: mkdosfs.c:1605
static UINT UINT last
Definition: font.c:45
static char memory[1024 *256]
Definition: process.c:116
static unsigned __int64 next
Definition: rand_nt.c:6
static Parse plist[]
Definition: dwarfinfo.c:339
#define exit(n)
Definition: config.h:202
static void Exit(void)
Definition: sock.c:1330
Definition: bug.cpp:8
Definition: copy.c:22
Definition: dlist.c:348
void * next
Definition: dlist.c:360