X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-lib%2Flist.c;h=c1a7039e108a339847159b7ad9d95d28c9bb4ce5;hp=c2c4f77cd36efd722c5d934dce8336006ac65405;hb=6920eb5798f2d9f25e5ea1af2ba86122cf408bd1;hpb=1ee89902de184a640c171ae3285bff6882a791bd diff --git a/lib-lib/list.c b/lib-lib/list.c index c2c4f77..c1a7039 100644 --- a/lib-lib/list.c +++ b/lib-lib/list.c @@ -37,6 +37,44 @@ string_list_t *string_list_dup(const string_list_t *p) { 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 = &(*l)->next; + } + } +} + /* 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;