From 5071196631d9f96b977b492558c48f5b66020c8b Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Mon, 8 Mar 2004 15:23:01 +0000 Subject: [PATCH] More str_list fns. --- lib/datastruct/str_list.c | 39 +++++++++++++++++++++++++++++++++++++++ lib/datastruct/str_list.h | 2 ++ 2 files changed, 41 insertions(+) diff --git a/lib/datastruct/str_list.c b/lib/datastruct/str_list.c index b414b51e2..dc1e59c15 100644 --- a/lib/datastruct/str_list.c +++ b/lib/datastruct/str_list.c @@ -57,6 +57,25 @@ int str_list_del(struct list *sll, const char *str) 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) { struct str_list *sl; @@ -68,6 +87,9 @@ int str_list_match_item(struct list *sll, const char *str) return 0; } +/* + * Is at least one item on both lists? + */ int str_list_match_list(struct list *sll, struct list *sll2) { struct str_list *sl; @@ -78,3 +100,20 @@ int str_list_match_list(struct list *sll, struct list *sll2) 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; +} diff --git a/lib/datastruct/str_list.h b/lib/datastruct/str_list.h index c4d03f868..a9180e20d 100644 --- a/lib/datastruct/str_list.h +++ b/lib/datastruct/str_list.h @@ -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_match_item(struct list *sll, const char *str); 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