summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-08-18 15:06:15 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-08-23 10:17:12 -0700
commitd815e0c9476ef62e6b84fb28ce48ab7cddefe77e (patch)
tree997b938f8080518d339797aae4630eb66b81e204 /core
parentecb64d7e3e3c6c875defc9dc4aab01c65ccddf8a (diff)
downloadsubsurface-d815e0c9476ef62e6b84fb28ce48ab7cddefe77e.tar.gz
Parse: pass dive_table argument to parse_file()
To enable undo of divelog-importing it is crucial that parse_file() can parse into arbitrary dive tables. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r--core/dive.h4
-rw-r--r--core/file.c42
-rw-r--r--core/file.h2
-rw-r--r--core/parse-xml.c4
4 files changed, 26 insertions, 26 deletions
diff --git a/core/dive.h b/core/dive.h
index 1338cb72a..9c56f1070 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -499,9 +499,9 @@ extern int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, i
extern int parse_shearwater_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);
+extern int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table);
-extern int parse_file(const char *filename);
+extern int parse_file(const char *filename, struct dive_table *table);
extern int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate);
extern int parse_seabear_log(const char *filename);
extern int parse_txt_file(const char *filename, const char *csv);
diff --git a/core/file.c b/core/file.c
index f350b5bc3..abef20a7d 100644
--- a/core/file.c
+++ b/core/file.c
@@ -75,7 +75,7 @@ out:
}
-static void zip_read(struct zip_file *file, const char *filename)
+static void zip_read(struct zip_file *file, const char *filename, struct dive_table *table)
{
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)
mem = realloc(mem, size);
}
mem[read] = 0;
- (void) parse_xml_buffer(filename, mem, read, &dive_table, NULL);
+ (void) parse_xml_buffer(filename, mem, read, table, NULL);
free(mem);
}
-int try_to_open_zip(const char *filename)
+int try_to_open_zip(const char *filename, struct dive_table *table)
{
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)
/* skip parsing the divelogs.de pictures */
if (strstr(zip_get_name(zip, index, 0), "pictures/"))
continue;
- zip_read(file, filename);
+ zip_read(file, filename, table);
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)
+static int try_to_open_db(const char *filename, struct memblock *mem, struct dive_table *table)
{
sqlite3 *handle;
char dm4_test[] = "select count(*) from sqlite_master where type='table' and name='Dive' and sql like '%ProfileBlob%'";
@@ -146,7 +146,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem)
/* 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, &dive_table);
+ retval = parse_dm5_buffer(handle, filename, mem->buffer, mem->size, table);
sqlite3_close(handle);
return retval;
}
@@ -154,7 +154,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem)
/* 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, &dive_table);
+ retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, table);
sqlite3_close(handle);
return retval;
}
@@ -162,7 +162,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem)
/* 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, &dive_table);
+ retval = parse_shearwater_buffer(handle, filename, mem->buffer, mem->size, table);
sqlite3_close(handle);
return retval;
}
@@ -170,7 +170,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem)
/* 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, &dive_table);
+ retval = parse_cobalt_buffer(handle, filename, mem->buffer, mem->size, table);
sqlite3_close(handle);
return retval;
}
@@ -178,7 +178,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem)
/* 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, &dive_table);
+ retval = parse_divinglog_buffer(handle, filename, mem->buffer, mem->size, table);
sqlite3_close(handle);
return retval;
}
@@ -204,7 +204,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem)
*
* 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)
+static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem, struct dive_table *table)
{
// hack to be able to provide a comment for the translated string
static char *csv_warning = QT_TRANSLATE_NOOP3("gettextFromC",
@@ -213,7 +213,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);
+ return try_to_open_zip(filename, table);
/* CSV files */
if (!strcasecmp(fmt, "CSV"))
@@ -234,17 +234,17 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo
return 0;
}
-static int parse_file_buffer(const char *filename, struct memblock *mem)
+static int parse_file_buffer(const char *filename, struct memblock *mem, struct dive_table *table)
{
int ret;
char *fmt = strrchr(filename, '.');
- if (fmt && (ret = open_by_filename(filename, fmt + 1, mem)) != 0)
+ if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table)) != 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, &dive_table, NULL);
+ return parse_xml_buffer(filename, mem->buffer, mem->size, table, NULL);
}
int check_git_sha(const char *filename, struct git_repository **git_p, const char **branch_p)
@@ -281,7 +281,7 @@ int check_git_sha(const char *filename, struct git_repository **git_p, const cha
return 1;
}
-int parse_file(const char *filename)
+int parse_file(const char *filename, struct dive_table *table)
{
struct git_repository *git;
const char *branch = NULL;
@@ -327,7 +327,7 @@ int parse_file(const char *filename)
fmt = strrchr(filename, '.');
if (fmt && (!strcasecmp(fmt + 1, "DB") || !strcasecmp(fmt + 1, "BAK") || !strcasecmp(fmt + 1, "SQL"))) {
- if (!try_to_open_db(filename, &mem)) {
+ if (!try_to_open_db(filename, &mem, table)) {
free(mem.buffer);
return 0;
}
@@ -335,14 +335,14 @@ int parse_file(const char *filename)
/* Divesoft Freedom */
if (fmt && (!strcasecmp(fmt + 1, "DLF"))) {
- ret = parse_dlf_buffer(mem.buffer, mem.size);
+ ret = parse_dlf_buffer(mem.buffer, mem.size, table);
free(mem.buffer);
return ret;
}
/* DataTrak/Wlog */
if (fmt && !strcasecmp(fmt + 1, "LOG")) {
- ret = datatrak_import(&mem, &dive_table);
+ ret = datatrak_import(&mem, table);
free(mem.buffer);
return ret;
}
@@ -350,11 +350,11 @@ int parse_file(const char *filename)
/* OSTCtools */
if (fmt && (!strcasecmp(fmt + 1, "DIVE"))) {
free(mem.buffer);
- ostctools_import(filename, &dive_table);
+ ostctools_import(filename, table);
return 0;
}
- ret = parse_file_buffer(filename, &mem);
+ ret = parse_file_buffer(filename, &mem, table);
free(mem.buffer);
return ret;
}
diff --git a/core/file.h b/core/file.h
index 9653fbb96..7dbd07b48 100644
--- a/core/file.h
+++ b/core/file.h
@@ -16,7 +16,7 @@ extern void ostctools_import(const char *file, struct dive_table *table);
extern "C" {
#endif
extern int readfile(const char *filename, struct memblock *mem);
-extern int try_to_open_zip(const char *filename);
+extern int try_to_open_zip(const char *filename, struct dive_table *table);
#ifdef __cplusplus
}
#endif
diff --git a/core/parse-xml.c b/core/parse-xml.c
index 681d05aa9..1f31d69d7 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -1654,7 +1654,7 @@ static timestamp_t parse_dlf_timestamp(unsigned char *buffer)
return offset + 946684800;
}
-int parse_dlf_buffer(unsigned char *buffer, size_t size)
+int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table)
{
unsigned char *ptr = buffer;
unsigned char event;
@@ -1663,7 +1663,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size)
int i;
char serial[6];
- target_table = &dive_table;
+ target_table = table;
// Check for the correct file magic
if (ptr[0] != 'D' || ptr[1] != 'i' || ptr[2] != 'v' || ptr[3] != 'E')