* Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
*/
-#include <stdlib.h>
-#include <string.h>
+#include "lib-lib.h"
-#include "mem.h"
-#include "str.h"
-#include "list.h"
-
-LIST *mutt_copy_list(LIST *p) {
- LIST *t, *r = NULL, *l = NULL;
+string_list_t *string_list_dup(const string_list_t *p) {
+ string_list_t *res = NULL;
+ string_list_t **last = &res;
for (; p; p = p->next) {
- t = p_new(LIST, 1);
- t->data = m_strdup(p->data);
- t->next = NULL;
- if (l) {
- r->next = t;
- r = r->next;
+ *last = string_item_new();
+ (*last)->data = m_strdup(p->data);
+ last = &(*last)->next;
+ }
+
+ return res;
+}
+
+int string_list_contains(const string_list_t *t, const char *s, const char *any)
+{
+ while (t) {
+ if (!ascii_strncasecmp(s, t->data, m_strlen(t->data))
+ || (any && !ascii_strcasecmp(t->data, any)))
+ return 1;
+ t = t->next;
+ }
+ return 0;
+}
+
+void string_list_add(string_list_t **list, const char *str)
+{
+ if (m_strisempty(str))
+ return;
+
+ while (*list) {
+ if (!ascii_strcasecmp(str, (*list)->data))
+ return;
+ list = &(*list)->next;
+ }
+
+ *list = p_new(string_list_t, 1);
+ (*list)->data = m_strdup(str);
+}
+
+void string_list_remove(string_list_t **l, const char *str)
+{
+ while (*l) {
+ if (!ascii_strcasecmp(str, (*l)->data)) {
+ string_list_t *it = string_list_pop(l);
+ string_item_delete(&it);
} else {
- l = r = t;
+ l = &(*l)->next;
}
}
- return l;
}
-LIST *mutt_add_list_n(LIST *head, const void *data, size_t len) {
- LIST *tmp;
+/* FIXME: b0rken API's, replace that at any cost */
+string_list_t *mutt_add_list_n(string_list_t *head, const void *data, size_t len) {
+ string_list_t *tmp;
for (tmp = head; tmp && tmp->next; tmp = tmp->next);
if (tmp) {
- tmp->next = p_new(LIST, 1);
+ tmp->next = p_new(string_list_t, 1);
tmp = tmp->next;
} else {
- head = tmp = p_new(LIST, 1);
+ head = tmp = p_new(string_list_t, 1);
}
tmp->data = p_dup((const char *)data, len);
return head;
}
-void mutt_free_list(LIST **list) {
- LIST *p;
-
- if (list) {
- while (*list) {
- p = *list;
- *list = (*list)->next;
- p_delete(&p->data);
- p_delete(&p);
- }
- }
-}