summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-15 21:25:26 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-15 21:25:26 -0700
commit1dbb6071bd0826790e8afb5be1020f42e257681b (patch)
treeb72ad6fa658f66f0dc886d85a0d25bea9df9efe3
parent542e04266d016c35e688e69d382204b7cefc3711 (diff)
downloadsubsurface-1dbb6071bd0826790e8afb5be1020f42e257681b.tar.gz
Add helper function that checks if a dive site is in use
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--divesite.c14
-rw-r--r--divesite.h1
-rw-r--r--save-xml.c12
3 files changed, 17 insertions, 10 deletions
diff --git a/divesite.c b/divesite.c
index b72672177..8bc9e04f7 100644
--- a/divesite.c
+++ b/divesite.c
@@ -108,6 +108,20 @@ struct dive_site *alloc_dive_site()
return ds;
}
+bool is_dive_site_used(uint32_t uuid, bool select_only)
+{
+ int j;
+ bool found = false;
+ struct dive *d;
+ for_each_dive(j, d) {
+ if (d->dive_site_uuid == uuid && (!select_only || d->selected)) {
+ found = true;
+ break;
+ }
+ }
+ return found;
+}
+
void delete_dive_site(uint32_t id)
{
int nr = dive_site_table.nr;
diff --git a/divesite.h b/divesite.h
index fd590eb2c..e0418b203 100644
--- a/divesite.h
+++ b/divesite.h
@@ -50,6 +50,7 @@ static inline struct dive_site *get_dive_site_by_uuid(uint32_t uuid)
}
struct dive_site *alloc_dive_site();
+bool is_dive_site_used(uint32_t uuid, bool select_only);
void delete_dive_site(uint32_t id);
uint32_t create_dive_site(const char *name);
uint32_t create_dive_site_with_gps(const char *name, degrees_t latitude, degrees_t longitude);
diff --git a/save-xml.c b/save-xml.c
index c8ce6fdf1..160b5fc84 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -520,17 +520,9 @@ void save_dives_buffer(struct membuffer *b, const bool select_only)
i--; // since we just deleted that one
continue;
}
- if (select_only) {
- bool found = false;
- for_each_dive(j, d) {
- if (d->selected && d->dive_site_uuid == ds->uuid) {
- found = true;
- break;
- }
- }
- if (!found)
+ if (select_only && !is_dive_site_used(ds->uuid, true))
continue;
- }
+
put_format(b, "<site uuid='%8x'", ds->uuid);
show_utf8(b, ds->name, " name='", "'", 1);
if (ds->latitude.udeg || ds->longitude.udeg) {