From d68d0f39ab7675745e7d177f6774736f7ec58783 Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Wed, 1 Dec 2021 00:31:01 +0100 Subject: Replace readline with own implementation for integration --- link.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 link.c (limited to 'link.c') diff --git a/link.c b/link.c new file mode 100644 index 0000000..60e701d --- /dev/null +++ b/link.c @@ -0,0 +1,54 @@ +#include "link.h" + +int +list_len(struct link *list) +{ + struct link *iter; + int len; + + len = 0; + for (iter = list; iter; iter = iter->next) + len += 1; + + return len; +} + +struct link * +list_back(struct link *link) +{ + for (; link->next; link = link->next); + return link; +} + +void +link_prepend(struct link *list, struct link *link) +{ + link->prev = list->prev; + link->next = list; + + if (link->prev) + link->prev->next = link; + if (link->next) + link->next->prev = link; +} + +void +link_append(struct link *list, struct link *link) +{ + link->prev = list; + link->next = list->next; + + if (link->prev) + link->prev->next = link; + if (link->next) + link->next->prev = link; +} + +void +link_pop(struct link *link) +{ + if (link->prev) + link->prev->next = link->next; + if (link->next) + link->next->prev = link->prev; +} -- cgit v1.2.3-71-gd317