diff options
author | Salvador Cuñat <salvador.cunat@gmail.com> | 2020-08-26 12:37:33 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-09-03 11:38:13 -0700 |
commit | c888a1727e250c27a8d494dac7d340c8b7475867 (patch) | |
tree | e975145aa9a672a6bf071944888602bb07ed2058 /core/file.c | |
parent | 37ae5a7d83bac4a002597bfc3df977b61d50d5ce (diff) | |
download | subsurface-c888a1727e250c27a8d494dac7d340c8b7475867.tar.gz |
DataTrak import: Add support for WLog extensions.
WLog is a Win32 based ancient shareware program whose target was:
1) fully support divelogs coming from DataTrak (DOS or Win)
2) fill some meaningful data which wasn't supported by Uwatec software
3) have a more user-friendly GUI than Datatrak had
The problem achieving goals 1) and 2) at the same time was solved by
adding a complementary file with .add extension and - mandatory - same
base name than .log file (including directory tree).
This .add file has a fixed structure composed of a 12 bytes header,
including file type check and Nº of dives following; then a fixed 850
bytes size for each dive in the log file. Data fields size and position
are fixed inside these blocks and heavily zero padded, so they are easy
to parse.
A serious restriction imposed to the WLog user was *Do not edit the logs
with other software than Wlog*; this was due the order of dives in .log
file being the same than the order of dives in .add file. Thought you
could show a WLog divelog in Datatrak, editing it resulted in mixing all
extended data for dives following the edited one.
Thus, we have to trust files are correct and is to the user ensure this
is so. If extended data are mangled, they are mangled in WLog too and we
are not trying to fix the mess, just importing.
On the technical side, we try to be smart about tank names as neither
DataTrak nor WLog record them. So we just take the first tank in users
list matching the volume recorded in WLog.
For weights we add a translatable "unknown" string as an empty string
results in weight not being shown in subsurface-mobile (which could be a
reportable issue, BTW).
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Diffstat (limited to 'core/file.c')
-rw-r--r-- | core/file.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/core/file.c b/core/file.c index 0fece03a9..ed00b7948 100644 --- a/core/file.c +++ b/core/file.c @@ -338,8 +338,20 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table /* DataTrak/Wlog */ if (fmt && !strcasecmp(fmt + 1, "LOG")) { - ret = datatrak_import(&mem, table, trips, sites); + struct memblock wl_mem; + const char *t = strrchr(filename, '.'); + char *wl_name = memcpy(calloc(t - filename + 1, 1), filename, t - filename); + wl_name = realloc(wl_name, strlen(wl_name) + 5); + wl_name = strcat(wl_name, ".add"); + if((ret = readfile(wl_name, &wl_mem)) < 0) { + fprintf(stderr, "No file %s found. No WLog extensions.\n", wl_name); + ret = datatrak_import(&mem, NULL, table, trips, sites); + } else { + ret = datatrak_import(&mem, &wl_mem, table, trips, sites); + free(wl_mem.buffer); + } free(mem.buffer); + free(wl_name); return ret; } |