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>
This commit is contained in:
Berthold Stoeger 2018-11-27 00:25:15 +01:00 committed by Dirk Hohndel
parent ec37c71f5e
commit 7e33369dc8
28 changed files with 157 additions and 143 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;
}

View file

@ -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

View file

@ -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";

View file

@ -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)

View file

@ -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
}

View file

@ -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)";

View file

@ -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";

View file

@ -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

View file

@ -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;

View file

@ -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')

View file

@ -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;
}

View file

@ -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;

View file

@ -904,10 +904,10 @@ void DiveLogImportDialog::on_buttonBox_accepted()
if (ui->knownImports->currentText() != "Manual import") {
for (int i = 0; i < fileNames.size(); ++i) {
if (ui->knownImports->currentText() == "Seabear CSV") {
parse_seabear_log(qPrintable(fileNames[i]), &table);
parse_seabear_log(qPrintable(fileNames[i]), &table, &trip_table);
} else if (ui->knownImports->currentText() == "Poseidon MkVI") {
QPair<QString, QString> pair = poseidonFileNames(fileNames[i]);
parse_txt_file(qPrintable(pair.second), qPrintable(pair.first), &table);
parse_txt_file(qPrintable(pair.second), qPrintable(pair.first), &table, &trip_table);
} else {
char *params[49];
int pnr = 0;
@ -924,7 +924,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
pnr = setup_csv_params(r, params, pnr);
parse_csv_file(qPrintable(fileNames[i]), params, pnr - 1,
specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv",
&table);
&table, &trip_table);
}
}
} else {
@ -988,7 +988,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
params[pnr++] = intdup(r.indexOf(tr("Rating")));
params[pnr++] = NULL;
parse_manual_file(qPrintable(fileNames[i]), params, pnr - 1, &table);
parse_manual_file(qPrintable(fileNames[i]), params, pnr - 1, &table, &trip_table);
} else {
char *params[51];
int pnr = 0;
@ -1005,7 +1005,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
pnr = setup_csv_params(r, params, pnr);
parse_csv_file(qPrintable(fileNames[i]), params, pnr - 1,
specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv",
&table);
&table, &trip_table);
}
}
}

View file

@ -614,7 +614,7 @@ void MainWindow::on_actionCloudstorageopen_triggered()
showProgressBar();
QByteArray fileNamePtr = QFile::encodeName(filename);
if (!parse_file(fileNamePtr.data(), &dive_table))
if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table))
setCurrentFile(fileNamePtr.data());
process_loaded_dives();
Command::clear();
@ -1711,7 +1711,7 @@ void MainWindow::importFiles(const QStringList fileNames)
for (int i = 0; i < fileNames.size(); ++i) {
fileNamePtr = QFile::encodeName(fileNames.at(i));
parse_file(fileNamePtr.data(), &table);
parse_file(fileNamePtr.data(), &table, &trip_table);
}
process_imported_dives(&table, false, false);
Command::clear();
@ -1729,7 +1729,7 @@ void MainWindow::loadFiles(const QStringList fileNames)
showProgressBar();
for (int i = 0; i < fileNames.size(); ++i) {
fileNamePtr = QFile::encodeName(fileNames.at(i));
if (!parse_file(fileNamePtr.data(), &dive_table)) {
if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table)) {
setCurrentFile(fileNamePtr.data());
addRecentFile(fileNamePtr, false);
}

View file

@ -769,7 +769,7 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button)
}
/* parse file and import dives */
struct dive_table table = { 0 };
parse_file(QFile::encodeName(zipFile.fileName()), &table);
parse_file(QFile::encodeName(zipFile.fileName()), &table, &trip_table);
process_imported_dives(&table, false, false);
MainWindow::instance()->refreshDisplay();

View file

