From 9f16b032d38613ca95e321e1d1e652c43129c68b Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 15 Aug 2020 17:42:36 +0200 Subject: Added libgui --- lib/list.c | 74 -------------------------------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 lib/list.c (limited to 'lib/list.c') diff --git a/lib/list.c b/lib/list.c deleted file mode 100644 index c36d6e1..0000000 --- a/lib/list.c +++ /dev/null @@ -1,74 +0,0 @@ -// MIT License, Copyright (c) 2020 Marvin Borner - -#include -#include -#include - -static int nonce = 0; - -struct list *list_new() -{ - struct list *list = malloc(sizeof(*list)); - list->head = NULL; - return list; -} - -struct node *list_new_node() -{ - struct node *node = malloc(sizeof(*node)); - node->data = NULL; - node->prev = NULL; - node->next = NULL; - node->nonce = nonce++; - return node; -} - -void list_add_node(struct list *list, struct node *node) -{ - if (list == NULL) - return; - - if (list->head == NULL) { - list->head = node; - return; - } - - struct node *iterator = list->head; - while (iterator != NULL) { - if (iterator->next == NULL) { - iterator->next = node; - node->prev = iterator; - break; - } - iterator = iterator->next; - } -} - -void list_add(struct list *list, void *data) -{ - struct node *node = list_new_node(); - node->data = data; - list_add_node(list, node); -} - -// Maybe list_remove_node? -void list_remove(struct list *list, struct node *node) -{ - if (list == NULL || list->head == NULL) - return; - - if (list->head == node) { - list->head = list->head->next; - return; - } - - struct node *iterator = list->head->next; - while (iterator != node) { - iterator = iterator->next; - if (iterator == NULL) - return; - } - - iterator->prev->next = iterator->next; - iterator->next->prev = iterator->prev; -} -- cgit v1.2.3