core: introduce divelog structure

The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.

Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).

The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.

To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.

The whole commit is large, but was mostly an automatic
conversion.

One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-11-08 21:31:08 +01:00 committed by bstoeger
parent eebb47ec22
commit 9c253ee6c5
81 changed files with 661 additions and 698 deletions

View file

@ -68,6 +68,8 @@ set(SUBSURFACE_CORE_LIB_SRCS
divefilter.h
divelist.c
divelist.h
divelog.cpp
divelog.h
divelogexportlogic.cpp
divelogexportlogic.h
divesite-helper.cpp

View file

@ -22,6 +22,7 @@
#include "gettext.h"
#include "cochran.h"
#include "divelist.h"
#include "divelog.h"
#include <libdivecomputer/parser.h>
@ -799,11 +800,9 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
free(buf);
}
int try_to_open_cochran(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
int try_to_open_cochran(const char *filename, struct memblock *mem, struct divelog *log)
{
UNUSED(filename);
UNUSED(trips);
UNUSED(sites);
unsigned int i;
unsigned int mod;
unsigned int *offsets, dive1, dive2;
@ -832,7 +831,7 @@ int try_to_open_cochran(const char *filename, struct memblock *mem, struct dive_
break;
cochran_parse_dive(decode, mod, mem->buffer + dive1,
dive2 - dive1, table);
dive2 - dive1, log->dives);
}
return 1; // no further processing needed

View file

@ -17,6 +17,7 @@
#include "file.h"
#include "divesite.h"
#include "dive.h"
#include "divelog.h"
#include "errorhelper.h"
#include "ssrf.h"
#include "tag.h"
@ -679,10 +680,8 @@ static void wlog_compl_parser(struct memblock *wl_mem, struct dive *dt_dive, int
* Main function call from file.c memblock is allocated (and freed) there.
* If parsing is aborted due to errors, stores correctly parsed dives.
*/
int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices)
int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct divelog *log)
{
UNUSED(trips);
unsigned char *runner;
int i = 0, numdives = 0, rc = 0;
@ -712,7 +711,7 @@ int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_t
while ((i < numdives) && ((long) runner < maxbuf)) {
struct dive *ptdive = alloc_dive();
runner = dt_dive_parser(runner, ptdive, sites, devices, maxbuf);
runner = dt_dive_parser(runner, ptdive, log->sites, log->devices, maxbuf);
if (wl_mem)
wlog_compl_parser(wl_mem, ptdive, i);
if (runner == NULL) {
@ -721,13 +720,13 @@ int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_t
rc = 1;
goto out;
} else {
record_dive_to_table(ptdive, table);
record_dive_to_table(ptdive, log->dives);
}
i++;
}
out:
taglist_cleanup(&g_tag_list);
sort_dive_table(table);
sort_dive_table(log->dives);
return rc;
bail:
return 1;

View file

@ -2,12 +2,12 @@
#include "device.h"
#include "dive.h"
#include "divelist.h"
#include "divelog.h"
#include "subsurface-string.h"
#include "errorhelper.h" // for verbose flag
#include "selection.h"
#include "core/settings/qPrefDiveComputer.h"
struct device_table device_table;
struct fingerprint_table fingerprint_table;
static bool same_device(const device &dev1, const device &dev2)
@ -140,7 +140,7 @@ extern "C" int is_default_dive_computer_device(const char *name)
const char *get_dc_nickname(const struct divecomputer *dc)
{
const device *existNode = get_device_for_dc(&device_table, dc);
const device *existNode = get_device_for_dc(divelog.devices, dc);
if (existNode && !existNode->nickName.empty())
return existNode->nickName.c_str();

View file

@ -14,7 +14,6 @@ struct device_table;
struct dive_table;
// global device table
extern struct device_table 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);

View file

@ -11,6 +11,7 @@
#include "libdivecomputer.h"
#include "device.h"
#include "divelist.h"
#include "divelog.h"
#include "divesite.h"
#include "errorhelper.h"
#include "event.h"
@ -2859,7 +2860,7 @@ static int split_dive_at(const struct dive *dive, int a, int b, struct dive **ou
* Otherwise the tail is unnumbered.
*/
if (d2->number) {
if (dive_table.nr == nr + 1)
if (divelog.dives->nr == nr + 1)
d2->number++;
else
d2->number = 0;
@ -3331,9 +3332,9 @@ depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int rou
struct dive *get_dive(int nr)
{
if (nr >= dive_table.nr || nr < 0)
if (nr >= divelog.dives->nr || nr < 0)
return NULL;
return dive_table.dives[nr];
return divelog.dives->dives[nr];
}
struct dive_site *get_dive_site_for_dive(const struct dive *dive)

View file

@ -2,6 +2,7 @@
#include "divefilter.h"
#include "divelist.h"
#include "divelog.h"
#include "gettextfromc.h"
#include "qthelper.h"
#include "selection.h"
@ -73,7 +74,7 @@ void DiveFilter::reset()
{
int i;
dive *d;
shown_dives = dive_table.nr;
shown_dives = divelog.dives->nr;
for_each_dive(i, d)
d->hidden_by_filter = false;
updateAll();
@ -201,10 +202,11 @@ bool DiveFilter::diveSiteMode() const
QString DiveFilter::shownText() const
{
int num = divelog.dives->nr;
if (diveSiteMode() || filterData.validFilter())
return gettextFromC::tr("%L1/%L2 shown").arg(shown_dives).arg(dive_table.nr);
return gettextFromC::tr("%L1/%L2 shown").arg(shown_dives).arg(num);
else
return gettextFromC::tr("%L1 dives").arg(dive_table.nr);
return gettextFromC::tr("%L1 dives").arg(num);
}
int DiveFilter::shownDives() const

View file

@ -5,8 +5,9 @@
#include "subsurface-string.h"
#include "deco.h"
#include "device.h"
#include "divesite.h"
#include "dive.h"
#include "divelog.h"
#include "divesite.h"
#include "event.h"
#include "eventname.h"
#include "filterpreset.h"
@ -226,7 +227,7 @@ static int calculate_cns(struct dive *dive)
return dive->cns;
divenr = get_divenr(dive);
i = divenr >= 0 ? divenr : dive_table.nr;
i = divenr >= 0 ? divenr : divelog.dives->nr;
#if DECO_CALC_DEBUG & 2
if (i >= 0 && i < dive_table.nr)
printf("\n\n*** CNS for dive #%d %d\n", i, get_dive(i)->number);
@ -234,7 +235,7 @@ static int calculate_cns(struct dive *dive)
printf("\n\n*** CNS for dive #%d\n", i);
#endif
/* Look at next dive in dive list table and correct i when needed */
while (i < dive_table.nr - 1) {
while (i < divelog.dives->nr - 1) {
struct dive *pdive = get_dive(i);
if (!pdive || pdive->when > dive->when)
break;
@ -279,7 +280,7 @@ static int calculate_cns(struct dive *dive)
#endif
}
/* Walk forward and add dives and surface intervals to CNS */
while (++i < dive_table.nr) {
while (++i < divelog.dives->nr) {
#if DECO_CALC_DEBUG & 2
printf("Check if dive #%d %d will be really added to CNS calc: ", i, get_dive(i)->number);
#endif
@ -463,7 +464,7 @@ int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_p
return false;
divenr = get_divenr(dive);
i = divenr >= 0 ? divenr : dive_table.nr;
i = divenr >= 0 ? divenr : divelog.dives->nr;
#if DECO_CALC_DEBUG & 2
if (i >= 0 && i < dive_table.nr)
printf("\n\n*** Init deco for dive #%d %d\n", i, get_dive(i)->number);
@ -471,7 +472,7 @@ int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_p
printf("\n\n*** Init deco for dive #%d\n", i);
#endif
/* Look at next dive in dive list table and correct i when needed */
while (i < dive_table.nr - 1) {
while (i < divelog.dives->nr - 1) {
struct dive *pdive = get_dive(i);
if (!pdive || pdive->when > dive->when)
break;
@ -516,7 +517,7 @@ int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_p
#endif
}
/* Walk forward an add dives and surface intervals to deco */
while (++i < dive_table.nr) {
while (++i < divelog.dives->nr) {
#if DECO_CALC_DEBUG & 2
printf("Check if dive #%d %d will be really added to deco calc: ", i, get_dive(i)->number);
#endif
@ -767,7 +768,7 @@ struct dive *unregister_dive(int idx)
/* When removing a dive from the global dive table,
* we also have to unregister its fulltext cache. */
fulltext_unregister(dive);
remove_from_dive_table(&dive_table, idx);
remove_from_dive_table(divelog.dives, idx);
if (dive->selected)
amount_selected--;
dive->selected = false;
@ -783,18 +784,18 @@ void delete_single_dive(int idx)
return; /* this should never happen */
if (dive->selected)
deselect_dive(dive);
remove_dive_from_trip(dive, &trip_table);
remove_dive_from_trip(dive, divelog.trips);
unregister_dive_from_dive_site(dive);
delete_dive_from_table(&dive_table, idx);
delete_dive_from_table(divelog.dives, idx);
}
void process_loaded_dives()
{
sort_dive_table(&dive_table);
sort_trip_table(&trip_table);
sort_dive_table(divelog.dives);
sort_trip_table(divelog.trips);
/* Autogroup dives if desired by user. */
autogroup_dives(&dive_table, &trip_table);
autogroup_dives(divelog.dives, divelog.trips);
fulltext_populate();
@ -876,9 +877,9 @@ static bool try_to_merge_into(struct dive *dive_to_add, int idx, struct dive_tab
/* Check if a dive is ranked after the last dive of the global dive list */
static bool dive_is_after_last(struct dive *d)
{
if (dive_table.nr == 0)
if (divelog.dives->nr == 0)
return true;
return dive_less_than(dive_table.dives[dive_table.nr - 1], d);
return dive_less_than(divelog.dives->dives[divelog.dives->nr - 1], d);
}
/* Merge dives from "dives_from" into "dives_to". Overlapping dives will be merged,
@ -967,9 +968,7 @@ static bool merge_dive_tables(struct dive_table *dives_from, struct dive_table *
/* Merge the dives of the trip "from" and the dive_table "dives_from" into the trip "to"
* and dive_table "dives_to". If "prefer_imported" is true, dive data of "from" takes
* precedence */
void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table,
struct dive_site_table *import_sites_table, struct device_table *import_device_table,
int flags)
void add_imported_dives(struct divelog *import_log, int flags)
{
int i, idx;
struct dive_table dives_to_add = empty_dive_table;
@ -980,7 +979,7 @@ void add_imported_dives(struct dive_table *import_table, struct trip_table *impo
/* Process imported dives and generate lists of dives
* to-be-added and to-be-removed */
process_imported_dives(import_table, import_trip_table, import_sites_table, import_device_table,
process_imported_dives(import_log->dives, import_log->trips, import_log->sites, import_log->devices,
flags, &dives_to_add, &dives_to_remove, &trips_to_add,
&dive_sites_to_add, devices_to_add);
@ -1004,12 +1003,12 @@ void add_imported_dives(struct dive_table *import_table, struct trip_table *impo
/* Add new dives */
for (i = 0; i < dives_to_add.nr; i++)
insert_dive(&dive_table, dives_to_add.dives[i]);
insert_dive(divelog.dives, dives_to_add.dives[i]);
dives_to_add.nr = 0;
/* Add new trips */
for (i = 0; i < trips_to_add.nr; i++)
insert_trip(trips_to_add.trips[i], &trip_table);
insert_trip(trips_to_add.trips[i], divelog.trips);
trips_to_add.nr = 0;
/* Add new dive sites */
@ -1020,12 +1019,12 @@ void add_imported_dives(struct dive_table *import_table, struct trip_table *impo
/* Add new devices */
for (i = 0; i < nr_devices(devices_to_add); i++) {
const struct device *dev = get_device(devices_to_add, i);
add_to_device_table(&device_table, dev);
add_to_device_table(divelog.devices, dev);
}
/* We might have deleted the old selected dive.
* Choose the newest dive as selected (if any) */
current_dive = dive_table.nr > 0 ? dive_table.dives[dive_table.nr - 1] : NULL;
current_dive = divelog.dives->nr > 0 ? divelog.dives->dives[divelog.dives->nr - 1] : NULL;
free_device_table(devices_to_add);
@ -1051,8 +1050,8 @@ bool try_to_merge_trip(struct dive_trip *trip_import, struct dive_table *import_
int i;
struct dive_trip *trip_old;
for (i = 0; i < trip_table.nr; i++) {
trip_old = trip_table.trips[i];
for (i = 0; i < divelog.trips->nr; i++) {
trip_old = divelog.trips->trips[i];
if (trips_overlap(trip_import, trip_old)) {
*sequence_changed |= merge_dive_tables(&trip_import->dives, import_table, &trip_old->dives,
prefer_imported, trip_old,
@ -1144,7 +1143,7 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
/* Add only the devices that we don't know about yet. */
for (i = 0; i < nr_devices(import_device_table); i++) {
const struct device *dev = get_device(import_device_table, i);
if (!device_exists(&device_table, dev))
if (!device_exists(divelog.devices, dev))
add_to_device_table(devices_to_add, dev);
}
@ -1237,7 +1236,7 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
/* The remaining dives in import_table are those that don't belong to
* a trip and the caller does not want them to be associated to a
* new trip. Merge them into the global table. */
sequence_changed |= merge_dive_tables(import_table, NULL, &dive_table, flags & IMPORT_PREFER_IMPORTED, NULL,
sequence_changed |= merge_dive_tables(import_table, NULL, divelog.dives, flags & IMPORT_PREFER_IMPORTED, NULL,
dives_to_add, dives_to_remove, &start_renumbering_at);
}
@ -1246,13 +1245,13 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
* - The last dive in the old dive table had a number itself (if there is a last dive).
* - None of the new dives has a number.
*/
last_old_dive_is_numbered = dive_table.nr == 0 || dive_table.dives[dive_table.nr - 1]->number > 0;
last_old_dive_is_numbered = divelog.dives->nr == 0 || divelog.dives->dives[divelog.dives->nr - 1]->number > 0;
/* We counted the number of merged dives that were added to dives_to_add.
* Skip those. Since sequence_changed is false all added dives are *after*
* all merged dives. */
if (!sequence_changed && last_old_dive_is_numbered && !new_dive_has_number) {
nr = dive_table.nr > 0 ? dive_table.dives[dive_table.nr - 1]->number : 0;
nr = divelog.dives->nr > 0 ? divelog.dives->dives[divelog.dives->nr - 1]->number : 0;
for (i = start_renumbering_at; i < dives_to_add->nr; i++)
dives_to_add->dives[i]->number = ++nr;
}
@ -1261,9 +1260,9 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
static struct dive *get_last_valid_dive()
{
int i;
for (i = dive_table.nr - 1; i >= 0; i--) {
if (!dive_table.dives[i]->invalid)
return dive_table.dives[i];
for (i = divelog.dives->nr - 1; i >= 0; i--) {
if (!divelog.dives->dives[i]->invalid)
return divelog.dives->dives[i];
}
return NULL;
}
@ -1277,7 +1276,7 @@ static struct dive *get_last_valid_dive()
*/
int get_dive_nr_at_idx(int idx)
{
if (idx < dive_table.nr)
if (idx < divelog.dives->nr)
return 0;
struct dive *last_dive = get_last_valid_dive();
if (!last_dive)
@ -1306,27 +1305,27 @@ void report_datafile_version(int version)
int get_dive_id_closest_to(timestamp_t when)
{
int i;
int nr = dive_table.nr;
int nr = divelog.dives->nr;
// deal with pathological cases
if (nr == 0)
return 0;
else if (nr == 1)
return dive_table.dives[0]->id;
return divelog.dives->dives[0]->id;
for (i = 0; i < nr && dive_table.dives[i]->when <= when; i++)
for (i = 0; i < nr && divelog.dives->dives[i]->when <= when; i++)
; // nothing
// again, capture the two edge cases first
if (i == nr)
return dive_table.dives[i - 1]->id;
return divelog.dives->dives[i - 1]->id;
else if (i == 0)
return dive_table.dives[0]->id;
return divelog.dives->dives[0]->id;
if (when - dive_table.dives[i - 1]->when < dive_table.dives[i]->when - when)
return dive_table.dives[i - 1]->id;
if (when - divelog.dives->dives[i - 1]->when < divelog.dives->dives[i]->when - when)
return divelog.dives->dives[i - 1]->id;
else
return dive_table.dives[i]->id;
return divelog.dives->dives[i]->id;
}
void clear_dive_file_data()
@ -1334,20 +1333,11 @@ void clear_dive_file_data()
fulltext_unregister_all();
select_single_dive(NULL); // This is propagate up to the UI and clears all the information.
while (dive_table.nr)
delete_single_dive(0);
current_dive = NULL;
while (dive_site_table.nr)
delete_dive_site(get_dive_site(0, &dive_site_table), &dive_site_table);
if (trip_table.nr != 0) {
fprintf(stderr, "Warning: trip table not empty in clear_dive_file_data()!\n");
trip_table.nr = 0;
}
clear_divelog(&divelog);
clear_dive(&displayed_dive);
clear_device_table(&device_table);
clear_event_names();
clear_filter_presets();
reset_min_datafile_version();
clear_git_id();
@ -1418,14 +1408,14 @@ timestamp_t get_surface_interval(timestamp_t when)
timestamp_t prev_end;
/* find previous dive. might want to use a binary search. */
for (i = dive_table.nr - 1; i >= 0; --i) {
if (dive_table.dives[i]->when < when)
for (i = divelog.dives->nr - 1; i >= 0; --i) {
if (divelog.dives->dives[i]->when < when)
break;
}
if (i < 0)
return -1;
prev_end = dive_endtime(dive_table.dives[i]);
prev_end = dive_endtime(divelog.dives->dives[i]);
if (prev_end > when)
return 0;
return when - prev_end;
@ -1437,11 +1427,11 @@ struct dive *find_next_visible_dive(timestamp_t when)
{
int i, j;
if (!dive_table.nr)
if (!divelog.dives->nr)
return NULL;
/* we might want to use binary search here */
for (i = 0; i < dive_table.nr; i++) {
for (i = 0; i < divelog.dives->nr; i++) {
if (when <= get_dive(i)->when)
break;
}
@ -1451,7 +1441,7 @@ struct dive *find_next_visible_dive(timestamp_t when)
return get_dive(j);
}
for (j = i; j < dive_table.nr; j++) {
for (j = i; j < divelog.dives->nr; j++) {
if (!get_dive(j)->hidden_by_filter)
return get_dive(j);
}

View file

@ -9,6 +9,7 @@ extern "C" {
#endif
struct dive;
struct divelog;
struct trip_table;
struct dive_site_table;
struct device_table;
@ -19,7 +20,6 @@ struct dive_table {
struct dive **dives;
};
static const struct dive_table empty_dive_table = { 0, 0, (struct dive **)0 };
extern struct dive_table dive_table;
/* this is used for both git and xml format */
#define DATAFORMAT_VERSION 3
@ -35,9 +35,7 @@ extern void process_loaded_dives();
#define IMPORT_IS_DOWNLOADED (1 << 1)
#define IMPORT_MERGE_ALL_TRIPS (1 << 2)
#define IMPORT_ADD_TO_NEW_TRIP (1 << 3)
extern void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table,
struct dive_site_table *import_sites_table, struct device_table *devices_to_add,
int flags);
extern void add_imported_dives(struct divelog *log, int flags);
extern void process_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table,
struct dive_site_table *import_sites_table, struct device_table *import_devices_table,
int flags,

56
core/divelog.cpp Normal file
View file

@ -0,0 +1,56 @@
// SPDX-License-Identifier: GPL-2.0
#include "divelog.h"
#include "divelist.h"
#include "divesite.h"
#include "device.h"
#include "filterpreset.h"
#include "trip.h"
struct divelog divelog;
// We can't use smart pointers, since this is used from C
// and it would be bold to presume that std::unique_ptr<>
// and a plain pointer have the same memory layout.
divelog::divelog() :
dives(new dive_table),
trips(new trip_table),
sites(new dive_site_table),
devices(new device_table),
filter_presets(new filter_preset_table),
autogroup(false)
{
*dives = empty_dive_table;
*trips = empty_trip_table;
*sites = empty_dive_site_table;
}
divelog::~divelog()
{
clear_dive_table(dives);
clear_trip_table(trips);
clear_dive_site_table(sites);
delete dives;
delete trips;
delete sites;
delete devices;
delete filter_presets;
}
void divelog::clear()
{
while (dives->nr)
delete_single_dive(0);
while (sites->nr)
delete_dive_site(get_dive_site(0, sites), sites);
if (trips->nr != 0) {
fprintf(stderr, "Warning: trip table not empty in divelog::clear()!\n");
trips->nr = 0;
}
clear_device_table(devices);
filter_presets->clear();
}
extern "C" void clear_divelog(struct divelog *log)
{
log->clear();
}

40
core/divelog.h Normal file
View file

@ -0,0 +1,40 @@
// SPDX-License-Identifier: GPL-2.0
// A structure that contains all the values we save in a divelog file
#ifndef DIVELOG_H
#define DIVELOG_H
struct dive_table;
struct trip_table;
struct dive_site_table;
struct device_table;
struct filter_preset_table;
#include <stdbool.h>
struct divelog {
struct dive_table *dives;
struct trip_table *trips;
struct dive_site_table *sites;
struct device_table *devices;
struct filter_preset_table *filter_presets;
bool autogroup;
#ifdef __cplusplus
void clear();
divelog();
~divelog();
#endif
};
extern struct divelog divelog;
#ifdef __cplusplus
extern "C" {
#endif
void clear_divelog(struct divelog *);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -2,16 +2,15 @@
/* divesite.c */
#include "divesite.h"
#include "dive.h"
#include "subsurface-string.h"
#include "divelist.h"
#include "divelog.h"
#include "membuffer.h"
#include "subsurface-string.h"
#include "table.h"
#include "sha1.h"
#include <math.h>
struct dive_site_table dive_site_table;
int get_divesite_idx(const struct dive_site *ds, struct dive_site_table *ds_table)
{
int i;
@ -110,7 +109,7 @@ struct dive_site *get_dive_site_by_gps_proximity(const location_t *loc, int dist
int register_dive_site(struct dive_site *ds)
{
return add_dive_site_to_table(ds, &dive_site_table);
return add_dive_site_to_table(ds, divelog.sites);
}
static int compare_sites(const struct dive_site *a, const struct dive_site *b)
@ -232,7 +231,7 @@ void free_dive_site(struct dive_site *ds)
int unregister_dive_site(struct dive_site *ds)
{
return remove_dive_site(ds, &dive_site_table);
return remove_dive_site(ds, divelog.sites);
}
void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table)
@ -319,7 +318,7 @@ struct dive_site *get_same_dive_site(const struct dive_site *site)
{
int i;
struct dive_site *ds;
for_each_dive_site (i, ds, &dive_site_table)
for_each_dive_site (i, ds, divelog.sites)
if (same_dive_site(ds, site))
return ds;
return NULL;

View file

@ -33,8 +33,6 @@ typedef struct dive_site_table {
static const dive_site_table_t empty_dive_site_table = { 0, 0, (struct dive_site **)0 };
extern struct dive_site_table dive_site_table;
static inline struct dive_site *get_dive_site(int nr, struct dive_site_table *ds_table)
{
if (nr >= ds_table->nr || nr < 0)

View file

@ -15,6 +15,7 @@
#include "gettext.h"
#include "dive.h"
#include "divelist.h"
#include "divelog.h"
#include "pref.h"
#include "subsurface-string.h"
#include "table.h"
@ -305,8 +306,8 @@ void reset_tank_info_table(struct tank_info_table *table)
add_default_tank_infos(table);
/* Add cylinders from dive list */
for (int i = 0; i < dive_table.nr; ++i) {
const struct dive *dive = dive_table.dives[i];
for (int i = 0; i < divelog.dives->nr; ++i) {
const struct dive *dive = divelog.dives->dives[i];
for (int j = 0; j < dive->cylinders.nr; j++) {
const cylinder_t *cyl = get_cylinder(dive, j);
add_cylinder_description(&cyl->type);

View file

@ -11,6 +11,7 @@
#include <time.h>
#include "dive.h"
#include "divelog.h"
#include "subsurface-string.h"
#include "errorhelper.h"
#include "file.h"
@ -76,8 +77,7 @@ out:
}
static void zip_read(struct zip_file *file, const char *filename, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices, struct filter_preset_table *filter_presets)
static void zip_read(struct zip_file *file, const char *filename, struct divelog *log)
{
int size = 1024, n, read = 0;
char *mem = malloc(size);
@ -88,12 +88,11 @@ static void zip_read(struct zip_file *file, const char *filename, struct dive_ta
mem = realloc(mem, size);
}
mem[read] = 0;
(void) parse_xml_buffer(filename, mem, read, table, trips, sites, devices, filter_presets, NULL);
(void) parse_xml_buffer(filename, mem, read, log, NULL);
free(mem);
}
int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets)
int try_to_open_zip(const char *filename, struct divelog *log)
{
int success = 0;
/* Grr. libzip needs to re-open the file, it can't take a buffer */
@ -108,7 +107,7 @@ int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_
/* skip parsing the divelogs.de pictures */
if (strstr(zip_get_name(zip, index, 0), "pictures/"))
continue;
zip_read(file, filename, table, trips, sites, devices, filter_presets);
zip_read(file, filename, log);
zip_fclose(file);
success++;
}
@ -128,8 +127,7 @@ static int db_test_func(void *param, int columns, char **data, char **column)
return *data[0] == '0';
}
static int try_to_open_db(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices)
static int try_to_open_db(const char *filename, struct memblock *mem, struct divelog *log)
{
sqlite3 *handle;
char dm4_test[] = "select count(*) from sqlite_master where type='table' and name='Dive' and sql like '%ProfileBlob%'";
@ -151,7 +149,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Suunto DM5 database format */
retval = sqlite3_exec(handle, dm5_test, &db_test_func, 0, NULL);
if (!retval) {
retval = parse_dm5_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices);
retval = parse_dm5_buffer(handle, filename, mem->buffer, mem->size, log);
sqlite3_close(handle);
return retval;
}
@ -159,7 +157,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Suunto DM4 database format */
retval = sqlite3_exec(handle, dm4_test, &db_test_func, 0, NULL);
if (!retval) {
retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices);
retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, log);
sqlite3_close(handle);
return retval;
}
@ -167,7 +165,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Shearwater database format */
retval = sqlite3_exec(handle, shearwater_test, &db_test_func, 0, NULL);
if (!retval) {
retval = parse_shearwater_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices);
retval = parse_shearwater_buffer(handle, filename, mem->buffer, mem->size, log);
sqlite3_close(handle);
return retval;
}
@ -175,7 +173,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Shearwater cloud database format */
retval = sqlite3_exec(handle, shearwater_cloud_test, &db_test_func, 0, NULL);
if (!retval) {
retval = parse_shearwater_cloud_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices);
retval = parse_shearwater_cloud_buffer(handle, filename, mem->buffer, mem->size, log);
sqlite3_close(handle);
return retval;
}
@ -183,7 +181,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Atomic Cobalt database format */
retval = sqlite3_exec(handle, cobalt_test, &db_test_func, 0, NULL);
if (!retval) {
retval = parse_cobalt_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices);
retval = parse_cobalt_buffer(handle, filename, mem->buffer, mem->size, log);
sqlite3_close(handle);
return retval;
}
@ -191,7 +189,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Divinglog database format */
retval = sqlite3_exec(handle, divinglog_test, &db_test_func, 0, NULL);
if (!retval) {
retval = parse_divinglog_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices);
retval = parse_divinglog_buffer(handle, filename, mem->buffer, mem->size, log);
sqlite3_close(handle);
return retval;
}
@ -199,7 +197,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Seac database format */
retval = sqlite3_exec(handle, seacsync_test, &db_test_func, 0, NULL);
if (!retval) {
retval = parse_seac_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices);
retval = parse_seac_buffer(handle, filename, mem->buffer, mem->size, log);
sqlite3_close(handle);
return retval;
}
@ -226,9 +224,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
*
* Followed by the data values (all comma-separated, all one long line).
*/
static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets)
static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem, struct divelog *log)
{
// hack to be able to provide a comment for the translated string
static char *csv_warning = QT_TRANSLATE_NOOP3("gettextFromC",
@ -237,40 +233,38 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo
/* Suunto Dive Manager files: SDE, ZIP; divelogs.de files: DLD */
if (!strcasecmp(fmt, "SDE") || !strcasecmp(fmt, "ZIP") || !strcasecmp(fmt, "DLD"))
return try_to_open_zip(filename, table, trips, sites, devices, filter_presets);
return try_to_open_zip(filename, log);
/* CSV files */
if (!strcasecmp(fmt, "CSV"))
return report_error(translate("gettextFromC", csv_warning), filename);
/* Truly nasty intentionally obfuscated Cochran Anal software */
if (!strcasecmp(fmt, "CAN"))
return try_to_open_cochran(filename, mem, table, trips, sites);
return try_to_open_cochran(filename, mem, log);
/* Cochran export comma-separated-value files */
if (!strcasecmp(fmt, "DPT"))
return try_to_open_csv(mem, CSV_DEPTH, table, trips, sites);
return try_to_open_csv(mem, CSV_DEPTH, log);
if (!strcasecmp(fmt, "LVD"))
return try_to_open_liquivision(filename, mem, table, trips, sites);
return try_to_open_liquivision(filename, mem, log);
if (!strcasecmp(fmt, "TMP"))
return try_to_open_csv(mem, CSV_TEMP, table, trips, sites);
return try_to_open_csv(mem, CSV_TEMP, log);
if (!strcasecmp(fmt, "HP1"))
return try_to_open_csv(mem, CSV_PRESSURE, table, trips, sites);
return try_to_open_csv(mem, CSV_PRESSURE, log);
return 0;
}
static int parse_file_buffer(const char *filename, struct memblock *mem, struct dive_table *table,
struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets)
static int parse_file_buffer(const char *filename, struct memblock *mem, struct divelog *log)
{
int ret;
char *fmt = strrchr(filename, '.');
if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table, trips, sites, devices, filter_presets)) != 0)
if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, log)) != 0)
return ret;
if (!mem->size || !mem->buffer)
return report_error("Out of memory parsing file %s\n", filename);
return parse_xml_buffer(filename, mem->buffer, mem->size, table, trips, sites, devices, filter_presets, NULL);
return parse_xml_buffer(filename, mem->buffer, mem->size, log, NULL);
}
bool remote_repo_uptodate(const char *filename, struct git_info *info)
@ -292,8 +286,7 @@ bool remote_repo_uptodate(const char *filename, struct git_info *info)
return false;
}
int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets)
int parse_file(const char *filename, struct divelog *log)
{
struct git_info info;
struct memblock mem;
@ -312,7 +305,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
}
}
ret = git_load_dives(&info, table, trips, sites, devices, filter_presets);
ret = git_load_dives(&info, log);
cleanup_git_info(&info);
return ret;
}
@ -329,7 +322,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
fmt = strrchr(filename, '.');
if (fmt && (!strcasecmp(fmt + 1, "DB") || !strcasecmp(fmt + 1, "BAK") || !strcasecmp(fmt + 1, "SQL"))) {
if (!try_to_open_db(filename, &mem, table, trips, sites, devices)) {
if (!try_to_open_db(filename, &mem, log)) {
free(mem.buffer);
return 0;
}
@ -337,7 +330,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
/* Divesoft Freedom */
if (fmt && (!strcasecmp(fmt + 1, "DLF"))) {
ret = parse_dlf_buffer(mem.buffer, mem.size, table, trips, sites, devices);
ret = parse_dlf_buffer(mem.buffer, mem.size, log);
free(mem.buffer);
return ret;
}
@ -351,9 +344,9 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
wl_name = strcat(wl_name, ".add");
if((ret = readfile(wl_name, &wl_mem)) < 0) {
fprintf(stderr, "No file %s found. No WLog extensions.\n", wl_name);
ret = datatrak_import(&mem, NULL, table, trips, sites, devices);
ret = datatrak_import(&mem, NULL, log);
} else {
ret = datatrak_import(&mem, &wl_mem, table, trips, sites, devices);
ret = datatrak_import(&mem, &wl_mem, log);
free(wl_mem.buffer);
}
free(mem.buffer);
@ -364,11 +357,11 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
/* OSTCtools */
if (fmt && (!strcasecmp(fmt + 1, "DIVE"))) {
free(mem.buffer);
ostctools_import(filename, table, trips, sites);
ostctools_import(filename, log);
return 0;
}
ret = parse_file_buffer(filename, &mem, table, trips, sites, devices, filter_presets);
ret = parse_file_buffer(filename, &mem, log);
free(mem.buffer);
return ret;
}

View file

@ -12,26 +12,20 @@ struct memblock {
size_t size;
};
struct trip_table;
struct device_table;
struct dive_site_table;
struct dive_table;
struct divelog;
struct zip;
#ifdef __cplusplus
extern "C" {
#endif
extern int try_to_open_cochran(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
extern int try_to_open_liquivision(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
extern int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices);
extern void ostctools_import(const char *file, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
extern int try_to_open_cochran(const char *filename, struct memblock *mem, struct divelog *log);
extern int try_to_open_liquivision(const char *filename, struct memblock *mem, struct divelog *log);
extern int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct divelog *log);
extern void ostctools_import(const char *file, struct divelog *log);
extern int readfile(const char *filename, struct memblock *mem);
extern int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets);
extern int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets);
extern int parse_file(const char *filename, struct divelog *log);
extern int try_to_open_zip(const char *filename, struct divelog *log);
// Platform specific functions
extern int subsurface_rename(const char *path, const char *newpath);
@ -40,7 +34,7 @@ extern int subsurface_open(const char *path, int oflags, mode_t mode);
extern FILE *subsurface_fopen(const char *path, const char *mode);
extern void *subsurface_opendir(const char *path);
extern int subsurface_access(const char *path, int mode);
extern int subsurface_stat(const char* path, struct stat* buf);
extern int subsurface_stat(const char *path, struct stat *buf);
extern struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp);
extern int subsurface_zip_close(struct zip *zip);

View file

@ -1,18 +1,17 @@
// SPDX-License-Identifier: GPL-2.0
#include "filterpreset.h"
#include "divelog.h"
#include "qthelper.h"
#include "subsurface-string.h"
struct filter_preset_table filter_preset_table;
extern "C" void clear_filter_presets(void)
static filter_preset_table &global_table()
{
filter_preset_table.clear();
return *divelog.filter_presets;
}
extern "C" int filter_presets_count(void)
{
return (int)filter_preset_table.size();
return (int)global_table().size();
}
extern "C" char *filter_preset_name(int preset)
@ -22,12 +21,12 @@ extern "C" char *filter_preset_name(int preset)
extern "C" char *filter_preset_fulltext_query(int preset)
{
return copy_qstring(filter_preset_table[preset].data.fullText.originalQuery);
return copy_qstring(global_table()[preset].data.fullText.originalQuery);
}
extern "C" const char *filter_preset_fulltext_mode(int preset)
{
switch (filter_preset_table[preset].data.fulltextStringMode) {
switch (global_table()[preset].data.fulltextStringMode) {
default:
case StringFilterMode::SUBSTRING:
return "substring";
@ -51,12 +50,12 @@ extern "C" void filter_preset_set_fulltext(struct filter_preset *preset, const c
extern "C" int filter_preset_constraint_count(int preset)
{
return (int)filter_preset_table[preset].data.constraints.size();
return (int)global_table()[preset].data.constraints.size();
}
extern "C" const filter_constraint *filter_preset_constraint(int preset, int constraint)
{
return &filter_preset_table[preset].data.constraints[constraint];
return &global_table()[preset].data.constraints[constraint];
}
extern "C" struct filter_preset *alloc_filter_preset()
@ -113,33 +112,33 @@ extern "C" void filter_preset_add_constraint(struct filter_preset *preset, const
int filter_preset_id(const QString &name)
{
auto it = std::find_if(filter_preset_table.begin(), filter_preset_table.end(),
auto it = std::find_if(global_table().begin(), global_table().end(),
[&name] (filter_preset &p) { return p.name == name; });
return it != filter_preset_table.end() ? it - filter_preset_table.begin() : -1;
return it != global_table().end() ? it - global_table().begin() : -1;
}
QString filter_preset_name_qstring(int preset)
{
return filter_preset_table[preset].name;
return global_table()[preset].name;
}
void filter_preset_set(int preset, const FilterData &data)
{
filter_preset_table[preset].data = data;
global_table()[preset].data = data;
}
FilterData filter_preset_get(int preset)
{
return filter_preset_table[preset].data;
return global_table()[preset].data;
}
int filter_preset_add(const QString &nameIn, const FilterData &d)
{
QString name = get_unique_preset_name(nameIn, filter_preset_table);
return filter_preset_add_to_table(name, d, filter_preset_table);
QString name = get_unique_preset_name(nameIn, global_table());
return filter_preset_add_to_table(name, d, global_table());
}
void filter_preset_delete(int preset)
{
filter_preset_table.erase(filter_preset_table.begin() + preset);
global_table().erase(global_table().begin() + preset);
}

View file

@ -32,7 +32,6 @@ struct filter_preset_table : public std::vector<filter_preset>
{
};
extern struct filter_preset_table filter_preset_table;
#else
struct filter_preset;
struct filter_preset_table;
@ -44,7 +43,6 @@ extern "C" {
#endif
// The C IO code accesses the filter presets via integer indices.
extern void clear_filter_presets(void);
extern int filter_presets_count(void);
extern char *filter_preset_name(int preset); // name of filter preset - caller must free the result.
extern char *filter_preset_fulltext_query(int preset); // fulltext query of filter preset - caller must free the result.

View file

@ -2,6 +2,7 @@
#include "fulltext.h"
#include "dive.h"
#include "divelog.h"
#include "divesite.h"
#include "tag.h"
#include "trip.h"
@ -155,7 +156,7 @@ void FullText::populate()
dive *d;
for_each_dive(i, d)
registerDive(d);
uiNotification(QObject::tr("%1 dives processed").arg(dive_table.nr));
uiNotification(QObject::tr("%1 dives processed").arg(divelog.dives->nr));
}
void FullText::registerDive(struct dive *d)

View file

@ -5,9 +5,7 @@
#include "git2.h"
#include "filterpreset.h"
struct dive_table;
struct dive_site_table;
struct trip_table;
struct dive_log;
#ifdef __cplusplus
extern "C" {
@ -26,7 +24,7 @@ enum remote_transport { RT_LOCAL, RT_HTTPS, RT_SSH, RT_OTHER };
struct git_oid;
struct git_repository;
struct device_table;
struct divelog;
struct git_info {
const char *url;
@ -43,9 +41,7 @@ extern bool open_git_repository(struct git_info *info);
extern bool remote_repo_uptodate(const char *filename, struct git_info *info);
extern int sync_with_remote(struct git_info *);
extern int git_save_dives(struct git_info *, bool select_only);
extern int git_load_dives(struct git_info *, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices,
struct filter_preset_table *filter_presets);
extern int git_load_dives(struct git_info *, struct divelog *log);
extern const char *get_sha(git_repository *repo, const char *branch);
extern int do_git_save(struct git_info *, bool select_only, bool create_empty);
extern void cleanup_git_info(struct git_info *);

View file

@ -12,6 +12,7 @@
#include "sample.h"
#include "subsurface-string.h"
#include "divelist.h"
#include "divelog.h"
#include "device.h"
#include "membuffer.h"
#include "gettext.h"
@ -219,9 +220,7 @@ static int cobalt_dive(void *param, int columns, char **data, char **column)
}
int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices)
int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
{
UNUSED(buffer);
UNUSED(size);
@ -230,10 +229,10 @@ int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buffer, in
struct parser_state state;
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
state.sites = sites;
state.devices = devices;
state.target_table = log->dives;
state.trips = log->trips;
state.sites = log->sites;
state.devices = log->devices;
state.sql_handle = handle;
char get_dives[] = "select Id,strftime('%s',DiveStartTime),LocationId,'buddy','notes',Units,(MaxDepthPressure*10000/SurfacePressure)-10000,DiveMinutes,SurfacePressure,SerialNumber,'model' from Dive where IsViewDeleted = 0";

View file

@ -8,6 +8,7 @@
#include "ssrf.h"
#include "subsurface-string.h"
#include "divelist.h"
#include "divelog.h"
#include "file.h"
#include "parse.h"
#include "sample.h"
@ -106,9 +107,7 @@ static char *parse_dan_new_line(char *buf, const char *NL)
}
static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, const char *tag);
static int parse_dan_format(const char *filename, struct xml_params *params, struct dive_table *table,
struct trip_table *trips, struct dive_site_table *sites, struct device_table *devices,
struct filter_preset_table *filter_presets)
static int parse_dan_format(const char *filename, struct xml_params *params, struct divelog *log)
{
int ret = 0, i;
size_t end_ptr = 0;
@ -212,7 +211,7 @@ static int parse_dan_format(const char *filename, struct xml_params *params, str
xml_params_add(params, "waterTemp", tmpbuf);
}
}
ret |= parse_xml_buffer(filename, "<csv></csv>", 11, table, trips, sites, devices, filter_presets, params);
ret |= parse_xml_buffer(filename, "<csv></csv>", 11, log, params);
continue;
}
@ -268,7 +267,7 @@ static int parse_dan_format(const char *filename, struct xml_params *params, str
if (try_to_xslt_open_csv(filename, &mem_csv, "csv"))
return -1;
ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, table, trips, sites, devices, filter_presets, params);
ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, log, params);
free(mem_csv.buffer);
}
@ -278,9 +277,7 @@ static int parse_dan_format(const char *filename, struct xml_params *params, str
return ret;
}
int parse_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets)
int parse_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct divelog *log)
{
int ret;
struct memblock mem;
@ -300,7 +297,7 @@ int parse_csv_file(const char *filename, struct xml_params *params, const char *
mem.size = 0;
if (!strcmp("DL7", csvtemplate)) {
return parse_dan_format(filename, params, table, trips, sites, devices, filter_presets);
return parse_dan_format(filename, params, log);
} else if (strcmp(xml_params_get_key(params, 0), "date")) {
time(&now);
timep = localtime(&now);
@ -332,7 +329,7 @@ int parse_csv_file(const char *filename, struct xml_params *params, const char *
fprintf(stderr, "%s/xslt/%s -\n", SUBSURFACE_SOURCE, csvtemplate);
}
#endif
ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, devices, filter_presets, params);
ret = parse_xml_buffer(filename, mem.buffer, mem.size, log, params);
free(mem.buffer);
@ -409,9 +406,8 @@ static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, cons
return 0;
}
int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
int try_to_open_csv(struct memblock *mem, enum csv_format type, struct divelog *log)
{
UNUSED(sites);
char *p = mem->buffer;
char *header[8];
int i, time;
@ -460,7 +456,7 @@ int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_tabl
break;
p = end + 1;
}
record_dive_to_table(dive, table);
record_dive_to_table(dive, log->dives);
return 1;
}
@ -502,15 +498,12 @@ static char *next_mkvi_key(const char *haystack)
return ret;
}
int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices)
int parse_txt_file(const char *filename, const char *csv, struct divelog *log)
{
UNUSED(sites);
struct memblock memtxt, memcsv;
if (readfile(filename, &memtxt) < 0) {
if (readfile(filename, &memtxt) < 0)
return report_error(translate("gettextFromC", "Failed to read '%s'"), filename);
}
/*
* MkVI stores some information in .txt file but the whole profile and events are stored in .csv file. First
@ -786,7 +779,7 @@ int parse_txt_file(const char *filename, const char *csv, struct dive_table *tab
if (!lineptr || !*lineptr)
break;
}
record_dive_to_table(dive, table);
record_dive_to_table(dive, log->dives);
return 1;
} else {
return 0;
@ -799,17 +792,14 @@ int parse_txt_file(const char *filename, const char *csv, struct dive_table *tab
#define TIMESTR 6
#define SBPARAMS 40
static int parse_seabear_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets);
int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets)
static int parse_seabear_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct divelog *log);
int parse_seabear_log(const char *filename, struct divelog *log)
{
struct xml_params *params = alloc_xml_params();
int ret;
parse_seabear_header(filename, params);
ret = parse_seabear_csv_file(filename, params, "csv", table, trips, sites, devices, filter_presets) < 0 ? -1 : 0;
ret = parse_seabear_csv_file(filename, params, "csv", log) < 0 ? -1 : 0;
free_xml_params(params);
@ -817,9 +807,7 @@ int parse_seabear_log(const char *filename, struct dive_table *table, struct tri
}
static int parse_seabear_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets)
static int parse_seabear_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct divelog *log)
{
int ret, i;
struct memblock mem;
@ -937,14 +925,13 @@ static int parse_seabear_csv_file(const char *filename, struct xml_params *param
fprintf(stderr, "xslt/csv2xml.xslt\n");
}
ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, devices, filter_presets, params);
ret = parse_xml_buffer(filename, mem.buffer, mem.size, log, params);
free(mem.buffer);
return ret;
}
int parse_manual_file(const char *filename, struct xml_params *params, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices, struct filter_preset_table *filter_presets)
int parse_manual_file(const char *filename, struct xml_params *params, struct divelog *log)
{
struct memblock mem;
time_t now;
@ -980,7 +967,7 @@ int parse_manual_file(const char *filename, struct xml_params *params, struct di
fprintf(stderr, "%s/xslt/manualcsv2xml.xslt -\n", SUBSURFACE_SOURCE);
}
#endif
ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, devices, filter_presets, params);
ret = parse_xml_buffer(filename, mem.buffer, mem.size, log, params);
free(mem.buffer);
return ret;

View file

@ -25,17 +25,12 @@ enum csv_format {
extern "C" {
#endif
int parse_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct dive_table *table,
struct trip_table *trips, struct dive_site_table *sites, struct device_table *devices,
struct filter_preset_table *filter_presets);
int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices);
int parse_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct divelog *log);
int try_to_open_csv(struct memblock *mem, enum csv_format type, struct divelog *log);
int parse_txt_file(const char *filename, const char *csv, struct divelog *log);
int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets);
int parse_manual_file(const char *filename, struct xml_params *params, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices, struct filter_preset_table *filter_presets);
int parse_seabear_log(const char *filename, struct divelog *log);
int parse_manual_file(const char *filename, struct xml_params *params, struct divelog *log);
#ifdef __cplusplus
}

View file

@ -11,6 +11,7 @@
#include "subsurface-string.h"
#include "parse.h"
#include "divelist.h"
#include "divelog.h"
#include "device.h"
#include "membuffer.h"
#include "gettext.h"
@ -390,9 +391,7 @@ static int divinglog_dive(void *param, int columns, char **data, char **column)
}
int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices)
int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
{
UNUSED(buffer);
UNUSED(size);
@ -401,10 +400,10 @@ int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buffer,
struct parser_state state;
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
state.sites = sites;
state.devices = devices;
state.target_table = log->dives;
state.trips = log->trips;
state.sites = log->sites;
state.devices = log->devices;
state.sql_handle = handle;
char get_dives[] = "select Number,strftime('%s',Divedate || ' ' || ifnull(Entrytime,'00:00')),Country || ' - ' || City || ' - ' || Place,Buddy,Comments,Depth,Divetime,Divemaster,Airtemp,Watertemp,Weight,Divesuit,Computer,ID,Visibility,SupplyType from Logbook where UUID not in (select UUID from DeletedRecords)";

View file

@ -11,6 +11,7 @@
#include "subsurface-string.h"
#include "parse.h"
#include "divelist.h"
#include "divelog.h"
#include "device.h"
#include "membuffer.h"
#include "gettext.h"
@ -262,9 +263,7 @@ static int seac_dive(void *param, int columns, char **data, char **column)
* The callback function performs another SQL query on the other
* table, to read in the sample values.
*/
int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices)
int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
{
UNUSED(buffer);
UNUSED(size);
@ -274,10 +273,10 @@ int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buffer, int
struct parser_state state;
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
state.sites = sites;
state.devices = devices;
state.target_table = log->dives;
state.trips = log->trips;
state.sites = log->sites;
state.devices = log->devices;
state.sql_handle = handle;
const char *get_dives = "SELECT dive_number, device_sn, date, timezone, time, elapsed_surface_time, dive_type, start_mode, water_type, comment, total_dive_time, max_depth, firmware_version, dive_id FROM headers_dive";

View file

@ -10,6 +10,7 @@
#include "subsurface-string.h"
#include "parse.h"
#include "divelist.h"
#include "divelog.h"
#include "device.h"
#include "membuffer.h"
#include "gettext.h"
@ -487,9 +488,7 @@ static int shearwater_cloud_dive(void *param, int columns, char **data, char **c
return SQLITE_OK;
}
int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices)
int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
{
UNUSED(buffer);
UNUSED(size);
@ -498,10 +497,10 @@ int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer
struct parser_state state;
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
state.sites = sites;
state.devices = devices;
state.target_table = log->dives;
state.trips = log->trips;
state.sites = log->sites;
state.devices = log->devices;
state.sql_handle = handle;
// So far have not seen any sample rate in Shearwater Desktop
@ -520,9 +519,7 @@ int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer
return 0;
}
int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices)
int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
{
UNUSED(buffer);
UNUSED(size);
@ -531,10 +528,10 @@ int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *
struct parser_state state;
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
state.sites = sites;
state.devices = devices;
state.target_table = log->dives;
state.trips = log->trips;
state.sites = log->sites;
state.devices = log->devices;
state.sql_handle = handle;
char get_dives[] = "select l.number,strftime('%s', DiveDate),location||' / '||site,buddy,notes,imperialUnits,maxDepth,DiveLengthTime,startSurfacePressure,computerSerial,computerModel,d.diveId,l.sampleRateMs / 1000 FROM dive_details AS d JOIN dive_logs AS l ON d.diveId=l.diveId";

View file

@ -10,6 +10,7 @@
#include "sample.h"
#include "subsurface-string.h"
#include "divelist.h"
#include "divelog.h"
#include "device.h"
#include "membuffer.h"
#include "gettext.h"
@ -292,9 +293,7 @@ static int dm4_dive(void *param, int columns, char **data, char **column)
return SQLITE_OK;
}
int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices)
int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
{
UNUSED(buffer);
UNUSED(size);
@ -304,10 +303,10 @@ int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buffer, int s
struct parser_state state;
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
state.sites = sites;
state.devices = devices;
state.target_table = log->dives;
state.trips = log->trips;
state.sites = log->sites;
state.devices = log->devices;
state.sql_handle = handle;
/* StartTime is converted from Suunto's nano seconds to standard
@ -579,9 +578,7 @@ static int dm5_dive(void *param, int columns, char **data, char **column)
return SQLITE_OK;
}
int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices)
int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
{
UNUSED(buffer);
UNUSED(size);
@ -591,10 +588,10 @@ int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buffer, int s
struct parser_state state;
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
state.sites = sites;
state.devices = devices;
state.target_table = log->dives;
state.trips = log->trips;
state.sites = log->sites;
state.devices = log->devices;
state.sql_handle = handle;
/* StartTime is converted from Suunto's nano seconds to standard

View file

@ -13,6 +13,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include "gettext.h"
#include "divelog.h"
#include "divesite.h"
#include "sample.h"
#include "subsurface-float.h"
@ -512,8 +513,8 @@ static int find_dive(struct divecomputer *match)
{
int i;
for (i = dive_table.nr - 1; i >= 0; i--) {
struct dive *old = dive_table.dives[i];
for (i = divelog.dives->nr - 1; i >= 0; i--) {
struct dive *old = divelog.dives->dives[i];
if (match_one_dive(match, old))
return 1;

View file

@ -4,6 +4,7 @@
#include "ssrf.h"
#include "divesite.h"
#include "dive.h"
#include "divelog.h"
#include "file.h"
#include "sample.h"
#include "strndup.h"
@ -436,10 +437,9 @@ static void parse_dives(int log_version, const unsigned char *buf, unsigned int
free_dive(dive);
}
int try_to_open_liquivision(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
int try_to_open_liquivision(const char *filename, struct memblock *mem, struct divelog *log)
{
UNUSED(filename);
UNUSED(trips);
const unsigned char *buf = mem->buffer;
unsigned int buf_size = mem->size;
unsigned int ptr;
@ -461,7 +461,7 @@ int try_to_open_liquivision(const char *filename, struct memblock *mem, struct d
}
ptr += 4;
parse_dives(log_version, buf + ptr, buf_size - ptr, table, sites);
parse_dives(log_version, buf + ptr, buf_size - ptr, log->dives, log->sites);
return 1;
}

View file

@ -15,6 +15,7 @@
#include "gettext.h"
#include "dive.h"
#include "divelog.h"
#include "divesite.h"
#include "event.h"
#include "errorhelper.h"
@ -1961,17 +1962,16 @@ const char *get_sha(git_repository *repo, const char *branch)
* If it is a git repository, we return zero for success,
* or report an error and return 1 if the load failed.
*/
int git_load_dives(struct git_info *info, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices, struct filter_preset_table *filter_presets)
int git_load_dives(struct git_info *info, struct divelog *log)
{
int ret;
struct git_parser_state state = { 0 };
state.repo = info->repo;
state.table = table;
state.trips = trips;
state.sites = sites;
state.devices = devices;
state.filter_presets = filter_presets;
state.table = log->dives;
state.trips = log->trips;
state.sites = log->sites;
state.devices = log->devices;
state.filter_presets = log->filter_presets;
if (!info->repo)
return report_error("Unable to open git repository '%s[%s]'", info->url, info->branch);

View file

@ -9,6 +9,7 @@
#include "gettext.h"
#include "dive.h"
#include "divelist.h"
#include "divelog.h"
#include "extradata.h"
#include "file.h"
#include "libdivecomputer.h"
@ -39,10 +40,8 @@ static int ostc_prepare_data(int data_model, dc_family_t dc_fam, device_data_t *
* each file. So it's not necessary to iterate once and again on a parsing
* function. Actually there's only one kind of archive for every DC model.
*/
void ostctools_import(const char *file, struct dive_table *divetable, struct trip_table *trips, struct dive_site_table *sites)
void ostctools_import(const char *file, struct divelog *log)
{
UNUSED(trips);
UNUSED(sites);
FILE *archive;
device_data_t *devdata = calloc(1, sizeof(device_data_t));
dc_family_t dc_fam;
@ -184,8 +183,8 @@ void ostctools_import(const char *file, struct dive_table *divetable, struct tri
} else {
add_extra_data(&ostcdive->dc, "Serial", ostcdive->dc.serial);
}
record_dive_to_table(ostcdive, divetable);
sort_dive_table(divetable);
record_dive_to_table(ostcdive, log->dives);
sort_dive_table(log->dives);
close_out:
fclose(archive);

View file

@ -22,6 +22,7 @@
#include "gettext.h"
#include "dive.h"
#include "divelog.h"
#include "divesite.h"
#include "errorhelper.h"
#include "parse.h"
@ -1750,9 +1751,7 @@ static const char *preprocess_divelog_de(const char *buffer)
return buffer;
}
int parse_xml_buffer(const char *url, const char *buffer, int size,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets,
int parse_xml_buffer(const char *url, const char *buffer, int size, struct divelog *log,
const struct xml_params *params)
{
UNUSED(size);
@ -1762,12 +1761,12 @@ int parse_xml_buffer(const char *url, const char *buffer, int size,
struct parser_state state;
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
state.sites = sites;
state.devices = devices;
state.target_table = log->dives;
state.trips = log->trips;
state.sites = log->sites;
state.devices = log->devices;
state.fingerprints = &fingerprint_table; // simply use the global table for now
state.filter_presets = filter_presets;
state.filter_presets = log->filter_presets;
doc = xmlReadMemory(res, strlen(res), url, NULL, XML_PARSE_HUGE | XML_PARSE_RECOVER);
if (!doc)
doc = xmlReadMemory(res, strlen(res), url, "latin1", XML_PARSE_HUGE | XML_PARSE_RECOVER);
@ -1809,8 +1808,7 @@ static timestamp_t parse_dlf_timestamp(unsigned char *buffer)
return offset + 946684800;
}
int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices)
int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
{
unsigned char *ptr = buffer;
unsigned char event;
@ -1831,10 +1829,10 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl
struct parser_state state;
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
state.sites = sites;
state.devices = devices;
state.target_table = log->dives;
state.trips = log->trips;
state.sites = log->sites;
state.devices = log->devices;
// Check for the correct file magic
if (ptr[0] != 'D' || ptr[1] != 'i' || ptr[2] != 'v' || ptr[3] != 'E')

View file

@ -18,8 +18,6 @@
#include "device.h"
#include "gettext.h"
struct dive_table dive_table;
void init_parser_state(struct parser_state *state)
{
memset(state, 0, sizeof(*state));

View file

@ -14,6 +14,7 @@
#include <time.h>
struct xml_params;
struct divelog;
typedef union {
struct event event;
@ -105,10 +106,6 @@ extern "C" {
void init_parser_state(struct parser_state *state);
void free_parser_state(struct parser_state *state);
/* the dive table holds the overall dive list; target table points at
* the table we are currently filling */
extern struct dive_table dive_table;
int trimspace(char *buffer);
void start_match(const char *type, const char *name, char *buffer);
void nonmatch(const char *type, const char *name, char *buffer);
@ -156,25 +153,16 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state)
int atoi_n(char *ptr, unsigned int len);
void parse_xml_init(void);
int parse_xml_buffer(const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets, const struct xml_params *params);
int parse_xml_buffer(const char *url, const char *buf, int size, struct divelog *log, const struct xml_params *params);
void parse_xml_exit(void);
int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices);
int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices);
int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices);
int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices);
int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices);
int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices);
int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices);
int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices);
int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log);
#ifdef __cplusplus
}
#endif

View file

@ -2,6 +2,7 @@
#include "qthelper.h"
#include "dive.h"
#include "divelist.h"
#include "divelog.h"
#include "core/settings/qPrefLanguage.h"
#include "core/settings/qPrefUpdateManager.h"
#include "core/subsurface-qt/divelistnotifier.h"
@ -1025,12 +1026,14 @@ static QString get_dive_only_date_string(timestamp_t when)
QString get_first_dive_date_string()
{
return dive_table.nr > 0 ? get_dive_only_date_string(dive_table.dives[0]->when) : gettextFromC::tr("no dives");
const dive_table *dives = divelog.dives;
return dives->nr > 0 ? get_dive_only_date_string(dives->dives[0]->when) : gettextFromC::tr("no dives");
}
QString get_last_dive_date_string()
{
return dive_table.nr > 0 ? get_dive_only_date_string(dive_table.dives[dive_table.nr - 1]->when) : gettextFromC::tr("no dives");
const dive_table *dives = divelog.dives;
return dives->nr > 0 ? get_dive_only_date_string(dives->dives[dives->nr - 1]->when) : gettextFromC::tr("no dives");
}
extern "C" char *get_current_date()

View file

@ -17,6 +17,7 @@
#include <git2.h>
#include "dive.h"
#include "divelog.h"
#include "divesite.h"
#include "filterconstraint.h"
#include "filterpreset.h"
@ -883,8 +884,8 @@ static void save_settings(git_repository *repo, struct dir *tree)
struct membuffer b = { 0 };
put_format(&b, "version %d\n", DATAFORMAT_VERSION);
for (int i = 0; i < nr_devices(&device_table); i++)
save_one_device(&b, get_device(&device_table, i));
for (int i = 0; i < nr_devices(divelog.devices); i++)
save_one_device(&b, get_device(divelog.devices, i));
/* save the fingerprint data */
for (unsigned int i = 0; i < nr_fingerprints(&fingerprint_table); i++)
save_one_fingerprint(&b, i);
@ -913,10 +914,10 @@ static void save_divesites(git_repository *repo, struct dir *tree)
subdir = new_directory(repo, tree, &dirname);
free_buffer(&dirname);
purge_empty_dive_sites(&dive_site_table);
for (int i = 0; i < dive_site_table.nr; i++) {
purge_empty_dive_sites(divelog.sites);
for (int i = 0; i < divelog.sites->nr; i++) {
struct membuffer b = { 0 };
struct dive_site *ds = get_dive_site(i, &dive_site_table);
struct dive_site *ds = get_dive_site(i, divelog.sites);
struct membuffer site_file_name = { 0 };
put_format(&site_file_name, "Site-%08x", ds->uuid);
show_utf8(&b, "name ", ds->name, "\n");
@ -1029,8 +1030,8 @@ static int create_git_tree(git_repository *repo, struct dir *root, bool select_o
save_divesites(repo, root);
save_filter_presets(repo, root);
for (i = 0; i < trip_table.nr; ++i)
trip_table.trips[i]->saved = 0;
for (i = 0; i < divelog.trips->nr; ++i)
divelog.trips->trips[i]->saved = 0;
/* save the dives */
git_storage_update_progress(translate("gettextFromC", "Start saving dives"));
@ -1140,7 +1141,7 @@ int get_authorship(git_repository *repo, git_signature **authorp)
static void create_commit_message(struct membuffer *msg, bool create_empty)
{
int nr = dive_table.nr;
int nr = divelog.dives->nr;
struct dive *dive = get_dive(nr-1);
char* changes_made = get_changes_made();

View file

@ -6,6 +6,7 @@
#include "save-html.h"
#include "dive.h"
#include "divelog.h"
#include "qthelper.h"
#include "gettext.h"
#include "divesite.h"
@ -452,8 +453,8 @@ static void write_trips(struct membuffer *b, const char *photos_dir, bool select
char sep_ = ' ';
char *sep = &sep_;
for (i = 0; i < trip_table.nr; ++i)
trip_table.trips[i]->saved = 0;
for (i = 0; i < divelog.trips->nr; ++i)
divelog.trips->trips[i]->saved = 0;
for_each_dive (i, dive) {
trip = dive->divetrip;

View file

@ -13,6 +13,7 @@
#include <fcntl.h>
#include "dive.h"
#include "divelog.h"
#include "divesite.h"
#include "errorhelper.h"
#include "extradata.h"
@ -682,8 +683,8 @@ static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonym
put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", DATAFORMAT_VERSION);
/* save the dive computer nicknames, if any */
for (int i = 0; i < nr_devices(&device_table); i++) {
const struct device *d = get_device(&device_table, i);
for (int i = 0; i < nr_devices(divelog.devices); i++) {
const struct device *d = get_device(divelog.devices, i);
if (!select_only || device_used_by_selected_dive(d))
save_one_device(b, d);
}
@ -697,8 +698,8 @@ static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonym
/* save the dive sites */
put_format(b, "<divesites>\n");
for (i = 0; i < dive_site_table.nr; i++) {
struct dive_site *ds = get_dive_site(i, &dive_site_table);
for (i = 0; i < divelog.sites->nr; i++) {
struct dive_site *ds = get_dive_site(i, divelog.sites);
/* Don't export empty dive sites */
if (dive_site_is_empty(ds))
continue;
@ -726,8 +727,8 @@ static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonym
put_format(b, "</site>\n");
}
put_format(b, "</divesites>\n<dives>\n");
for (i = 0; i < trip_table.nr; ++i)
trip_table.trips[i]->saved = 0;
for (i = 0; i < divelog.trips->nr; ++i)
divelog.trips->trips[i]->saved = 0;
/* save the filter presets */
save_filter_presets(b);

View file

@ -3,6 +3,7 @@
#include "selection.h"
#include "divelist.h"
#include "divelog.h"
#include "trip.h"
#include "subsurface-qt/divelistnotifier.h"
@ -40,7 +41,7 @@ extern "C" void deselect_dive(struct dive *dive)
}
}
selected_dive = idx;
while (++selected_dive < dive_table.nr) {
while (++selected_dive < divelog.dives->nr) {
dive = get_dive(selected_dive);
if (dive && dive->selected) {
current_dive = dive;
@ -163,8 +164,8 @@ void setSelection(const std::vector<dive *> &selection, dive *currentDive)
// Since we select only dives, there are no selected trips!
amount_trips_selected = 0;
for (int i = 0; i < trip_table.nr; ++i)
trip_table.trips[i]->selected = false;
for (int i = 0; i < divelog.trips->nr; ++i)
divelog.trips->trips[i]->selected = false;
// TODO: We might want to keep track of selected dives in a more efficient way!
int i;
@ -233,8 +234,8 @@ std::vector<dive *> getDiveSelection()
// Select the first dive that is visible
extern "C" void select_newest_visible_dive()
{
for (int i = dive_table.nr - 1; i >= 0; --i) {
dive *d = dive_table.dives[i];
for (int i = divelog.dives->nr - 1; i >= 0; --i) {
dive *d = divelog.dives->dives[i];
if (!d->hidden_by_filter)
return select_single_dive(d);
}
@ -263,9 +264,9 @@ extern "C" struct dive_trip *single_selected_trip()
{
if (amount_trips_selected != 1)
return NULL;
for (int i = 0; i < trip_table.nr; ++i) {
if (trip_table.trips[i]->selected)
return trip_table.trips[i];
for (int i = 0; i < divelog.trips->nr; ++i) {
if (divelog.trips->trips[i]->selected)
return divelog.trips->trips[i];
}
fprintf(stderr, "warning: found no selected trip even though one should be selected\n");
return NULL; // shouldn't happen
@ -280,6 +281,6 @@ extern "C" void clear_selection(void)
struct dive *dive;
for_each_dive (i, dive)
dive->selected = false;
for (int i = 0; i < trip_table.nr; ++i)
trip_table.trips[i]->selected = false;
for (int i = 0; i < divelog.trips->nr; ++i)
divelog.trips->trips[i]->selected = false;
}

View file

@ -8,6 +8,7 @@
#include "statistics.h"
#include "dive.h"
#include "divelog.h"
#include "event.h"
#include "gettext.h"
#include "sample.h"
@ -105,17 +106,17 @@ void calculate_stats_summary(struct stats_summary *out, bool selected_only)
size_t size, tsize, dsize, tmsize;
stats_t stats = { 0 };
if (dive_table.nr > 0) {
stats.shortest_time.seconds = dive_table.dives[0]->duration.seconds;
stats.min_depth.mm = dive_table.dives[0]->maxdepth.mm;
stats.selection_size = dive_table.nr;
if (divelog.dives->nr > 0) {
stats.shortest_time.seconds = divelog.dives->dives[0]->duration.seconds;
stats.min_depth.mm = divelog.dives->dives[0]->maxdepth.mm;
stats.selection_size = divelog.dives->nr;
}
/* allocate sufficient space to hold the worst
* case (one dive per year or all dives during
* one month) for yearly and monthly statistics*/
size = sizeof(stats_t) * (dive_table.nr + 1);
size = sizeof(stats_t) * (divelog.dives->nr + 1);
tsize = sizeof(stats_t) * (NUM_DIVEMODE + 1);
dsize = sizeof(stats_t) * ((STATS_MAX_DEPTH / STATS_DEPTH_BUCKET) + 1);
tmsize = sizeof(stats_t) * ((STATS_MAX_TEMP / STATS_TEMP_BUCKET) + 1);

View file

@ -2,14 +2,13 @@
#include "trip.h"
#include "dive.h"
#include "divelog.h"
#include "subsurface-time.h"
#include "subsurface-string.h"
#include "selection.h"
#include "table.h"
#include "core/qthelper.h"
struct trip_table trip_table;
#ifdef DEBUG_TRIP
void dump_trip_list(void)
{
@ -17,9 +16,9 @@ void dump_trip_list(void)
int i = 0;
timestamp_t last_time = 0;
for (i = 0; i < trip_table.nr; ++i) {
for (i = 0; i < divelog.trips->nr; ++i) {
struct tm tm;
trip = trip_table.trips[i];
trip = divelog.trips->trips[i];
utc_mkdate(trip_date(trip), &tm);
if (trip_date(trip) < last_time)
printf("\n\ntrip_table OUT OF ORDER!!!\n\n\n");
@ -203,9 +202,9 @@ dive_trip_t *get_trip_for_new_dive(struct dive *new_dive, bool *allocated)
/* lookup of trip in main trip_table based on its id */
dive_trip_t *get_trip_by_uniq_id(int tripId)
{
for (int i = 0; i < trip_table.nr; i++) {
if (trip_table.trips[i]->id == tripId)
return trip_table.trips[i];
for (int i = 0; i < divelog.trips->nr; i++) {
if (divelog.trips->trips[i]->id == tripId)
return divelog.trips->trips[i];
}
return NULL;
}

View file

@ -63,7 +63,6 @@ void clear_trip_table(struct trip_table *table);
extern void dump_trip_list(void);
#endif
extern struct trip_table trip_table;
#ifdef __cplusplus
}

View file

@ -25,6 +25,7 @@
#include "libdivecomputer.h"
#include "uemis.h"
#include "divelist.h"
#include "divelog.h"
#include "divesite.h"
#include "errorhelper.h"
#include "file.h"
@ -1051,7 +1052,7 @@ static char *uemis_get_divenr(char *deviceidstr, struct dive_table *table, int f
* Otherwise, use the global dive table.
*/
if (!force && !table->nr)
table = &dive_table;
table = divelog.dives;
for (i = 0; i < table->nr; i++) {
struct dive *d = table->dives[i];