summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/string_list.c40
-rw-r--r--src/types.h16
3 files changed, 57 insertions, 1 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3a640e74..f1af4895 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -11,7 +11,7 @@ SET(SRCS
monster1.c monster2.c monster3.c
xtra1.c xtra2.c skills.c powers.c gods.c
spells1.c spells2.c spells3.c spells4.c corrupt.c mimic.c
- status.c files.c notes.c loadsave.c
+ status.c files.c notes.c loadsave.c string_list.c
cmd1.c cmd2.c cmd3.c cmd4.c cmd5.c cmd6.c cmd7.c
help.c
generate.c gen_maze.c gen_evol.c wild.c levels.c store.c bldg.c
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;
+}
diff --git a/src/types.h b/src/types.h
index ea8ca019..3a408ed1 100644
--- a/src/types.h
+++ b/src/types.h
@@ -46,6 +46,22 @@
*/
+/*
+ * String list.
+ */
+typedef struct string_list string_list;
+struct string_list {
+ /* The string list owns the string */
+ cptr s;
+ /* Next */
+ string_list *next;
+};
+
+int compare_string_list(string_list *a, string_list *b);
+SGLIB_DEFINE_LIST_PROTOTYPES(string_list, compare_string, next);
+
+void string_list_init(string_list *sl, cptr s); /* Initialize element; copies string */
+void string_list_destroy(string_list *sl); /* Destroy element */