@ -41,7 +41,7 @@ int main(int argc, char **argv)
qDebug() << "need --source and --output";
exit(1);
}
int ret = parse_file(qPrintable(source), &dive_table);
int ret = parse_file(qPrintable(source), &dive_table, &trip_table);
if (ret) {
fprintf(stderr, "parse_file returned %d\n", ret);
exit(1);

View file

@ -271,7 +271,7 @@ void QMLManager::openLocalThenRemote(QString url)
QByteArray fileNamePrt = QFile::encodeName(url);
bool glo = git_local_only;
git_local_only = true;
int error = parse_file(fileNamePrt.data(), &dive_table);
int error = parse_file(fileNamePrt.data(), &dive_table, &trip_table);
git_local_only = glo;
if (error) {
appendTextToLog(QStringLiteral("loading dives from cache failed %1").arg(error));
@ -339,7 +339,7 @@ void QMLManager::mergeLocalRepo()
{
char *filename = NOCLOUD_LOCALSTORAGE;
struct dive_table table = { 0 };
parse_file(filename, &table);
parse_file(filename, &table, &trip_table);
process_imported_dives(&table, false, false);
}
@ -404,7 +404,7 @@ void QMLManager::finishSetup()
QMLPrefs::instance()->setCredentialStatus(qPrefCloudStorage::CS_NOCLOUD);
saveCloudCredentials();
appendTextToLog(tr("working in no-cloud mode"));
int error = parse_file(existing_filename, &dive_table);
int error = parse_file(existing_filename, &dive_table, &trip_table);
if (error) {
// we got an error loading the local file
setNotificationText(tr("Error parsing local storage, giving up"));
@ -664,7 +664,7 @@ void QMLManager::loadDivesWithValidCredentials()
error = git_load_dives(git, branch);
} else {
appendTextToLog(QString("didn't receive valid git repo, try again"));
error = parse_file(fileNamePrt.data(), &dive_table);
error = parse_file(fileNamePrt.data(), &dive_table, &trip_table);
}
if (!error) {
report_error("filename is now %s", fileNamePrt.data());

View file

@ -5,7 +5,7 @@
void TestDiveSiteDuplication::testReadV2()
{
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TwoTimesTwo.ssrf", &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TwoTimesTwo.ssrf", &dive_table, &trip_table), 0);
QCOMPARE(dive_site_table.nr, 2);
}

View file

@ -79,7 +79,7 @@ void TestGitStorage::testGitStorageLocal()
// test writing and reading back from local git storage
git_repository *repo;
git_libgit2_init();
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table), 0);
QFETCH(QString, testDirName);
QFETCH(QString, prefixRead);
QFETCH(QString, prefixWrite);
@ -92,7 +92,7 @@ void TestGitStorage::testGitStorageLocal()
QCOMPARE(save_dives(qPrintable(repoNameWrite + "[test]")), 0);
QCOMPARE(save_dives("./SampleDivesV3.ssrf"), 0);
clear_dive_file_data();
QCOMPARE(parse_file(qPrintable(repoNameRead + "[test]"), &dive_table), 0);
QCOMPARE(parse_file(qPrintable(repoNameRead + "[test]"), &dive_table, &trip_table), 0);
QCOMPARE(save_dives("./SampleDivesV3viagit.ssrf"), 0);
QFile org("./SampleDivesV3.ssrf");
org.open(QFile::ReadOnly);
@ -111,10 +111,10 @@ void TestGitStorage::testGitStorageCloud()
// connect to the ssrftest repository on the cloud server
// and repeat the same test as before with the local git storage
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table), 0);
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0);
QCOMPARE(save_dives("./SampleDivesV3viacloud.ssrf"), 0);
QFile org("./SampleDivesV3.ssrf");
org.open(QFile::ReadOnly);
@ -135,8 +135,8 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]";
// read the local repo from the previous test and add dive 10
QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml", &dive_table), 0);
QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table, &trip_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml", &dive_table, &trip_table), 0);
// calling process_loaded_dives() sorts the table, but calling process_imported_dives()
// causes it to try to update the window title... let's not do that
process_loaded_dives();
@ -145,7 +145,7 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
QCOMPARE(save_dives("./SampleDivesV3plus10local.ssrf"), 0);
clear_dive_file_data();
// open the cloud storage and compare
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0);
QCOMPARE(save_dives("./SampleDivesV3plus10viacloud.ssrf"), 0);
QFile org("./SampleDivesV3plus10local.ssrf");
org.open(QFile::ReadOnly);
@ -163,7 +163,7 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
QDir localCacheDirectorySave(localCacheDir + "save");
QCOMPARE(localCacheDirectorySave.removeRecursively(), true);
QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0);
QCOMPARE(save_dives("./SampleDivesV3plus10fromcloud.ssrf"), 0);
org.close();
org.open(QFile::ReadOnly);
@ -184,15 +184,15 @@ void TestGitStorage::testGitStorageCloudMerge()
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
QString localCacheRepoSave = localCacheDir + "save[ssrftest@hohndel.org]";
QCOMPARE(parse_file(qPrintable(localCacheRepoSave), &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table), 0);
QCOMPARE(parse_file(qPrintable(localCacheRepoSave), &dive_table, &trip_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table), 0);
process_loaded_dives();
QCOMPARE(save_dives(qPrintable(localCacheRepoSave)), 0);
clear_dive_file_data();
// now we open the cloud storage repo and add a different dive to it
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table, &trip_table), 0);
process_loaded_dives();
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
@ -203,13 +203,13 @@ void TestGitStorage::testGitStorageCloudMerge()
QCOMPARE(localCacheDirectory.removeRecursively(), true);
QDir localCacheDirectorySave(localCacheDir + "save");
QCOMPARE(localCacheDirectory.rename(localCacheDir + "save", localCacheDir), true);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0);
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged.ssrf"), 0);
clear_dive_file_data();
QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf", &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table), 0);
QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf", &dive_table, &trip_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table), 0);
process_loaded_dives();
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table, &trip_table), 0);
process_loaded_dives();
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12.ssrf"), 0);
QFile org("./SampleDivesV3plus10-11-12-merged.ssrf");
@ -231,7 +231,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]";
QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table), 0);
QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table, &trip_table), 0);
process_loaded_dives();
struct dive *dive = get_dive(1);
delete_single_dive(1);
@ -247,7 +247,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true);
}
// now we open the cloud storage repo and modify that first dive
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0);
process_loaded_dives();
dive = get_dive(1);
QVERIFY(dive != NULL);
@ -263,7 +263,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
QCOMPARE(localCacheDirectory.removeRecursively(), true);
QCOMPARE(localCacheDirectorySave.rename(localCacheDir + "save", localCacheDir), true);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0);
QCOMPARE(save_dives("./SampleDivesMinus1-merged.ssrf"), 0);
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
QFile org("./SampleDivesMinus1-merged.ssrf");
@ -287,7 +287,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]";
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0);
process_loaded_dives();
struct dive *dive = get_dive(0);
QVERIFY(dive != 0);
@ -299,7 +299,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table), 0);
QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table, &trip_table), 0);
process_loaded_dives();
dive = get_dive(0);
dive->notes = strdup("Create multi line dive notes\nDifferent line 2 and removed 3-5\n\nThat should be enough");
@ -318,7 +318,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true);
}
// now we open the cloud storage repo and modify those first dive notes differently
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0);
process_loaded_dives();
dive = get_dive(0);
dive->notes = strdup("Completely different dive notes\nBut also multi line");
@ -336,7 +336,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
QCOMPARE(localCacheDirectory.removeRecursively(), true);
QCOMPARE(localCacheDirectorySave.rename(localCacheDir + "save", localCacheDir), true);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0);
QCOMPARE(save_dives("./SampleDivesMerge3.ssrf"), 0);
// we are not trying to compare this to a pre-determined result... what this test
// checks is that there are no parsing errors with the merge

