diff options
Diffstat (limited to 'core/taxonomy.c')
-rw-r--r-- | core/taxonomy.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/core/taxonomy.c b/core/taxonomy.c index 1689d1952..9592843f0 100644 --- a/core/taxonomy.c +++ b/core/taxonomy.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include "taxonomy.h" #include "gettext.h" +#include "subsurface-string.h" #include <stdlib.h> #include <stdio.h> @@ -41,6 +42,27 @@ void free_taxonomy(struct taxonomy_data *t) } } +void copy_taxonomy(struct taxonomy_data *orig, struct taxonomy_data *copy) +{ + if (orig->category == NULL) { + free_taxonomy(copy); + } else { + if (copy->category == NULL) + copy->category = alloc_taxonomy(); + for (int i = 0; i < TC_NR_CATEGORIES; i++) { + if (i < copy->nr) { + free((void *)copy->category[i].value); + copy->category[i].value = NULL; + } + if (i < orig->nr) { + copy->category[i] = orig->category[i]; + copy->category[i].value = copy_string(orig->category[i].value); + } + } + copy->nr = orig->nr; + } +} + int taxonomy_index_for_category(struct taxonomy_data *t, enum taxonomy_category cat) { for (int i = 0; i < t->nr; i++) |