mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-27 20:58:47 +00:00
core: turn string data in struct divecomputer into std::string
Simplifies memory management. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
cc39f709ce
commit
b9a2eff3c9
28 changed files with 114 additions and 147 deletions
|
@ -179,7 +179,7 @@ void export_TeX(const char *filename, bool selected_only, bool plain, ExportCall
|
|||
put_format(&buf, "\\def\\%ssitename{%s}\n", ssrf, site ? site->name.c_str() : "");
|
||||
site ? put_format(&buf, "\\def\\%sgpslat{%f}\n", ssrf, site->location.lat.udeg / 1000000.0) : put_format(&buf, "\\def\\%sgpslat{}\n", ssrf);
|
||||
site ? put_format(&buf, "\\def\\%sgpslon{%f}\n", ssrf, site->location.lon.udeg / 1000000.0) : put_format(&buf, "\\def\\gpslon{}\n");
|
||||
put_format(&buf, "\\def\\%scomputer{%s}\n", ssrf, dive->dc.model);
|
||||
put_format(&buf, "\\def\\%scomputer{%s}\n", ssrf, dive->dc.model.c_str());
|
||||
put_format(&buf, "\\def\\%scountry{%s}\n", ssrf, country.c_str());
|
||||
put_format(&buf, "\\def\\%stime{%u:%02u}\n", ssrf, FRACTION_TUPLE(dive->duration.seconds, 60));
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ EditDeviceNickname::EditDeviceNickname(const struct divecomputer *dc, const QStr
|
|||
if (index == -1)
|
||||
return;
|
||||
|
||||
setText(Command::Base::tr("Set nickname of device %1 (serial %2) to %3").arg(dc->model, dc->serial, nicknameIn));
|
||||
setText(Command::Base::tr("Set nickname of device %1 (serial %2) to %3").arg(dc->model.c_str(), dc->serial.c_str(), nicknameIn));
|
||||
}
|
||||
|
||||
bool EditDeviceNickname::workToBeDone()
|
||||
|
|
|
@ -29,7 +29,7 @@ bool device::operator<(const device &a) const
|
|||
|
||||
const struct device *get_device_for_dc(const struct device_table *table, const struct divecomputer *dc)
|
||||
{
|
||||
if (!dc->model || !dc->serial)
|
||||
if (dc->model.empty() || dc->serial.empty())
|
||||
return NULL;
|
||||
|
||||
const std::vector<device> &dcs = table->devices;
|
||||
|
@ -40,14 +40,14 @@ const struct device *get_device_for_dc(const struct device_table *table, const s
|
|||
|
||||
int get_or_add_device_for_dc(struct device_table *table, const struct divecomputer *dc)
|
||||
{
|
||||
if (!dc->model || !dc->serial)
|
||||
if (dc->model.empty() || dc->serial.empty())
|
||||
return -1;
|
||||
const struct device *dev = get_device_for_dc(table, dc);
|
||||
if (dev) {
|
||||
auto it = std::lower_bound(table->devices.begin(), table->devices.end(), *dev);
|
||||
return it - table->devices.begin();
|
||||
}
|
||||
return create_device_node(table, dc->model, dc->serial, "");
|
||||
return create_device_node(table, dc->model, dc->serial, std::string());
|
||||
}
|
||||
|
||||
bool device_exists(const struct device_table *device_table, const struct device *dev)
|
||||
|
@ -86,14 +86,14 @@ static int addDC(std::vector<device> &dcs, const std::string &m, const std::stri
|
|||
}
|
||||
}
|
||||
|
||||
int create_device_node(struct device_table *device_table, const char *model, const char *serial, const char *nickname)
|
||||
int create_device_node(struct device_table *device_table, const std::string &model, const std::string &serial, const std::string &nickname)
|
||||
{
|
||||
return addDC(device_table->devices, model ?: "", serial ?: "", nickname ?: "");
|
||||
return addDC(device_table->devices, model, serial, nickname);
|
||||
}
|
||||
|
||||
int add_to_device_table(struct device_table *device_table, const struct device *dev)
|
||||
{
|
||||
return create_device_node(device_table, dev->model.c_str(), dev->serialNumber.c_str(), dev->nickName.c_str());
|
||||
return create_device_node(device_table, dev->model, dev->serialNumber, dev->nickName);
|
||||
}
|
||||
|
||||
int remove_device(struct device_table *device_table, const struct device *dev)
|
||||
|
@ -138,12 +138,12 @@ int is_default_dive_computer_device(const char *name)
|
|||
return qPrefDiveComputer::device() == name;
|
||||
}
|
||||
|
||||
const char *get_dc_nickname(const struct divecomputer *dc)
|
||||
std::string get_dc_nickname(const struct divecomputer *dc)
|
||||
{
|
||||
const device *existNode = get_device_for_dc(divelog.devices.get(), dc);
|
||||
|
||||
if (existNode && !existNode->nickName.empty())
|
||||
return existNode->nickName.c_str();
|
||||
return existNode->nickName;
|
||||
else
|
||||
return dc->model;
|
||||
}
|
||||
|
@ -167,19 +167,19 @@ struct device *get_device_mutable(struct device_table *table, int i)
|
|||
return &table->devices[i];
|
||||
}
|
||||
|
||||
const char *device_get_model(const struct device *dev)
|
||||
std::string device_get_model(const struct device *dev)
|
||||
{
|
||||
return dev ? dev->model.c_str() : NULL;
|
||||
return dev ? dev->model : std::string();
|
||||
}
|
||||
|
||||
const char *device_get_serial(const struct device *dev)
|
||||
std::string device_get_serial(const struct device *dev)
|
||||
{
|
||||
return dev ? dev->serialNumber.c_str() : NULL;
|
||||
return dev ? dev->serialNumber : std::string();
|
||||
}
|
||||
|
||||
const char *device_get_nickname(const struct device *dev)
|
||||
std::string device_get_nickname(const struct device *dev)
|
||||
{
|
||||
return dev ? dev->nickName.c_str() : NULL;
|
||||
return dev ? dev->nickName : std::string();
|
||||
}
|
||||
|
||||
struct device_table *alloc_device_table()
|
||||
|
|
|
@ -14,12 +14,12 @@ struct dive_table;
|
|||
// global device table
|
||||
extern struct fingerprint_table fingerprint_table;
|
||||
|
||||
extern int create_device_node(struct device_table *table, const char *model, const char *serial, const char *nickname);
|
||||
extern int create_device_node(struct device_table *table, const std::string &model, const std::string &serial, const std::string &nickname);
|
||||
extern int nr_devices(const struct device_table *table);
|
||||
extern const struct device *get_device(const struct device_table *table, int i);
|
||||
extern struct device *get_device_mutable(struct device_table *table, int i);
|
||||
extern void clear_device_table(struct device_table *table);
|
||||
const char *get_dc_nickname(const struct divecomputer *dc);
|
||||
std::string get_dc_nickname(const struct divecomputer *dc);
|
||||
extern bool device_used_by_selected_dive(const struct device *dev);
|
||||
|
||||
extern const struct device *get_device_for_dc(const struct device_table *table, const struct divecomputer *dc);
|
||||
|
@ -30,9 +30,9 @@ extern int remove_device(struct device_table *table, const struct device *dev);
|
|||
extern void remove_from_device_table(struct device_table *table, int idx);
|
||||
|
||||
// struct device accessors for C-code. The returned strings are not stable!
|
||||
const char *device_get_model(const struct device *dev);
|
||||
const char *device_get_serial(const struct device *dev);
|
||||
const char *device_get_nickname(const struct device *dev);
|
||||
std::string device_get_model(const struct device *dev);
|
||||
std::string device_get_serial(const struct device *dev);
|
||||
std::string device_get_nickname(const struct device *dev);
|
||||
|
||||
// for C code that needs to alloc/free a device table. (Let's try to get rid of those)
|
||||
extern struct device_table *alloc_device_table();
|
||||
|
|
|
@ -181,14 +181,11 @@ static void copy_extra_data(struct extra_data *sed, struct extra_data *ded)
|
|||
ded->value = copy_string(sed->value);
|
||||
}
|
||||
|
||||
/* this is very different from the copy_divecomputer later in this file;
|
||||
/* this is very different from the copy_dive_computer later in this file;
|
||||
* this function actually makes full copies of the content */
|
||||
static void copy_dc(const struct divecomputer *sdc, struct divecomputer *ddc)
|
||||
{
|
||||
*ddc = *sdc;
|
||||
ddc->model = copy_string(sdc->model);
|
||||
ddc->serial = copy_string(sdc->serial);
|
||||
ddc->fw_version = copy_string(sdc->fw_version);
|
||||
copy_samples(sdc, ddc);
|
||||
copy_events(sdc, ddc);
|
||||
STRUCTURED_LIST_COPY(struct extra_data, sdc->extra_data, ddc->extra_data, copy_extra_data);
|
||||
|
@ -616,9 +613,9 @@ void update_setpoint_events(const struct dive *dive, struct divecomputer *dc)
|
|||
new_setpoint = prefs.defaultsetpoint;
|
||||
|
||||
if (dc->divemode == OC &&
|
||||
(same_string(dc->model, "Shearwater Predator") ||
|
||||
same_string(dc->model, "Shearwater Petrel") ||
|
||||
same_string(dc->model, "Shearwater Nerd"))) {
|
||||
(dc->model == "Shearwater Predator" ||
|
||||
dc->model == "Shearwater Petrel" ||
|
||||
dc->model == "Shearwater Nerd")) {
|
||||
// make sure there's no setpoint in the samples
|
||||
// this is an irreversible change - so switching a dive to OC
|
||||
// by mistake when it's actually CCR is _bad_
|
||||
|
@ -2399,11 +2396,11 @@ static int same_dc(struct divecomputer *a, struct divecomputer *b)
|
|||
static int might_be_same_device(const struct divecomputer *a, const struct divecomputer *b)
|
||||
{
|
||||
/* No dive computer model? That matches anything */
|
||||
if (!a->model || !b->model)
|
||||
if (a->model.empty() || b->model.empty())
|
||||
return 1;
|
||||
|
||||
/* Otherwise at least the model names have to match */
|
||||
if (strcasecmp(a->model, b->model))
|
||||
if (strcasecmp(a->model.c_str(), b->model.c_str()))
|
||||
return 0;
|
||||
|
||||
/* No device ID? Match */
|
||||
|
@ -2452,9 +2449,6 @@ static const struct divecomputer *find_matching_computer(const struct divecomput
|
|||
static void copy_dive_computer(struct divecomputer *res, const struct divecomputer *a)
|
||||
{
|
||||
*res = *a;
|
||||
res->model = copy_string(a->model);
|
||||
res->serial = copy_string(a->serial);
|
||||
res->fw_version = copy_string(a->fw_version);
|
||||
STRUCTURED_LIST_COPY(struct extra_data, a->extra_data, res->extra_data, copy_extra_data);
|
||||
res->samples = res->alloc_samples = 0;
|
||||
res->sample = NULL;
|
||||
|
@ -2520,11 +2514,11 @@ static void join_dive_computers(struct dive *d, struct divecomputer *res,
|
|||
{
|
||||
struct divecomputer *tmp;
|
||||
|
||||
if (a->model && !b->model) {
|
||||
if (!a->model.empty() && b->model.empty()) {
|
||||
copy_dc_renumber(d, a, res, cylinders_map_a);
|
||||
return;
|
||||
}
|
||||
if (b->model && !a->model) {
|
||||
if (!b->model.empty() && a->model.empty()) {
|
||||
copy_dc_renumber(d, b, res, cylinders_map_b);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -489,10 +489,10 @@ void add_extra_data(struct divecomputer *dc, const char *key, const char *value)
|
|||
|
||||
if (!strcasecmp(key, "Serial")) {
|
||||
dc->deviceid = calculate_string_hash(value);
|
||||
dc->serial = strdup(value);
|
||||
dc->serial = value;
|
||||
}
|
||||
if (!strcmp(key, "FW Version")) {
|
||||
dc->fw_version = strdup(value);
|
||||
dc->fw_version = value;
|
||||
}
|
||||
|
||||
while (*ed)
|
||||
|
@ -505,14 +505,6 @@ void add_extra_data(struct divecomputer *dc, const char *key, const char *value)
|
|||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
bool is_dc_planner(const struct divecomputer *dc)
|
||||
{
|
||||
return same_string(dc->model, "planned dive");
|
||||
}
|
||||
|
||||
>>>>>>> ed6cdf19f (build: remove extern "C" linkage)
|
||||
/*
|
||||
* Match two dive computer entries against each other, and
|
||||
* tell if it's the same dive. Return 0 if "don't know",
|
||||
|
@ -522,9 +514,9 @@ bool is_dc_planner(const struct divecomputer *dc)
|
|||
int match_one_dc(const struct divecomputer *a, const struct divecomputer *b)
|
||||
{
|
||||
/* Not same model? Don't know if matching.. */
|
||||
if (!a->model || !b->model)
|
||||
if (a->model.empty() || b->model.empty())
|
||||
return 0;
|
||||
if (strcasecmp(a->model, b->model))
|
||||
if (strcasecmp(a->model.c_str(), b->model.c_str()))
|
||||
return 0;
|
||||
|
||||
/* Different device ID's? Don't know */
|
||||
|
@ -551,9 +543,6 @@ static void free_extra_data(struct extra_data *ed)
|
|||
void free_dc_contents(struct divecomputer *dc)
|
||||
{
|
||||
free(dc->sample);
|
||||
free((void *)dc->model);
|
||||
free((void *)dc->serial);
|
||||
free((void *)dc->fw_version);
|
||||
free_events(dc->events);
|
||||
STRUCTURED_LIST_FREE(struct extra_data, dc->extra_data, free_extra_data);
|
||||
}
|
||||
|
@ -562,24 +551,22 @@ static const char *planner_dc_name = "planned dive";
|
|||
|
||||
bool is_dc_planner(const struct divecomputer *dc)
|
||||
{
|
||||
return same_string(dc->model, planner_dc_name);
|
||||
return dc->model == planner_dc_name;
|
||||
}
|
||||
|
||||
void make_planner_dc(struct divecomputer *dc)
|
||||
{
|
||||
free((void *)dc->model);
|
||||
dc->model = strdup(planner_dc_name);
|
||||
dc->model = planner_dc_name;
|
||||
}
|
||||
|
||||
const char *manual_dc_name = "manually added dive";
|
||||
|
||||
bool is_dc_manually_added_dive(const struct divecomputer *dc)
|
||||
{
|
||||
return dc && same_string(dc->model, manual_dc_name);
|
||||
return dc->model == manual_dc_name;
|
||||
}
|
||||
|
||||
void make_manually_added_dive_dc(struct divecomputer *dc)
|
||||
{
|
||||
free((void *)dc->model);
|
||||
dc->model = strdup(manual_dc_name);
|
||||
dc->model = manual_dc_name;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ struct divecomputer {
|
|||
enum divemode_t divemode = OC; // dive computer type: OC(default) or CCR
|
||||
uint8_t no_o2sensors = 0; // rebreathers: number of O2 sensors used
|
||||
int salinity = 0; // kg per 10000 l
|
||||
const char *model = nullptr, *serial = nullptr, *fw_version = nullptr;
|
||||
std::string model, serial, fw_version;
|
||||
uint32_t deviceid = 0, diveid = 0;
|
||||
int samples = 0, alloc_samples = 0;
|
||||
struct sample *sample = nullptr;
|
||||
|
|
|
@ -631,7 +631,7 @@ static int comp_dc(const struct divecomputer *dc1, const struct divecomputer *dc
|
|||
return -1;
|
||||
if (!dc2)
|
||||
return 1;
|
||||
if ((cmp = safe_strcmp(dc1->model, dc2->model)) != 0)
|
||||
if ((cmp = dc1->model.compare(dc2->model)) != 0)
|
||||
return cmp;
|
||||
dc1 = dc1->next;
|
||||
dc2 = dc2->next;
|
||||
|
|
|
@ -133,7 +133,7 @@ static int cobalt_dive(void *param, int, char **data, char **)
|
|||
if (data[9]) {
|
||||
utf8_string_std(data[9], &state->cur_settings.dc.serial_nr);
|
||||
state->cur_settings.dc.deviceid = atoi(data[9]);
|
||||
state->cur_settings.dc.model = strdup("Cobalt import");
|
||||
state->cur_settings.dc.model = "Cobalt import";
|
||||
}
|
||||
|
||||
dc_settings_end(state);
|
||||
|
@ -141,7 +141,7 @@ static int cobalt_dive(void *param, int, char **data, char **)
|
|||
|
||||
if (data[9]) {
|
||||
state->cur_dive->dc.deviceid = atoi(data[9]);
|
||||
state->cur_dive->dc.model = strdup("Cobalt import");
|
||||
state->cur_dive->dc.model = "Cobalt import";
|
||||
}
|
||||
|
||||
snprintf(get_buffer, sizeof(get_buffer) - 1, get_cylinder_template, state->cur_dive->number);
|
||||
|
|
|
@ -512,7 +512,7 @@ int parse_txt_file(const char *filename, const char *csv, struct divelog *log)
|
|||
|
||||
auto dive = std::make_unique<struct dive>();
|
||||
dive->when = utc_mktime(&cur_tm);;
|
||||
dive->dc.model = strdup("Poseidon MkVI Discovery");
|
||||
dive->dc.model = "Poseidon MkVI Discovery";
|
||||
value = parse_mkvi_value(memtxt.data(), "Rig Serial number");
|
||||
dive->dc.deviceid = atoi(value.c_str());
|
||||
dive->dc.divemode = CCR;
|
||||
|
|
|
@ -330,9 +330,9 @@ static int divinglog_dive(void *param, int, char **data, char **)
|
|||
dc_settings_start(state);
|
||||
|
||||
if (data[12]) {
|
||||
state->cur_dive->dc.model = strdup(data[12]);
|
||||
state->cur_dive->dc.model = data[12];
|
||||
} else {
|
||||
state->cur_settings.dc.model = strdup("Divinglog import");
|
||||
state->cur_settings.dc.model = "Divinglog import";
|
||||
}
|
||||
|
||||
snprintf(get_buffer, sizeof(get_buffer) - 1, get_cylinder0_template, diveid);
|
||||
|
@ -367,9 +367,9 @@ static int divinglog_dive(void *param, int, char **data, char **)
|
|||
settings_end(state);
|
||||
|
||||
if (data[12]) {
|
||||
state->cur_dive->dc.model = strdup(data[12]);
|
||||
state->cur_dive->dc.model = data[12];
|
||||
} else {
|
||||
state->cur_dive->dc.model = strdup("Divinglog import");
|
||||
state->cur_dive->dc.model = "Divinglog import";
|
||||
}
|
||||
|
||||
snprintf(get_buffer, sizeof(get_buffer) - 1, get_profile_template, diveid);
|
||||
|
|
|
@ -205,10 +205,8 @@ static int seac_dive(void *param, int, char **data, char **)
|
|||
settings_start(state);
|
||||
dc_settings_start(state);
|
||||
|
||||
// These dc values are const char *, therefore we have to cast.
|
||||
// Will be fixed by converting to std::string
|
||||
utf8_string(data[1], (char **)&state->cur_dive->dc.serial);
|
||||
utf8_string(data[12], (char **)&state->cur_dive->dc.fw_version);
|
||||
utf8_string_std(data[1], &state->cur_dive->dc.serial);
|
||||
utf8_string_std(data[12],&state->cur_dive->dc.fw_version);
|
||||
state->cur_dive->dc.model = strdup("Seac Action");
|
||||
|
||||
state->cur_dive->dc.deviceid = calculate_string_hash(data[1]);
|
||||
|
@ -225,7 +223,6 @@ static int seac_dive(void *param, int, char **data, char **)
|
|||
|
||||
curcyl->gasmix.o2.permille = 10 * sqlite3_column_int(sqlstmt, 4);
|
||||
|
||||
|
||||
// Track gasses to tell when switch occurs
|
||||
lastgas = curcyl->gasmix;
|
||||
curgas = curcyl->gasmix;
|
||||
|
|
|
@ -266,13 +266,13 @@ static int shearwater_dive(void *param, int, char **data, char **)
|
|||
if (data[10]) {
|
||||
switch (atoi(data[10])) {
|
||||
case 2:
|
||||
state->cur_settings.dc.model = strdup("Shearwater Petrel/Perdix");
|
||||
state->cur_settings.dc.model = "Shearwater Petrel/Perdix";
|
||||
break;
|
||||
case 4:
|
||||
state->cur_settings.dc.model = strdup("Shearwater Predator");
|
||||
state->cur_settings.dc.model = "Shearwater Predator";
|
||||
break;
|
||||
default:
|
||||
state->cur_settings.dc.model = strdup("Shearwater import");
|
||||
state->cur_settings.dc.model = "Shearwater import";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -285,13 +285,13 @@ static int shearwater_dive(void *param, int, char **data, char **)
|
|||
if (data[10]) {
|
||||
switch (atoi(data[10])) {
|
||||
case 2:
|
||||
state->cur_dive->dc.model = strdup("Shearwater Petrel/Perdix");
|
||||
state->cur_dive->dc.model = "Shearwater Petrel/Perdix";
|
||||
break;
|
||||
case 4:
|
||||
state->cur_dive->dc.model = strdup("Shearwater Predator");
|
||||
state->cur_dive->dc.model = "Shearwater Predator";
|
||||
break;
|
||||
default:
|
||||
state->cur_dive->dc.model = strdup("Shearwater import");
|
||||
state->cur_dive->dc.model = "Shearwater import";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -396,13 +396,13 @@ static int shearwater_cloud_dive(void *param, int, char **data, char **)
|
|||
if (data[10]) {
|
||||
switch (atoi(data[10])) {
|
||||
case 2:
|
||||
state->cur_settings.dc.model = strdup("Shearwater Petrel/Perdix");
|
||||
state->cur_settings.dc.model = "Shearwater Petrel/Perdix";
|
||||
break;
|
||||
case 4:
|
||||
state->cur_settings.dc.model = strdup("Shearwater Predator");
|
||||
state->cur_settings.dc.model = "Shearwater Predator";
|
||||
break;
|
||||
default:
|
||||
state->cur_settings.dc.model = strdup("Shearwater import");
|
||||
state->cur_settings.dc.model = "Shearwater import";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -415,13 +415,13 @@ static int shearwater_cloud_dive(void *param, int, char **data, char **)
|
|||
if (data[10]) {
|
||||
switch (atoi(data[10])) {
|
||||
case 2:
|
||||
state->cur_dive->dc.model = strdup("Shearwater Petrel/Perdix");
|
||||
state->cur_dive->dc.model = "Shearwater Petrel/Perdix";
|
||||
break;
|
||||
case 4:
|
||||
state->cur_dive->dc.model = strdup("Shearwater Predator");
|
||||
state->cur_dive->dc.model = "Shearwater Predator";
|
||||
break;
|
||||
default:
|
||||
state->cur_dive->dc.model = strdup("Shearwater import");
|
||||
state->cur_dive->dc.model = "Shearwater import";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -399,10 +399,8 @@ static int dm5_dive(void *param, int, char **data, char **)
|
|||
if (data[4]) {
|
||||
state->cur_dive->dc.deviceid = atoi(data[4]);
|
||||
}
|
||||
// Ugh. dc.model is const char * -> we are not supposed to write into it. This will
|
||||
// change when we convert to std::string.
|
||||
if (data[5])
|
||||
utf8_string(data[5], (char **)&state->cur_dive->dc.model);
|
||||
utf8_string_std(data[5], &state->cur_dive->dc.model);
|
||||
|
||||
if (data[25]) {
|
||||
switch(atoi(data[25])) {
|
||||
|
|
|
@ -436,7 +436,7 @@ sample_cb(dc_sample_type_t type, const dc_sample_value_t *pvalue, void *userdata
|
|||
handle_event(dc, sample, value);
|
||||
break;
|
||||
case DC_SAMPLE_RBT:
|
||||
sample->rbt.seconds = (!strncasecmp(dc->model, "suunto", 6)) ? value.rbt : value.rbt * 60;
|
||||
sample->rbt.seconds = (!strncasecmp(dc->model.c_str(), "suunto", 6)) ? value.rbt : value.rbt * 60;
|
||||
break;
|
||||
#ifdef DC_SAMPLE_TTS
|
||||
case DC_SAMPLE_TTS:
|
||||
|
@ -534,9 +534,9 @@ static dc_status_t parse_samples(device_data_t *, struct divecomputer *dc, dc_pa
|
|||
|
||||
static int might_be_same_dc(struct divecomputer *a, struct divecomputer *b)
|
||||
{
|
||||
if (!a->model || !b->model)
|
||||
if (a->model.empty() || b->model.empty())
|
||||
return 1;
|
||||
if (strcasecmp(a->model, b->model))
|
||||
if (strcasecmp(a->model.c_str(), b->model.c_str()))
|
||||
return 0;
|
||||
if (!a->deviceid || !b->deviceid)
|
||||
return 1;
|
||||
|
@ -827,7 +827,7 @@ static int dive_cb(const unsigned char *data, unsigned int size,
|
|||
auto dive = std::make_unique<struct dive>();
|
||||
|
||||
// Fill in basic fields
|
||||
dive->dc.model = strdup(devdata->model.c_str());
|
||||
dive->dc.model = devdata->model;
|
||||
dive->dc.diveid = calculate_diveid(fingerprint, fsize);
|
||||
|
||||
// Parse the dive's header data
|
||||
|
@ -878,7 +878,7 @@ static int dive_cb(const unsigned char *data, unsigned int size,
|
|||
/* special case for bug in Tecdiving DiveComputer.eu
|
||||
* often the first sample has a water temperature of 0C, followed by the correct
|
||||
* temperature in the next sample */
|
||||
if (same_string(dive->dc.model, "Tecdiving DiveComputer.eu") &&
|
||||
if (dive->dc.model == "Tecdiving DiveComputer.eu" &&
|
||||
dive->dc.sample[0].temperature.mkelvin == ZERO_C_IN_MKELVIN &&
|
||||
dive->dc.sample[1].temperature.mkelvin > dive->dc.sample[0].temperature.mkelvin)
|
||||
dive->dc.sample[0].temperature.mkelvin = dive->dc.sample[1].temperature.mkelvin;
|
||||
|
|
|
@ -156,17 +156,17 @@ static void parse_dives(int log_version, const unsigned char *buf, unsigned int
|
|||
model = *(buf + ptr);
|
||||
switch (model) {
|
||||
case 0:
|
||||
dc->model = strdup("Xen");
|
||||
dc->model = "Xen";
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
dc->model = strdup("Xeo");
|
||||
dc->model = "Xeo";
|
||||
break;
|
||||
case 4:
|
||||
dc->model = strdup("Lynx");
|
||||
dc->model = "Lynx";
|
||||
break;
|
||||
default:
|
||||
dc->model = strdup("Liquivision");
|
||||
dc->model = "Liquivision";
|
||||
break;
|
||||
}
|
||||
ptr++;
|
||||
|
|
|
@ -754,7 +754,7 @@ static void parse_dc_meandepth(char *line, struct git_parser_state *state)
|
|||
{ state->active_dc->meandepth = get_depth(line); }
|
||||
|
||||
static void parse_dc_model(char *, struct git_parser_state *state)
|
||||
{ state->active_dc->model = get_first_converted_string_c(state); }
|
||||
{ state->active_dc->model = get_first_converted_string(state); }
|
||||
|
||||
static void parse_dc_numberofoxygensensors(char *line, struct git_parser_state *state)
|
||||
{ state->active_dc->no_o2sensors = get_index(line); }
|
||||
|
@ -1649,7 +1649,7 @@ static struct divecomputer *create_new_dc(struct dive *dive)
|
|||
while (dc->next)
|
||||
dc = dc->next;
|
||||
/* Did we already fill that in? */
|
||||
if (dc->samples || dc->model || dc->when) {
|
||||
if (dc->samples || !dc->model.empty() || dc->when) {
|
||||
struct divecomputer *newdc = new divecomputer;
|
||||
dc->next = newdc;
|
||||
dc = newdc;
|
||||
|
|
|
@ -28,8 +28,8 @@ static int ostc_prepare_data(int data_model, dc_family_t dc_fam, device_data_t &
|
|||
data_descriptor = get_descriptor(dc_fam, data_model);
|
||||
if (data_descriptor) {
|
||||
dev_data.descriptor = data_descriptor;
|
||||
dev_data.vendor = copy_string(dc_descriptor_get_vendor(data_descriptor));
|
||||
dev_data.model = copy_string(dc_descriptor_get_product(data_descriptor));
|
||||
dev_data.vendor = dc_descriptor_get_vendor(data_descriptor);
|
||||
dev_data.model = dc_descriptor_get_product(data_descriptor);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ void ostctools_import(const char *file, struct divelog *log)
|
|||
return;
|
||||
}
|
||||
std::string tmp = devdata.vendor + " " + devdata.model + " (Imported from OSTCTools)";
|
||||
ostcdive->dc.model = copy_string(tmp.c_str());
|
||||
ostcdive->dc.model = tmp.c_str();
|
||||
|
||||
// Parse the dive data
|
||||
rc = libdc_buffer_parser(ostcdive.get(), &devdata, buffer.data(), i + 1);
|
||||
|
@ -163,18 +163,18 @@ void ostctools_import(const char *file, struct divelog *log)
|
|||
// Serial number is not part of the header nor the profile, so libdc won't
|
||||
// catch it. If Serial is part of the extra_data, and set to zero, remove
|
||||
// it from the list and add again.
|
||||
ostcdive->dc.serial = copy_string(std::to_string(serial).c_str());
|
||||
ostcdive->dc.serial = std::to_string(serial);
|
||||
|
||||
if (ostcdive->dc.extra_data) {
|
||||
ptr = ostcdive->dc.extra_data;
|
||||
while (strcmp(ptr->key, "Serial"))
|
||||
ptr = ptr->next;
|
||||
if (!strcmp(ptr->value, "0")) {
|
||||
add_extra_data(&ostcdive->dc, "Serial", ostcdive->dc.serial);
|
||||
add_extra_data(&ostcdive->dc, "Serial", ostcdive->dc.serial.c_str());
|
||||
*ptr = *(ptr)->next;
|
||||
}
|
||||
} else {
|
||||
add_extra_data(&ostcdive->dc, "Serial", ostcdive->dc.serial);
|
||||
add_extra_data(&ostcdive->dc, "Serial", ostcdive->dc.serial.c_str());
|
||||
}
|
||||
record_dive_to_table(ostcdive.release(), log->dives.get());
|
||||
sort_dive_table(log->dives.get());
|
||||
|
|
|
@ -835,7 +835,7 @@ static void try_to_fill_dc(struct divecomputer *dc, const char *name, char *buf,
|
|||
return;
|
||||
if (MATCH_STATE("time", divetime, &dc->when))
|
||||
return;
|
||||
if (MATCH("model", utf8_string, (char **)&dc->model))
|
||||
if (MATCH("model", utf8_string_std, &dc->model))
|
||||
return;
|
||||
if (MATCH("deviceid", hex_value, &deviceid))
|
||||
return;
|
||||
|
@ -1821,10 +1821,10 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
|
|||
dive_start(&state);
|
||||
divecomputer_start(&state);
|
||||
|
||||
state.cur_dc->model = strdup("DLF import");
|
||||
state.cur_dc->model = "DLF import";
|
||||
// (ptr[7] << 8) + ptr[6] Is "Serial"
|
||||
snprintf(serial, sizeof(serial), "%d", (ptr[7] << 8) + ptr[6]);
|
||||
state.cur_dc->serial = strdup(serial);
|
||||
state.cur_dc->serial = serial;
|
||||
state.cur_dc->when = parse_dlf_timestamp(ptr + 8);
|
||||
state.cur_dive->when = state.cur_dc->when;
|
||||
|
||||
|
|
|
@ -178,9 +178,9 @@ void dc_settings_start(struct parser_state *state)
|
|||
void dc_settings_end(struct parser_state *state)
|
||||
{
|
||||
create_device_node(state->log->devices.get(),
|
||||
state->cur_settings.dc.model.c_str(),
|
||||
state->cur_settings.dc.serial_nr.c_str(),
|
||||
state->cur_settings.dc.nickname.c_str());
|
||||
state->cur_settings.dc.model,
|
||||
state->cur_settings.dc.serial_nr,
|
||||
state->cur_settings.dc.nickname);
|
||||
reset_dc_settings(state);
|
||||
}
|
||||
|
||||
|
@ -392,7 +392,7 @@ void divecomputer_start(struct parser_state *state)
|
|||
dc = dc->next;
|
||||
|
||||
/* Did we already fill that in? */
|
||||
if (dc->samples || dc->model || dc->when) {
|
||||
if (dc->samples || !dc->model.empty() || dc->when) {
|
||||
struct divecomputer *newdc = new divecomputer;
|
||||
if (newdc) {
|
||||
dc->next = newdc;
|
||||
|
|
|
@ -420,7 +420,7 @@ static void save_events(struct membuffer *b, struct dive *dive, struct event *ev
|
|||
|
||||
static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer *dc)
|
||||
{
|
||||
show_utf8(b, "model ", dc->model, "\n");
|
||||
show_utf8(b, "model ", dc->model.c_str(), "\n");
|
||||
if (dc->last_manual_time.seconds)
|
||||
put_duration(b, dc->last_manual_time, "lastmanualtime ", "min\n");
|
||||
if (dc->deviceid)
|
||||
|
@ -862,19 +862,17 @@ static void save_units(void *_b)
|
|||
|
||||
static void save_one_device(struct membuffer *b, const struct device *d)
|
||||
{
|
||||
const char *model = device_get_model(d);
|
||||
const char *nickname = device_get_nickname(d);
|
||||
const char *serial = device_get_serial(d);
|
||||
std::string model = device_get_model(d);
|
||||
std::string nickname = device_get_nickname(d);
|
||||
std::string serial = device_get_serial(d);
|
||||
|
||||
if (empty_string(serial)) serial = NULL;
|
||||
if (empty_string(nickname)) nickname = NULL;
|
||||
if (!nickname || !serial)
|
||||
if (nickname.empty() || serial.empty())
|
||||
return;
|
||||
|
||||
show_utf8(b, "divecomputerid ", model, "");
|
||||
put_format(b, " deviceid=%08x", calculate_string_hash(serial));
|
||||
show_utf8(b, " serial=", serial, "");
|
||||
show_utf8(b, " nickname=", nickname, "");
|
||||
show_utf8(b, "divecomputerid ", model.c_str(), "");
|
||||
put_format(b, " deviceid=%08x", calculate_string_hash(serial.c_str()));
|
||||
show_utf8(b, " serial=", serial.c_str(), "");
|
||||
show_utf8(b, " nickname=", nickname.c_str(), "");
|
||||
put_string(b, "\n");
|
||||
}
|
||||
|
||||
|
@ -1154,8 +1152,8 @@ static void create_commit_message(struct membuffer *msg, bool create_empty)
|
|||
put_format(msg, " (%s)", trip->location);
|
||||
put_format(msg, "\n");
|
||||
do {
|
||||
if (!empty_string(dc->model)) {
|
||||
put_format(msg, "%s%s", sep, dc->model);
|
||||
if (!dc->model.empty()) {
|
||||
put_format(msg, "%s%s", sep, dc->model.c_str());
|
||||
sep = ", ";
|
||||
}
|
||||
} while ((dc = dc->next) != NULL);
|
||||
|
|
|
@ -58,7 +58,7 @@ static void write_divecomputers(struct membuffer *b, struct dive *dive)
|
|||
put_string(b, separator);
|
||||
separator = ", ";
|
||||
put_format(b, "{");
|
||||
write_attribute(b, "model", dc->model, ", ");
|
||||
write_attribute(b, "model", dc->model.c_str(), ", ");
|
||||
if (dc->deviceid)
|
||||
put_format(b, "\"deviceid\":\"%08x\", ", dc->deviceid);
|
||||
else
|
||||
|
|
|
@ -447,7 +447,7 @@ static void save_samples(struct membuffer *b, struct dive *dive, struct divecomp
|
|||
static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer *dc)
|
||||
{
|
||||
put_format(b, " <divecomputer");
|
||||
show_utf8(b, dc->model, " model='", "'", 1);
|
||||
show_utf8(b, dc->model.c_str(), " model='", "'", 1);
|
||||
if (dc->last_manual_time.seconds)
|
||||
put_duration(b, dc->last_manual_time, " last-manual-time='", " min'");
|
||||
if (dc->deviceid)
|
||||
|
@ -593,27 +593,19 @@ static void save_trip(struct membuffer *b, dive_trip_t *trip, bool anonymize)
|
|||
|
||||
static void save_one_device(struct membuffer *b, const struct device *d)
|
||||
{
|
||||
const char *model = device_get_model(d);
|
||||
const char *nickname = device_get_nickname(d);
|
||||
const char *serial_nr = device_get_serial(d);
|
||||
std::string model = device_get_model(d);
|
||||
std::string nickname = device_get_nickname(d);
|
||||
std::string serial_nr = device_get_serial(d);
|
||||
|
||||
/* Nicknames that are empty or the same as the device model are not interesting */
|
||||
if (empty_string(nickname) || !strcmp(model, nickname))
|
||||
nickname = NULL;
|
||||
|
||||
/* Serial numbers that are empty are not interesting */
|
||||
if (empty_string(serial_nr))
|
||||
serial_nr = NULL;
|
||||
|
||||
/* Do we have anything interesting about this dive computer to save? */
|
||||
if (!serial_nr || !nickname)
|
||||
if (nickname.empty() || serial_nr.empty() || model == nickname)
|
||||
return;
|
||||
|
||||
put_format(b, "<divecomputerid");
|
||||
show_utf8(b, model, " model='", "'", 1);
|
||||
put_format(b, " deviceid='%08x'", calculate_string_hash(serial_nr));
|
||||
show_utf8(b, serial_nr, " serial='", "'", 1);
|
||||
show_utf8(b, nickname, " nickname='", "'", 1);
|
||||
show_utf8(b, model.c_str(), " model='", "'", 1);
|
||||
put_format(b, " deviceid='%08x'", calculate_string_hash(serial_nr.c_str()));
|
||||
show_utf8(b, serial_nr.c_str(), " serial='", "'", 1);
|
||||
show_utf8(b, nickname.c_str(), " nickname='", "'", 1);
|
||||
put_format(b, "/>\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@ static void uemis_get_weight(std::string_view buffer, weightsystem_t &weight, in
|
|||
static std::unique_ptr<dive> uemis_start_dive(uint32_t deviceid)
|
||||
{
|
||||
auto dive = std::make_unique<struct dive>();
|
||||
dive->dc.model = strdup("Uemis Zurich");
|
||||
dive->dc.model = "Uemis Zurich";
|
||||
dive->dc.deviceid = deviceid;
|
||||
return dive;
|
||||
}
|
||||
|
@ -985,7 +985,7 @@ static std::pair<uint32_t, uint32_t> uemis_get_divenr(uint32_t deviceid, struct
|
|||
if (!d)
|
||||
continue;
|
||||
for_each_dc (d, dc) {
|
||||
if (dc->model && !strcmp(dc->model, "Uemis Zurich") &&
|
||||
if (dc->model == "Uemis Zurich" &&
|
||||
(dc->deviceid == 0 || dc->deviceid == 0x7fffffff || dc->deviceid == deviceid)) {
|
||||
if (dc->diveid > maxdiveid)
|
||||
maxdiveid = dc->diveid;
|
||||
|
|
|
@ -295,7 +295,7 @@ void uemis::parse_divelog_binary(std::string_view base64, struct dive *dive)
|
|||
dive->dc.salinity = FRESHWATER_SALINITY; /* grams per 10l fresh water */
|
||||
|
||||
/* this will allow us to find the last dive read so far from this computer */
|
||||
dc->model = strdup("Uemis Zurich");
|
||||
dc->model = "Uemis Zurich";
|
||||
dc->deviceid = *(uint32_t *)(data.data() + 9);
|
||||
dc->diveid = *(uint16_t *)(data.data() + 7);
|
||||
/* remember the weight units used in this dive - we may need this later when
|
||||
|
|
|
@ -577,7 +577,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM
|
|||
event = event->next;
|
||||
}
|
||||
|
||||
QString dcText = get_dc_nickname(currentdc);
|
||||
QString dcText = QString::fromStdString(get_dc_nickname(currentdc));
|
||||
if (is_dc_planner(currentdc))
|
||||
dcText = tr("Planned dive");
|
||||
else if (is_dc_manually_added_dive(currentdc))
|
||||
|
|
|
@ -681,8 +681,9 @@ void ProfileWidget2::renameCurrentDC()
|
|||
if (!currentdc)
|
||||
return;
|
||||
QString newName = QInputDialog::getText(this, tr("Edit nickname"),
|
||||
tr("Set new nickname for %1 (serial %2):").arg(currentdc->model).arg(currentdc->serial),
|
||||
QLineEdit::Normal, get_dc_nickname(currentdc), &ok);
|
||||
tr("Set new nickname for %1 (serial %2):").arg(QString::fromStdString(currentdc->model)).
|
||||
arg(QString::fromStdString(currentdc->serial)),
|
||||
QLineEdit::Normal, QString::fromStdString(get_dc_nickname(currentdc)), &ok);
|
||||
if (ok)
|
||||
Command::editDeviceNickname(currentdc, newName);
|
||||
}
|
||||
|
|
|
@ -945,7 +945,7 @@ void smartrak_import(const char *file, struct divelog *log)
|
|||
dc_fam = DC_FAMILY_UWATEC_ALADIN;
|
||||
}
|
||||
rc = prepare_data(dc_model, (char *)col[coln(DCNUMBER)]->bind_ptr, dc_fam, devdata);
|
||||
smtkdive->dc.model = copy_string(devdata.model.c_str());
|
||||
smtkdive->dc.model = devdata.model;
|
||||
if (rc == DC_STATUS_SUCCESS && mdb_table.get_len(coln(PROFILE))) {
|
||||
prf_buffer = static_cast<unsigned char *>(mdb_ole_read_full(mdb, col[coln(PROFILE)], &prf_length));
|
||||
if (prf_length > 0) {
|
||||
|
|
Loading…
Reference in a new issue