summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAlexander Aring <a.aring@phytec.de>2011-12-21 09:07:55 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2011-12-21 12:38:14 +0100
commit049100fe37024979060df8af5702fa4214a2790e (patch)
tree3a731df021714140c46ce9ad4dca0704d2f306ae /lib
parent56ddc233e41cd67b4467b21fdbea2213900db5c7 (diff)
downloadbarebox-049100fe37024979060df8af5702fa4214a2790e.tar.gz
barebox-049100fe37024979060df8af5702fa4214a2790e.tar.xz
stringlist-functions: add sorted insert
Add sorted insert in stringlist functions. Also added function to checked if string is already in string list. Signed-off-by: Alexander Aring <a.aring@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/stringlist.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/stringlist.c b/lib/stringlist.c
index 9ccf8fa836..a8ff97964f 100644
--- a/lib/stringlist.c
+++ b/lib/stringlist.c
@@ -3,6 +3,15 @@
#include <malloc.h>
#include <stringlist.h>
+static int string_list_compare(struct list_head *a, struct list_head *b)
+{
+ char *astr, *bstr;
+ astr = (char *)list_entry(a, struct string_list, list)->str;
+ bstr = (char *)list_entry(b, struct string_list, list)->str;
+
+ return strcmp(astr, bstr);
+}
+
int string_list_add(struct string_list *sl, char *str)
{
struct string_list *new;
@@ -16,6 +25,31 @@ int string_list_add(struct string_list *sl, char *str)
return 0;
}
+int string_list_add_sorted(struct string_list *sl, char *str)
+{
+ struct string_list *new;
+
+ new = xmalloc(sizeof(struct string_list) + strlen(str) + 1);
+
+ strcpy(new->str, str);
+
+ list_add_sort(&new->list, &sl->list, string_list_compare);
+
+ return 0;
+}
+
+int string_list_contains(struct string_list *sl, char *str)
+{
+ struct string_list *entry;
+
+ list_for_each_entry(entry, &sl->list, list) {
+ if (!strcmp(str, entry->str))
+ return 1;
+ }
+
+ return 0;
+}
+
void string_list_print_by_column(struct string_list *sl)
{
int len = 0, num, i;