summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-11-27 00:25:15 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-01-09 20:58:04 -0800
commit7e33369dc8b27b20385ab055b662e06bbf369784 (patch)
treeaf674ccdd1ccb67d4de84d68cb585b481d020fb3 /core
parentec37c71f5eeb7d4b0c4b8719b52583fadb0b8f4c (diff)
downloadsubsurface-7e33369dc8b27b20385ab055b662e06bbf369784.tar.gz
Parser: add trip_table parameter to parsing functions
To allow parsing into arbitrary trip_tables, add the corresponding parameter to the parsing functions and the parser state. Currently, all callers pass the global trip_table so there should be no change in functionality. These arguments will be replaced in subsequent commits. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r--core/cochran.c3
-rw-r--r--core/datatrak.c4
-rw-r--r--core/dive.h19
-rw-r--r--core/file.c55
-rw-r--r--core/file.h10
-rw-r--r--core/import-cobalt.c3
-rw-r--r--core/import-csv.c33
-rw-r--r--core/import-csv.h10
-rw-r--r--core/import-divinglog.c3
-rw-r--r--core/import-shearwater.c6
-rw-r--r--core/import-suunto.c6
-rw-r--r--core/liquivision.c3
-rw-r--r--core/parse-xml.c6
-rw-r--r--core/parse.c2
-rw-r--r--core/parse.h1
15 files changed, 89 insertions, 75 deletions
diff --git a/core/cochran.c b/core/cochran.c
index 01f733043..a3e4c9a13 100644
--- a/core/cochran.c
+++ b/core/cochran.c
@@ -791,9 +791,10 @@ 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)
+int try_to_open_cochran(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips)
{
UNUSED(filename);
+ UNUSED(trips);
unsigned int i;
unsigned int mod;
unsigned int *offsets, dive1, dive2;
diff --git a/core/datatrak.c b/core/datatrak.c
index 931fcb811..87bed5f55 100644
--- a/core/datatrak.c
+++ b/core/datatrak.c
@@ -14,6 +14,7 @@
#include "units.h"
#include "device.h"
#include "file.h"
+#include "ssrf.h"
unsigned char lector_bytes[2], lector_word[4], tmp_1byte, *byte;
unsigned int tmp_2bytes;
@@ -576,8 +577,9 @@ 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)
+int datatrak_import(struct memblock *mem, struct dive_table *table, struct trip_table *trips)
{
+ UNUSED(trips);
unsigned char *runner;
int i = 0, numdives = 0, rc = 0;
diff --git a/core/dive.h b/core/dive.h
index 1325a8bb9..f7cf060b7 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -475,19 +475,19 @@ struct dive *find_dive_n_near(timestamp_t when, int n, timestamp_t offset);
extern int match_one_dc(const struct divecomputer *a, const struct divecomputer *b);
extern void parse_xml_init(void);
-extern int parse_xml_buffer(const char *url, const char *buf, int size, struct dive_table *table, const char **params);
+extern int parse_xml_buffer(const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, const char **params);
extern void parse_xml_exit(void);
extern void set_filename(const char *filename);
-extern int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table);
-extern int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table);
-extern int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table);
-extern int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table);
-extern int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table);
-extern int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table);
-extern int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table);
+extern int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips);
+extern int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips);
+extern int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips);
+extern int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips);
+extern int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips);
+extern int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips);
+extern int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table, struct trip_table *trips);
-extern int parse_file(const char *filename, struct dive_table *table);
+extern int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips);
extern int save_dives(const char *filename);
extern int save_dives_logic(const char *filename, bool select_only, bool anonymize);
extern int save_dive(FILE *f, struct dive *dive, bool anonymize);
@@ -498,7 +498,6 @@ extern void save_one_dive_to_mb(struct membuffer *b, struct dive *dive, bool ano
int cylinderuse_from_text(const char *text);
-
struct user_info {
char *name;
char *email;
diff --git a/core/file.c b/core/file.c
index fe2b0878b..89338e167 100644
--- a/core/file.c
+++ b/core/file.c
@@ -75,7 +75,7 @@ out:
}
-static void zip_read(struct zip_file *file, const char *filename, struct dive_table *table)
+static void zip_read(struct zip_file *file, const char *filename, struct dive_table *table, struct trip_table *trips)
{
int size = 1024, n, read = 0;
char *mem = malloc(size);
@@ -86,11 +86,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, NULL);
+ (void) parse_xml_buffer(filename, mem, read, table, trips, NULL);
free(mem);
}
-int try_to_open_zip(const char *filename, struct dive_table *table)
+int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips)
{
int success = 0;
/* Grr. libzip needs to re-open the file, it can't take a buffer */
@@ -105,7 +105,7 @@ int try_to_open_zip(const char *filename, struct dive_table *table)
/* skip parsing the divelogs.de pictures */
if (strstr(zip_get_name(zip, index, 0), "pictures/"))
continue;
- zip_read(file, filename, table);
+ zip_read(file, filename, table, trips);
zip_fclose(file);
success++;
}
@@ -126,7 +126,7 @@ static int db_test_func(void *param, int columns, char **data, char **column)
}
-static int try_to_open_db(const char *filename, struct memblock *mem, struct dive_table *table)
+static int try_to_open_db(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips)
{
sqlite3 *handle;
char dm4_test[] = "select count(*) from sqlite_master where type='table' and name='Dive' and sql like '%ProfileBlob%'";
@@ -147,7 +147,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);
+ retval = parse_dm5_buffer(handle, filename, mem->buffer, mem->size, table, trips);
sqlite3_close(handle);
return retval;
}
@@ -155,7 +155,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);
+ retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, table, trips);
sqlite3_close(handle);
return retval;
}
@@ -163,7 +163,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);
+ retval = parse_shearwater_buffer(handle, filename, mem->buffer, mem->size, table, trips);
sqlite3_close(handle);
return retval;
}
@@ -171,7 +171,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);
+ retval = parse_shearwater_cloud_buffer(handle, filename, mem->buffer, mem->size, table, trips);
sqlite3_close(handle);
return retval;
}
@@ -179,7 +179,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);
+ retval = parse_cobalt_buffer(handle, filename, mem->buffer, mem->size, table, trips);
sqlite3_close(handle);
return retval;
}
@@ -187,7 +187,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);
+ retval = parse_divinglog_buffer(handle, filename, mem->buffer, mem->size, table, trips);
sqlite3_close(handle);
return retval;
}
@@ -213,7 +213,8 @@ 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)
+static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem,
+ struct dive_table *table, struct trip_table *trips)
{
// hack to be able to provide a comment for the translated string
static char *csv_warning = QT_TRANSLATE_NOOP3("gettextFromC",
@@ -222,38 +223,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);
+ return try_to_open_zip(filename, table, trips);
/* 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);
+ return try_to_open_cochran(filename, mem, table, trips);
/* Cochran export comma-separated-value files */
if (!strcasecmp(fmt, "DPT"))
- return try_to_open_csv(mem, CSV_DEPTH, table);
+ return try_to_open_csv(mem, CSV_DEPTH, table, trips);
if (!strcasecmp(fmt, "LVD"))
- return try_to_open_liquivision(filename, mem, table);
+ return try_to_open_liquivision(filename, mem, table, trips);
if (!strcasecmp(fmt, "TMP"))
- return try_to_open_csv(mem, CSV_TEMP, table);
+ return try_to_open_csv(mem, CSV_TEMP, table, trips);
if (!strcasecmp(fmt, "HP1"))
- return try_to_open_csv(mem, CSV_PRESSURE, table);
+ return try_to_open_csv(mem, CSV_PRESSURE, table, trips);
return 0;
}
-static int parse_file_buffer(const char *filename, struct memblock *mem, struct dive_table *table)
+static int parse_file_buffer(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips)
{
int ret;
char *fmt = strrchr(filename, '.');
- if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table)) != 0)
+ if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table, trips)) != 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, NULL);
+ return parse_xml_buffer(filename, mem->buffer, mem->size, table, trips, NULL);
}
int check_git_sha(const char *filename, struct git_repository **git_p, const char **branch_p)
@@ -290,7 +291,7 @@ int check_git_sha(const char *filename, struct git_repository **git_p, const cha
return 1;
}
-int parse_file(const char *filename, struct dive_table *table)
+int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips)
{
struct git_repository *git;
const char *branch = NULL;
@@ -336,7 +337,7 @@ int parse_file(const char *filename, struct dive_table *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)) {
+ if (!try_to_open_db(filename, &mem, table, trips)) {
free(mem.buffer);
return 0;
}
@@ -344,14 +345,14 @@ int parse_file(const char *filename, struct dive_table *table)
/* Divesoft Freedom */
if (fmt && (!strcasecmp(fmt + 1, "DLF"))) {
- ret = parse_dlf_buffer(mem.buffer, mem.size, table);
+ ret = parse_dlf_buffer(mem.buffer, mem.size, table, trips);
free(mem.buffer);
return ret;
}
/* DataTrak/Wlog */
if (fmt && !strcasecmp(fmt + 1, "LOG")) {
- ret = datatrak_import(&mem, table);
+ ret = datatrak_import(&mem, table, trips);
free(mem.buffer);
return ret;
}
@@ -359,11 +360,11 @@ int parse_file(const char *filename, struct dive_table *table)
/* OSTCtools */
if (fmt && (!strcasecmp(fmt + 1, "DIVE"))) {
free(mem.buffer);
- ostctools_import(filename, table);
+ ostctools_import(filename, table, trips);
return 0;
}
- ret = parse_file_buffer(filename, &mem, table);
+ ret = parse_file_buffer(filename, &mem, table, trips);
free(mem.buffer);
return ret;
}
diff --git a/core/file.h b/core/file.h
index e0033d94e..fbb6d221d 100644
--- a/core/file.h
+++ b/core/file.h
@@ -7,16 +7,16 @@ struct memblock {
size_t size;
};
-extern int try_to_open_cochran(const char *filename, struct memblock *mem, struct dive_table *table);
-extern int try_to_open_liquivision(const char *filename, struct memblock *mem, struct dive_table *table);
-extern int datatrak_import(struct memblock *mem, struct dive_table *table);
-extern void ostctools_import(const char *file, struct dive_table *table);
+extern int try_to_open_cochran(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips);
+extern int try_to_open_liquivision(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips);
+extern int datatrak_import(struct memblock *mem, struct dive_table *table, struct trip_table *trips);
+extern void ostctools_import(const char *file, struct dive_table *table, struct trip_table *trips);
#ifdef __cplusplus
extern "C" {
#endif
extern int readfile(const char *filename, struct memblock *mem);
-extern int try_to_open_zip(const char *filename, struct dive_table *table);
+extern int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips);
#ifdef __cplusplus
}
#endif
diff --git a/core/import-cobalt.c b/core/import-cobalt.c
index 48faf73c0..ae36707af 100644
--- a/core/import-cobalt.c
+++ b/core/import-cobalt.c
@@ -217,7 +217,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 dive_table *table, struct trip_table *trips)
{
UNUSED(buffer);
UNUSED(size);
@@ -228,6 +228,7 @@ int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buffer, in
init_parser_state(&state);
state.target_table = table;
+ state.trips = trips;
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";
diff --git a/core/import-csv.c b/core/import-csv.c
index c196d9283..341375851 100644
--- a/core/import-csv.c
+++ b/core/import-csv.c
@@ -101,7 +101,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, char **params, int pnr, struct dive_table *table)
+static int parse_dan_format(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips)
{
int ret = 0, i;
size_t end_ptr = 0;
@@ -211,7 +211,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
}
}
params[pnr_local] = NULL;
- ret |= parse_xml_buffer(filename, "<csv></csv>", 11, table, (const char **)params);
+ ret |= parse_xml_buffer(filename, "<csv></csv>", 11, table, trips, (const char **)params);
continue;
}
@@ -268,7 +268,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
if (try_to_xslt_open_csv(filename, &mem_csv, "csv"))
return -1;
- ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, table, (const char **)params);
+ ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, table, trips, (const char **)params);
end_ptr += ptr - (char *)mem_csv.buffer;
free(mem_csv.buffer);
}
@@ -280,7 +280,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
return ret;
}
-int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, struct dive_table *table)
+int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, struct dive_table *table, struct trip_table *trips)
{
int ret, i;
struct memblock mem;
@@ -300,7 +300,7 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv
mem.size = 0;
if (!strcmp("DL7", csvtemplate)) {
- return parse_dan_format(filename, params, pnr, table);
+ return parse_dan_format(filename, params, pnr, table, trips);
} else if (strcmp(params[0], "date")) {
time(&now);
timep = localtime(&now);
@@ -335,7 +335,7 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv
fprintf(stderr, "%s/xslt/csv2xml.xslt -\n", SUBSURFACE_SOURCE);
}
#endif
- ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, (const char **)params);
+ ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, (const char **)params);
free(mem.buffer);
for (i = 0; params[i]; i += 2)
@@ -394,7 +394,7 @@ 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)
+int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_table *table, struct trip_table *trips)
{
char *p = mem->buffer;
char *header[8];
@@ -486,7 +486,7 @@ static char *next_mkvi_key(const char *haystack)
return ret;
}
-int parse_txt_file(const char *filename, const char *csv, struct dive_table *table)
+int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips)
{
struct memblock memtxt, memcsv;
@@ -778,15 +778,16 @@ 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, char **params, int pnr, const char *csvtemplate, struct dive_table *table);
-int parse_seabear_log(const char *filename, struct dive_table *table)
+static int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate,
+ struct dive_table *table, struct trip_table *trips);
+int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips)
{
char *params[SBPARAMS];
int pnr = 0;
pnr = parse_seabear_header(filename, params, pnr);
- if (parse_seabear_csv_file(filename, params, pnr, "csv", table) < 0) {
+ if (parse_seabear_csv_file(filename, params, pnr, "csv", table, trips) < 0) {
return -1;
}
@@ -794,7 +795,8 @@ int parse_seabear_log(const char *filename, struct dive_table *table)
}
-static int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, struct dive_table *table)
+static int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate,
+ struct dive_table *table, struct trip_table *trips)
{
int ret, i;
struct memblock mem;
@@ -913,7 +915,7 @@ static int parse_seabear_csv_file(const char *filename, char **params, int pnr,
fprintf(stderr, "xslt/csv2xml.xslt\n");
}
- ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, (const char **)params);
+ ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, (const char **)params);
free(mem.buffer);
for (i = 0; params[i]; i += 2)
free(params[i + 1]);
@@ -921,7 +923,7 @@ static int parse_seabear_csv_file(const char *filename, char **params, int pnr,
return ret;
}
-int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table)
+int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips)
{
struct memblock mem;
time_t now;
@@ -939,7 +941,6 @@ int parse_manual_file(const char *filename, char **params, int pnr, struct dive_
* is not discarded during the transform, thus prepend time with 1 */
strftime(curtime, TIMESTR, "1%H%M", timep);
-
params[pnr++] = strdup("date");
params[pnr++] = strdup(curdate);
params[pnr++] = strdup("time");
@@ -961,7 +962,7 @@ int parse_manual_file(const char *filename, char **params, int pnr, struct dive_
fprintf(stderr, "%s/xslt/manualcsv2xml.xslt -\n", SUBSURFACE_SOURCE);
}
#endif
- ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, (const char **)params);
+ ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, (const char **)params);
free(mem.buffer);
for (i = 0; i < pnr - 2; ++i)
diff --git a/core/import-csv.h b/core/import-csv.h
index 363daa291..2ae9cffdf 100644
--- a/core/import-csv.h
+++ b/core/import-csv.h
@@ -21,12 +21,12 @@ enum csv_format {
extern "C" {
#endif
-int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, struct dive_table *table);
-int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_table *table);
-int parse_txt_file(const char *filename, const char *csv, struct dive_table *table);
+int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, struct dive_table *table, struct trip_table *trips);
+int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_table *table, struct trip_table *trips);
+int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips);
-int parse_seabear_log(const char *filename, struct dive_table *table);
-int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table);
+int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips);
+int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips);
#ifdef __cplusplus
}
diff --git a/core/import-divinglog.c b/core/import-divinglog.c
index 66a9ba2c0..ee5dccbd0 100644
--- a/core/import-divinglog.c
+++ b/core/import-divinglog.c
@@ -397,7 +397,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 dive_table *table, struct trip_table *trips)
{
UNUSED(buffer);
UNUSED(size);
@@ -408,6 +408,7 @@ int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buffer,
init_parser_state(&state);
state.target_table = table;
+ state.trips = trips;
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)";
diff --git a/core/import-shearwater.c b/core/import-shearwater.c
index 451b04fe5..b4815d960 100644
--- a/core/import-shearwater.c
+++ b/core/import-shearwater.c
@@ -438,7 +438,7 @@ static int shearwater_cloud_dive(void *param, int columns, char **data, char **c
}
int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
- struct dive_table *table)
+ struct dive_table *table, struct trip_table *trips)
{
UNUSED(buffer);
UNUSED(size);
@@ -449,6 +449,7 @@ int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer
init_parser_state(&state);
state.target_table = table;
+ state.trips = trips;
state.sql_handle = handle;
// So far have not seen any sample rate in Shearwater Desktop
@@ -468,7 +469,7 @@ int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer
}
int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
- struct dive_table *table)
+ struct dive_table *table, struct trip_table *trips)
{
UNUSED(buffer);
UNUSED(size);
@@ -479,6 +480,7 @@ int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *
init_parser_state(&state);
state.target_table = table;
+ state.trips = trips;
state.sql_handle = handle;
char get_dives[] = "select l.number,strftime('%s', DiveDate),location||' / '||site,buddy,notes,imperialUnits,maxDepth,maxTime,startSurfacePressure,computerSerial,computerModel,d.diveId,l.sampleRateMs FROM dive_details AS d JOIN dive_logs AS l ON d.diveId=l.diveId";
diff --git a/core/import-suunto.c b/core/import-suunto.c
index 9aa311347..df59fcc46 100644
--- a/core/import-suunto.c
+++ b/core/import-suunto.c
@@ -289,7 +289,7 @@ static int dm4_dive(void *param, int columns, char **data, char **column)
}
int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
- struct dive_table *table)
+ struct dive_table *table, struct trip_table *trips)
{
UNUSED(buffer);
UNUSED(size);
@@ -300,6 +300,7 @@ int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buffer, int s
init_parser_state(&state);
state.target_table = table;
+ state.trips = trips;
state.sql_handle = handle;
/* StartTime is converted from Suunto's nano seconds to standard
@@ -557,7 +558,7 @@ static int dm5_dive(void *param, int columns, char **data, char **column)
}
int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
- struct dive_table *table)
+ struct dive_table *table, struct trip_table *trips)
{
UNUSED(buffer);
UNUSED(size);
@@ -568,6 +569,7 @@ int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buffer, int s
init_parser_state(&state);
state.target_table = table;
+ state.trips = trips;
state.sql_handle = handle;
/* StartTime is converted from Suunto's nano seconds to standard
diff --git a/core/liquivision.c b/core/liquivision.c
index bb3f2c7b4..5d9fa0a73 100644
--- a/core/liquivision.c
+++ b/core/liquivision.c
@@ -441,9 +441,10 @@ static void parse_dives (int log_version, const unsigned char *buf, unsigned int
free(dive);
}
-int try_to_open_liquivision(const char *filename, struct memblock *mem, struct dive_table *table)
+int try_to_open_liquivision(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips)
{
UNUSED(filename);
+ UNUSED(trips);
const unsigned char *buf = mem->buffer;
unsigned int buf_size = mem->size;
unsigned int ptr;
diff --git a/core/parse-xml.c b/core/parse-xml.c
index 931d12f6b..d779d3e56 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -1636,7 +1636,7 @@ static const char *preprocess_divelog_de(const char *buffer)
}
int parse_xml_buffer(const char *url, const char *buffer, int size,
- struct dive_table *table, const char **params)
+ struct dive_table *table, struct trip_table *trips, const char **params)
{
UNUSED(size);
xmlDoc *doc;
@@ -1646,6 +1646,7 @@ int parse_xml_buffer(const char *url, const char *buffer, int size,
init_parser_state(&state);
state.target_table = table;
+ state.trips = trips;
doc = xmlReadMemory(res, strlen(res), url, NULL, 0);
if (!doc)
doc = xmlReadMemory(res, strlen(res), url, "latin1", 0);
@@ -1687,7 +1688,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)
+int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table, struct trip_table *trips)
{
unsigned char *ptr = buffer;
unsigned char event;
@@ -1708,6 +1709,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl
init_parser_state(&state);
state.target_table = table;
+ state.trips = trips;
// Check for the correct file magic
if (ptr[0] != 'D' || ptr[1] != 'i' || ptr[2] != 'v' || ptr[3] != 'E')
diff --git a/core/parse.c b/core/parse.c
index 4178c5fb8..af1046014 100644
--- a/core/parse.c
+++ b/core/parse.c
@@ -278,7 +278,7 @@ void trip_end(struct parser_state *state)
{
if (!state->cur_trip)
return;
- insert_trip(state->cur_trip, &trip_table);
+ insert_trip(state->cur_trip, state->trips);
state->cur_trip = NULL;
}
diff --git a/core/parse.h b/core/parse.h
index 31f549e20..f49fd96bc 100644
--- a/core/parse.h
+++ b/core/parse.h
@@ -59,6 +59,7 @@ struct parser_state {
struct extra_data cur_extra_data;
struct units xml_parsing_units;
struct dive_table *target_table; /* non-owning */
+ struct trip_table *trips; /* non-owning */
sqlite3 *sql_handle; /* for SQL based parsers */
event_allocation_t event_allocation;