2 * fontconfig/src/fcptrlist.c
4 * Copyright © 2000 Keith Packard
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of the author(s) not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. The authors make no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
16 * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
27 typedef struct _FcPtrListEntry {
28 struct _FcPtrListEntry *next;
32 FcDestroyFunc destroy_func;
35 typedef struct _FcPtrListIterPrivate {
36 const FcPtrList *list;
37 FcPtrListEntry *entry;
39 } FcPtrListIterPrivate;
42 FcPtrListCreate (FcDestroyFunc func)
44 FcPtrList *ret = (FcPtrList *) malloc (sizeof (FcPtrList));
48 ret->destroy_func = func;
56 FcPtrListDestroy (FcPtrList *list)
60 FcPtrListIterInit (list, &iter);
63 if (FcPtrListIterGetValue (list, &iter))
64 list->destroy_func (FcPtrListIterGetValue (list, &iter));
65 FcPtrListIterRemove (list, &iter);
66 } while (FcPtrListIterIsValid (list, &iter));
72 FcPtrListIterInit (const FcPtrList *list,
75 FcPtrListIterPrivate *priv = (FcPtrListIterPrivate *) iter;
78 priv->entry = list->list;
83 FcPtrListIterInitAtLast (FcPtrList *list,
86 FcPtrListIterPrivate *priv = (FcPtrListIterPrivate *) iter;
87 FcPtrListEntry **e, **p;
91 for (; *e; p = e, e = &(*e)->next);
99 FcPtrListIterNext (const FcPtrList *list,
102 FcPtrListIterPrivate *priv = (FcPtrListIterPrivate *) iter;
104 if (list != priv->list)
106 priv->prev = priv->entry;
107 priv->entry = priv->entry->next;
109 return priv->entry != NULL;
113 FcPtrListIterIsValid (const FcPtrList *list,
114 const FcPtrListIter *iter)
116 FcPtrListIterPrivate *priv = (FcPtrListIterPrivate *) iter;
118 return list == priv->list && priv->entry;
122 FcPtrListIterGetValue (const FcPtrList *list,
123 const FcPtrListIter *iter)
125 FcPtrListIterPrivate *priv = (FcPtrListIterPrivate *) iter;
127 if (list != priv->list ||
131 return priv->entry->data;
135 FcPtrListIterAdd (FcPtrList *list,
140 FcPtrListIterPrivate *priv = (FcPtrListIterPrivate *) iter;
142 if (list != priv->list)
145 e = (FcPtrListEntry *) malloc (sizeof (FcPtrListEntry));
150 e->next = priv->entry->next;
151 priv->entry->next = e;
158 priv->prev->next = e;
159 priv->entry = priv->prev;
170 return FcPtrListIterNext (list, iter);
174 FcPtrListIterRemove (FcPtrList *list,
177 FcPtrListIterPrivate *priv = (FcPtrListIterPrivate *) iter;
180 if (list != priv->list)
185 if (list->list == priv->entry)
186 list->list = list->list->next;
189 priv->prev->next = priv->entry->next;
190 priv->entry = priv->entry->next;
197 #include "fcaliastail.h"