View file

@ -22,9 +22,9 @@ void TestMerge::testMergeEmpty()
* check that we correctly merge mixed cylinder dives
*/
struct dive_table table = { 0 };
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trip_table), 0);
process_imported_dives(&table, false, false);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trip_table), 0);
process_imported_dives(&table, false, false);
QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0);
QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml");
@ -46,9 +46,9 @@ void TestMerge::testMergeBackwards()
* check that we correctly merge mixed cylinder dives
*/
struct dive_table table = { 0 };
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trip_table), 0);
process_imported_dives(&table, false, false);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trip_table), 0);
process_imported_dives(&table, false, false);
QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0);
QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml");

View file

@ -107,7 +107,7 @@ int TestParse::parseCSV(int units, std::string file)
params[pnr++] = intdup(-1);
params[pnr++] = NULL;
return parse_manual_file(file.c_str(), params, pnr - 1, &dive_table);
return parse_manual_file(file.c_str(), params, pnr - 1, &dive_table, &trip_table);
}
int TestParse::parseDivingLog()
@ -118,7 +118,7 @@ int TestParse::parseDivingLog()
int ret = sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql", &_sqlite3_handle);
if (ret == 0)
ret = parse_divinglog_buffer(_sqlite3_handle, 0, 0, 0, &dive_table);
ret = parse_divinglog_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table);
else
fprintf(stderr, "Can't open sqlite3 db: " SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql");
@ -128,13 +128,13 @@ int TestParse::parseDivingLog()
int TestParse::parseV2NoQuestion()
{
// parsing of a V2 file should work
return parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table);
return parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table);
}
int TestParse::parseV3()
{
// parsing of a V3 files should succeed
return parse_file(SUBSURFACE_TEST_DATA "/dives/test42.xml", &dive_table);
return parse_file(SUBSURFACE_TEST_DATA "/dives/test42.xml", &dive_table, &trip_table);
}
void TestParse::testParse()
@ -159,7 +159,7 @@ void TestParse::testParse()
void TestParse::testParseDM4()
{
QCOMPARE(sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDiveDM4.db", &_sqlite3_handle), 0);
QCOMPARE(parse_dm4_buffer(_sqlite3_handle, 0, 0, 0, &dive_table), 0);
QCOMPARE(parse_dm4_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table), 0);
QCOMPARE(save_dives("./testdm4out.ssrf"), 0);
FILE_COMPARE("./testdm4out.ssrf",
@ -169,7 +169,7 @@ void TestParse::testParseDM4()
void TestParse::testParseDM5()
{
QCOMPARE(sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDiveDM5.db", &_sqlite3_handle), 0);
QCOMPARE(parse_dm5_buffer(_sqlite3_handle, 0, 0, 0, &dive_table), 0);
QCOMPARE(parse_dm5_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table), 0);
QCOMPARE(save_dives("./testdm5out.ssrf"), 0);
FILE_COMPARE("./testdm5out.ssrf",
@ -216,7 +216,7 @@ void TestParse::testParseHUDC()
params[pnr++] = NULL;
QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/TestDiveSeabearHUDC.csv",
params, pnr - 1, "csv", &dive_table),
params, pnr - 1, "csv", &dive_table, &trip_table),
0);
QCOMPARE(dive_table.nr, 1);
@ -261,7 +261,7 @@ void TestParse::testParseNewFormat()
"/dives/")
.append(files.at(i))
.toLatin1()
.data(), &dive_table),
.data(), &dive_table, &trip_table),
0);
QCOMPARE(dive_table.nr, i + 1);
}
@ -280,7 +280,7 @@ void TestParse::testParseDLD()
QString filename = SUBSURFACE_TEST_DATA "/dives/TestDiveDivelogsDE.DLD";
QVERIFY(readfile(filename.toLatin1().data(), &mem) > 0);
QVERIFY(try_to_open_zip(filename.toLatin1().data(), &dive_table) > 0);
QVERIFY(try_to_open_zip(filename.toLatin1().data(), &dive_table, &trip_table) > 0);
fprintf(stderr, "number of dives from DLD: %d \n", dive_table.nr);
@ -300,8 +300,8 @@ void TestParse::testParseMerge()
/*
* check that we correctly merge mixed cylinder dives
*/
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/ostc.xml", &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/vyper.xml", &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/ostc.xml", &dive_table, &trip_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/vyper.xml", &dive_table, &trip_table), 0);
QCOMPARE(save_dives("./testmerge.ssrf"), 0);
FILE_COMPARE("./testmerge.ssrf",
SUBSURFACE_TEST_DATA "/dives/mergedVyperOstc.xml");
@ -367,12 +367,12 @@ int TestParse::parseCSVmanual(int units, std::string file)
params[pnr++] = intdup(units);
params[pnr++] = NULL;
return parse_manual_file(file.c_str(), params, pnr - 1, &dive_table);
return parse_manual_file(file.c_str(), params, pnr - 1, &dive_table, &trip_table);
}
void TestParse::exportCSVDiveDetails()
{
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table);
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table);
export_dives_xslt("testcsvexportmanual.csv", 0, 0, "xml2manualcsv.xslt", false);
export_dives_xslt("testcsvexportmanualimperial.csv", 0, 1, "xml2manualcsv.xslt", false);
@ -416,12 +416,12 @@ int TestParse::parseCSVprofile(int units, std::string file)
params[pnr++] = intdup(units);
params[pnr++] = NULL;
return parse_csv_file(file.c_str(), params, pnr - 1, "csv", &dive_table);
return parse_csv_file(file.c_str(), params, pnr - 1, "csv", &dive_table, &trip_table);
}
void TestParse::exportCSVDiveProfile()
{
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table);
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table);
export_dives_xslt("testcsvexportprofile.csv", 0, 0, "xml2csv.xslt", false);
export_dives_xslt("testcsvexportprofileimperial.csv", 0, 1, "xml2csv.xslt", false);
@ -439,13 +439,13 @@ void TestParse::exportCSVDiveProfile()
void TestParse::exportUDDF()
{
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table);
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table);
export_dives_xslt("testuddfexport.uddf", 0, 1, "uddf-export.xslt", false);
clear_dive_file_data();
parse_file("testuddfexport.uddf", &dive_table);
parse_file("testuddfexport.uddf", &dive_table, &trip_table);
export_dives_xslt("testuddfexport2.uddf", 0, 1, "uddf-export.xslt", false);
FILE_COMPARE("testuddfexport.uddf",
@ -510,7 +510,7 @@ void TestParse::parseDL7()
clear_dive_file_data();
QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/DL7.zxu",
params, pnr - 1, "DL7", &dive_table),
params, pnr - 1, "DL7", &dive_table, &trip_table),
0);
QCOMPARE(dive_table.nr, 3);

