summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2017-11-27 20:01:19 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-11-27 13:42:10 -0800
commitddb9dba66cef3a1c88e0f91a4f65c44f5769b0f5 (patch)
tree94b3f733de5c91324a15f412aa0ec3e126e214a6
parent1c6e189c2bd97c29d1ec3f1a98fa76e19ebef9b0 (diff)
downloadsubsurface-ddb9dba66cef3a1c88e0f91a4f65c44f5769b0f5.tar.gz
Move add_dive_site to parse.c
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
-rw-r--r--core/parse-xml.c66
-rw-r--r--core/parse.c66
-rw-r--r--core/parse.h2
3 files changed, 68 insertions, 66 deletions
diff --git a/core/parse-xml.c b/core/parse-xml.c
index d3d2d8ef3..e7aa8c68c 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -1140,72 +1140,6 @@ static void gps_in_dive(char *buffer, struct dive *dive)
}
}
-static void add_dive_site(char *ds_name, struct dive *dive)
-{
- static int suffix = 1;
- char *buffer = ds_name;
- char *to_free = NULL;
- int size = trimspace(buffer);
- if(size) {
- uint32_t uuid = dive->dive_site_uuid;
- struct dive_site *ds = get_dive_site_by_uuid(uuid);
- if (uuid && !ds) {
- // that's strange - we have a uuid but it doesn't exist - let's just ignore it
- fprintf(stderr, "dive contains a non-existing dive site uuid %x\n", dive->dive_site_uuid);
- uuid = 0;
- }
- if (!uuid) {
- // if the dive doesn't have a uuid, check if there's already a dive site by this name
- uuid = get_dive_site_uuid_by_name(buffer, &ds);
- if (uuid && import_source == SSRF_WS) {
- // when downloading GPS fixes from the Subsurface webservice we will often
- // get a lot of dives with identical names (the autogenerated fixes).
- // So in this case modify the name to make it unique
- int name_size = strlen(buffer) + 10; // 8 digits - enough for 100 million sites
- to_free = buffer = malloc(name_size);
- do {
- suffix++;
- snprintf(buffer, name_size, "%s %8d", ds_name, suffix);
- } while (get_dive_site_uuid_by_name(buffer, NULL) != 0);
- ds = NULL;
- }
- }
- if (ds) {
- // we have a uuid, let's hope there isn't a different name
- if (same_string(ds->name, "")) {
- ds->name = copy_string(buffer);
- } else if (!same_string(ds->name, buffer)) {
- // if it's not the same name, it's not the same dive site
- // but wait, we could have gotten this one based on GPS coords and could
- // have had two different names for the same site... so let's search the other
- // way around
- uint32_t exact_match_uuid = get_dive_site_uuid_by_gps_and_name(buffer, ds->latitude, ds->longitude);
- if (exact_match_uuid) {
- dive->dive_site_uuid = exact_match_uuid;
- } else {
- dive->dive_site_uuid = create_dive_site(buffer, dive->when);
- struct dive_site *newds = get_dive_site_by_uuid(dive->dive_site_uuid);
- if (cur_latitude.udeg || cur_longitude.udeg) {
- // we started this uuid with GPS data, so lets use those
- newds->latitude = cur_latitude;
- newds->longitude = cur_longitude;
- } else {
- newds->latitude = ds->latitude;
- newds->longitude = ds->longitude;
- }
- newds->notes = add_to_string(newds->notes, translate("gettextFromC", "additional name for site: %s\n"), ds->name);
- }
- } else {
- // add the existing dive site to the current dive
- dive->dive_site_uuid = uuid;
- }
- } else {
- dive->dive_site_uuid = create_dive_site(buffer, dive->when);
- }
- }
- free(to_free);
-}
-
static void gps_picture_location(char *buffer, struct picture *pic)
{
char *end;
diff --git a/core/parse.c b/core/parse.c
index ba440f1b9..228b8d59f 100644
--- a/core/parse.c
+++ b/core/parse.c
@@ -447,3 +447,69 @@ void utf8_string(char *buffer, void *_res)
*res = strdup(buffer);
}
+void add_dive_site(char *ds_name, struct dive *dive)
+{
+ static int suffix = 1;
+ char *buffer = ds_name;
+ char *to_free = NULL;
+ int size = trimspace(buffer);
+ if(size) {
+ uint32_t uuid = dive->dive_site_uuid;
+ struct dive_site *ds = get_dive_site_by_uuid(uuid);
+ if (uuid && !ds) {
+ // that's strange - we have a uuid but it doesn't exist - let's just ignore it
+ fprintf(stderr, "dive contains a non-existing dive site uuid %x\n", dive->dive_site_uuid);
+ uuid = 0;
+ }
+ if (!uuid) {
+ // if the dive doesn't have a uuid, check if there's already a dive site by this name
+ uuid = get_dive_site_uuid_by_name(buffer, &ds);
+ if (uuid && import_source == SSRF_WS) {
+ // when downloading GPS fixes from the Subsurface webservice we will often
+ // get a lot of dives with identical names (the autogenerated fixes).
+ // So in this case modify the name to make it unique
+ int name_size = strlen(buffer) + 10; // 8 digits - enough for 100 million sites
+ to_free = buffer = malloc(name_size);
+ do {
+ suffix++;
+ snprintf(buffer, name_size, "%s %8d", ds_name, suffix);
+ } while (get_dive_site_uuid_by_name(buffer, NULL) != 0);
+ ds = NULL;
+ }
+ }
+ if (ds) {
+ // we have a uuid, let's hope there isn't a different name
+ if (same_string(ds->name, "")) {
+ ds->name = copy_string(buffer);
+ } else if (!same_string(ds->name, buffer)) {
+ // if it's not the same name, it's not the same dive site
+ // but wait, we could have gotten this one based on GPS coords and could
+ // have had two different names for the same site... so let's search the other
+ // way around
+ uint32_t exact_match_uuid = get_dive_site_uuid_by_gps_and_name(buffer, ds->latitude, ds->longitude);
+ if (exact_match_uuid) {
+ dive->dive_site_uuid = exact_match_uuid;
+ } else {
+ dive->dive_site_uuid = create_dive_site(buffer, dive->when);
+ struct dive_site *newds = get_dive_site_by_uuid(dive->dive_site_uuid);
+ if (cur_latitude.udeg || cur_longitude.udeg) {
+ // we started this uuid with GPS data, so lets use those
+ newds->latitude = cur_latitude;
+ newds->longitude = cur_longitude;
+ } else {
+ newds->latitude = ds->latitude;
+ newds->longitude = ds->longitude;
+ }
+ newds->notes = add_to_string(newds->notes, translate("gettextFromC", "additional name for site: %s\n"), ds->name);
+ }
+ } else {
+ // add the existing dive site to the current dive
+ dive->dive_site_uuid = uuid;
+ }
+ } else {
+ dive->dive_site_uuid = create_dive_site(buffer, dive->when);
+ }
+ }
+ free(to_free);
+}
+
diff --git a/core/parse.h b/core/parse.h
index 003ef9929..14c24a1d8 100644
--- a/core/parse.h
+++ b/core/parse.h
@@ -93,4 +93,6 @@ void userid_start(void);
void userid_stop(void);
void utf8_string(char *buffer, void *_res);
+void add_dive_site(char *ds_name, struct dive *dive);
+
#endif