diff options
author | Bardur Arantsson <bardur@scientician.net> | 2012-05-27 15:32:35 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2012-05-28 07:26:46 +0200 |
commit | 1c616215c7568b20f701ef3d5f9b15315d7f7d3a (patch) | |
tree | 7ddc2ef5cc775615672f29a80dcb721377c5073a /src | |
parent | cfa5b41a11e8be1ef8b5d92be523d4713a445dd7 (diff) |
Lua: Factor out "string_list_append" function
Diffstat (limited to 'src')
-rw-r--r-- | src/spells4.c | 4 | ||||
-rw-r--r-- | src/string_list.c | 12 | ||||
-rw-r--r-- | src/types.h | 1 |
3 files changed, 14 insertions, 3 deletions
diff --git a/src/spells4.c b/src/spells4.c index 40cca814..ba97e065 100644 --- a/src/spells4.c +++ b/src/spells4.c @@ -599,7 +599,5 @@ void lua_cast_school_spell(s32b s, bool_ no_cost) void spell_description_add_line(s32b spell_idx, cptr line) { - string_list *e = malloc(sizeof(string_list)); - string_list_init(e, line); - sglib_string_list_add(&school_spells[spell_idx].description, e); + string_list_append(&school_spells[spell_idx].description, line); } diff --git a/src/string_list.c b/src/string_list.c index b39ecd6f..8a63cc3c 100644 --- a/src/string_list.c +++ b/src/string_list.c @@ -30,6 +30,7 @@ void string_list_destroy(string_list *sl) { assert(sl != NULL); + /* Free contained string */ if (sl->s) { string_free(sl->s); sl->s = NULL; @@ -38,3 +39,14 @@ void string_list_destroy(string_list *sl) /* 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 = malloc(sizeof(string_list)); + string_list_init(e, s); + + sglib_string_list_add(slist, e); +} diff --git a/src/types.h b/src/types.h index 06634be5..9927e7a5 100644 --- a/src/types.h +++ b/src/types.h @@ -62,6 +62,7 @@ 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 */ +void string_list_append(string_list **slist, cptr s); /* Append string */ |