aboutsummaryrefslogtreecommitdiff
path: root/src/list.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/list.c')
-rw-r--r--src/list.c177
1 files changed, 85 insertions, 92 deletions
diff --git a/src/list.c b/src/list.c
index 4a5d3f6..7d7f934 100644
--- a/src/list.c
+++ b/src/list.c
@@ -23,139 +23,132 @@
#include <string.h>
struct grecs_list *
-grecs_list_create ()
+grecs_list_create()
{
- struct grecs_list *lp = grecs_malloc (sizeof (*lp));
- memset (lp, 0, sizeof (*lp));
- return lp;
+ struct grecs_list *lp = grecs_malloc(sizeof(*lp));
+ memset(lp, 0, sizeof(*lp));
+ return lp;
}
size_t
-grecs_list_size (struct grecs_list *lp)
+grecs_list_size(struct grecs_list *lp)
{
- return lp ? lp->count : 0;
+ return lp ? lp->count : 0;
}
void
-grecs_list_append (struct grecs_list *lp, void *val)
+grecs_list_append(struct grecs_list *lp, void *val)
{
- struct grecs_list_entry *ep = grecs_malloc (sizeof (*ep));
- ep->data = val;
- ep->next = NULL;
- if (lp->tail)
- lp->tail->next = ep;
- else
- lp->head = ep;
- lp->tail = ep;
- lp->count++;
+ struct grecs_list_entry *ep = grecs_malloc(sizeof(*ep));
+ ep->data = val;
+ ep->next = NULL;
+ if (lp->tail)
+ lp->tail->next = ep;
+ else
+ lp->head = ep;
+ lp->tail = ep;
+ lp->count++;
}
void
-grecs_list_push (struct grecs_list *lp, void *val)
+grecs_list_push(struct grecs_list *lp, void *val)
{
- struct grecs_list_entry *ep = grecs_malloc (sizeof (*ep));
- ep->data = val;
- ep->next = lp->head;
- lp->head = ep;
- lp->count++;
+ struct grecs_list_entry *ep = grecs_malloc(sizeof(*ep));
+ ep->data = val;
+ ep->next = lp->head;
+ lp->head = ep;
+ lp->count++;
}
void *
-grecs_list_pop (struct grecs_list *lp)
+grecs_list_pop(struct grecs_list *lp)
{
- void *data;
- struct grecs_list_entry *ep = lp->head;
- if (ep)
- {
- data = ep->data;
- lp->head = ep->next;
- if (!lp->head)
- lp->tail = NULL;
- lp->count--;
- free (ep);
- }
- else
- data = NULL;
- return data;
+ void *data;
+ struct grecs_list_entry *ep = lp->head;
+ if (ep) {
+ data = ep->data;
+ lp->head = ep->next;
+ if (!lp->head)
+ lp->tail = NULL;
+ lp->count--;
+ free (ep);
+ } else
+ data = NULL;
+ return data;
}
void
-grecs_list_clear (struct grecs_list *lp)
+grecs_list_clear(struct grecs_list *lp)
{
- struct grecs_list_entry *ep = lp->head;
-
- while (ep)
- {
- struct grecs_list_entry *next = ep->next;
- if (lp->free_entry)
- lp->free_entry (ep->data);
- free (ep);
- ep = next;
- }
- lp->head = lp->tail = NULL;
- lp->count = 0;
+ struct grecs_list_entry *ep = lp->head;
+
+ while (ep) {
+ struct grecs_list_entry *next = ep->next;
+ if (lp->free_entry)
+ lp->free_entry(ep->data);
+ free(ep);
+ ep = next;
+ }
+ lp->head = lp->tail = NULL;
+ lp->count = 0;
}
void
-grecs_list_free (struct grecs_list *lp)
+grecs_list_free(struct grecs_list *lp)
{
- grecs_list_clear (lp);
- free (lp);
+ grecs_list_clear(lp);
+ free(lp);
}
static int
-_ptrcmp (const void *a, const void *b)
+_ptrcmp(const void *a, const void *b)
{
- return a != b;
+ return a != b;
}
void *
-grecs_list_locate (struct grecs_list *lp, void *data)
+grecs_list_locate(struct grecs_list *lp, void *data)
{
- struct grecs_list_entry *ep;
- int (*cmp)(const void *, const void *) = lp->cmp ? lp->cmp : _ptrcmp;
-
- for (ep = lp->head; ep; ep = ep->next)
- {
- if (cmp (ep->data, data) == 0)
- return ep->data;
- }
- return NULL;
+ struct grecs_list_entry *ep;
+ int (*cmp)(const void *, const void *) = lp->cmp ? lp->cmp : _ptrcmp;
+
+ for (ep = lp->head; ep; ep = ep->next) {
+ if (cmp(ep->data, data) == 0)
+ return ep->data;
+ }
+ return NULL;
}
void *
-grecs_list_index (struct grecs_list *lp, size_t idx)
+grecs_list_index(struct grecs_list *lp, size_t idx)
{
- struct grecs_list_entry *ep;
-
- for (ep = lp->head; ep && idx; ep = ep->next, idx--)
- ;
- return ep ? ep->data : NULL;
+ struct grecs_list_entry *ep;
+
+ for (ep = lp->head; ep && idx; ep = ep->next, idx--)
+ ;
+ return ep ? ep->data : NULL;
}
void *
-grecs_list_remove_tail (struct grecs_list *lp)
+grecs_list_remove_tail(struct grecs_list *lp)
{
- void *data;
+ void *data;
- if (!lp->head)
- return NULL;
- data = lp->tail;
- if (lp->head == lp->tail)
- {
- free (lp->tail);
- lp->head = lp->tail = NULL;
- lp->count = 0;
- }
- else
- {
- struct grecs_list_entry *ep;
+ if (!lp->head)
+ return NULL;
+ data = lp->tail;
+ if (lp->head == lp->tail) {
+ free(lp->tail);
+ lp->head = lp->tail = NULL;
+ lp->count = 0;
+ } else {
+ struct grecs_list_entry *ep;
- for (ep = lp->head; ep->next != lp->tail; ep = ep->next)
- ;
- free (lp->tail);
- ep->next = NULL;
- lp->tail = ep;
- }
- return data;
+ for (ep = lp->head; ep->next != lp->tail; ep = ep->next)
+ ;
+ free(lp->tail);
+ ep->next = NULL;
+ lp->tail = ep;
+ }
+ return data;
}

Return to:

Send suggestions and report system problems to the System administrator.