summaryrefslogtreecommitdiff
path: root/src/string_list.c
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-05-18 15:07:28 +0200
committerBardur Arantsson <bardur@scientician.net>2012-05-18 19:48:31 +0200
commitf7e4d1b4d9da8c42f02f79c0328477dd787fecd2 (patch)
tree386699529778c888063d2839719f79cac09491ed /src/string_list.c
parent38ab9bd955e7516cdc0279dcdcf461f975fde3ef (diff)
Lua: Add string_list for dynamic string lists
Diffstat (limited to 'src/string_list.c')
-rw-r--r--src/string_list.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/string_list.c b/src/string_list.c
new file mode 100644
index 00000000..b39ecd6f
--- /dev/null
+++ b/src/string_list.c
@@ -0,0 +1,40 @@
+#include "angband.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);
+
+ if (sl->s) {
+ string_free(sl->s);
+ sl->s = NULL;
+ }
+
+ /* We do NOT free the rest of the list. */
+ sl->next = NULL;
+}