1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-23 21:35:29 +03:00

More str_list fns.

This commit is contained in:
Alasdair Kergon 2004-03-08 15:23:01 +00:00
parent 060c45d8a1
commit 6dbf31c0c3
2 changed files with 41 additions and 0 deletions

View File

@ -57,6 +57,25 @@ int str_list_del(struct list *sll, const char *str)
return 1; return 1;
} }
int str_list_dup(struct pool *mem, struct list *sllnew, struct list *sllold)
{
struct str_list *sl;
list_init(sllnew);
list_iterate_items(sl, sllold) {
if (!str_list_add(mem, sllnew, strdup(sl->str))) {
stack;
return 0;
}
}
return 1;
}
/*
* Is item on list?
*/
int str_list_match_item(struct list *sll, const char *str) int str_list_match_item(struct list *sll, const char *str)
{ {
struct str_list *sl; struct str_list *sl;
@ -68,6 +87,9 @@ int str_list_match_item(struct list *sll, const char *str)
return 0; return 0;
} }
/*
* Is at least one item on both lists?
*/
int str_list_match_list(struct list *sll, struct list *sll2) int str_list_match_list(struct list *sll, struct list *sll2)
{ {
struct str_list *sl; struct str_list *sl;
@ -78,3 +100,20 @@ int str_list_match_list(struct list *sll, struct list *sll2)
return 0; return 0;
} }
/*
* Do both lists contain the same set of items?
*/
int str_list_lists_equal(struct list *sll, struct list *sll2)
{
struct str_list *sl;
if (list_size(sll) != list_size(sll2))
return 0;
list_iterate_items(sl, sll)
if (!str_list_match_item(sll2, sl->str))
return 0;
return 1;
}

View File

@ -14,5 +14,7 @@ int str_list_add(struct pool *mem, struct list *sll, const char *str);
int str_list_del(struct list *sll, const char *str); int str_list_del(struct list *sll, const char *str);
int str_list_match_item(struct list *sll, const char *str); int str_list_match_item(struct list *sll, const char *str);
int str_list_match_list(struct list *sll, struct list *sll2); int str_list_match_list(struct list *sll, struct list *sll2);
int str_list_lists_equal(struct list *sll, struct list *sll2);
int str_list_dup(struct pool *mem, struct list *sllnew, struct list *sllold);
#endif #endif