mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-01 06:30:26 +00:00
Improve helper functions
Sometimes we want to create a dive site just based on a name, sometimes we have both a name and GPS coordinates. Let's make a helper for either case. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
ccf833b45c
commit
cd28e88bee
3 changed files with 26 additions and 8 deletions
14
divesite.c
14
divesite.c
|
@ -37,7 +37,17 @@ struct dive_site *alloc_dive_site()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate a new site and add it to the table */
|
/* allocate a new site and add it to the table */
|
||||||
uint32_t create_dive_site(const char *name, degrees_t latitude, degrees_t longitude)
|
uint32_t create_dive_site(const char *name)
|
||||||
|
{
|
||||||
|
struct dive_site *ds = alloc_dive_site();
|
||||||
|
ds->uuid = dive_site_getUniqId();
|
||||||
|
ds->name = copy_string(name);
|
||||||
|
|
||||||
|
return ds->uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* same as before, but with GPS data */
|
||||||
|
uint32_t create_dive_site_with_gps(const char *name, degrees_t latitude, degrees_t longitude)
|
||||||
{
|
{
|
||||||
struct dive_site *ds = alloc_dive_site();
|
struct dive_site *ds = alloc_dive_site();
|
||||||
ds->uuid = dive_site_getUniqId();
|
ds->uuid = dive_site_getUniqId();
|
||||||
|
@ -53,7 +63,7 @@ uint32_t dive_site_uuid_by_name(const char *name)
|
||||||
{
|
{
|
||||||
uint32_t id = get_dive_site_uuid_by_name(name);
|
uint32_t id = get_dive_site_uuid_by_name(name);
|
||||||
if (id == 0)
|
if (id == 0)
|
||||||
id = create_dive_site(name, (degrees_t){0}, (degrees_t){0});
|
id = create_dive_site(name);
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
10
divesite.h
10
divesite.h
|
@ -4,6 +4,10 @@
|
||||||
#include "units.h"
|
#include "units.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
struct dive_site
|
struct dive_site
|
||||||
{
|
{
|
||||||
uint32_t uuid;
|
uint32_t uuid;
|
||||||
|
@ -53,7 +57,11 @@ static inline uint32_t get_dive_site_uuid_by_name(const char *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dive_site *alloc_dive_site();
|
struct dive_site *alloc_dive_site();
|
||||||
uint32_t create_dive_site(const char *name, degrees_t latitude, degrees_t longitude);
|
uint32_t create_dive_site(const char *name);
|
||||||
|
uint32_t create_dive_site_with_gps(const char *name, degrees_t latitude, degrees_t longitude);
|
||||||
uint32_t dive_site_uuid_by_name(const char *name);
|
uint32_t dive_site_uuid_by_name(const char *name);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif // DIVESITE_H
|
#endif // DIVESITE_H
|
||||||
|
|
10
parse-xml.c
10
parse-xml.c
|
@ -983,7 +983,7 @@ static void divinglog_place(char *place, uint32_t *uuid)
|
||||||
country ? country : "");
|
country ? country : "");
|
||||||
*uuid = get_dive_site_uuid_by_name(buffer);
|
*uuid = get_dive_site_uuid_by_name(buffer);
|
||||||
if (*uuid == 0)
|
if (*uuid == 0)
|
||||||
*uuid = create_dive_site(buffer, (degrees_t){0}, (degrees_t){0});
|
*uuid = create_dive_site(buffer);
|
||||||
|
|
||||||
city = NULL;
|
city = NULL;
|
||||||
country = NULL;
|
country = NULL;
|
||||||
|
@ -1156,7 +1156,7 @@ static void gps_in_dive(char *buffer, struct dive *dive)
|
||||||
uint32_t uuid = dive->dive_site_uuid;
|
uint32_t uuid = dive->dive_site_uuid;
|
||||||
if (uuid == 0) {
|
if (uuid == 0) {
|
||||||
fprintf(stderr, "found no uuid in dive, creating a divesite without name and above GPS\n");
|
fprintf(stderr, "found no uuid in dive, creating a divesite without name and above GPS\n");
|
||||||
dive->dive_site_uuid = create_dive_site("", latitude, longitude);
|
dive->dive_site_uuid = create_dive_site_with_gps("", latitude, longitude);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "found uuid in dive, checking to see if we should add GPS\n");
|
fprintf(stderr, "found uuid in dive, checking to see if we should add GPS\n");
|
||||||
struct dive_site *ds = get_dive_site_by_uuid(uuid);
|
struct dive_site *ds = get_dive_site_by_uuid(uuid);
|
||||||
|
@ -1193,7 +1193,7 @@ static void add_dive_site(char *buffer, struct dive *dive)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dive->dive_site_uuid = create_dive_site(buffer, (degrees_t){0}, (degrees_t){0});
|
dive->dive_site_uuid = create_dive_site(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1437,7 +1437,7 @@ static void dive_site_end(void)
|
||||||
if (!cur_dive_site)
|
if (!cur_dive_site)
|
||||||
return;
|
return;
|
||||||
if (cur_dive_site->uuid) {
|
if (cur_dive_site->uuid) {
|
||||||
uint32_t tmp = create_dive_site(cur_dive_site->name, cur_dive_site->latitude, cur_dive_site->longitude);
|
uint32_t tmp = create_dive_site_with_gps(cur_dive_site->name, cur_dive_site->latitude, cur_dive_site->longitude);
|
||||||
struct dive_site *ds = get_dive_site_by_uuid(tmp);
|
struct dive_site *ds = get_dive_site_by_uuid(tmp);
|
||||||
ds->uuid = cur_dive_site->uuid;
|
ds->uuid = cur_dive_site->uuid;
|
||||||
ds->notes = cur_dive_site->notes;
|
ds->notes = cur_dive_site->notes;
|
||||||
|
@ -2502,7 +2502,7 @@ extern int cobalt_location(void *handle, int columns, char **data, char **column
|
||||||
sprintf(tmp, "%s / %s", location, data[0]);
|
sprintf(tmp, "%s / %s", location, data[0]);
|
||||||
free(location);
|
free(location);
|
||||||
location = NULL;
|
location = NULL;
|
||||||
cur_dive->dive_site_uuid = create_dive_site(tmp, (degrees_t){0}, (degrees_t){0});
|
cur_dive->dive_site_uuid = create_dive_site(tmp);
|
||||||
} else {
|
} else {
|
||||||
location = strdup(data[0]);
|
location = strdup(data[0]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue