parser: replace params[] code by new xml_params struct

This fixes a load of memory holes, and makes the code
(hopefully) more readable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-10-17 20:15:23 +02:00 committed by Dirk Hohndel
parent b9b51ffd4e
commit d508a16aca
10 changed files with 301 additions and 498 deletions

View file

@ -13,6 +13,7 @@
#include "gettext.h" #include "gettext.h"
#include "import-csv.h" #include "import-csv.h"
#include "qthelper.h" #include "qthelper.h"
#include "xmlparams.h"
#define MATCH(buffer, pattern) \ #define MATCH(buffer, pattern) \
memcmp(buffer, pattern, strlen(pattern)) memcmp(buffer, pattern, strlen(pattern))
@ -103,7 +104,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 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, struct xml_params *params, struct dive_table *table,
struct trip_table *trips, struct dive_site_table *sites, struct trip_table *trips, struct dive_site_table *sites,
struct filter_preset_table *filter_presets) struct filter_preset_table *filter_presets)
{ {
@ -111,9 +112,10 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
size_t end_ptr = 0; size_t end_ptr = 0;
struct memblock mem, mem_csv; struct memblock mem, mem_csv;
char tmpbuf[MAXCOLDIGITS]; char tmpbuf[MAXCOLDIGITS];
int params_orig_size = xml_params_count(params);
char *ptr = NULL; char *ptr = NULL;
char *NL = NULL; const char *NL = NULL;
char *iter = NULL; char *iter = NULL;
if (readfile(filename, &mem) < 0) if (readfile(filename, &mem) < 0)
@ -130,8 +132,8 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
} }
while ((end_ptr < mem.size) && (ptr = strstr(mem.buffer + end_ptr, "ZDH"))) { while ((end_ptr < mem.size) && (ptr = strstr(mem.buffer + end_ptr, "ZDH"))) {
xml_params_resize(params, params_orig_size); // restart with original parameter block
char *iter_end = NULL; char *iter_end = NULL;
unsigned int pnr_local = pnr;
mem_csv.buffer = malloc(mem.size + 1); mem_csv.buffer = malloc(mem.size + 1);
mem_csv.size = mem.size; mem_csv.size = mem.size;
@ -141,8 +143,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
if (iter) { if (iter) {
memcpy(tmpbuf, ptr + 4, iter - ptr - 4); memcpy(tmpbuf, ptr + 4, iter - ptr - 4);
tmpbuf[iter - ptr - 4] = 0; tmpbuf[iter - ptr - 4] = 0;
params[pnr_local++] = "diveNro"; xml_params_add(params, "diveNro", tmpbuf);
params[pnr_local++] = strdup(tmpbuf);
} }
//fprintf(stderr, "DEBUG: BEGIN end_ptr %d round %d <%s>\n", end_ptr, j++, ptr); //fprintf(stderr, "DEBUG: BEGIN end_ptr %d round %d <%s>\n", end_ptr, j++, ptr);
@ -161,8 +162,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
/* Setting date */ /* Setting date */
memcpy(tmpbuf, iter, 8); memcpy(tmpbuf, iter, 8);
tmpbuf[8] = 0; tmpbuf[8] = 0;
params[pnr_local++] = "date"; xml_params_add(params, "date", tmpbuf);
params[pnr_local++] = strdup(tmpbuf);
/* Setting time, gotta prepend it with 1 to /* Setting time, gotta prepend it with 1 to
* avoid octal parsing (this is stripped out in * avoid octal parsing (this is stripped out in
@ -170,8 +170,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
tmpbuf[0] = '1'; tmpbuf[0] = '1';
memcpy(tmpbuf + 1, iter + 8, 6); memcpy(tmpbuf + 1, iter + 8, 6);
tmpbuf[7] = 0; tmpbuf[7] = 0;
params[pnr_local++] = "time"; xml_params_add(params, "time", tmpbuf);
params[pnr_local++] = strdup(tmpbuf);
/* Air temperature */ /* Air temperature */
memset(tmpbuf, 0, sizeof(tmpbuf)); memset(tmpbuf, 0, sizeof(tmpbuf));
@ -183,11 +182,9 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
if (iter_end) { if (iter_end) {
memcpy(tmpbuf, iter, iter_end - iter); memcpy(tmpbuf, iter, iter_end - iter);
params[pnr_local++] = "airTemp"; xml_params_add(params, "airTemp", tmpbuf);
params[pnr_local++] = strdup(tmpbuf);
} }
} }
params[pnr_local] = NULL;
/* Search for the next line */ /* Search for the next line */
if (iter) if (iter)
@ -210,12 +207,10 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
if (iter_end) { if (iter_end) {
memcpy(tmpbuf, iter, iter_end - iter); memcpy(tmpbuf, iter, iter_end - iter);
params[pnr_local++] = "waterTemp"; xml_params_add(params, "waterTemp", tmpbuf);
params[pnr_local++] = strdup(tmpbuf);
} }
} }
params[pnr_local] = NULL; ret |= parse_xml_buffer(filename, "<csv></csv>", 11, table, trips, sites, filter_presets, params);
ret |= parse_xml_buffer(filename, "<csv></csv>", 11, table, trips, sites, filter_presets, (const char **)params);
continue; continue;
} }
@ -262,29 +257,25 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
if (iter_end) { if (iter_end) {
memcpy(tmpbuf, iter, iter_end - iter); memcpy(tmpbuf, iter, iter_end - iter);
params[pnr_local++] = "waterTemp"; xml_params_add(params, "waterTemp", tmpbuf);
params[pnr_local++] = strdup(tmpbuf);
} }
} }
params[pnr_local] = NULL;
} }
if (try_to_xslt_open_csv(filename, &mem_csv, "csv")) if (try_to_xslt_open_csv(filename, &mem_csv, "csv"))
return -1; return -1;
ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, table, trips, sites, filter_presets, (const char **)params); ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, table, trips, sites, filter_presets, params);
end_ptr += ptr - (char *)mem_csv.buffer; end_ptr += ptr - (char *)mem_csv.buffer;
free(mem_csv.buffer); free(mem_csv.buffer);
} }
free(mem.buffer); free(mem.buffer);
for (i = 0; params[i]; i += 2)
free(params[i + 1]);
return ret; return ret;
} }
int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, 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 dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct filter_preset_table *filter_presets) struct filter_preset_table *filter_presets)
{ {
@ -306,22 +297,19 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv
mem.size = 0; mem.size = 0;
if (!strcmp("DL7", csvtemplate)) { if (!strcmp("DL7", csvtemplate)) {
return parse_dan_format(filename, params, pnr, table, trips, sites, filter_presets); return parse_dan_format(filename, params, table, trips, sites, filter_presets);
} else if (strcmp(params[0], "date")) { } else if (strcmp(xml_params_get_key(params, 0), "date")) {
time(&now); time(&now);
timep = localtime(&now); timep = localtime(&now);
strftime(tmpbuf, MAXCOLDIGITS, "%Y%m%d", timep); strftime(tmpbuf, MAXCOLDIGITS, "%Y%m%d", timep);
params[pnr++] = "date"; xml_params_add(params, "date", tmpbuf);
params[pnr++] = strdup(tmpbuf);
/* As the parameter is numeric, we need to ensure that the leading zero /* As the parameter is numeric, we need to ensure that the leading zero
* is not discarded during the transform, thus prepend time with 1 */ * is not discarded during the transform, thus prepend time with 1 */
strftime(tmpbuf, MAXCOLDIGITS, "1%H%M", timep); strftime(tmpbuf, MAXCOLDIGITS, "1%H%M", timep);
params[pnr++] = "time"; xml_params_add(params, "time", tmpbuf);
params[pnr++] = strdup(tmpbuf);
params[pnr++] = NULL;
} }
if (try_to_xslt_open_csv(filename, &mem, csvtemplate)) if (try_to_xslt_open_csv(filename, &mem, csvtemplate))
@ -336,16 +324,14 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, "(echo '<csv>'; cat %s;echo '</csv>') | xsltproc ", filename); fprintf(stderr, "(echo '<csv>'; cat %s;echo '</csv>') | xsltproc ", filename);
for (i=0; params[i]; i+=2) for (i = 0; i < xml_params_count(params); i++)
fprintf(stderr, "--stringparam %s %s ", params[i], params[i+1]); fprintf(stderr, "--stringparam %s %s ", xml_params_get_key(params, i), xml_params_get_value(params, i));
fprintf(stderr, "%s/xslt/%s -\n", SUBSURFACE_SOURCE, csvtemplate); fprintf(stderr, "%s/xslt/%s -\n", SUBSURFACE_SOURCE, csvtemplate);
} }
#endif #endif
ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, filter_presets, (const char **)params); ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, filter_presets, params);
free(mem.buffer); free(mem.buffer);
for (i = 0; params[i]; i += 2)
free(params[i + 1]);
return ret; return ret;
} }
@ -807,24 +793,23 @@ int parse_txt_file(const char *filename, const char *csv, struct dive_table *tab
#define TIMESTR 6 #define TIMESTR 6
#define SBPARAMS 40 #define SBPARAMS 40
static int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, 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 filter_preset_table *filter_presets); struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, 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 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 filter_preset_table *filter_presets)
{ {
char *params[SBPARAMS]; struct xml_params *params = alloc_xml_params();
int pnr = 0; int ret;
pnr = parse_seabear_header(filename, params, pnr); parse_seabear_header(filename, params);
ret = parse_seabear_csv_file(filename, params, "csv", table, trips, sites, filter_presets) < 0 ? -1 : 0;
if (parse_seabear_csv_file(filename, params, pnr, "csv", table, trips, sites, filter_presets) < 0) { free_xml_params(params);
return -1;
}
return 0; return ret;
} }
static int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, 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 dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct filter_preset_table *filter_presets) struct filter_preset_table *filter_presets)
{ {
@ -847,15 +832,12 @@ static int parse_seabear_csv_file(const char *filename, char **params, int pnr,
timep = localtime(&now); timep = localtime(&now);
strftime(tmpbuf, MAXCOLDIGITS, "%Y%m%d", timep); strftime(tmpbuf, MAXCOLDIGITS, "%Y%m%d", timep);
params[pnr++] = "date"; xml_params_add(params, "date", tmpbuf);
params[pnr++] = strdup(tmpbuf);
/* As the parameter is numeric, we need to ensure that the leading zero /* As the parameter is numeric, we need to ensure that the leading zero
* is not discarded during the transform, thus prepend time with 1 */ * is not discarded during the transform, thus prepend time with 1 */
strftime(tmpbuf, MAXCOLDIGITS, "1%H%M", timep); strftime(tmpbuf, MAXCOLDIGITS, "1%H%M", timep);
params[pnr++] = "time"; xml_params_add(params, "time", tmpbuf);
params[pnr++] = strdup(tmpbuf);
if (filename == NULL) if (filename == NULL)
return report_error("No CSV filename"); return report_error("No CSV filename");
@ -879,8 +861,9 @@ static int parse_seabear_csv_file(const char *filename, char **params, int pnr,
NL = "\n"; NL = "\n";
} }
ptr_old += 2; ptr_old += 2;
} else } else {
ptr_old += 4; ptr_old += 4;
}
/* /*
* If file does not contain empty lines, it is not a valid * If file does not contain empty lines, it is not a valid
@ -905,26 +888,27 @@ static int parse_seabear_csv_file(const char *filename, char **params, int pnr,
*/ */
if (ptr) { if (ptr) {
ptr += strlen(NL) + 2;
/* /*
* pnr is the index of NULL on the params as filled by * The two last entries should be date and time.
* the init function. The two last entries should be * Here we overwrite them with the data from the
* date and time. Here we overwrite them with the data * CSV header.
* from the CSV header.
*/ */
char buf[10];
memcpy(params[pnr - 3], ptr, 4); ptr += strlen(NL) + 2;
memcpy(params[pnr - 3] + 4, ptr + 5, 2); memcpy(buf, ptr, 4);
memcpy(params[pnr - 3] + 6, ptr + 8, 2); memcpy(buf + 4, ptr + 5, 2);
params[pnr - 3][8] = 0; memcpy(buf + 6, ptr + 8, 2);
buf[8] = 0;
xml_params_set_value(params, xml_params_count(params) - 2, buf);
memcpy(params[pnr - 1] + 1, ptr + 11, 2); buf[0] = xml_params_get_value(params, xml_params_count(params) - 1)[0];
memcpy(params[pnr - 1] + 3, ptr + 14, 2); memcpy(buf + 1, ptr + 11, 2);
params[pnr - 1][5] = 0; memcpy(buf + 3, ptr + 14, 2);
buf[5] = 0;
xml_params_set_value(params, xml_params_count(params) - 1, buf);
} }
params[pnr++] = NULL;
/* Move the CSV data to the start of mem buffer */ /* Move the CSV data to the start of mem buffer */
memmove(mem.buffer, ptr_old, mem.size - (ptr_old - (char*)mem.buffer)); memmove(mem.buffer, ptr_old, mem.size - (ptr_old - (char*)mem.buffer));
mem.size = (int)mem.size - (ptr_old - (char*)mem.buffer); mem.size = (int)mem.size - (ptr_old - (char*)mem.buffer);
@ -940,20 +924,18 @@ static int parse_seabear_csv_file(const char *filename, char **params, int pnr,
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, "xsltproc "); fprintf(stderr, "xsltproc ");
for (i=0; params[i]; i+=2) for (i = 0; i < xml_params_count(params); i++)
fprintf(stderr, "--stringparam %s %s ", params[i], params[i+1]); fprintf(stderr, "--stringparam %s %s ", xml_params_get_key(params, i), xml_params_get_value(params, i));
fprintf(stderr, "xslt/csv2xml.xslt\n"); fprintf(stderr, "xslt/csv2xml.xslt\n");
} }
ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, filter_presets, (const char **)params); ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, filter_presets, params);
free(mem.buffer); free(mem.buffer);
for (i = 0; params[i]; i += 2)
free(params[i + 1]);
return ret; return ret;
} }
int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips, 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 filter_preset_table *filter_presets) struct dive_site_table *sites, struct filter_preset_table *filter_presets)
{ {
struct memblock mem; struct memblock mem;
@ -972,11 +954,8 @@ int parse_manual_file(const char *filename, char **params, int pnr, struct dive_
* is not discarded during the transform, thus prepend time with 1 */ * is not discarded during the transform, thus prepend time with 1 */
strftime(curtime, TIMESTR, "1%H%M", timep); strftime(curtime, TIMESTR, "1%H%M", timep);
params[pnr++] = strdup("date"); xml_params_add(params, "date", curdate);
params[pnr++] = strdup(curdate); xml_params_add(params, "time", curtime);
params[pnr++] = strdup("time");
params[pnr++] = strdup(curtime);
params[pnr++] = NULL;
if (filename == NULL) if (filename == NULL)
return report_error("No manual CSV filename"); return report_error("No manual CSV filename");
@ -988,15 +967,13 @@ int parse_manual_file(const char *filename, char **params, int pnr, struct dive_
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
if (verbose >= 2) { if (verbose >= 2) {
fprintf(stderr, "(echo '<manualCSV>'; cat %s;echo '</manualCSV>') | xsltproc ", filename); fprintf(stderr, "(echo '<manualCSV>'; cat %s;echo '</manualCSV>') | xsltproc ", filename);
for (i=0; params[i]; i+=2) for (i = 0; i < xml_params_count(params); i++)
fprintf(stderr, "--stringparam %s %s ", params[i], params[i+1]); fprintf(stderr, "--stringparam %s %s ", xml_params_get_key(params, i), xml_params_get_value(params, i));
fprintf(stderr, "%s/xslt/manualcsv2xml.xslt -\n", SUBSURFACE_SOURCE); fprintf(stderr, "%s/xslt/manualcsv2xml.xslt -\n", SUBSURFACE_SOURCE);
} }
#endif #endif
ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, filter_presets, (const char **)params); ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, filter_presets, params);
free(mem.buffer); free(mem.buffer);
for (i = 0; i < pnr - 2; ++i)
free(params[i]);
return ret; return ret;
} }

View file

@ -4,6 +4,8 @@
#include "filterpreset.h" #include "filterpreset.h"
struct xml_params;
enum csv_format { enum csv_format {
CSV_DEPTH, CSV_DEPTH,
CSV_TEMP, CSV_TEMP,
@ -23,14 +25,14 @@ enum csv_format {
extern "C" { extern "C" {
#endif #endif
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, struct xml_params *params, const char *csvtemplate, struct dive_table *table,
struct trip_table *trips, struct dive_site_table *sites, struct filter_preset_table *filter_presets); struct trip_table *trips, struct dive_site_table *sites, 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 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); int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct filter_preset_table *filter_presets); struct filter_preset_table *filter_presets);
int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips, 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 filter_preset_table *filter_presets); struct dive_site_table *sites, struct filter_preset_table *filter_presets);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -32,11 +32,12 @@
#include "picture.h" #include "picture.h"
#include "qthelper.h" #include "qthelper.h"
#include "tag.h" #include "tag.h"
#include "xmlparams.h"
int quit, force_root; int quit, force_root;
int last_xml_version = -1; int last_xml_version = -1;
static xmlDoc *test_xslt_transforms(xmlDoc *doc, const char **params); static xmlDoc *test_xslt_transforms(xmlDoc *doc, const struct xml_params *params);
const struct units SI_units = SI_UNITS; const struct units SI_units = SI_UNITS;
const struct units IMPERIAL_units = IMPERIAL_UNITS; const struct units IMPERIAL_units = IMPERIAL_UNITS;
@ -1721,7 +1722,7 @@ static const char *preprocess_divelog_de(const char *buffer)
int parse_xml_buffer(const char *url, const char *buffer, int size, 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 dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct filter_preset_table *filter_presets, const char **params) struct filter_preset_table *filter_presets, const struct xml_params *params)
{ {
UNUSED(size); UNUSED(size);
xmlDoc *doc; xmlDoc *doc;
@ -2308,7 +2309,7 @@ static struct xslt_files {
{ NULL, } { NULL, }
}; };
static xmlDoc *test_xslt_transforms(xmlDoc *doc, const char **params) static xmlDoc *test_xslt_transforms(xmlDoc *doc, const struct xml_params *params)
{ {
struct xslt_files *info = xslt_files; struct xslt_files *info = xslt_files;
xmlDoc *transformed; xmlDoc *transformed;
@ -2341,7 +2342,7 @@ static xmlDoc *test_xslt_transforms(xmlDoc *doc, const char **params)
report_error(translate("gettextFromC", "Can't open stylesheet %s"), info->file); report_error(translate("gettextFromC", "Can't open stylesheet %s"), info->file);
return doc; return doc;
} }
transformed = xsltApplyStylesheet(xslt, doc, params); transformed = xsltApplyStylesheet(xslt, doc, xml_params_get(params));
xmlFreeDoc(doc); xmlFreeDoc(doc);
xsltFreeStylesheet(xslt); xsltFreeStylesheet(xslt);

View file

@ -9,6 +9,8 @@
#include <sqlite3.h> #include <sqlite3.h>
struct xml_params;
typedef union { typedef union {
struct event event; struct event event;
char allocation[sizeof(struct event) + MAX_EVENT_NAME]; char allocation[sizeof(struct event) + MAX_EVENT_NAME];
@ -140,7 +142,7 @@ int atoi_n(char *ptr, unsigned int len);
void parse_xml_init(void); 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, 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 filter_preset_table *filter_presets, const char **params); struct filter_preset_table *filter_presets, const struct xml_params *params);
void parse_xml_exit(void); 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); 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);
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); 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);

View file

@ -23,6 +23,7 @@
#include "tag.h" #include "tag.h"
#include "trip.h" #include "trip.h"
#include "imagedownloader.h" #include "imagedownloader.h"
#include "xmlparams.h"
#include <QFile> #include <QFile>
#include <QRegExp> #include <QRegExp>
#include <QDir> #include <QDir>
@ -1474,7 +1475,7 @@ QString getUUID()
return uuidString; return uuidString;
} }
int parse_seabear_header(const char *filename, char **params, int pnr) void parse_seabear_header(const char *filename, struct xml_params *params)
{ {
QFile f(filename); QFile f(filename);
@ -1487,8 +1488,8 @@ int parse_seabear_header(const char *filename, char **params, int pnr)
while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) { while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) {
if (parseLine.contains("//DIVE NR: ")) { if (parseLine.contains("//DIVE NR: ")) {
params[pnr++] = strdup("diveNro"); xml_params_add(params, "diveNro",
params[pnr++] = copy_qstring(parseLine.replace(QString::fromLatin1("//DIVE NR: "), QString::fromLatin1(""))); qPrintable(parseLine.replace(QString::fromLatin1("//DIVE NR: "), QString::fromLatin1(""))));
break; break;
} }
} }
@ -1502,8 +1503,9 @@ int parse_seabear_header(const char *filename, char **params, int pnr)
while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) { while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) {
if (parseLine.contains("//Hardware Version: ")) { if (parseLine.contains("//Hardware Version: ")) {
params[pnr++] = strdup("hw"); xml_params_add(params, "hw",
params[pnr++] = copy_qstring(parseLine.replace(QString::fromLatin1("//Hardware Version: "), QString::fromLatin1("\"Seabear ")).trimmed().append("\"")); qPrintable(parseLine.replace(QString::fromLatin1("//Hardware Version: "),
QString::fromLatin1("\"Seabear ")).trimmed().append("\"")));
break; break;
} }
} }
@ -1515,8 +1517,8 @@ int parse_seabear_header(const char *filename, char **params, int pnr)
while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) { while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) {
if (parseLine.contains("//Log interval: ")) { if (parseLine.contains("//Log interval: ")) {
params[pnr++] = strdup("delta"); xml_params_add(params, "delta",
params[pnr++] = copy_qstring(parseLine.remove(QString::fromLatin1("//Log interval: ")).trimmed().remove(QString::fromLatin1(" s"))); qPrintable(parseLine.remove(QString::fromLatin1("//Log interval: ")).trimmed().remove(QString::fromLatin1(" s"))));
break; break;
} }
} }
@ -1530,8 +1532,8 @@ int parse_seabear_header(const char *filename, char **params, int pnr)
while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) { while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) {
QString needle = "//Mode: "; QString needle = "//Mode: ";
if (parseLine.contains(needle)) { if (parseLine.contains(needle)) {
params[pnr++] = strdup("diveMode"); xml_params_add(params, "diveMode",
params[pnr++] = copy_qstring(parseLine.replace(needle, QString::fromLatin1("")).prepend("\"").append("\"")); qPrintable(parseLine.replace(needle, QString::fromLatin1("")).prepend("\"").append("\"")));
} }
} }
f.seek(0); f.seek(0);
@ -1543,8 +1545,8 @@ int parse_seabear_header(const char *filename, char **params, int pnr)
while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) { while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) {
QString needle = "//Firmware Version: "; QString needle = "//Firmware Version: ";
if (parseLine.contains(needle)) { if (parseLine.contains(needle)) {
params[pnr++] = strdup("Firmware"); xml_params_add(params, "Firmware",
params[pnr++] = copy_qstring(parseLine.replace(needle, QString::fromLatin1("")).prepend("\"").append("\"")); qPrintable(parseLine.replace(needle, QString::fromLatin1("")).prepend("\"").append("\"")));
} }
} }
f.seek(0); f.seek(0);
@ -1552,8 +1554,8 @@ int parse_seabear_header(const char *filename, char **params, int pnr)
while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) { while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) {
QString needle = "//Serial number: "; QString needle = "//Serial number: ";
if (parseLine.contains(needle)) { if (parseLine.contains(needle)) {
params[pnr++] = strdup("Serial"); xml_params_add(params, "Serial",
params[pnr++] = copy_qstring(parseLine.replace(needle, QString::fromLatin1("")).prepend("\"").append("\"")); qPrintable(parseLine.replace(needle, QString::fromLatin1("")).prepend("\"").append("\"")));
} }
} }
f.seek(0); f.seek(0);
@ -1561,8 +1563,8 @@ int parse_seabear_header(const char *filename, char **params, int pnr)
while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) { while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) {
QString needle = "//GF: "; QString needle = "//GF: ";
if (parseLine.contains(needle)) { if (parseLine.contains(needle)) {
params[pnr++] = strdup("GF"); xml_params_add(params, "GF",
params[pnr++] = copy_qstring(parseLine.replace(needle, QString::fromLatin1("")).prepend("\"").append("\"")); qPrintable(parseLine.replace(needle, QString::fromLatin1("")).prepend("\"").append("\"")));
} }
} }
f.seek(0); f.seek(0);
@ -1580,36 +1582,26 @@ int parse_seabear_header(const char *filename, char **params, int pnr)
unsigned short index = 0; unsigned short index = 0;
for (const QString &columnText: currColumns) { for (const QString &columnText: currColumns) {
if (columnText == "Time") { if (columnText == "Time") {
params[pnr++] = strdup("timeField"); xml_params_add_int(params, "timeField", index++);
params[pnr++] = intdup(index++);
} else if (columnText == "Depth") { } else if (columnText == "Depth") {
params[pnr++] = strdup("depthField"); xml_params_add_int(params, "depthField", index++);
params[pnr++] = intdup(index++);
} else if (columnText == "Temperature") { } else if (columnText == "Temperature") {
params[pnr++] = strdup("tempField"); xml_params_add_int(params, "tempField", index++);
params[pnr++] = intdup(index++);
} else if (columnText == "NDT") { } else if (columnText == "NDT") {
params[pnr++] = strdup("ndlField"); xml_params_add_int(params, "ndlField", index++);
params[pnr++] = intdup(index++);
} else if (columnText == "TTS") { } else if (columnText == "TTS") {
params[pnr++] = strdup("ttsField"); xml_params_add_int(params, "ttsField", index++);
params[pnr++] = intdup(index++);
} else if (columnText == "pO2_1") { } else if (columnText == "pO2_1") {
params[pnr++] = strdup("o2sensor1Field"); xml_params_add_int(params, "o2sensor1Field", index++);
params[pnr++] = intdup(index++);
} else if (columnText == "pO2_2") { } else if (columnText == "pO2_2") {
params[pnr++] = strdup("o2sensor2Field"); xml_params_add_int(params, "o2sensor2Field", index++);
params[pnr++] = intdup(index++);
} else if (columnText == "pO2_3") { } else if (columnText == "pO2_3") {
params[pnr++] = strdup("o2sensor3Field"); xml_params_add_int(params, "o2sensor3Field", index++);
params[pnr++] = intdup(index++);
} else if (columnText == "Ceiling") { } else if (columnText == "Ceiling") {
/* TODO: Add support for dive computer reported ceiling*/ /* TODO: Add support for dive computer reported ceiling*/
params[pnr++] = strdup("ceilingField"); xml_params_add_int(params, "ceilingField", index++);
params[pnr++] = intdup(index++);
} else if (columnText == "Tank pressure") { } else if (columnText == "Tank pressure") {
params[pnr++] = strdup("pressureField"); xml_params_add_int(params, "pressureField", index++);
params[pnr++] = intdup(index++);
} else { } else {
// We do not know about this value // We do not know about this value
qDebug() << "Seabear import found an un-handled field: " << columnText; qDebug() << "Seabear import found an un-handled field: " << columnText;
@ -1617,16 +1609,12 @@ int parse_seabear_header(const char *filename, char **params, int pnr)
} }
/* Separator is ';' and the index for that in DiveLogImportDialog constructor is 2 */ /* Separator is ';' and the index for that in DiveLogImportDialog constructor is 2 */
params[pnr++] = strdup("separatorIndex"); xml_params_add_int(params, "separatorIndex", 2);
params[pnr++] = intdup(2);
/* And metric units */ /* And metric units */
params[pnr++] = strdup("units"); xml_params_add_int(params, "units", 0);
params[pnr++] = intdup(0);
params[pnr] = NULL;
f.close(); f.close();
return pnr;
} }
char *intdup(int index) char *intdup(int index)

View file

@ -9,6 +9,7 @@
struct picture; struct picture;
struct dive_trip; struct dive_trip;
struct xml_params;
// 1) Types // 1) Types
@ -148,7 +149,7 @@ char *hashfile_name_string();
char *picturedir_string(); char *picturedir_string();
const char *subsurface_user_agent(); const char *subsurface_user_agent();
enum deco_mode decoMode(); enum deco_mode decoMode();
int parse_seabear_header(const char *filename, char **params, int pnr); void parse_seabear_header(const char *filename, struct xml_params *params);
char *get_current_date(); char *get_current_date();
time_t get_dive_datetime_from_isostring(char *when); time_t get_dive_datetime_from_isostring(char *when);
void print_qt_versions(); void print_qt_versions();

View file

@ -29,6 +29,7 @@
#include "qthelper.h" #include "qthelper.h"
#include "gettext.h" #include "gettext.h"
#include "tag.h" #include "tag.h"
#include "xmlparams.h"
/* /*
* We're outputting utf8 in xml. * We're outputting utf8 in xml.
@ -834,7 +835,17 @@ int save_dives_logic(const char *filename, const bool select_only, bool anonymiz
return error; return error;
} }
static int export_dives_xslt_doit(const char *filename, struct xml_params *params, bool selected, int units, const char *export_xslt, bool anonymize);
int export_dives_xslt(const char *filename, const bool selected, const int units, const char *export_xslt, bool anonymize) int export_dives_xslt(const char *filename, const bool selected, const int units, const char *export_xslt, bool anonymize)
{
struct xml_params *params = alloc_xml_params();
int ret = export_dives_xslt_doit(filename, params, selected, units, export_xslt, anonymize);
free_xml_params(params);
return ret;
}
static int export_dives_xslt_doit(const char *filename, struct xml_params *params, bool selected, int units, const char *export_xslt, bool anonymize)
{ {
FILE *f; FILE *f;
struct membuffer buf = { 0 }; struct membuffer buf = { 0 };
@ -842,9 +853,6 @@ int export_dives_xslt(const char *filename, const bool selected, const int units
xsltStylesheetPtr xslt = NULL; xsltStylesheetPtr xslt = NULL;
xmlDoc *transformed; xmlDoc *transformed;
int res = 0; int res = 0;
char *params[3];
int pnr = 0;
char unitstr[3];
if (verbose) if (verbose)
fprintf(stderr, "export_dives_xslt with stylesheet %s\n", export_xslt); fprintf(stderr, "export_dives_xslt with stylesheet %s\n", export_xslt);
@ -870,12 +878,9 @@ int export_dives_xslt(const char *filename, const bool selected, const int units
if (!xslt) if (!xslt)
return report_error("Failed to open export conversion stylesheet"); return report_error("Failed to open export conversion stylesheet");
snprintf(unitstr, 3, "%d", units); xml_params_add_int(params, "units", units);
params[pnr++] = "units";
params[pnr++] = unitstr;
params[pnr++] = NULL;
transformed = xsltApplyStylesheet(xslt, doc, (const char **)params); transformed = xsltApplyStylesheet(xslt, doc, xml_params_get(params));
xmlFreeDoc(doc); xmlFreeDoc(doc);
/* Write the transformed export to file */ /* Write the transformed export to file */

View file

@ -15,6 +15,7 @@
#include "core/divesite.h" #include "core/divesite.h"
#include "core/trip.h" #include "core/trip.h"
#include "core/import-csv.h" #include "core/import-csv.h"
#include "core/xmlparams.h"
static QString subsurface_mimedata = "subsurface/csvcolumns"; static QString subsurface_mimedata = "subsurface/csvcolumns";
static QString subsurface_index = "subsurface/csvindex"; static QString subsurface_index = "subsurface/csvindex";
@ -801,64 +802,37 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy)
resultModel->setData(resultModel->index(0, i),headers.at(i),Qt::EditRole); resultModel->setData(resultModel->index(0, i),headers.at(i),Qt::EditRole);
} }
int DiveLogImportDialog::setup_csv_params(QStringList r, char **params, int pnr) void DiveLogImportDialog::setup_csv_params(QStringList r, xml_params &params)
{ {
params[pnr++] = strdup("dateField"); xml_params_add_int(&params, "dateField", r.indexOf(tr("Date")));
params[pnr++] = intdup(r.indexOf(tr("Date"))); xml_params_add_int(&params, "datefmt", ui->DateFormat->currentIndex());
params[pnr++] = strdup("datefmt"); xml_params_add_int(&params, "starttimeField", r.indexOf(tr("Time")));
params[pnr++] = intdup(ui->DateFormat->currentIndex()); xml_params_add_int(&params, "numberField", r.indexOf(tr("Dive #")));
params[pnr++] = strdup("starttimeField"); xml_params_add_int(&params, "timeField", r.indexOf(tr("Sample time")));
params[pnr++] = intdup(r.indexOf(tr("Time"))); xml_params_add_int(&params, "depthField", r.indexOf(tr("Sample depth")));
params[pnr++] = strdup("numberField"); xml_params_add_int(&params, "tempField", r.indexOf(tr("Sample temperature")));
params[pnr++] = intdup(r.indexOf(tr("Dive #"))); xml_params_add_int(&params, "po2Field", r.indexOf(tr("Sample pO₂")));
params[pnr++] = strdup("timeField"); xml_params_add_int(&params, "o2sensor1Field", r.indexOf(tr("Sample sensor1 pO₂")));
params[pnr++] = intdup(r.indexOf(tr("Sample time"))); xml_params_add_int(&params, "o2sensor2Field", r.indexOf(tr("Sample sensor2 pO₂")));
params[pnr++] = strdup("depthField"); xml_params_add_int(&params, "o2sensor3Field", r.indexOf(tr("Sample sensor3 pO₂")));
params[pnr++] = intdup(r.indexOf(tr("Sample depth"))); xml_params_add_int(&params, "cnsField", r.indexOf(tr("Sample CNS")));
params[pnr++] = strdup("tempField"); xml_params_add_int(&params, "ndlField", r.indexOf(tr("Sample NDL")));
params[pnr++] = intdup(r.indexOf(tr("Sample temperature"))); xml_params_add_int(&params, "ttsField", r.indexOf(tr("Sample TTS")));
params[pnr++] = strdup("po2Field"); xml_params_add_int(&params, "stopdepthField", r.indexOf(tr("Sample stopdepth")));
params[pnr++] = intdup(r.indexOf(tr("Sample pO₂"))); xml_params_add_int(&params, "pressureField", r.indexOf(tr("Sample pressure")));
params[pnr++] = strdup("o2sensor1Field"); xml_params_add_int(&params, "heartBeat", r.indexOf(tr("Sample heartrate")));
params[pnr++] = intdup(r.indexOf(tr("Sample sensor1 pO₂"))); xml_params_add_int(&params, "setpointField", r.indexOf(tr("Sample setpoint")));
params[pnr++] = strdup("o2sensor2Field"); xml_params_add_int(&params, "visibilityField", r.indexOf(tr("Visibility")));
params[pnr++] = intdup(r.indexOf(tr("Sample sensor2 pO₂"))); xml_params_add_int(&params, "ratingField", r.indexOf(tr("Rating")));
params[pnr++] = strdup("o2sensor3Field"); xml_params_add_int(&params, "separatorIndex", ui->CSVSeparator->currentIndex());
params[pnr++] = intdup(r.indexOf(tr("Sample sensor3 pO₂"))); xml_params_add_int(&params, "units", ui->CSVUnits->currentIndex());
params[pnr++] = strdup("cnsField"); if (hw.length())
params[pnr++] = intdup(r.indexOf(tr("Sample CNS"))); xml_params_add(&params, "hw", qPrintable(hw));
params[pnr++] = strdup("ndlField"); else if (ui->knownImports->currentText().length() > 0)
params[pnr++] = intdup(r.indexOf(tr("Sample NDL"))); xml_params_add(&params, "hw", qPrintable(ui->knownImports->currentText().prepend("\"").append("\"")));
params[pnr++] = strdup("ttsField");
params[pnr++] = intdup(r.indexOf(tr("Sample TTS")));
params[pnr++] = strdup("stopdepthField");
params[pnr++] = intdup(r.indexOf(tr("Sample stopdepth")));
params[pnr++] = strdup("pressureField");
params[pnr++] = intdup(r.indexOf(tr("Sample pressure")));
params[pnr++] = strdup("heartBeat");
params[pnr++] = intdup(r.indexOf(tr("Sample heartrate")));
params[pnr++] = strdup("setpointField");
params[pnr++] = intdup(r.indexOf(tr("Sample setpoint")));
params[pnr++] = strdup("visibilityField");
params[pnr++] = intdup(r.indexOf(tr("Visibility")));
params[pnr++] = strdup("ratingField");
params[pnr++] = intdup(r.indexOf(tr("Rating")));
params[pnr++] = strdup("separatorIndex");
params[pnr++] = intdup(ui->CSVSeparator->currentIndex());
params[pnr++] = strdup("units");
params[pnr++] = intdup(ui->CSVUnits->currentIndex());
if (hw.length()) {
params[pnr++] = strdup("hw");
params[pnr++] = copy_qstring(hw);
} else if (ui->knownImports->currentText().length() > 0) {
params[pnr++] = strdup("hw");
params[pnr++] = copy_qstring(ui->knownImports->currentText().prepend("\"").append("\""));
}
params[pnr++] = NULL;
return pnr;
} }
int DiveLogImportDialog::parseTxtHeader(QString fileName, char **params, int pnr)
void DiveLogImportDialog::parseTxtHeader(QString fileName, xml_params &params)
{ {
QFile f(fileName); QFile f(fileName);
QString date; QString date;
@ -897,11 +871,8 @@ int DiveLogImportDialog::parseTxtHeader(QString fileName, char **params, int pnr
} }
f.close(); f.close();
params[pnr++] = strdup("date"); xml_params_add(&params, "date", qPrintable(date));
params[pnr++] = strdup(date.toLatin1()); xml_params_add(&params, "time", qPrintable(time));
params[pnr++] = strdup("time");
params[pnr++] = strdup(time.toLatin1());
return pnr;
} }
void DiveLogImportDialog::on_buttonBox_accepted() void DiveLogImportDialog::on_buttonBox_accepted()
@ -919,20 +890,17 @@ void DiveLogImportDialog::on_buttonBox_accepted()
QPair<QString, QString> pair = poseidonFileNames(fileNames[i]); QPair<QString, QString> pair = poseidonFileNames(fileNames[i]);
parse_txt_file(qPrintable(pair.second), qPrintable(pair.first), &table, &trips, &sites); parse_txt_file(qPrintable(pair.second), qPrintable(pair.first), &table, &trips, &sites);
} else { } else {
char *params[50]; xml_params params;
int pnr = 0;
QRegExp apdRe("^.*[/\\][0-9a-zA-Z]*_([0-9]{6})_([0-9]{6})\\.apd"); QRegExp apdRe("^.*[/\\][0-9a-zA-Z]*_([0-9]{6})_([0-9]{6})\\.apd");
if (txtLog) { if (txtLog) {
pnr = parseTxtHeader(fileNames[i], params, pnr); parseTxtHeader(fileNames[i], params);
} else if (apdRe.exactMatch(fileNames[i])) { } else if (apdRe.exactMatch(fileNames[i])) {
params[pnr++] = strdup("date"); xml_params_add(&params, "date", qPrintable("20" + apdRe.cap(1)));
params[pnr++] = strdup("20" + apdRe.cap(1).toLatin1()); xml_params_add(&params, "time", qPrintable("1" + apdRe.cap(2)));
params[pnr++] = strdup("time");
params[pnr++] = strdup("1" + apdRe.cap(2).toLatin1());
} }
pnr = setup_csv_params(r, params, pnr); setup_csv_params(r, params);
parse_csv_file(qPrintable(fileNames[i]), params, pnr - 1, parse_csv_file(qPrintable(fileNames[i]), &params,
specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv", specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv",
&table, &trips, &sites, &filter_presets); &table, &trips, &sites, &filter_presets);
} }
@ -940,82 +908,49 @@ void DiveLogImportDialog::on_buttonBox_accepted()
} else { } else {
for (int i = 0; i < fileNames.size(); ++i) { for (int i = 0; i < fileNames.size(); ++i) {
if (r.indexOf(tr("Sample time")) < 0) { if (r.indexOf(tr("Sample time")) < 0) {
char *params[61]; xml_params params;
int pnr = 0; xml_params_add_int(&params, "numberField", r.indexOf(tr("Dive #")));
params[pnr++] = strdup("numberField"); xml_params_add_int(&params, "dateField", r.indexOf(tr("Date")));
params[pnr++] = intdup(r.indexOf(tr("Dive #"))); xml_params_add_int(&params, "timeField", r.indexOf(tr("Time")));
params[pnr++] = strdup("dateField"); xml_params_add_int(&params, "durationField", r.indexOf(tr("Duration")));
params[pnr++] = intdup(r.indexOf(tr("Date"))); xml_params_add_int(&params, "modeField", r.indexOf(tr("Mode")));
params[pnr++] = strdup("timeField"); xml_params_add_int(&params, "locationField", r.indexOf(tr("Location")));
params[pnr++] = intdup(r.indexOf(tr("Time"))); xml_params_add_int(&params, "gpsField", r.indexOf(tr("GPS")));
params[pnr++] = strdup("durationField"); xml_params_add_int(&params, "maxDepthField", r.indexOf(tr("Max. depth")));
params[pnr++] = intdup(r.indexOf(tr("Duration"))); xml_params_add_int(&params, "meanDepthField", r.indexOf(tr("Avg. depth")));
params[pnr++] = strdup("modeField"); xml_params_add_int(&params, "divemasterField", r.indexOf(tr("Divemaster")));
params[pnr++] = intdup(r.indexOf(tr("Mode"))); xml_params_add_int(&params, "buddyField", r.indexOf(tr("Buddy")));
params[pnr++] = strdup("locationField"); xml_params_add_int(&params, "suitField", r.indexOf(tr("Suit")));
params[pnr++] = intdup(r.indexOf(tr("Location"))); xml_params_add_int(&params, "notesField", r.indexOf(tr("Notes")));
params[pnr++] = strdup("gpsField"); xml_params_add_int(&params, "weightField", r.indexOf(tr("Weight")));
params[pnr++] = intdup(r.indexOf(tr("GPS"))); xml_params_add_int(&params, "tagsField", r.indexOf(tr("Tags")));
params[pnr++] = strdup("maxDepthField"); xml_params_add_int(&params, "separatorIndex", ui->CSVSeparator->currentIndex());
params[pnr++] = intdup(r.indexOf(tr("Max. depth"))); xml_params_add_int(&params, "units", ui->CSVUnits->currentIndex());
params[pnr++] = strdup("meanDepthField"); xml_params_add_int(&params, "datefmt", ui->DateFormat->currentIndex());
params[pnr++] = intdup(r.indexOf(tr("Avg. depth"))); xml_params_add_int(&params, "durationfmt", ui->DurationFormat->currentIndex());
params[pnr++] = strdup("divemasterField"); xml_params_add_int(&params, "cylindersizeField", r.indexOf(tr("Cyl. size")));
params[pnr++] = intdup(r.indexOf(tr("Divemaster"))); xml_params_add_int(&params, "startpressureField", r.indexOf(tr("Start pressure")));
params[pnr++] = strdup("buddyField"); xml_params_add_int(&params, "endpressureField", r.indexOf(tr("End pressure")));
params[pnr++] = intdup(r.indexOf(tr("Buddy"))); xml_params_add_int(&params, "o2Field", r.indexOf(tr("O₂")));
params[pnr++] = strdup("suitField"); xml_params_add_int(&params, "heField", r.indexOf(tr("He")));
params[pnr++] = intdup(r.indexOf(tr("Suit"))); xml_params_add_int(&params, "airtempField", r.indexOf(tr("Air temp.")));
params[pnr++] = strdup("notesField"); xml_params_add_int(&params, "watertempField", r.indexOf(tr("Water temp.")));
params[pnr++] = intdup(r.indexOf(tr("Notes"))); xml_params_add_int(&params, "visibilityField", r.indexOf(tr("Visibility")));
params[pnr++] = strdup("weightField"); xml_params_add_int(&params, "ratingField", r.indexOf(tr("Rating")));
params[pnr++] = intdup(r.indexOf(tr("Weight")));
params[pnr++] = strdup("tagsField");
params[pnr++] = intdup(r.indexOf(tr("Tags")));
params[pnr++] = strdup("separatorIndex");
params[pnr++] = intdup(ui->CSVSeparator->currentIndex());
params[pnr++] = strdup("units");
params[pnr++] = intdup(ui->CSVUnits->currentIndex());
params[pnr++] = strdup("datefmt");
params[pnr++] = intdup(ui->DateFormat->currentIndex());
params[pnr++] = strdup("durationfmt");
params[pnr++] = intdup(ui->DurationFormat->currentIndex());
params[pnr++] = strdup("cylindersizeField");
params[pnr++] = intdup(r.indexOf(tr("Cyl. size")));
params[pnr++] = strdup("startpressureField");
params[pnr++] = intdup(r.indexOf(tr("Start pressure")));
params[pnr++] = strdup("endpressureField");
params[pnr++] = intdup(r.indexOf(tr("End pressure")));
params[pnr++] = strdup("o2Field");
params[pnr++] = intdup(r.indexOf(tr("O₂")));
params[pnr++] = strdup("heField");
params[pnr++] = intdup(r.indexOf(tr("He")));
params[pnr++] = strdup("airtempField");
params[pnr++] = intdup(r.indexOf(tr("Air temp.")));
params[pnr++] = strdup("watertempField");
params[pnr++] = intdup(r.indexOf(tr("Water temp.")));
params[pnr++] = strdup("visibilityField");
params[pnr++] = intdup(r.indexOf(tr("Visibility")));
params[pnr++] = strdup("ratingField");
params[pnr++] = intdup(r.indexOf(tr("Rating")));
params[pnr++] = NULL;
parse_manual_file(qPrintable(fileNames[i]), params, pnr - 1, &table, &trips, &sites, &filter_presets); parse_manual_file(qPrintable(fileNames[i]), &params, &table, &trips, &sites, &filter_presets);
} else { } else {
char *params[53]; xml_params params;
int pnr = 0;
QRegExp apdRe("^.*[/\\][0-9a-zA-Z]*_([0-9]{6})_([0-9]{6})\\.apd"); QRegExp apdRe("^.*[/\\][0-9a-zA-Z]*_([0-9]{6})_([0-9]{6})\\.apd");
if (txtLog) { if (txtLog) {
pnr = parseTxtHeader(fileNames[i], params, pnr); parseTxtHeader(fileNames[i], params);
} else if (apdRe.exactMatch(fileNames[i])) { } else if (apdRe.exactMatch(fileNames[i])) {
params[pnr++] = strdup("date"); xml_params_add(&params, "date", qPrintable("20" + apdRe.cap(1)));
params[pnr++] = strdup("20" + apdRe.cap(1).toLatin1()); xml_params_add(&params, "time", qPrintable("1" + apdRe.cap(2)));
params[pnr++] = strdup("time");
params[pnr++] = strdup("1" + apdRe.cap(2).toLatin1());
} }
pnr = setup_csv_params(r, params, pnr); setup_csv_params(r, params);
parse_csv_file(qPrintable(fileNames[i]), params, pnr - 1, parse_csv_file(qPrintable(fileNames[i]), &params,
specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv", specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv",
&table, &trips, &sites, &filter_presets); &table, &trips, &sites, &filter_presets);
} }

View file

@ -13,6 +13,7 @@
#include "core/dive.h" #include "core/dive.h"
#include "core/divelist.h" #include "core/divelist.h"
struct xml_params;
namespace Ui { namespace Ui {
class DiveLogImportDialog; class DiveLogImportDialog;
} }
@ -87,8 +88,8 @@ slots:
void loadFileContentsSeperatorSelected(int value); void loadFileContentsSeperatorSelected(int value);
void loadFileContentsKnownTypesSelected(int value); void loadFileContentsKnownTypesSelected(int value);
void loadFileContents(int value, enum whatChanged triggeredBy); void loadFileContents(int value, enum whatChanged triggeredBy);
int setup_csv_params(QStringList r, char **params, int pnr); void setup_csv_params(QStringList r, xml_params &params);
int parseTxtHeader(QString fileName, char **params, int pnr); void parseTxtHeader(QString fileName, xml_params &params);
private: private:
bool selector; bool selector;

View file

@ -8,6 +8,7 @@
#include "core/parse.h" #include "core/parse.h"
#include "core/qthelper.h" #include "core/qthelper.h"
#include "core/subsurface-string.h" #include "core/subsurface-string.h"
#include "core/xmlparams.h"
#include <QTextStream> #include <QTextStream>
/* We have to use a macro since QCOMPARE /* We have to use a macro since QCOMPARE
@ -53,62 +54,35 @@ int TestParse::parseCSV(int units, std::string file)
// //
// CSV import should work // CSV import should work
verbose = 1; verbose = 1;
char *params[55]; xml_params params;
int pnr = 0;
params[pnr++] = strdup("numberField"); xml_params_add_int(&params, "numberField", 0);
params[pnr++] = intdup(0); xml_params_add_int(&params, "dateField", 1);
params[pnr++] = strdup("dateField"); xml_params_add_int(&params, "timeField", 2);
params[pnr++] = intdup(1); xml_params_add_int(&params, "durationField", 3);
params[pnr++] = strdup("timeField"); xml_params_add_int(&params, "locationField", -1);
params[pnr++] = intdup(2); xml_params_add_int(&params, "gpsField", -1);
params[pnr++] = strdup("durationField"); xml_params_add_int(&params, "maxDepthField", 4);
params[pnr++] = intdup(3); xml_params_add_int(&params, "meanDepthField", 5);
params[pnr++] = strdup("locationField"); xml_params_add_int(&params, "divemasterField", -1);
params[pnr++] = intdup(-1); xml_params_add_int(&params, "buddyField", 6);
params[pnr++] = strdup("gpsField"); xml_params_add_int(&params, "suitField", 7);
params[pnr++] = intdup(-1); xml_params_add_int(&params, "notesField", -1);
params[pnr++] = strdup("maxDepthField"); xml_params_add_int(&params, "weightField", -1);
params[pnr++] = intdup(4); xml_params_add_int(&params, "tagsField", -1);
params[pnr++] = strdup("meanDepthField"); xml_params_add_int(&params, "separatorIndex", 0);
params[pnr++] = intdup(5); xml_params_add_int(&params, "units", units);
params[pnr++] = strdup("divemasterField"); xml_params_add_int(&params, "datefmt", 1);
params[pnr++] = intdup(-1); xml_params_add_int(&params, "durationfmt", 2);
params[pnr++] = strdup("buddyField"); xml_params_add_int(&params, "cylindersizeField", -1);
params[pnr++] = intdup(6); xml_params_add_int(&params, "startpressureField", -1);
params[pnr++] = strdup("suitField"); xml_params_add_int(&params, "endpressureField", -1);
params[pnr++] = intdup(7); xml_params_add_int(&params, "o2Field", -1);
params[pnr++] = strdup("notesField"); xml_params_add_int(&params, "heField", -1);
params[pnr++] = intdup(-1); xml_params_add_int(&params, "airtempField", -1);
params[pnr++] = strdup("weightField"); xml_params_add_int(&params, "watertempField", -1);
params[pnr++] = intdup(-1);
params[pnr++] = strdup("tagsField");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("separatorIndex");
params[pnr++] = intdup(0);
params[pnr++] = strdup("units");
params[pnr++] = intdup(units);
params[pnr++] = strdup("datefmt");
params[pnr++] = intdup(1);
params[pnr++] = strdup("durationfmt");
params[pnr++] = intdup(2);
params[pnr++] = strdup("cylindersizeField");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("startpressureField");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("endpressureField");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("o2Field");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("heField");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("airtempField");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("watertempField");
params[pnr++] = intdup(-1);
params[pnr++] = NULL;
return parse_manual_file(file.c_str(), params, pnr - 1, &dive_table, &trip_table, &dive_site_table, &filter_preset_table); return parse_manual_file(file.c_str(), &params, &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
} }
int TestParse::parseDivingLog() int TestParse::parseDivingLog()
@ -179,45 +153,27 @@ void TestParse::testParseDM5()
void TestParse::testParseHUDC() void TestParse::testParseHUDC()
{ {
char *params[37]; xml_params params;
int pnr = 0;
params[pnr++] = strdup("timeField"); xml_params_add_int(&params, "timeField", 0);
params[pnr++] = intdup(0); xml_params_add_int(&params, "depthField", 1);
params[pnr++] = strdup("depthField"); xml_params_add_int(&params, "tempField", 5);
params[pnr++] = intdup(1); xml_params_add_int(&params, "po2Field", -1);
params[pnr++] = strdup("tempField"); xml_params_add_int(&params, "o2sensor1Field", -1);
params[pnr++] = intdup(5); xml_params_add_int(&params, "o2sensor2Field", -1);
params[pnr++] = strdup("po2Field"); xml_params_add_int(&params, "o2sensor3Field", -1);
params[pnr++] = intdup(-1); xml_params_add_int(&params, "cnsField", -1);
params[pnr++] = strdup("o2sensor1Field"); xml_params_add_int(&params, "ndlField", 2);
params[pnr++] = intdup(-1); xml_params_add_int(&params, "ttsField", -1);
params[pnr++] = strdup("o2sensor2Field"); xml_params_add_int(&params, "stopdepthField", -1);
params[pnr++] = intdup(-1); xml_params_add_int(&params, "pressureField", -1);
params[pnr++] = strdup("o2sensor3Field"); xml_params_add_int(&params, "setpointField", -1);
params[pnr++] = intdup(-1); xml_params_add_int(&params, "separatorIndex", 2);
params[pnr++] = strdup("cnsField"); xml_params_add_int(&params, "units", 0);
params[pnr++] = intdup(-1); xml_params_add(&params, "hw", "\"DC text\"");
params[pnr++] = strdup("ndlField");
params[pnr++] = intdup(2);
params[pnr++] = strdup("ttsField");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("stopdepthField");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("pressureField");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("setpointField");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("separatorIndex");
params[pnr++] = intdup(2);
params[pnr++] = strdup("units");
params[pnr++] = intdup(0);
params[pnr++] = strdup("hw");
params[pnr++] = strdup("\"DC text\"");
params[pnr++] = NULL;
QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/TestDiveSeabearHUDC.csv", QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/TestDiveSeabearHUDC.csv",
params, pnr - 1, "csv", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), &params, "csv", &dive_table, &trip_table, &dive_site_table, &filter_preset_table),
0); 0);
QCOMPARE(dive_table.nr, 1); QCOMPARE(dive_table.nr, 1);
@ -306,67 +262,39 @@ void TestParse::testParseMerge()
int TestParse::parseCSVmanual(int units, std::string file) int TestParse::parseCSVmanual(int units, std::string file)
{ {
verbose = 1; verbose = 1;
char *params[59]; xml_params params;
int pnr = 0;
// Numbers are column numbers // Numbers are column numbers
params[pnr++] = strdup("numberField"); xml_params_add_int(&params, "numberField", 0);
params[pnr++] = intdup(0); xml_params_add_int(&params, "dateField", 1);
params[pnr++] = strdup("dateField"); xml_params_add_int(&params, "timeField", 2);
params[pnr++] = intdup(1); xml_params_add_int(&params, "durationField", 3);
params[pnr++] = strdup("timeField");
params[pnr++] = intdup(2);
params[pnr++] = strdup("durationField");
params[pnr++] = intdup(3);
// 4 Will be SAC, once we add support for reading it // 4 Will be SAC, once we add support for reading it
params[pnr++] = strdup("maxDepthField"); xml_params_add_int(&params, "maxDepthField", 5);
params[pnr++] = intdup(5); xml_params_add_int(&params, "meanDepthField", 6);
params[pnr++] = strdup("meanDepthField"); xml_params_add_int(&params, "modeField", 7);
params[pnr++] = intdup(6); xml_params_add_int(&params, "airtempField", 8);
params[pnr++] = strdup("modeField"); xml_params_add_int(&params, "watertempField", 9);
params[pnr++] = intdup(7); xml_params_add_int(&params, "cylindersizeField", 10);
params[pnr++] = strdup("airtempField"); xml_params_add_int(&params, "startpressureField", 11);
params[pnr++] = intdup(8); xml_params_add_int(&params, "endpressureField", 12);
params[pnr++] = strdup("watertempField"); xml_params_add_int(&params, "o2Field", 13);
params[pnr++] = intdup(9); xml_params_add_int(&params, "heField", 14);
params[pnr++] = strdup("cylindersizeField"); xml_params_add_int(&params, "locationField", 15);
params[pnr++] = intdup(10); xml_params_add_int(&params, "gpsField", 16);
params[pnr++] = strdup("startpressureField"); xml_params_add_int(&params, "divemasterField", 17);
params[pnr++] = intdup(11); xml_params_add_int(&params, "buddyField", 18);
params[pnr++] = strdup("endpressureField"); xml_params_add_int(&params, "suitField", 19);
params[pnr++] = intdup(12); xml_params_add_int(&params, "notesField", 22);
params[pnr++] = strdup("o2Field"); xml_params_add_int(&params, "weightField", 23);
params[pnr++] = intdup(13); xml_params_add_int(&params, "tagsField", 24);
params[pnr++] = strdup("heField");
params[pnr++] = intdup(14);
params[pnr++] = strdup("locationField");
params[pnr++] = intdup(15);
params[pnr++] = strdup("gpsField");
params[pnr++] = intdup(16);
params[pnr++] = strdup("divemasterField");
params[pnr++] = intdup(17);
params[pnr++] = strdup("buddyField");
params[pnr++] = intdup(18);
params[pnr++] = strdup("suitField");
params[pnr++] = intdup(19);
params[pnr++] = strdup("notesField");
params[pnr++] = intdup(22);
params[pnr++] = strdup("weightField");
params[pnr++] = intdup(23);
params[pnr++] = strdup("tagsField");
params[pnr++] = intdup(24);
// Numbers are indices of possible options // Numbers are indices of possible options
params[pnr++] = strdup("separatorIndex"); xml_params_add_int(&params, "separatorIndex", 0);
params[pnr++] = intdup(0); xml_params_add_int(&params, "datefmt", 2);
params[pnr++] = strdup("datefmt"); xml_params_add_int(&params, "durationfmt", 2);
params[pnr++] = intdup(2); xml_params_add_int(&params, "units", units);
params[pnr++] = strdup("durationfmt");
params[pnr++] = intdup(2);
params[pnr++] = strdup("units");
params[pnr++] = intdup(units);
params[pnr++] = NULL;
return parse_manual_file(file.c_str(), params, pnr - 1, &dive_table, &trip_table, &dive_site_table, &filter_preset_table); return parse_manual_file(file.c_str(), &params, &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
} }
void TestParse::exportCSVDiveDetails() void TestParse::exportCSVDiveDetails()
@ -405,8 +333,7 @@ void TestParse::exportCSVDiveDetails()
void TestParse::exportSubsurfaceCSV() void TestParse::exportSubsurfaceCSV()
{ {
int saved_sac = 0; int saved_sac = 0;
char *params[59]; xml_params params;
int pnr = 0;
/* Test SubsurfaceCSV with multiple cylinders */ /* Test SubsurfaceCSV with multiple cylinders */
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table); parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
@ -421,12 +348,9 @@ void TestParse::exportSubsurfaceCSV()
clear_dive_file_data(); clear_dive_file_data();
params[pnr++] = strdup("separatorIndex"); xml_params_add_int(&params, "separatorIndex", 0);
params[pnr++] = intdup(0); xml_params_add_int(&params, "units", 1);
params[pnr++] = strdup("units"); parse_csv_file("testcsvexportmanualimperial-cyl.csv", &params, "SubsurfaceCSV", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
params[pnr++] = intdup(1);
params[pnr++] = 0;
parse_csv_file("testcsvexportmanualimperial-cyl.csv", params, pnr - 1, "SubsurfaceCSV", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
// We do not currently support reading SAC, thus faking it // We do not currently support reading SAC, thus faking it
if (dive_table.nr > 0) { if (dive_table.nr > 0) {
@ -445,32 +369,21 @@ void TestParse::exportSubsurfaceCSV()
int TestParse::parseCSVprofile(int units, std::string file) int TestParse::parseCSVprofile(int units, std::string file)
{ {
verbose = 1; verbose = 1;
char *params[55]; xml_params params;
int pnr = 0;
// Numbers are column numbers // Numbers are column numbers
params[pnr++] = strdup("numberField"); xml_params_add_int(&params, "numberField", 0);
params[pnr++] = intdup(0); xml_params_add_int(&params, "dateField", 1);
params[pnr++] = strdup("dateField"); xml_params_add_int(&params, "starttimeField", 2);
params[pnr++] = intdup(1); xml_params_add_int(&params, "timeField", 3);
params[pnr++] = strdup("starttimeField"); xml_params_add_int(&params, "depthField", 4);
params[pnr++] = intdup(2); xml_params_add_int(&params, "tempField", 5);
params[pnr++] = strdup("timeField"); xml_params_add_int(&params, "pressureField", 6);
params[pnr++] = intdup(3);
params[pnr++] = strdup("depthField");
params[pnr++] = intdup(4);
params[pnr++] = strdup("tempField");
params[pnr++] = intdup(5);
params[pnr++] = strdup("pressureField");
params[pnr++] = intdup(6);
// Numbers are indices of possible options // Numbers are indices of possible options
params[pnr++] = strdup("datefmt"); xml_params_add_int(&params, "datefmt", 2);
params[pnr++] = intdup(2); xml_params_add_int(&params, "units", units);
params[pnr++] = strdup("units");
params[pnr++] = intdup(units);
params[pnr++] = NULL;
return parse_csv_file(file.c_str(), params, pnr - 1, "csv", &dive_table, &trip_table, &dive_site_table, &filter_preset_table); return parse_csv_file(file.c_str(), &params, "csv", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
} }
void TestParse::exportCSVDiveProfile() void TestParse::exportCSVDiveProfile()
@ -518,54 +431,32 @@ void TestParse::testExport()
void TestParse::parseDL7() void TestParse::parseDL7()
{ {
char *params[51]; xml_params params;
int pnr = 0;
params[pnr++] = strdup("dateField"); xml_params_add_int(&params, "dateField", -1);
params[pnr++] = intdup(-1); xml_params_add_int(&params, "datefmt", 0);
params[pnr++] = strdup("datefmt"); xml_params_add_int(&params, "starttimeField", -1);
params[pnr++] = intdup(0); xml_params_add_int(&params, "numberField", -1);
params[pnr++] = strdup("starttimeField"); xml_params_add_int(&params, "timeField", 1);
params[pnr++] = intdup(-1); xml_params_add_int(&params, "depthField", 2);
params[pnr++] = strdup("numberField"); xml_params_add_int(&params, "tempField", -1);
params[pnr++] = intdup(-1); xml_params_add_int(&params, "po2Field", -1);
params[pnr++] = strdup("timeField"); xml_params_add_int(&params, "o2sensor1Field", -1);
params[pnr++] = intdup(1); xml_params_add_int(&params, "o2sensor2Field", -1);
params[pnr++] = strdup("depthField"); xml_params_add_int(&params, "o2sensor3Field", -1);
params[pnr++] = intdup(2); xml_params_add_int(&params, "cnsField", -1);
params[pnr++] = strdup("tempField"); xml_params_add_int(&params, "ndlField", -1);
params[pnr++] = intdup(-1); xml_params_add_int(&params, "ttsField", -1);
params[pnr++] = strdup("po2Field"); xml_params_add_int(&params, "stopdepthField", -1);
params[pnr++] = intdup(-1); xml_params_add_int(&params, "pressureField", -1);
params[pnr++] = strdup("o2sensor1Field"); xml_params_add_int(&params, "setpointField", -1);
params[pnr++] = intdup(-1); xml_params_add_int(&params, "separatorIndex", 3);
params[pnr++] = strdup("o2sensor2Field"); xml_params_add_int(&params, "units", 0);
params[pnr++] = intdup(-1); xml_params_add(&params, "hw", "DL7");
params[pnr++] = strdup("o2sensor3Field");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("cnsField");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("ndlField");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("ttsField");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("stopdepthField");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("pressureField");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("setpointField");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("separatorIndex");
params[pnr++] = intdup(3);
params[pnr++] = strdup("units");
params[pnr++] = intdup(0);
params[pnr++] = strdup("hw");
params[pnr++] = strdup("DL7");
params[pnr++] = 0;
clear_dive_file_data(); clear_dive_file_data();
QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/DL7.zxu", QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/DL7.zxu",
params, pnr - 1, "DL7", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), &params, "DL7", &dive_table, &trip_table, &dive_site_table, &filter_preset_table),
0); 0);
QCOMPARE(dive_table.nr, 3); QCOMPARE(dive_table.nr, 3);