1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-08-03 08:22:00 +03:00

more str_list fns

This commit is contained in:
Alasdair Kergon
2003-10-15 20:04:29 +00:00
parent f2b7349e2f
commit ac21f47034
3 changed files with 53 additions and 26 deletions

View File

@ -7,10 +7,23 @@
#include "lib.h"
#include "str_list.h"
int str_list_add(struct pool *mem, struct list *sl, const char *str)
struct list *str_list_create(struct pool *mem)
{
struct list *sl;
if (!(sl = pool_alloc(mem, sizeof(struct list)))) {
stack;
return NULL;
}
list_init(sl);
return sl;
}
int str_list_add(struct pool *mem, struct list *sll, const char *str)
{
struct str_list *sln;
struct list *slh;
if (!str) {
stack;
@ -18,10 +31,8 @@ int str_list_add(struct pool *mem, struct list *sl, const char *str)
}
/* Already in list? */
list_iterate(slh, sl) {
if (!strcmp(str, list_item(slh, struct str_list)->str))
return 1;
}
if (str_list_match_item(sll, str))
return 1;
if (!(sln = pool_alloc(mem, sizeof(*sln)))) {
stack;
@ -29,16 +40,16 @@ int str_list_add(struct pool *mem, struct list *sl, const char *str)
}
sln->str = str;
list_add(sl, &sln->list);
list_add(sll, &sln->list);
return 1;
}
int str_list_del(struct list *sl, const char *str)
int str_list_del(struct list *sll, const char *str)
{
struct list *slh, *slht;
list_iterate_safe(slh, slht, sl) {
list_iterate_safe(slh, slht, sll) {
if (!strcmp(str, list_item(slh, struct str_list)->str))
list_del(slh);
}
@ -46,3 +57,24 @@ int str_list_del(struct list *sl, const char *str)
return 1;
}
int str_list_match_item(struct list *sll, const char *str)
{
struct str_list *sl;
list_iterate_items(sl, sll)
if (!strcmp(str, sl->str))
return 1;
return 0;
}
int str_list_match_list(struct list *sll, struct list *sll2)
{
struct str_list *sl;
list_iterate_items(sl, sll)
if (str_list_match_item(sll2, sl->str))
return 1;
return 0;
}