Parser: parse into custom dive site table

To extend the undo system to dive sites, the importers and downloaders
must not parse directly into the global dive site table. Instead,
pass a dive_site_table argument to parse into.

For now, always pass the global dive_site_table so that this commit
should not cause any functional change.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-02-28 22:45:17 +01:00 committed by Dirk Hohndel
parent 926b6895bb
commit 37146c5742
36 changed files with 216 additions and 185 deletions

View file

@ -138,7 +138,7 @@ static dc_status_t dt_libdc_buffer(unsigned char *ptr, int prf_length, int dc_mo
* Parses a mem buffer extracting its data and filling a subsurface's dive structure.
* Returns a pointer to last position in buffer, or NULL on failure.
*/
static unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive, long maxbuf)
static unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive, struct dive_site_table *sites, long maxbuf)
{
int rc, profile_length, libdc_model;
char *tmp_notes_str = NULL;
@ -193,10 +193,10 @@ static unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive
* Locality and Dive points.
*/
snprintf(buffer, sizeof(buffer), "%s, %s", locality, dive_point);
ds = get_dive_site_by_name(buffer, &dive_site_table);
ds = get_dive_site_by_name(buffer, sites);
dt_dive->dive_site = ds;
if (!dt_dive->dive_site)
dt_dive->dive_site = create_dive_site(buffer, dt_dive->when, &dive_site_table);
dt_dive->dive_site = create_dive_site(buffer, dt_dive->when, sites);
free(locality);
locality = NULL;
free(dive_point);
@ -560,7 +560,7 @@ bail:
* 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 dive_table *table, struct trip_table *trips)
int datatrak_import(struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
UNUSED(trips);
unsigned char *runner;
@ -582,7 +582,7 @@ int datatrak_import(struct memblock *mem, struct dive_table *table, struct trip_
while ((i < numdives) && ((long) runner < maxbuf)) {
struct dive *ptdive = alloc_dive();
runner = dt_dive_parser(runner, ptdive, maxbuf);
runner = dt_dive_parser(runner, ptdive, sites, maxbuf);
if (runner == NULL) {
report_error(translate("gettextFromC", "Error: no dive"));
free(ptdive);