summaryrefslogtreecommitdiff
path: root/src/string_list.cc
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2013-03-26 17:10:10 +0100
committerBardur Arantsson <bardur@scientician.net>2013-09-27 14:46:42 +0200
commitcbef37bd5bfb938a2303ee3887520c08be85d8e8 (patch)
treeb604e49323e46af4ea582f9a9e1977b3daa90611 /src/string_list.cc
parentb9f824effb037a53556e02955cace6c09ff646c3 (diff)
Switch almost everything over to C++
Diffstat (limited to 'src/string_list.cc')
-rw-r--r--src/string_list.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/string_list.cc b/src/string_list.cc
new file mode 100644
index 00000000..03080e46
--- /dev/null
+++ b/src/string_list.cc
@@ -0,0 +1,52 @@
+#include "string_list.h"
+
+int compare_string_list(string_list *a, string_list *b)
+{
+ if (a == b)
+ {
+ return 0;
+ }
+
+ return strcmp(a->s, b->s);
+}
+
+SGLIB_DEFINE_LIST_FUNCTIONS(string_list, compare_string_list, next);
+
+/*
+ * Initialize a string_list value. Copies the input string.
+ */
+void string_list_init(string_list *sl, cptr s)
+{
+ assert(sl != NULL);
+
+ sl->s = string_make(s);
+ sl->next = NULL;
+}
+
+/*
+ * Destroy string_value.
+ */
+void string_list_destroy(string_list *sl)
+{
+ assert(sl != NULL);
+
+ /* Free contained string */
+ if (sl->s) {
+ string_free(sl->s);
+ sl->s = NULL;
+ }
+
+ /* We do NOT free the rest of the list. */
+ sl->next = NULL;
+}
+
+/**
+ * Append a string to a string_list.
+ */
+void string_list_append(string_list **slist, cptr s)
+{
+ string_list *e = new string_list;
+ string_list_init(e, s);
+
+ sglib_string_list_add(slist, e);
+}