X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=lib%2Flist.c;h=1dd865ffcc28e2a4717c4ae9d93c736b3323cb00;hb=b0a700a4558d9bb59395ddcf08565a5e709841e1;hp=a454c8f7c44b27284bab307ce4bdc88a2d9bf6e6;hpb=ba5e3af4ea19e1d20c80941c077039871ec84258;p=apps%2Fmadmutt.git diff --git a/lib/list.c b/lib/list.c index a454c8f..1dd865f 100644 --- a/lib/list.c +++ b/lib/list.c @@ -13,6 +13,7 @@ #include "list.h" #include "mem.h" +#include "str.h" list2_t* list_new (void) { return (mem_calloc (1, sizeof (list2_t))); @@ -109,3 +110,19 @@ int list_lookup (list2_t* l, int (*cmp) (const void*, const void*), const void* return (i); return (-1); } + +list2_t* list_from_str (const char* str, const char* delim) { + list2_t* ret = NULL; + char* tmp = NULL, *p = NULL; + + if (!str || !*str || !delim || !*delim) + return (NULL); + + tmp = str_dup (str); + for (p = strtok (tmp, delim); p; p = strtok (NULL, delim)) { + list_push_back (&ret, str_dup (p)); + } + mem_free (&tmp); + return (ret); +} +