mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
cleanup: use taxonomy_index_for_category() in taxonomy_set_category()
Instead of recoding the "search for category" loop, reuse the already existing functionality. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
f93acdace7
commit
754b4a5c9d
1 changed files with 6 additions and 13 deletions
|
@ -83,26 +83,19 @@ const char *taxonomy_get_country(struct taxonomy_data *t)
|
|||
|
||||
void taxonomy_set_category(struct taxonomy_data *t, enum taxonomy_category category, const char *value, enum taxonomy_origin origin)
|
||||
{
|
||||
int idx = -1;
|
||||
int idx = taxonomy_index_for_category(t, category);
|
||||
|
||||
// make sure we have taxonomy data allocated
|
||||
alloc_taxonomy_table(t);
|
||||
|
||||
for (int i = 0; i < t->nr; i++) {
|
||||
if (t->category[i].category == category) {
|
||||
free((void *)t->category[i].value);
|
||||
t->category[i].value = NULL;
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (idx == -1) {
|
||||
if (idx < 0) {
|
||||
alloc_taxonomy_table(t); // make sure we have taxonomy data allocated
|
||||
if (t->nr == TC_NR_CATEGORIES - 1) {
|
||||
// can't add another one
|
||||
fprintf(stderr, "Error adding taxonomy category\n");
|
||||
return;
|
||||
}
|
||||
idx = t->nr++;
|
||||
} else {
|
||||
free((void *)t->category[idx].value);
|
||||
t->category[idx].value = NULL;
|
||||
}
|
||||
t->category[idx].value = strdup(value);
|
||||
t->category[idx].origin = origin;
|
||||
|
|
Loading…
Add table
Reference in a new issue