summaryrefslogtreecommitdiffstats
path: root/core/taxonomy.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-09-05 13:23:23 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-09-06 12:59:54 -0700
commit6da78a29c4bcd42b93ef0044ec5e005f2ff93e0f (patch)
treefa415e566d5b9cb9b84d66a7b60a85cc4bd78c44 /core/taxonomy.c
parent86c24dd8321664a50a9c0ee4e54e21b21bbe46fc (diff)
downloadsubsurface-6da78a29c4bcd42b93ef0044ec5e005f2ff93e0f.tar.gz
cleanup: add helper function to set taxonomy category
Setting a taxonomy category was cumbersome: the caller had to make sure that the category-table was allocated. Introduce a helper function to make that simpler. Make taxonomy_set_country() the first caller of the new function, since it is just a special case with category = TC_COUNTRY. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/taxonomy.c')
-rw-r--r--core/taxonomy.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/core/taxonomy.c b/core/taxonomy.c
index 63c7fc507..45989e6c7 100644
--- a/core/taxonomy.c
+++ b/core/taxonomy.c
@@ -81,7 +81,7 @@ const char *taxonomy_get_country(struct taxonomy_data *t)
return NULL;
}
-void taxonomy_set_country(struct taxonomy_data *t, const char *country, enum taxonomy_origin origin)
+void taxonomy_set_category(struct taxonomy_data *t, enum taxonomy_category category, const char *value, enum taxonomy_origin origin)
{
int idx = -1;
@@ -90,7 +90,7 @@ void taxonomy_set_country(struct taxonomy_data *t, const char *country, enum tax
t->category = alloc_taxonomy();
for (int i = 0; i < t->nr; i++) {
- if (t->category[i].category == TC_COUNTRY) {
+ if (t->category[i].category == category) {
free((void *)t->category[i].value);
t->category[i].value = NULL;
idx = i;
@@ -100,13 +100,18 @@ void taxonomy_set_country(struct taxonomy_data *t, const char *country, enum tax
if (idx == -1) {
if (t->nr == TC_NR_CATEGORIES - 1) {
// can't add another one
- fprintf(stderr, "Error adding country taxonomy\n");
+ fprintf(stderr, "Error adding taxonomy category\n");
return;
}
idx = t->nr++;
}
- t->category[idx].value = country;
+ t->category[idx].value = value;
t->category[idx].origin = origin;
- t->category[idx].category = TC_COUNTRY;
+ t->category[idx].category = category;
+}
+
+void taxonomy_set_country(struct taxonomy_data *t, const char *country, enum taxonomy_origin origin)
+{
fprintf(stderr, "%s: set the taxonomy country to %s\n", __func__, country);
+ taxonomy_set_category(t, TC_COUNTRY, country, origin);
}