summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-10 09:39:51 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-10 09:42:28 -0700
commita8a8bcd86a01e006b3f45ce916ad626fe3efe70c (patch)
tree149eacc38486fc52524e5efef3ab48be270df99c /dive.c
parent634df1a337f61f2b7fa7cb6195ac680411c620e2 (diff)
downloadsubsurface-a8a8bcd86a01e006b3f45ce916ad626fe3efe70c.tar.gz
Add helper functions to ensure we have sane tag lists
There should never be empty or duplicate tags on those lists. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/dive.c b/dive.c
index ce04bd54e..349bc104a 100644
--- a/dive.c
+++ b/dive.c
@@ -2089,6 +2089,30 @@ static void join_dive_computers(struct divecomputer *res, struct divecomputer *a
remove_redundant_dc(res, prefer_downloaded);
}
+static bool tag_seen_before(struct tag_entry *start, struct tag_entry *before)
+{
+ while(start && start != before) {
+ if (same_string(start->tag->name, before->tag->name))
+ return true;
+ start = start->next;
+ }
+ return false;
+}
+
+/* remove duplicates and empty nodes */
+void taglist_cleanup(struct tag_entry **tag_list)
+{
+ struct tag_entry **tl = tag_list;
+ while (*tl) {
+ /* skip tags that are empty or that we have seen before */
+ if (same_string((*tl)->tag->name, "") || tag_seen_before(*tag_list, *tl)) {
+ *tl = (*tl)->next;
+ continue;
+ }
+ tl = &(*tl)->next;
+ }
+}
+
int taglist_get_tagstring(struct tag_entry *tag_list, char *buffer, int len)
{
int i = 0;