diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-02-28 22:45:17 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-04-12 18:19:07 +0300 |
commit | 37146c5742503becf75468fb07aab56011cb9101 (patch) | |
tree | 666e4d609b3d9b882082fcc258d6d153c6c68fa5 /core/file.c | |
parent | 926b6895bbce7cc539ca4d0c3a425876dfa33d6b (diff) | |
download | subsurface-37146c5742503becf75468fb07aab56011cb9101.tar.gz |
Parser: parse into custom dive site table
To extend the undo system to dive sites, the importers and downloaders
must not parse directly into the global dive site table. Instead,
pass a dive_site_table argument to parse into.
For now, always pass the global dive_site_table so that this commit
should not cause any functional change.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/file.c')
-rw-r--r-- | core/file.c | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/core/file.c b/core/file.c index 89338e167..8a1a1ec1e 100644 --- a/core/file.c +++ b/core/file.c @@ -75,7 +75,7 @@ out: } -static void zip_read(struct zip_file *file, const char *filename, struct dive_table *table, struct trip_table *trips) +static void zip_read(struct zip_file *file, const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) { 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, trips, NULL); + (void) parse_xml_buffer(filename, mem, read, table, trips, sites, NULL); free(mem); } -int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips) +int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) { 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, struct trip_ /* skip parsing the divelogs.de pictures */ if (strstr(zip_get_name(zip, index, 0), "pictures/")) continue; - zip_read(file, filename, table, trips); + zip_read(file, filename, table, trips, sites); 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, struct trip_table *trips) +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) { 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, trips); + retval = parse_dm5_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites); 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, trips); + retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites); 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, trips); + retval = parse_shearwater_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites); 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, trips); + retval = parse_shearwater_cloud_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites); 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, trips); + retval = parse_cobalt_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites); 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, trips); + retval = parse_divinglog_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites); sqlite3_close(handle); return retval; } @@ -214,7 +214,7 @@ 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, struct trip_table *trips) + struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) { // hack to be able to provide a comment for the translated string static char *csv_warning = QT_TRANSLATE_NOOP3("gettextFromC", @@ -223,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, trips); + return try_to_open_zip(filename, table, trips, sites); /* 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, trips); + return try_to_open_cochran(filename, mem, table, trips, sites); /* Cochran export comma-separated-value files */ if (!strcasecmp(fmt, "DPT")) - return try_to_open_csv(mem, CSV_DEPTH, table, trips); + return try_to_open_csv(mem, CSV_DEPTH, table, trips, sites); if (!strcasecmp(fmt, "LVD")) - return try_to_open_liquivision(filename, mem, table, trips); + return try_to_open_liquivision(filename, mem, table, trips, sites); if (!strcasecmp(fmt, "TMP")) - return try_to_open_csv(mem, CSV_TEMP, table, trips); + return try_to_open_csv(mem, CSV_TEMP, table, trips, sites); if (!strcasecmp(fmt, "HP1")) - return try_to_open_csv(mem, CSV_PRESSURE, table, trips); + return try_to_open_csv(mem, CSV_PRESSURE, table, trips, sites); return 0; } -static int parse_file_buffer(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips) +static int parse_file_buffer(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) { int ret; char *fmt = strrchr(filename, '.'); - if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table, trips)) != 0) + if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table, trips, sites)) != 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, NULL); + return parse_xml_buffer(filename, mem->buffer, mem->size, table, trips, sites, NULL); } int check_git_sha(const char *filename, struct git_repository **git_p, const char **branch_p) @@ -291,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, struct trip_table *trips) +int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) { struct git_repository *git; const char *branch = NULL; @@ -337,7 +337,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)) { + if (!try_to_open_db(filename, &mem, table, trips, sites)) { free(mem.buffer); return 0; } @@ -345,14 +345,14 @@ 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); + ret = parse_dlf_buffer(mem.buffer, mem.size, table, trips, sites); free(mem.buffer); return ret; } /* DataTrak/Wlog */ if (fmt && !strcasecmp(fmt + 1, "LOG")) { - ret = datatrak_import(&mem, table, trips); + ret = datatrak_import(&mem, table, trips, sites); free(mem.buffer); return ret; } @@ -360,11 +360,11 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table /* OSTCtools */ if (fmt && (!strcasecmp(fmt + 1, "DIVE"))) { free(mem.buffer); - ostctools_import(filename, table, trips); + ostctools_import(filename, table, trips, sites); return 0; } - ret = parse_file_buffer(filename, &mem, table, trips); + ret = parse_file_buffer(filename, &mem, table, trips, sites); free(mem.buffer); return ret; } |