mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: convert divesite strings to std::string
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
3916125786
commit
7d3977481a
38 changed files with 181 additions and 222 deletions
|
@ -169,7 +169,6 @@ static char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive, struct
|
|||
unsigned char tmp_1byte;
|
||||
unsigned int tmp_2bytes;
|
||||
unsigned long tmp_4bytes;
|
||||
struct dive_site *ds;
|
||||
char is_nitrox = 0, is_O2 = 0, is_SCR = 0;
|
||||
|
||||
device_data_t devdata;
|
||||
|
@ -211,11 +210,13 @@ static char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive, struct
|
|||
* Subsurface only have a location variable, so we have to merge DTrak's
|
||||
* Locality and Dive points.
|
||||
*/
|
||||
snprintf(buffer, sizeof(buffer), "%s, %s", locality, dive_point);
|
||||
ds = get_dive_site_by_name(buffer, log->sites);
|
||||
if (!ds)
|
||||
ds = create_dive_site(buffer, log->sites);
|
||||
add_dive_to_dive_site(dt_dive, ds);
|
||||
{
|
||||
std::string buffer2 = std::string((char *)locality) + " " + (char *)dive_point;
|
||||
struct dive_site *ds = get_dive_site_by_name(buffer2, log->sites);
|
||||
if (!ds)
|
||||
ds = create_dive_site(buffer2, log->sites);
|
||||
add_dive_to_dive_site(dt_dive, ds);
|
||||
}
|
||||
free(locality);
|
||||
locality = NULL;
|
||||
free(dive_point);
|
||||
|
|
|
@ -3341,12 +3341,10 @@ std::string get_dive_country(const struct dive *dive)
|
|||
return ds ? taxonomy_get_country(ds->taxonomy) : std::string();
|
||||
}
|
||||
|
||||
extern "C" const char *get_dive_location(const struct dive *dive)
|
||||
std::string get_dive_location(const struct dive *dive)
|
||||
{
|
||||
const struct dive_site *ds = dive->dive_site;
|
||||
if (ds && ds->name)
|
||||
return ds->name;
|
||||
return NULL;
|
||||
return ds ? ds->name : std::string();
|
||||
}
|
||||
|
||||
extern "C" unsigned int number_of_computers(const struct dive *dive)
|
||||
|
|
|
@ -118,9 +118,9 @@ extern struct dive_site *get_dive_site_for_dive(const struct dive *dive);
|
|||
#ifdef __cplusplus
|
||||
} // TODO: remove
|
||||
extern std::string get_dive_country(const struct dive *dive);
|
||||
extern std::string get_dive_location(const struct dive *dive);
|
||||
extern "C" {
|
||||
#endif
|
||||
extern const char *get_dive_location(const struct dive *dive);
|
||||
extern unsigned int number_of_computers(const struct dive *dive);
|
||||
extern struct divecomputer *get_dive_dc(struct dive *dive, int nr);
|
||||
extern const struct divecomputer *get_dive_dc_const(const struct dive *dive, int nr);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
#include "errorhelper.h"
|
||||
#include "format.h"
|
||||
#include "gettextfromc.h"
|
||||
#include "membuffer.h"
|
||||
#include "pref.h"
|
||||
|
@ -39,12 +40,12 @@ struct dive_site *get_dive_site_by_uuid(uint32_t uuid, struct dive_site_table *d
|
|||
}
|
||||
|
||||
/* there could be multiple sites of the same name - return the first one */
|
||||
struct dive_site *get_dive_site_by_name(const char *name, struct dive_site_table *ds_table)
|
||||
struct dive_site *get_dive_site_by_name(const std::string &name, struct dive_site_table *ds_table)
|
||||
{
|
||||
int i;
|
||||
struct dive_site *ds;
|
||||
for_each_dive_site (i, ds, ds_table) {
|
||||
if (same_string(ds->name, name))
|
||||
if (ds->name == name)
|
||||
return ds;
|
||||
}
|
||||
return NULL;
|
||||
|
@ -65,12 +66,12 @@ struct dive_site *get_dive_site_by_gps(const location_t *loc, struct dive_site_t
|
|||
/* to avoid a bug where we have two dive sites with different name and the same GPS coordinates
|
||||
* and first get the gps coordinates (reading a V2 file) and happen to get back "the other" name,
|
||||
* this function allows us to verify if a very specific name/GPS combination already exists */
|
||||
struct dive_site *get_dive_site_by_gps_and_name(const char *name, const location_t *loc, struct dive_site_table *ds_table)
|
||||
struct dive_site *get_dive_site_by_gps_and_name(const std::string &name, const location_t *loc, struct dive_site_table *ds_table)
|
||||
{
|
||||
int i;
|
||||
struct dive_site *ds;
|
||||
for_each_dive_site (i, ds, ds_table) {
|
||||
if (same_location(loc, &ds->location) && same_string(ds->name, name))
|
||||
if (same_location(loc, &ds->location) && ds->name == name)
|
||||
return ds;
|
||||
}
|
||||
return NULL;
|
||||
|
@ -146,12 +147,12 @@ int add_dive_site_to_table(struct dive_site *ds, struct dive_site_table *ds_tabl
|
|||
* Make this deterministic for testing. */
|
||||
if (!ds->uuid) {
|
||||
SHA1 sha;
|
||||
if (ds->name)
|
||||
sha.update(ds->name, strlen(ds->name));
|
||||
if (ds->description)
|
||||
sha.update(ds->description, strlen(ds->description));
|
||||
if (ds->notes)
|
||||
sha.update(ds->notes, strlen(ds->notes));
|
||||
if (!ds->name.empty())
|
||||
sha.update(ds->name);
|
||||
if (!ds->description.empty())
|
||||
sha.update(ds->description);
|
||||
if (!ds->notes.empty())
|
||||
sha.update(ds->notes);
|
||||
ds->uuid = sha.hash_uint32();
|
||||
}
|
||||
|
||||
|
@ -169,19 +170,16 @@ dive_site::dive_site()
|
|||
{
|
||||
}
|
||||
|
||||
dive_site::dive_site(const char *name) : name(copy_string(name))
|
||||
dive_site::dive_site(const std::string &name) : name(name)
|
||||
{
|
||||
}
|
||||
|
||||
dive_site::dive_site(const char *name, const location_t *loc) : name(copy_string(name)), location(*loc)
|
||||
dive_site::dive_site(const std::string &name, const location_t *loc) : name(name), location(*loc)
|
||||
{
|
||||
}
|
||||
|
||||
dive_site::~dive_site()
|
||||
{
|
||||
free(name);
|
||||
free(notes);
|
||||
free(description);
|
||||
}
|
||||
|
||||
/* when parsing, dive sites are identified by uuid */
|
||||
|
@ -225,7 +223,7 @@ void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table)
|
|||
}
|
||||
|
||||
/* allocate a new site and add it to the table */
|
||||
struct dive_site *create_dive_site(const char *name, struct dive_site_table *ds_table)
|
||||
struct dive_site *create_dive_site(const std::string &name, struct dive_site_table *ds_table)
|
||||
{
|
||||
struct dive_site *ds = new dive_site(name);
|
||||
add_dive_site_to_table(ds, ds_table);
|
||||
|
@ -233,7 +231,7 @@ struct dive_site *create_dive_site(const char *name, struct dive_site_table *ds_
|
|||
}
|
||||
|
||||
/* same as before, but with GPS data */
|
||||
struct dive_site *create_dive_site_with_gps(const char *name, const location_t *loc, struct dive_site_table *ds_table)
|
||||
struct dive_site *create_dive_site_with_gps(const std::string &name, const location_t *loc, struct dive_site_table *ds_table)
|
||||
{
|
||||
struct dive_site *ds = new dive_site(name, loc);
|
||||
add_dive_site_to_table(ds, ds_table);
|
||||
|
@ -244,42 +242,26 @@ struct dive_site *create_dive_site_with_gps(const char *name, const location_t *
|
|||
bool dive_site_is_empty(struct dive_site *ds)
|
||||
{
|
||||
return !ds ||
|
||||
(empty_string(ds->name) &&
|
||||
empty_string(ds->description) &&
|
||||
empty_string(ds->notes) &&
|
||||
!has_location(&ds->location));
|
||||
(ds->name.empty() &&
|
||||
ds->description.empty() &&
|
||||
ds->notes.empty() &&
|
||||
!has_location(&ds->location));
|
||||
}
|
||||
|
||||
void copy_dive_site(struct dive_site *orig, struct dive_site *copy)
|
||||
static void merge_string(std::string &a, const std::string &b)
|
||||
{
|
||||
free(copy->name);
|
||||
free(copy->notes);
|
||||
free(copy->description);
|
||||
|
||||
copy->location = orig->location;
|
||||
copy->name = copy_string(orig->name);
|
||||
copy->notes = copy_string(orig->notes);
|
||||
copy->description = copy_string(orig->description);
|
||||
copy->taxonomy = orig->taxonomy;
|
||||
}
|
||||
|
||||
static void merge_string(char **a, char **b)
|
||||
{
|
||||
char *s1 = *a, *s2 = *b;
|
||||
|
||||
if (!s2)
|
||||
if (b.empty())
|
||||
return;
|
||||
|
||||
if (same_string(s1, s2))
|
||||
if (a == b)
|
||||
return;
|
||||
|
||||
if (!s1) {
|
||||
*a = strdup(s2);
|
||||
if (a.empty()) {
|
||||
a = b;
|
||||
return;
|
||||
}
|
||||
|
||||
*a = format_string("(%s) or (%s)", s1, s2);
|
||||
free(s1);
|
||||
a = format_string_std("(%s) or (%s)", a.c_str(), b.c_str());
|
||||
}
|
||||
|
||||
/* Used to check on import if two dive sites are equivalent.
|
||||
|
@ -290,10 +272,10 @@ static void merge_string(char **a, char **b)
|
|||
*/
|
||||
static bool same_dive_site(const struct dive_site *a, const struct dive_site *b)
|
||||
{
|
||||
return same_string(a->name, b->name)
|
||||
return a->name == b->name
|
||||
&& same_location(&a->location, &b->location)
|
||||
&& same_string(a->description, b->description)
|
||||
&& same_string(a->notes, b->notes);
|
||||
&& a->description == b->description
|
||||
&& a->notes == b->notes;
|
||||
}
|
||||
|
||||
struct dive_site *get_same_dive_site(const struct dive_site *site)
|
||||
|
@ -309,20 +291,20 @@ struct dive_site *get_same_dive_site(const struct dive_site *site)
|
|||
void merge_dive_site(struct dive_site *a, struct dive_site *b)
|
||||
{
|
||||
if (!has_location(&a->location)) a->location = b->location;
|
||||
merge_string(&a->name, &b->name);
|
||||
merge_string(&a->notes, &b->notes);
|
||||
merge_string(&a->description, &b->description);
|
||||
merge_string(a->name, b->name);
|
||||
merge_string(a->notes, b->notes);
|
||||
merge_string(a->description, b->description);
|
||||
|
||||
if (a->taxonomy.empty())
|
||||
a->taxonomy = std::move(b->taxonomy);
|
||||
}
|
||||
|
||||
struct dive_site *find_or_create_dive_site_with_name(const char *name, struct dive_site_table *ds_table)
|
||||
struct dive_site *find_or_create_dive_site_with_name(const std::string &name, struct dive_site_table *ds_table)
|
||||
{
|
||||
int i;
|
||||
struct dive_site *ds;
|
||||
for_each_dive_site(i,ds, ds_table) {
|
||||
if (same_string(name, ds->name))
|
||||
if (name == ds->name)
|
||||
break;
|
||||
}
|
||||
if (ds)
|
||||
|
|
|
@ -13,15 +13,15 @@
|
|||
struct dive_site
|
||||
{
|
||||
uint32_t uuid = 0;
|
||||
char *name = nullptr;
|
||||
std::string name;
|
||||
std::vector<dive *> dives;
|
||||
location_t location = { { 9 }, { 0 } };
|
||||
char *description = nullptr;
|
||||
char *notes = nullptr;
|
||||
std::string description;
|
||||
std::string notes;
|
||||
taxonomy_data taxonomy;
|
||||
dive_site();
|
||||
dive_site(const char *name);
|
||||
dive_site(const char *name, const location_t *loc);
|
||||
dive_site(const std::string &name);
|
||||
dive_site(const std::string &name, const location_t *loc);
|
||||
~dive_site();
|
||||
};
|
||||
|
||||
|
@ -54,19 +54,17 @@ bool is_dive_site_selected(const struct dive_site &ds);
|
|||
int unregister_dive_site(struct dive_site *ds);
|
||||
int register_dive_site(struct dive_site *ds);
|
||||
void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table);
|
||||
struct dive_site *create_dive_site(const char *name, struct dive_site_table *ds_table);
|
||||
struct dive_site *create_dive_site_with_gps(const char *name, const location_t *, struct dive_site_table *ds_table);
|
||||
struct dive_site *get_dive_site_by_name(const char *name, struct dive_site_table *ds_table);
|
||||
struct dive_site *create_dive_site(const std::string &name, struct dive_site_table *ds_table);
|
||||
struct dive_site *create_dive_site_with_gps(const std::string &name, const location_t *, struct dive_site_table *ds_table);
|
||||
struct dive_site *get_dive_site_by_name(const std::string &name, struct dive_site_table *ds_table);
|
||||
struct dive_site *get_dive_site_by_gps(const location_t *, struct dive_site_table *ds_table);
|
||||
struct dive_site *get_dive_site_by_gps_and_name(const char *name, const location_t *, struct dive_site_table *ds_table);
|
||||
struct dive_site *get_dive_site_by_gps_and_name(const std::string &name, const location_t *, struct dive_site_table *ds_table);
|
||||
struct dive_site *get_dive_site_by_gps_proximity(const location_t *, int distance, struct dive_site_table *ds_table);
|
||||
struct dive_site *get_same_dive_site(const struct dive_site *);
|
||||
bool dive_site_is_empty(struct dive_site *ds);
|
||||
void copy_dive_site_taxonomy(struct dive_site *orig, struct dive_site *copy);
|
||||
void copy_dive_site(struct dive_site *orig, struct dive_site *copy);
|
||||
void merge_dive_site(struct dive_site *a, struct dive_site *b);
|
||||
unsigned int get_distance(const location_t *loc1, const location_t *loc2);
|
||||
struct dive_site *find_or_create_dive_site_with_name(const char *name, struct dive_site_table *ds_table);
|
||||
struct dive_site *find_or_create_dive_site_with_name(const std::string &name, struct dive_site_table *ds_table);
|
||||
void purge_empty_dive_sites(struct dive_site_table *ds_table);
|
||||
void clear_dive_site_table(struct dive_site_table *ds_table);
|
||||
void move_dive_site_table(struct dive_site_table *src, struct dive_site_table *dst);
|
||||
|
|
|
@ -840,7 +840,7 @@ static bool has_locations(const filter_constraint &c, const struct dive *d)
|
|||
diveLocations.push_back(QString(d->divetrip->location).trimmed());
|
||||
|
||||
if (d->dive_site)
|
||||
diveLocations.push_back(QString(d->dive_site->name).trimmed());
|
||||
diveLocations.push_back(QString::fromStdString(d->dive_site->name).trimmed());
|
||||
|
||||
return check(c, diveLocations);
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ static std::vector<QString> getWords(const dive *d)
|
|||
// TODO: We should tokenize all dive-sites and trips first and then
|
||||
// take the tokens from a cache.
|
||||
if (d->dive_site) {
|
||||
tokenize(d->dive_site->name, res);
|
||||
tokenize(QString::fromStdString(d->dive_site->name), res);
|
||||
std::string country = taxonomy_get_country(d->dive_site->taxonomy);
|
||||
if (!country.empty())
|
||||
tokenize(country.c_str(), res);
|
||||
|
|
|
@ -181,15 +181,8 @@ static int cobalt_dive(void *param, int, char **data, char **)
|
|||
}
|
||||
|
||||
if (location && location_site) {
|
||||
char *tmp = (char *)malloc(strlen(location) + strlen(location_site) + 4);
|
||||
if (!tmp) {
|
||||
free(location);
|
||||
free(location_site);
|
||||
return 1;
|
||||
}
|
||||
sprintf(tmp, "%s / %s", location, location_site);
|
||||
std::string tmp = std::string(location) + " / " + location_site;
|
||||
add_dive_to_dive_site(state->cur_dive, find_or_create_dive_site_with_name(tmp, state->log->sites));
|
||||
free(tmp);
|
||||
}
|
||||
free(location);
|
||||
free(location_site);
|
||||
|
@ -206,7 +199,6 @@ static int cobalt_dive(void *param, int, char **data, char **)
|
|||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
extern "C" int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *, int, struct divelog *log)
|
||||
{
|
||||
int retval;
|
||||
|
|
|
@ -275,7 +275,7 @@ static int divinglog_dive(void *param, int, char **data, char **)
|
|||
state->cur_dive->when = (time_t)(atol(data[1]));
|
||||
|
||||
if (data[2])
|
||||
add_dive_to_dive_site(state->cur_dive, find_or_create_dive_site_with_name(data[2], state->log->sites));
|
||||
add_dive_to_dive_site(state->cur_dive, find_or_create_dive_site_with_name(std::string(data[2]), state->log->sites));
|
||||
|
||||
if (data[3])
|
||||
utf8_string(data[3], &state->cur_dive->buddy);
|
||||
|
|
|
@ -637,7 +637,7 @@ static void parse_string_field(device_data_t *devdata, struct dive *dive, dc_fie
|
|||
|
||||
if (location.lat.udeg && location.lon.udeg) {
|
||||
unregister_dive_from_dive_site(dive);
|
||||
add_dive_to_dive_site(dive, create_dive_site_with_gps(str->value, &location, devdata->log->sites));
|
||||
add_dive_to_dive_site(dive, create_dive_site_with_gps(std::string(str->value), &location, devdata->log->sites));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ static void parse_dives(int log_version, const unsigned char *buf, unsigned int
|
|||
|
||||
/* Store the location only if we have one */
|
||||
if (!location.empty())
|
||||
add_dive_to_dive_site(dive, find_or_create_dive_site_with_name(location.c_str(), sites));
|
||||
add_dive_to_dive_site(dive, find_or_create_dive_site_with_name(location, sites));
|
||||
|
||||
ptr += len + 4 + place_len;
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ static void parse_dive_gps(char *line, struct git_parser_state *state)
|
|||
if (!ds) {
|
||||
ds = get_dive_site_by_gps(&location, state->log->sites);
|
||||
if (!ds)
|
||||
ds = create_dive_site_with_gps("", &location, state->log->sites);
|
||||
ds = create_dive_site_with_gps(std::string(), &location, state->log->sites);
|
||||
add_dive_to_dive_site(state->active_dive, ds);
|
||||
} else {
|
||||
if (dive_site_has_gps_location(ds) && !same_location(&ds->location, &location)) {
|
||||
|
@ -189,10 +189,8 @@ static void parse_dive_gps(char *line, struct git_parser_state *state)
|
|||
// note 2: we could include the first newline in the
|
||||
// translation string, but that would be weird and cause
|
||||
// a new string.
|
||||
std::string new_text = std::string(ds->notes) + '\n' +
|
||||
format_string_std(translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords.c_str());
|
||||
free(ds->notes);
|
||||
ds->notes = strdup(new_text.c_str());
|
||||
ds->notes += '\n';
|
||||
ds->notes += format_string_std(translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords.c_str());
|
||||
}
|
||||
ds->location = location;
|
||||
}
|
||||
|
@ -224,21 +222,19 @@ static void parse_dive_location(char *, struct git_parser_state *state)
|
|||
std::string name = get_first_converted_string(state);
|
||||
struct dive_site *ds = get_dive_site_for_dive(state->active_dive);
|
||||
if (!ds) {
|
||||
ds = get_dive_site_by_name(name.c_str(), state->log->sites);
|
||||
ds = get_dive_site_by_name(name, state->log->sites);
|
||||
if (!ds)
|
||||
ds = create_dive_site(name.c_str(), state->log->sites);
|
||||
ds = create_dive_site(name, state->log->sites);
|
||||
add_dive_to_dive_site(state->active_dive, ds);
|
||||
} else {
|
||||
// we already had a dive site linked to the dive
|
||||
if (empty_string(ds->name)) {
|
||||
free(ds->name); // empty_string could mean pointer to a 0-byte!
|
||||
ds->name = strdup(name.c_str());
|
||||
if (ds->name.empty()) {
|
||||
ds->name = name.c_str();
|
||||
} else {
|
||||
// and that dive site had a name. that's weird - if our name is different, add it to the notes
|
||||
if (!same_string(ds->name, name.c_str())) {
|
||||
std::string new_string = std::string(ds->notes) + '\n' +
|
||||
format_string_std(translate("gettextFromC", "additional name for site: %s\n"), name.c_str());
|
||||
ds->notes = strdup(new_string.c_str());
|
||||
if (ds->name == name) {
|
||||
ds->notes += '\n';
|
||||
ds->notes += format_string_std(translate("gettextFromC", "additional name for site: %s\n"), name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -314,7 +310,7 @@ static void parse_dive_invalid(char *, struct git_parser_state *state)
|
|||
}
|
||||
|
||||
static void parse_site_description(char *, struct git_parser_state *state)
|
||||
{ state->active_site->description = get_first_converted_string_c(state); }
|
||||
{ state->active_site->description = get_first_converted_string(state); }
|
||||
|
||||
static void parse_site_name(char *, struct git_parser_state *state)
|
||||
{ state->active_site->name = get_first_converted_string_c(state); }
|
||||
|
|
|
@ -978,10 +978,9 @@ static void try_to_fill_sample(struct sample *sample, const char *name, char *bu
|
|||
|
||||
static void divinglog_place(const char *place, struct dive *d, struct parser_state *state)
|
||||
{
|
||||
char buffer[1024];
|
||||
struct dive_site *ds;
|
||||
|
||||
snprintf(buffer, sizeof(buffer),
|
||||
std::string buffer = format_string_std(
|
||||
"%s%s%s%s%s",
|
||||
place,
|
||||
!state->city.empty() ? ", " : "",
|
||||
|
@ -1160,10 +1159,11 @@ static void gps_lat(const char *buffer, struct dive *dive, struct parser_state *
|
|||
|
||||
location.lat = parse_degrees(buffer, &end);
|
||||
if (!ds) {
|
||||
add_dive_to_dive_site(dive, create_dive_site_with_gps(NULL, &location, state->log->sites));
|
||||
add_dive_to_dive_site(dive, create_dive_site_with_gps(std::string(), &location, state->log->sites));
|
||||
} else {
|
||||
if (ds->location.lat.udeg && ds->location.lat.udeg != location.lat.udeg)
|
||||
report_info("Oops, changing the latitude of existing dive site id %8x name %s; not good", ds->uuid, ds->name ?: "(unknown)");
|
||||
report_info("Oops, changing the latitude of existing dive site id %8x name %s; not good", ds->uuid,
|
||||
ds->name.empty() ? "(unknown)" : ds->name.c_str());
|
||||
ds->location.lat = location.lat;
|
||||
}
|
||||
}
|
||||
|
@ -1176,10 +1176,11 @@ static void gps_long(const char *buffer, struct dive *dive, struct parser_state
|
|||
|
||||
location.lon = parse_degrees(buffer, &end);
|
||||
if (!ds) {
|
||||
add_dive_to_dive_site(dive, create_dive_site_with_gps(NULL, &location, state->log->sites));
|
||||
add_dive_to_dive_site(dive, create_dive_site_with_gps(std::string(), &location, state->log->sites));
|
||||
} else {
|
||||
if (ds->location.lon.udeg && ds->location.lon.udeg != location.lon.udeg)
|
||||
report_info("Oops, changing the longitude of existing dive site id %8x name %s; not good", ds->uuid, ds->name ?: "(unknown)");
|
||||
report_info("Oops, changing the longitude of existing dive site id %8x name %s; not good", ds->uuid,
|
||||
ds->name.empty() ? "(unknown)" : ds->name.c_str());
|
||||
ds->location.lon = location.lon;
|
||||
}
|
||||
}
|
||||
|
@ -1213,7 +1214,7 @@ static void gps_in_dive(const char *buffer, struct dive *dive, struct parser_sta
|
|||
// remember the original coordinates so we can create the correct dive site later
|
||||
state->cur_location = location;
|
||||
} else {
|
||||
ds = create_dive_site_with_gps("", &location, state->log->sites);
|
||||
ds = create_dive_site_with_gps(std::string(), &location, state->log->sites);
|
||||
}
|
||||
add_dive_to_dive_site(dive, ds);
|
||||
} else {
|
||||
|
@ -1224,7 +1225,8 @@ static void gps_in_dive(const char *buffer, struct dive *dive, struct parser_sta
|
|||
ds->location.lat.udeg / 1000000.0, ds->location.lon.udeg / 1000000.0,
|
||||
location.lat.udeg / 1000000.0, location.lon.udeg / 1000000.0);
|
||||
std::string coords = printGPSCoordsC(&location);
|
||||
ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords.c_str());
|
||||
ds->notes += '\n';
|
||||
ds->notes += format_string_std(translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords.c_str());
|
||||
} else {
|
||||
ds->location = location;
|
||||
}
|
||||
|
@ -1417,11 +1419,11 @@ static void try_to_fill_dive_site(struct parser_state *state, const char *name,
|
|||
|
||||
if (MATCH("uuid", hex_value, &ds->uuid))
|
||||
return;
|
||||
if (MATCH("name", utf8_string, &ds->name))
|
||||
if (MATCH("name", utf8_string_std, &ds->name))
|
||||
return;
|
||||
if (MATCH("description", utf8_string, &ds->description))
|
||||
if (MATCH("description", utf8_string_std, &ds->description))
|
||||
return;
|
||||
if (MATCH("notes", utf8_string, &ds->notes))
|
||||
if (MATCH("notes", utf8_string_std, &ds->notes))
|
||||
return;
|
||||
if (MATCH("gps", gps_location, ds.get()))
|
||||
return;
|
||||
|
@ -1802,6 +1804,7 @@ static timestamp_t parse_dlf_timestamp(unsigned char *buffer)
|
|||
|
||||
extern "C" int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
unsigned char *ptr = buffer;
|
||||
unsigned char event;
|
||||
bool found;
|
||||
|
@ -2232,7 +2235,7 @@ extern "C" int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divel
|
|||
/* Measure GPS */
|
||||
state.cur_location.lat.udeg = (int)((ptr[7] << 24) + (ptr[6] << 16) + (ptr[5] << 8) + (ptr[4] << 0));
|
||||
state.cur_location.lon.udeg = (int)((ptr[11] << 24) + (ptr[10] << 16) + (ptr[9] << 8) + (ptr[8] << 0));
|
||||
add_dive_to_dive_site(state.cur_dive, create_dive_site_with_gps("DLF imported", &state.cur_location, state.log->sites));
|
||||
add_dive_to_dive_site(state.cur_dive, create_dive_site_with_gps("DLF imported"s, &state.cur_location, state.log->sites));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "divelog.h"
|
||||
#include "divesite.h"
|
||||
#include "errorhelper.h"
|
||||
#include "format.h"
|
||||
#include "sample.h"
|
||||
#include "subsurface-string.h"
|
||||
#include "picture.h"
|
||||
|
@ -203,7 +204,7 @@ void dive_site_end(struct parser_state *state)
|
|||
merge_dive_site(ds, state->cur_dive_site.get());
|
||||
|
||||
if (verbose > 3)
|
||||
printf("completed dive site uuid %x8 name {%s}\n", ds->uuid, ds->name);
|
||||
printf("completed dive site uuid %x8 name {%s}\n", ds->uuid, ds->name.c_str());
|
||||
|
||||
state->cur_dive_site.reset();
|
||||
}
|
||||
|
@ -470,18 +471,18 @@ void add_dive_site(const char *ds_name, struct dive *dive, struct parser_state *
|
|||
struct dive_site *ds = dive->dive_site;
|
||||
if (!ds) {
|
||||
// if the dive doesn't have a dive site, check if there's already a dive site by this name
|
||||
ds = get_dive_site_by_name(trimmed.c_str(), state->log->sites);
|
||||
ds = get_dive_site_by_name(trimmed, state->log->sites);
|
||||
}
|
||||
if (ds) {
|
||||
// we have a dive site, let's hope there isn't a different name
|
||||
if (empty_string(ds->name)) {
|
||||
ds->name = copy_string(trimmed.c_str());
|
||||
if (ds->name.empty()) {
|
||||
ds->name = trimmed;
|
||||
} else if (trimmed != ds->name) {
|
||||
// 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
|
||||
struct dive_site *exact_match = get_dive_site_by_gps_and_name(trimmed.c_str(), &ds->location, state->log->sites);
|
||||
struct dive_site *exact_match = get_dive_site_by_gps_and_name(trimmed, &ds->location, state->log->sites);
|
||||
if (exact_match) {
|
||||
unregister_dive_from_dive_site(dive);
|
||||
add_dive_to_dive_site(dive, exact_match);
|
||||
|
@ -495,7 +496,8 @@ void add_dive_site(const char *ds_name, struct dive *dive, struct parser_state *
|
|||
} else {
|
||||
newds->location = ds->location;
|
||||
}
|
||||
newds->notes = add_to_string(newds->notes, translate("gettextFromC", "additional name for site: %s\n"), ds->name);
|
||||
newds->notes += '\n';
|
||||
newds->notes += format_string_std(translate("gettextFromC", "additional name for site: %s\n"), ds->name.c_str());
|
||||
}
|
||||
} else if (dive->dive_site != ds) {
|
||||
// add the existing dive site to the current dive
|
||||
|
@ -503,7 +505,7 @@ void add_dive_site(const char *ds_name, struct dive *dive, struct parser_state *
|
|||
add_dive_to_dive_site(dive, ds);
|
||||
}
|
||||
} else {
|
||||
add_dive_to_dive_site(dive, create_dive_site(trimmed.c_str(), state->log->sites));
|
||||
add_dive_to_dive_site(dive, create_dive_site(trimmed, state->log->sites));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -929,9 +929,9 @@ static void save_divesites(git_repository *repo, struct dir *tree)
|
|||
struct dive_site *ds = get_dive_site(i, divelog.sites);
|
||||
struct membufferpp site_file_name;
|
||||
put_format(&site_file_name, "Site-%08x", ds->uuid);
|
||||
show_utf8(&b, "name ", ds->name, "\n");
|
||||
show_utf8(&b, "description ", ds->description, "\n");
|
||||
show_utf8(&b, "notes ", ds->notes, "\n");
|
||||
show_utf8(&b, "name ", ds->name.c_str(), "\n");
|
||||
show_utf8(&b, "description ", ds->description.c_str(), "\n");
|
||||
show_utf8(&b, "notes ", ds->notes.c_str(), "\n");
|
||||
put_location(&b, &ds->location, "gps ", "\n");
|
||||
for (const auto &t: ds->taxonomy) {
|
||||
if (t.category != TC_NONE && !t.value.empty()) {
|
||||
|
@ -1142,15 +1142,17 @@ static void create_commit_message(struct membuffer *msg, bool create_empty)
|
|||
put_format(msg, "Changes made: \n\n%s\n", changes_made.c_str());
|
||||
} else if (dive) {
|
||||
dive_trip_t *trip = dive->divetrip;
|
||||
const char *location = get_dive_location(dive) ? : "no location";
|
||||
std::string location = get_dive_location(dive);
|
||||
if (location.empty())
|
||||
location = "no location";
|
||||
struct divecomputer *dc = &dive->dc;
|
||||
const char *sep = "\n";
|
||||
|
||||
if (dive->number)
|
||||
nr = dive->number;
|
||||
|
||||
put_format(msg, "dive %d: %s", nr, location);
|
||||
if (trip && !empty_string(trip->location) && strcmp(trip->location, location))
|
||||
put_format(msg, "dive %d: %s", nr, location.c_str());
|
||||
if (trip && !empty_string(trip->location) && location != trip->location)
|
||||
put_format(msg, " (%s)", trip->location);
|
||||
put_format(msg, "\n");
|
||||
do {
|
||||
|
|
|
@ -355,7 +355,7 @@ static void write_one_dive(struct membuffer *b, struct dive *dive, const char *p
|
|||
put_format(b, "\"subsurface_number\":%d,", dive->number);
|
||||
put_HTML_date(b, dive, "\"date\":\"", "\",");
|
||||
put_HTML_time(b, dive, "\"time\":\"", "\",");
|
||||
write_attribute(b, "location", get_dive_location(dive), ", ");
|
||||
write_attribute(b, "location", get_dive_location(dive).c_str(), ", ");
|
||||
put_HTML_coordinates(b, dive);
|
||||
put_format(b, "\"rating\":%d,", dive->rating);
|
||||
put_format(b, "\"visibility\":%d,", dive->visibility);
|
||||
|
|
|
@ -711,11 +711,11 @@ static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonym
|
|||
continue;
|
||||
|
||||
put_format(b, "<site uuid='%8x'", ds->uuid);
|
||||
show_utf8_blanked(b, ds->name, " name='", "'", 1, anonymize);
|
||||
show_utf8_blanked(b, ds->name.c_str(), " name='", "'", 1, anonymize);
|
||||
put_location(b, &ds->location, " gps='", "'");
|
||||
show_utf8_blanked(b, ds->description, " description='", "'", 1, anonymize);
|
||||
show_utf8_blanked(b, ds->description.c_str(), " description='", "'", 1, anonymize);
|
||||
put_format(b, ">\n");
|
||||
show_utf8_blanked(b, ds->notes, " <notes>", " </notes>\n", 0, anonymize);
|
||||
show_utf8_blanked(b, ds->notes.c_str(), " <notes>", " </notes>\n", 0, anonymize);
|
||||
for (auto const &t: ds->taxonomy) {
|
||||
if (t.category != TC_NONE && !t.value.empty()) {
|
||||
put_format(b, " <geo cat='%d'", t.category);
|
||||
|
@ -913,11 +913,11 @@ static void save_dive_sites_buffer(struct membuffer *b, const struct dive_site *
|
|||
const struct dive_site *ds = sites[i];
|
||||
|
||||
put_format(b, "<site uuid='%8x'", ds->uuid);
|
||||
show_utf8_blanked(b, ds->name, " name='", "'", 1, anonymize);
|
||||
show_utf8_blanked(b, ds->name.c_str(), " name='", "'", 1, anonymize);
|
||||
put_location(b, &ds->location, " gps='", "'");
|
||||
show_utf8_blanked(b, ds->description, " description='", "'", 1, anonymize);
|
||||
show_utf8_blanked(b, ds->description.c_str(), " description='", "'", 1, anonymize);
|
||||
put_format(b, ">\n");
|
||||
show_utf8_blanked(b, ds->notes, " <notes>", " </notes>\n", 0, anonymize);
|
||||
show_utf8_blanked(b, ds->notes.c_str(), " <notes>", " </notes>\n", 0, anonymize);
|
||||
for (const auto &t: ds->taxonomy) {
|
||||
if (t.category != TC_NONE && !t.value.empty()) {
|
||||
put_format(b, " <geo cat='%d'", t.category);
|
||||
|
|
|
@ -148,7 +148,7 @@ dive_trip_t *create_trip_from_dive(struct dive *dive)
|
|||
dive_trip_t *trip;
|
||||
|
||||
trip = alloc_trip();
|
||||
trip->location = copy_string(get_dive_location(dive));
|
||||
trip->location = copy_string(get_dive_location(dive).c_str());
|
||||
|
||||
return trip;
|
||||
}
|
||||
|
@ -265,8 +265,9 @@ dive_trip_t *get_dives_to_autogroup(struct dive_table *table, int start, int *fr
|
|||
if (dive->divetrip || dive->notrip ||
|
||||
dive->when >= lastdive->when + TRIP_THRESHOLD)
|
||||
break;
|
||||
if (get_dive_location(dive) && !trip->location)
|
||||
trip->location = copy_string(get_dive_location(dive));
|
||||
std::string location = get_dive_location(dive);
|
||||
if (!location.empty() && !trip->location)
|
||||
trip->location = copy_string(get_dive_location(dive).c_str());
|
||||
lastdive = dive;
|
||||
}
|
||||
return trip;
|
||||
|
|
|
@ -808,6 +808,7 @@ static bool uemis_delete_dive(device_data_t *devdata, uint32_t diveid)
|
|||
* the addresses of those fields for every dive that references the dive spot. */
|
||||
static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, std::string_view buf, int &max_divenr, int *for_dive)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
bool done = false;
|
||||
bool is_log = false, is_dive = false;
|
||||
std::vector<std::string_view> sections;
|
||||
|
@ -914,7 +915,7 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, std::s
|
|||
} else if (!is_log && dive && tag == "divespot_id") {
|
||||
int divespot_id;
|
||||
if (from_chars(val, divespot_id).ec != std::errc::invalid_argument) {
|
||||
struct dive_site *ds = create_dive_site("from Uemis", devdata->log->sites);
|
||||
struct dive_site *ds = create_dive_site("from Uemis"s, devdata->log->sites);
|
||||
unregister_dive_from_dive_site(dive);
|
||||
add_dive_to_dive_site(dive, ds);
|
||||
uemis_obj.mark_divelocation(dive->dc.diveid, divespot_id, ds);
|
||||
|
@ -1099,17 +1100,16 @@ static void get_uemis_divespot(device_data_t *devdata, const std::string &mountp
|
|||
struct dive_site *ds = it->second;
|
||||
unregister_dive_from_dive_site(dive);
|
||||
add_dive_to_dive_site(dive, ds);
|
||||
} else if (nds && nds->name && strstr(nds->name,"from Uemis")) {
|
||||
} else if (nds && !nds->name.empty() && nds->name.find("from Uemis") != std::string::npos) {
|
||||
if (load_uemis_divespot(mountpath, divespot_id)) {
|
||||
/* get the divesite based on the diveid, this should give us
|
||||
* the newly created site
|
||||
*/
|
||||
struct dive_site *ods;
|
||||
/* with the divesite name we got from parse_dive, that is called on load_uemis_divespot
|
||||
* we search all existing divesites if we have one with the same name already. The function
|
||||
* returns the first found which is luckily not the newly created.
|
||||
*/
|
||||
ods = get_dive_site_by_name(nds->name, devdata->log->sites);
|
||||
struct dive_site *ods = get_dive_site_by_name(nds->name, devdata->log->sites);
|
||||
if (ods) {
|
||||
/* if the uuid's are the same, the new site is a duplicate and can be deleted */
|
||||
if (nds->uuid != ods->uuid) {
|
||||
|
|
|
@ -165,8 +165,7 @@ void uemis::set_divelocation(int divespot, const std::string &text, double longi
|
|||
if (it.second.divespot == divespot) {
|
||||
struct dive_site *ds = it.second.dive_site;
|
||||
if (ds) {
|
||||
free(ds->name);
|
||||
ds->name = strdup(text.c_str());
|
||||
ds->name = text;
|
||||
ds->location = create_location(latitude, longitude);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ bool uploadDiveLogsDE::prepareDives(const QString &tempfile, bool selected)
|
|||
|
||||
if (ds) {
|
||||
put_format(&mb, "<divelog><divesites><site uuid='%8x' name='", ds->uuid);
|
||||
put_quoted(&mb, ds->name, 1, 0);
|
||||
put_quoted(&mb, ds->name.c_str(), 1, 0);
|
||||
put_format(&mb, "'");
|
||||
put_location(&mb, &ds->location, " gps='", "'");
|
||||
put_format(&mb, ">\n");
|
||||
|
|
|
@ -61,7 +61,7 @@ static void writeMarkers(struct membuffer *b, bool selected_only)
|
|||
put_HTML_watertemp(b, dive, " ", "</p>");
|
||||
pre = format_string_std("<p>%s <b>", translate("gettextFromC", "Location:"));
|
||||
put_string(b, pre.c_str());
|
||||
put_HTML_quoted(b, get_dive_location(dive));
|
||||
put_HTML_quoted(b, get_dive_location(dive).c_str());
|
||||
put_string(b, "</b></p>");
|
||||
pre = format_string_std("<p> %s ", translate("gettextFromC", "Notes:"));
|
||||
put_HTML_notes(b, dive, pre.c_str(), " </p>");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue