aboutsummaryrefslogtreecommitdiffstats
path: root/core/file.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-10-17 12:32:22 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-24 09:51:37 -0700
commita2614665942959b95eef8453730cd3ac66ac42a3 (patch)
treee8491231112634e6fa188a605ddab47910cfe8c2 /core/file.c
parent41975435a2a93733a0e46a7e594ffba193be6e87 (diff)
downloadsubsurface-a2614665942959b95eef8453730cd3ac66ac42a3.tar.gz
parser: add device_table to parser state
If we want to avoid the parsers to directly modify global data, we have to provide a device_table to parse into. This adds such a state and the corresponding function parameters. However, for now this is unused. Adding new parameters is very painful and this commit shows that we urgently need a "struct divelog" collecting all those tables! Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/file.c')
-rw-r--r--core/file.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/core/file.c b/core/file.c
index d8f9d48a9..e6fe28df6 100644
--- a/core/file.c
+++ b/core/file.c
@@ -77,7 +77,7 @@ out:
static void zip_read(struct zip_file *file, const char *filename, 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 device_table *devices, struct filter_preset_table *filter_presets)
{
int size = 1024, n, read = 0;
char *mem = malloc(size);
@@ -88,12 +88,12 @@ 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, trips, sites, filter_presets, NULL);
+ (void) parse_xml_buffer(filename, mem, read, table, trips, sites, devices, filter_presets, NULL);
free(mem);
}
int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
- struct filter_preset_table *filter_presets)
+ struct device_table *devices, struct filter_preset_table *filter_presets)
{
int success = 0;
/* Grr. libzip needs to re-open the file, it can't take a buffer */
@@ -108,7 +108,7 @@ int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_
/* skip parsing the divelogs.de pictures */
if (strstr(zip_get_name(zip, index, 0), "pictures/"))
continue;
- zip_read(file, filename, table, trips, sites, filter_presets);
+ zip_read(file, filename, table, trips, sites, devices, filter_presets);
zip_fclose(file);
success++;
}
@@ -128,7 +128,8 @@ static int db_test_func(void *param, int columns, char **data, char **column)
return *data[0] == '0';
}
-static int try_to_open_db(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
+static int try_to_open_db(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips,
+ struct dive_site_table *sites, struct device_table *devices)
{
sqlite3 *handle;
char dm4_test[] = "select count(*) from sqlite_master where type='table' and name='Dive' and sql like '%ProfileBlob%'";
@@ -150,7 +151,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, trips, sites);
+ retval = parse_dm5_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices);
sqlite3_close(handle);
return retval;
}
@@ -158,7 +159,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, trips, sites);
+ retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices);
sqlite3_close(handle);
return retval;
}
@@ -166,7 +167,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, trips, sites);
+ retval = parse_shearwater_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices);
sqlite3_close(handle);
return retval;
}
@@ -174,7 +175,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, trips, sites);
+ retval = parse_shearwater_cloud_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices);
sqlite3_close(handle);
return retval;
}
@@ -182,7 +183,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, trips, sites);
+ retval = parse_cobalt_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices);
sqlite3_close(handle);
return retval;
}
@@ -190,7 +191,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, trips, sites);
+ retval = parse_divinglog_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices);
sqlite3_close(handle);
return retval;
}
@@ -198,7 +199,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Seac database format */
retval = sqlite3_exec(handle, seacsync_test, &db_test_func, 0, NULL);
if (!retval) {
- retval = parse_seac_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites);
+ retval = parse_seac_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices);
sqlite3_close(handle);
return retval;
}
@@ -227,7 +228,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
*/
static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
- struct filter_preset_table *filter_presets)
+ struct device_table *devices, struct filter_preset_table *filter_presets)
{
// hack to be able to provide a comment for the translated string
static char *csv_warning = QT_TRANSLATE_NOOP3("gettextFromC",
@@ -236,7 +237,7 @@ 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, trips, sites, filter_presets);
+ return try_to_open_zip(filename, table, trips, sites, devices, filter_presets);
/* CSV files */
if (!strcasecmp(fmt, "CSV"))
@@ -258,17 +259,18 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo
}
static int parse_file_buffer(const char *filename, struct memblock *mem, 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 device_table *devices, struct filter_preset_table *filter_presets)
{
int ret;
char *fmt = strrchr(filename, '.');
- if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table, trips, sites, filter_presets)) != 0)
+ if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table, trips, sites, devices, filter_presets)) != 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, trips, sites, filter_presets, NULL);
+ return parse_xml_buffer(filename, mem->buffer, mem->size, table, trips, sites, devices, filter_presets, NULL);
}
int check_git_sha(const char *filename, struct git_repository **git_p, const char **branch_p)
@@ -305,7 +307,8 @@ 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, struct trip_table *trips, struct dive_site_table *sites, struct filter_preset_table *filter_presets)
+int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
+ struct device_table *devices, struct filter_preset_table *filter_presets)
{
struct git_repository *git;
const char *branch = NULL;
@@ -336,7 +339,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_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, trips, sites)) {
+ if (!try_to_open_db(filename, &mem, table, trips, sites, devices)) {
free(mem.buffer);
return 0;
}
@@ -344,7 +347,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
/* Divesoft Freedom */
if (fmt && (!strcasecmp(fmt + 1, "DLF"))) {
- ret = parse_dlf_buffer(mem.buffer, mem.size, table, trips, sites);
+ ret = parse_dlf_buffer(mem.buffer, mem.size, table, trips, sites, devices);
free(mem.buffer);
return ret;
}
@@ -375,7 +378,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
return 0;
}
- ret = parse_file_buffer(filename, &mem, table, trips, sites, filter_presets);
+ ret = parse_file_buffer(filename, &mem, table, trips, sites, devices, filter_presets);
free(mem.buffer);
return ret;
}