aboutsummaryrefslogtreecommitdiff
path: root/list.c
diff options
context:
space:
mode:
authorOskari Timperi <oskari.timperi@iki.fi>2014-05-17 12:37:09 +0300
committerOskari Timperi <oskari.timperi@iki.fi>2014-05-17 12:37:09 +0300
commit2836fa60045bcdd8c1c8c5ed775d711cc7f385a9 (patch)
tree7892216d6ae7f0c51bd6c147dadc0bb88f06070c /list.c
parent6814f6b99562620e70538787b6f8d66c80f7b990 (diff)
downloadlispish-2836fa60045bcdd8c1c8c5ed775d711cc7f385a9.tar.gz
lispish-2836fa60045bcdd8c1c8c5ed775d711cc7f385a9.zip
refactor code to use LIST from sys/queue.h
It's now easier and more natural to work with the code. :-P
Diffstat (limited to 'list.c')
-rw-r--r--list.c99
1 files changed, 0 insertions, 99 deletions
diff --git a/list.c b/list.c
deleted file mode 100644
index 58510ac..0000000
--- a/list.c
+++ /dev/null
@@ -1,99 +0,0 @@
-#include "list.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-void list_init(struct list *list)
-{
- memset(list, 0, sizeof(*list));
-}
-
-struct list *list_new(void *data)
-{
- struct list *list = calloc(1, sizeof(*list));
- list->data = data;
- return list;
-}
-
-struct list *list_append(struct list *list, void *data)
-{
- if (list == NULL)
- {
- return list_new(data);
- }
-
- struct list *last = list_get_last(list);
- list = list_new(data);
- last->next = list;
-
- return list;
-}
-
-struct list *list_get_last(struct list *list)
-{
- while (list && list->next)
- list = list->next;
- return list;
-}
-
-struct list *list_pop_front(struct list **list)
-{
- struct list *popped = *list;
-
- if (!popped)
- return NULL;
-
- *list = popped->next;
- popped->next = NULL;
-
- return popped;
-}
-
-void list_free(struct list *list, list_free_cb free_cb, void *userdata)
-{
- struct list *popped;
-
- while ((popped = list_pop_front(&list)) != NULL)
- {
- if (free_cb)
- free_cb(popped->data, userdata);
- free(popped);
- }
-}
-
-#ifdef BUILD_TEST
-
-#include "test_util.h"
-
-TEST(list_init)
-{
-
-}
-
-TEST(list_new)
-{
-
-}
-
-TEST(list_append)
-{
-
-}
-
-TEST(list_get_last)
-{
-
-}
-
-TEST(list_pop_front)
-{
-
-}
-
-TEST(list_free)
-{
-
-}
-
-
-#endif