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)
62 FcPtrListIterInit (list, &iter);
65 if (FcPtrListIterGetValue (list, &iter))
66 list->destroy_func (FcPtrListIterGetValue (list, &iter));
67 FcPtrListIterRemove (list, &iter);
68 } while (FcPtrListIterIsValid (list, &iter));
75 FcPtrListIterInit (const FcPtrList *list,
78 FcPtrListIterPrivate *priv = (FcPtrListIterPrivate *) iter;
81 priv->entry = list->list;
86 FcPtrListIterInitAtLast (FcPtrList *list,
89 FcPtrListIterPrivate *priv = (FcPtrListIterPrivate *) iter;
90 FcPtrListEntry **e, **p;
94 for (; *e; p = e, e = &(*e)->next);
102 FcPtrListIterNext (const FcPtrList *list,
105 FcPtrListIterPrivate *priv = (FcPtrListIterPrivate *) iter;
107 if (list != priv->list)
109 priv->prev = priv->entry;
110 priv->entry = priv->entry->next;
112 return priv->entry != NULL;
116 FcPtrListIterIsValid (const FcPtrList *list,
117 const FcPtrListIter *iter)
119 FcPtrListIterPrivate *priv = (FcPtrListIterPrivate *) iter;
121 return list == priv->list && priv->entry;
125 FcPtrListIterGetValue (const FcPtrList *list,
126 const FcPtrListIter *iter)
128 FcPtrListIterPrivate *priv = (FcPtrListIterPrivate *) iter;
130 if (list != priv->list ||
134 return priv->entry->data;
138 FcPtrListIterAdd (FcPtrList *list,
143 FcPtrListIterPrivate *priv = (FcPtrListIterPrivate *) iter;
145 if (list != priv->list)
148 e = (FcPtrListEntry *) malloc (sizeof (FcPtrListEntry));
155 e->next = priv->entry->next;
156 priv->entry->next = e;
163 priv->prev->next = e;
164 priv->entry = priv->prev;
175 return FcPtrListIterNext (list, iter);
179 FcPtrListIterRemove (FcPtrList *list,
182 FcPtrListIterPrivate *priv = (FcPtrListIterPrivate *) iter;
185 if (list != priv->list)
190 if (list->list == priv->entry)
191 list->list = list->list->next;
194 priv->prev->next = priv->entry->next;
195 priv->entry = priv->entry->next;
202 #include "fcaliastail.h"