mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
eebb47ec22
commit
9c253ee6c5
81 changed files with 661 additions and 698 deletions
|
@ -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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue