diff options
| author | Louis Burda <quent.burda@gmail.com> | 2021-12-01 00:31:01 +0100 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2021-12-20 15:31:03 +0100 |
| commit | d68d0f39ab7675745e7d177f6774736f7ec58783 (patch) | |
| tree | 9f0cf6732517619e370186f288be172eead73fb0 /link.c | |
| parent | 02141177f8055a2d0edace481d631adbcb4b4c47 (diff) | |
| download | tmus-d68d0f39ab7675745e7d177f6774736f7ec58783.tar.gz tmus-d68d0f39ab7675745e7d177f6774736f7ec58783.zip | |
Replace readline with own implementation for integration
Diffstat (limited to 'link.c')
| -rw-r--r-- | link.c | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -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; +} |