View file

@ -63,7 +63,7 @@ void TestParsePerformance::parseSsrf()
return;
}
QBENCHMARK {
parse_file(SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf", &dive_table);
parse_file(SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf", &dive_table, &trip_table);
}
}
@ -74,12 +74,12 @@ void TestParsePerformance::parseGit()
// first parse this once to populate the local cache - this way network
// effects don't dominate the parse time
parse_file(LARGE_TEST_REPO "[git]", &dive_table);
parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table);
cleanup();
QBENCHMARK {
parse_file(LARGE_TEST_REPO "[git]", &dive_table);
parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table);
}
}

View file

@ -23,7 +23,7 @@ void TestPicture::addPicture()
struct picture *pic1, *pic2;
verbose = 1;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test44.xml", &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test44.xml", &dive_table, &trip_table), 0);
dive = get_dive(0);
// Pictures will be added to selected dives
dive->selected = true;

View file

@ -4,7 +4,7 @@
void TestProfile::testRedCeiling()
{
parse_file("../dives/deep.xml", &dive_table);
parse_file("../dives/deep.xml", &dive_table, &trip_table);
}
QTEST_GUILESS_MAIN(TestProfile)

View file

@ -7,14 +7,14 @@
void TestRenumber::setup()
{
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &dive_table, &trip_table), 0);
process_loaded_dives();
}
void TestRenumber::testMerge()
{
struct dive_table table = { 0 };
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &table, &trip_table), 0);
process_imported_dives(&table, false, false);
QCOMPARE(dive_table.nr, 1);
QCOMPARE(unsaved_changes(), 1);
@ -24,7 +24,7 @@ void TestRenumber::testMerge()
void TestRenumber::testMergeAndAppend()
{
struct dive_table table = { 0 };
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &table, &trip_table), 0);
process_imported_dives(&table, false, false);
QCOMPARE(dive_table.nr, 2);
QCOMPARE(unsaved_changes(), 1);