David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
| 3 | /* ftlist.c */ |
| 4 | /* */ |
| 5 | /* Generic list support for FreeType (body). */ |
| 6 | /* */ |
Werner Lemberg | 415235d | 2001-06-28 17:49:10 +0000 | [diff] [blame] | 7 | /* Copyright 1996-2001 by */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
| 9 | /* */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 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 */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 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 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 18 | /*************************************************************************/ |
| 19 | /* */ |
| 20 | /* This file implements functions relative to list processing. Its */ |
Werner Lemberg | a3b6c6c | 2000-05-31 06:55:12 +0000 | [diff] [blame] | 21 | /* data structures are defined in `freetype/internal/ftlist.h'. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 22 | /* */ |
| 23 | /*************************************************************************/ |
| 24 | |
| 25 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 26 | #include <ft2build.h> |
| 27 | #include FT_LIST_H |
| 28 | #include FT_INTERNAL_DEBUG_H |
| 29 | #include FT_INTERNAL_OBJECTS_H |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 30 | |
| 31 | |
| 32 | /*************************************************************************/ |
| 33 | /* */ |
Werner Lemberg | eb81e37 | 2000-06-03 06:03:11 +0000 | [diff] [blame] | 34 | /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
| 35 | /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
| 36 | /* messages during execution. */ |
| 37 | /* */ |
| 38 | #undef FT_COMPONENT |
| 39 | #define FT_COMPONENT trace_list |
| 40 | |
| 41 | |
Werner Lemberg | 8ec9dfd | 2000-11-07 23:56:02 +0000 | [diff] [blame] | 42 | /* documentation is in ftlist.h */ |
| 43 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 44 | FT_EXPORT_DEF( FT_ListNode ) |
| 45 | FT_List_Find( FT_List list, |
| 46 | void* data ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 47 | { |
| 48 | FT_ListNode cur; |
| 49 | |
| 50 | |
| 51 | cur = list->head; |
| 52 | while ( cur ) |
| 53 | { |
Werner Lemberg | 7880dd6 | 2000-01-10 17:19:45 +0000 | [diff] [blame] | 54 | if ( cur->data == data ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 55 | return cur; |
| 56 | |
| 57 | cur = cur->next; |
| 58 | } |
| 59 | |
| 60 | return (FT_ListNode)0; |
| 61 | } |
| 62 | |
| 63 | |
Werner Lemberg | 8ec9dfd | 2000-11-07 23:56:02 +0000 | [diff] [blame] | 64 | /* documentation is in ftlist.h */ |
| 65 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 66 | FT_EXPORT_DEF( void ) |
| 67 | FT_List_Add( FT_List list, |
| 68 | FT_ListNode node ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 69 | { |
| 70 | FT_ListNode before = list->tail; |
| 71 | |
| 72 | |
| 73 | node->next = 0; |
| 74 | node->prev = before; |
| 75 | |
| 76 | if ( before ) |
| 77 | before->next = node; |
| 78 | else |
| 79 | list->head = node; |
| 80 | |
| 81 | list->tail = node; |
| 82 | } |
| 83 | |
| 84 | |
Werner Lemberg | 8ec9dfd | 2000-11-07 23:56:02 +0000 | [diff] [blame] | 85 | /* documentation is in ftlist.h */ |
| 86 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 87 | FT_EXPORT_DEF( void ) |
| 88 | FT_List_Insert( FT_List list, |
| 89 | FT_ListNode node ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 90 | { |
| 91 | FT_ListNode after = list->head; |
| 92 | |
| 93 | |
| 94 | node->next = after; |
| 95 | node->prev = 0; |
| 96 | |
| 97 | if ( !after ) |
| 98 | list->tail = node; |
| 99 | else |
| 100 | after->prev = node; |
| 101 | |
| 102 | list->head = node; |
| 103 | } |
| 104 | |
| 105 | |
Werner Lemberg | 8ec9dfd | 2000-11-07 23:56:02 +0000 | [diff] [blame] | 106 | /* documentation is in ftlist.h */ |
| 107 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 108 | FT_EXPORT_DEF( void ) |
| 109 | FT_List_Remove( FT_List list, |
| 110 | FT_ListNode node ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 111 | { |
| 112 | FT_ListNode before, after; |
| 113 | |
| 114 | |
| 115 | before = node->prev; |
| 116 | after = node->next; |
| 117 | |
| 118 | if ( before ) |
| 119 | before->next = after; |
| 120 | else |
| 121 | list->head = after; |
| 122 | |
| 123 | if ( after ) |
| 124 | after->prev = before; |
| 125 | else |
| 126 | list->tail = before; |
| 127 | } |
| 128 | |
| 129 | |
Werner Lemberg | 8ec9dfd | 2000-11-07 23:56:02 +0000 | [diff] [blame] | 130 | /* documentation is in ftlist.h */ |
| 131 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 132 | FT_EXPORT_DEF( void ) |
| 133 | FT_List_Up( FT_List list, |
| 134 | FT_ListNode node ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 135 | { |
| 136 | FT_ListNode before, after; |
| 137 | |
| 138 | |
| 139 | before = node->prev; |
| 140 | after = node->next; |
| 141 | |
Werner Lemberg | a3b6c6c | 2000-05-31 06:55:12 +0000 | [diff] [blame] | 142 | /* check whether we are already on top of the list */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 143 | if ( !before ) |
| 144 | return; |
| 145 | |
| 146 | before->next = after; |
| 147 | |
| 148 | if ( after ) |
| 149 | after->prev = before; |
| 150 | else |
| 151 | list->tail = before; |
| 152 | |
| 153 | node->prev = 0; |
| 154 | node->next = list->head; |
| 155 | list->head->prev = node; |
| 156 | list->head = node; |
| 157 | } |
| 158 | |
| 159 | |
Werner Lemberg | 8ec9dfd | 2000-11-07 23:56:02 +0000 | [diff] [blame] | 160 | /* documentation is in ftlist.h */ |
| 161 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 162 | FT_EXPORT_DEF( FT_Error ) |
| 163 | FT_List_Iterate( FT_List list, |
| 164 | FT_List_Iterator iterator, |
| 165 | void* user ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 166 | { |
| 167 | FT_ListNode cur = list->head; |
| 168 | FT_Error error = FT_Err_Ok; |
| 169 | |
| 170 | |
| 171 | while ( cur ) |
| 172 | { |
| 173 | FT_ListNode next = cur->next; |
| 174 | |
| 175 | |
| 176 | error = iterator( cur, user ); |
| 177 | if ( error ) |
| 178 | break; |
| 179 | |
| 180 | cur = next; |
| 181 | } |
| 182 | |
| 183 | return error; |
| 184 | } |
| 185 | |
| 186 | |
Werner Lemberg | 8ec9dfd | 2000-11-07 23:56:02 +0000 | [diff] [blame] | 187 | /* documentation is in ftlist.h */ |
| 188 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 189 | FT_EXPORT_DEF( void ) |
| 190 | FT_List_Finalize( FT_List list, |
| 191 | FT_List_Destructor destroy, |
| 192 | FT_Memory memory, |
| 193 | void* user ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 194 | { |
| 195 | FT_ListNode cur; |
| 196 | |
| 197 | |
| 198 | cur = list->head; |
| 199 | while ( cur ) |
| 200 | { |
| 201 | FT_ListNode next = cur->next; |
| 202 | void* data = cur->data; |
| 203 | |
| 204 | |
| 205 | if ( destroy ) |
| 206 | destroy( memory, data, user ); |
| 207 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 208 | FT_FREE( cur ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 209 | cur = next; |
| 210 | } |
| 211 | |
| 212 | list->head = 0; |
| 213 | list->tail = 0; |
| 214 | } |
| 215 | |
| 216 | |
| 217 | /* END */ |