summaryrefslogtreecommitdiffstats
path: root/list.c
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2021-12-16 17:11:12 +0100
committerLouis Burda <quent.burda@gmail.com>2021-12-20 15:31:31 +0100
commit3eea7a245a7ed49127a222628543f9509a6ff2b6 (patch)
tree345a923819b73bc88b551af5f708476239b6b7d9 /list.c
parent15a8fe2cf2b16af8739a7ec2b64b5c5f184161b8 (diff)
downloadtmus-3eea7a245a7ed49127a222628543f9509a6ff2b6.tar.gz
tmus-3eea7a245a7ed49127a222628543f9509a6ff2b6.zip
Switched most buffers to wide chars, added general ref class, now clear mpd errors, added track and command completion
Diffstat (limited to 'list.c')
-rw-r--r--list.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/list.c b/list.c
new file mode 100644
index 0000000..66b9d8a
--- /dev/null
+++ b/list.c
@@ -0,0 +1,102 @@
+#include "list.h"
+#include "util.h"
+
+int
+list_len(struct link *head)
+{
+ struct link *iter;
+ int len;
+
+ ASSERT(head != NULL);
+
+ len = 0;
+ for (iter = head->next; iter; iter = iter->next)
+ len += 1;
+
+ return len;
+}
+
+int
+list_ffind(struct link *head, struct link *link)
+{
+ struct link *iter;
+
+ ASSERT(head != NULL);
+
+ for (iter = head->next; iter && iter != link; iter = iter->next);
+
+ return (iter == link);
+}
+
+struct link *
+link_back(struct link *link)
+{
+ ASSERT(link != NULL);
+
+ for (; link->next; link = link->next);
+
+ return link;
+}
+
+void
+link_prepend(struct link *cur, struct link *link)
+{
+ ASSERT(cur != NULL && link != NULL);
+
+ link->prev = cur->prev;
+ link->next = cur;
+
+ if (link->prev)
+ link->prev->next = link;
+ if (link->next)
+ link->next->prev = link;
+}
+
+void
+link_append(struct link *cur, struct link *link)
+{
+ ASSERT(cur != NULL && link != NULL);
+
+ link->prev = cur;
+ link->next = cur->next;
+
+ if (link->prev)
+ link->prev->next = link;
+ if (link->next)
+ link->next->prev = link;
+}
+
+struct link *
+link_pop(struct link *link)
+{
+ ASSERT(link != NULL);
+
+ if (link->prev)
+ link->prev->next = link->next;
+ if (link->next)
+ link->next->prev = link->prev;
+
+ return link;
+}
+
+struct link *
+link_iter(struct link *link, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++) {
+ if (!link) return NULL;
+ link = link->next;
+ }
+
+ return link;
+}
+
+void
+list_push_back(struct link *cur, struct link *link)
+{
+ struct link *back;
+
+ back = link_back(cur);
+ link_append(back, link);
+}