aboutsummaryrefslogtreecommitdiff
path: root/src/list.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/list.c')
-rw-r--r--src/list.c84
1 files changed, 42 insertions, 42 deletions
diff --git a/src/list.c b/src/list.c
index b2d9f13..a2628d2 100644
--- a/src/list.c
+++ b/src/list.c
@@ -1,4 +1,4 @@
1/* grecs - Gray's Extensible Configuration System 1/* argot - Gray's Extensible Configuration System
2 Copyright (C) 2007-2016 Sergey Poznyakoff 2 Copyright (C) 2007-2016 Sergey Poznyakoff
3 3
4 Grecs is free software; you can redistribute it and/or modify it 4 Grecs is free software; you can redistribute it and/or modify it
@@ -17,31 +17,31 @@
17#ifdef HAVE_CONFIG_H 17#ifdef HAVE_CONFIG_H
18# include <config.h> 18# include <config.h>
19#endif 19#endif
20#include <grecs.h> 20#include <argot.h>
21#include <grecs-gram.h> 21#include <argot-gram.h>
22#include <stdlib.h> 22#include <stdlib.h>
23#include <string.h> 23#include <string.h>
24 24
25struct grecs_list * 25struct argot_list *
26grecs_list_create() 26argot_list_create()
27{ 27{
28 struct grecs_list *lp = grecs_malloc(sizeof(*lp)); 28 struct argot_list *lp = argot_malloc(sizeof(*lp));
29 memset(lp, 0, sizeof(*lp)); 29 memset(lp, 0, sizeof(*lp));
30 return lp; 30 return lp;
31} 31}
32 32
33size_t 33size_t
34grecs_list_size(struct grecs_list *lp) 34argot_list_size(struct argot_list *lp)
35{ 35{
36 return lp ? lp->count : 0; 36 return lp ? lp->count : 0;
37} 37}
38 38
39void 39void
40grecs_list_insert_entry(struct grecs_list *lp, 40argot_list_insert_entry(struct argot_list *lp,
41 struct grecs_list_entry *anchor, 41 struct argot_list_entry *anchor,
42 struct grecs_list_entry *ent, int before) 42 struct argot_list_entry *ent, int before)
43{ 43{
44 struct grecs_list_entry *p; 44 struct argot_list_entry *p;
45 45
46 if (!anchor) { 46 if (!anchor) {
47 ent->prev = NULL; 47 ent->prev = NULL;
@@ -56,7 +56,7 @@ grecs_list_insert_entry(struct grecs_list *lp,
56 } 56 }
57 57
58 if (before) { 58 if (before) {
59 grecs_list_insert_entry(lp, anchor->prev, ent, 0); 59 argot_list_insert_entry(lp, anchor->prev, ent, 0);
60 return; 60 return;
61 } 61 }
62 62
@@ -71,9 +71,9 @@ grecs_list_insert_entry(struct grecs_list *lp,
71} 71}
72 72
73void 73void
74grecs_list_remove_entry(struct grecs_list *lp, struct grecs_list_entry *ent) 74argot_list_remove_entry(struct argot_list *lp, struct argot_list_entry *ent)
75{ 75{
76 struct grecs_list_entry *p; 76 struct argot_list_entry *p;
77 if ((p = ent->prev)) 77 if ((p = ent->prev))
78 p->next = ent->next; 78 p->next = ent->next;
79 else 79 else
@@ -82,20 +82,20 @@ grecs_list_remove_entry(struct grecs_list *lp, struct grecs_list_entry *ent)
82 p->prev = ent->prev; 82 p->prev = ent->prev;
83 else 83 else
84 lp->tail = ent->prev; 84 lp->tail = ent->prev;
85 grecs_free(ent); 85 argot_free(ent);
86 lp->count--; 86 lp->count--;
87} 87}
88 88
89void 89void
90grecs_list_append(struct grecs_list *lp, void *val) 90argot_list_append(struct argot_list *lp, void *val)
91{ 91{
92 struct grecs_list_entry *ep = grecs_malloc(sizeof(*ep)); 92 struct argot_list_entry *ep = argot_malloc(sizeof(*ep));
93 ep->data = val; 93 ep->data = val;
94 grecs_list_insert_entry(lp, lp->tail, ep, 0); 94 argot_list_insert_entry(lp, lp->tail, ep, 0);
95} 95}
96 96
97void 97void
98grecs_list_add(struct grecs_list *dst, struct grecs_list *src) 98argot_list_add(struct argot_list *dst, struct argot_list *src)
99{ 99{
100 if (!src->head) 100 if (!src->head)
101 return; 101 return;
@@ -112,50 +112,50 @@ grecs_list_add(struct grecs_list *dst, struct grecs_list *src)
112} 112}
113 113
114void 114void
115grecs_list_push(struct grecs_list *lp, void *val) 115argot_list_push(struct argot_list *lp, void *val)
116{ 116{
117 struct grecs_list_entry *ep = grecs_malloc(sizeof(*ep)); 117 struct argot_list_entry *ep = argot_malloc(sizeof(*ep));
118 ep->data = val; 118 ep->data = val;
119 grecs_list_insert_entry(lp, NULL, ep, 0); 119 argot_list_insert_entry(lp, NULL, ep, 0);
120} 120}
121 121
122void * 122void *
123grecs_list_pop(struct grecs_list *lp) 123argot_list_pop(struct argot_list *lp)
124{ 124{
125 void *data; 125 void *data;
126 struct grecs_list_entry *ep = lp->head; 126 struct argot_list_entry *ep = lp->head;
127 if (ep) { 127 if (ep) {
128 data = ep->data; 128 data = ep->data;
129 grecs_list_remove_entry(lp, ep); 129 argot_list_remove_entry(lp, ep);
130 } else 130 } else
131 data = NULL; 131 data = NULL;
132 return data; 132 return data;
133} 133}
134 134
135void * 135void *
136grecs_list_remove_tail(struct grecs_list *lp) 136argot_list_remove_tail(struct argot_list *lp)
137{ 137{
138 void *data; 138 void *data;
139 struct grecs_list_entry *ep; 139 struct argot_list_entry *ep;
140 140
141 if (!lp->tail) 141 if (!lp->tail)
142 return NULL; 142 return NULL;
143 ep = lp->tail; 143 ep = lp->tail;
144 data = lp->tail->data; 144 data = lp->tail->data;
145 grecs_list_remove_entry(lp, ep); 145 argot_list_remove_entry(lp, ep);
146 return data; 146 return data;
147} 147}
148 148
149void 149void
150grecs_list_clear(struct grecs_list *lp) 150argot_list_clear(struct argot_list *lp)
151{ 151{
152 struct grecs_list_entry *ep = lp->head; 152 struct argot_list_entry *ep = lp->head;
153 153
154 while (ep) { 154 while (ep) {
155 struct grecs_list_entry *next = ep->next; 155 struct argot_list_entry *next = ep->next;
156 if (lp->free_entry) 156 if (lp->free_entry)
157 lp->free_entry(ep->data); 157 lp->free_entry(ep->data);
158 grecs_free(ep); 158 argot_free(ep);
159 ep = next; 159 ep = next;
160 } 160 }
161 lp->head = lp->tail = NULL; 161 lp->head = lp->tail = NULL;
@@ -163,11 +163,11 @@ grecs_list_clear(struct grecs_list *lp)
163} 163}
164 164
165void 165void
166grecs_list_free(struct grecs_list *lp) 166argot_list_free(struct argot_list *lp)
167{ 167{
168 if (lp) { 168 if (lp) {
169 grecs_list_clear(lp); 169 argot_list_clear(lp);
170 grecs_free(lp); 170 argot_free(lp);
171 } 171 }
172} 172}
173 173
@@ -178,9 +178,9 @@ _ptrcmp(const void *a, const void *b)
178} 178}
179 179
180void * 180void *
181grecs_list_locate(struct grecs_list *lp, void *data) 181argot_list_locate(struct argot_list *lp, void *data)
182{ 182{
183 struct grecs_list_entry *ep; 183 struct argot_list_entry *ep;
184 int (*cmp)(const void *, const void *) = lp->cmp ? lp->cmp : _ptrcmp; 184 int (*cmp)(const void *, const void *) = lp->cmp ? lp->cmp : _ptrcmp;
185 185
186 for (ep = lp->head; ep; ep = ep->next) { 186 for (ep = lp->head; ep; ep = ep->next) {
@@ -191,9 +191,9 @@ grecs_list_locate(struct grecs_list *lp, void *data)
191} 191}
192 192
193void * 193void *
194grecs_list_index(struct grecs_list *lp, size_t idx) 194argot_list_index(struct argot_list *lp, size_t idx)
195{ 195{
196 struct grecs_list_entry *ep; 196 struct argot_list_entry *ep;
197 197
198 for (ep = lp->head; ep && idx; ep = ep->next, idx--) 198 for (ep = lp->head; ep && idx; ep = ep->next, idx--)
199 ; 199 ;
@@ -201,9 +201,9 @@ grecs_list_index(struct grecs_list *lp, size_t idx)
201} 201}
202 202