summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2016-04-24 21:11:24 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-04-25 12:32:22 -0700
commit14aafaa67ddf24405751db4a8d19d41b9eefa7fa (patch)
tree149132f202e1bfbde69b2e8a9dc7da4d85db13f9
parent6df8752d7d380f68e3fe84c81f62a56b0680ac75 (diff)
downloadsubsurface-14aafaa67ddf24405751db4a8d19d41b9eefa7fa.tar.gz
Parse date and time in DL7 import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--file.c58
-rw-r--r--qt-ui/divelogimportdialog.cpp4
2 files changed, 44 insertions, 18 deletions
diff --git a/file.c b/file.c
index e7a79ea2d..ad70551be 100644
--- a/file.c
+++ b/file.c
@@ -859,26 +859,12 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv
if (filename == NULL)
return report_error("No CSV filename");
- time(&now);
- timep = localtime(&now);
-
- strftime(tmpbuf, MAXCOLDIGITS, "%Y%m%d", timep);
- params[pnr++] = "date";
- params[pnr++] = strdup(tmpbuf);
-
- /* As the parameter is numeric, we need to ensure that the leading zero
- * is not discarded during the transform, thus prepend time with 1 */
-
- strftime(tmpbuf, MAXCOLDIGITS, "1%H%M", timep);
- params[pnr++] = "time";
- params[pnr++] = strdup(tmpbuf);
- params[pnr++] = NULL;
-
mem.size = 0;
-
if (!strcmp("DL7", csvtemplate)) {
char *ptr = NULL;
char *NL = NULL;
+ char *iter = NULL;
+ char *tmp = NULL;
csvtemplate = "csv";
if (readfile(filename, &mem) < 0)
@@ -894,6 +880,31 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv
return -1;
}
+ ptr = strstr(mem.buffer, "ZDH");
+ if (ptr) {
+ iter = ptr + 1;
+ for (i = 0; i <= 4 && iter; ++i) {
+ iter = strchr(iter, '|');
+ if (iter)
+ ++iter;
+ }
+
+ /* Setting date */
+ memcpy(tmpbuf, iter, 8);
+ tmpbuf[8] = 0;
+ params[pnr++] = "date";
+ params[pnr++] = strdup(tmpbuf);
+
+ /* Setting time, gotta prepend it with 1 to
+ * avoid octal parsing (this is stripped out in
+ * XSLT */
+ tmpbuf[0] = '1';
+ memcpy(tmpbuf + 1, iter + 8, 6);
+ tmpbuf[7] = 0;
+ params[pnr++] = "time";
+ params[pnr++] = strdup(tmpbuf);
+ }
+
ptr = strstr(mem.buffer, "ZDP");
if (ptr)
ptr = strstr(ptr, NL);
@@ -910,6 +921,21 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv
return -1;
}
mem.size = ptr - (char*)mem.buffer;
+ } else {
+ time(&now);
+ timep = localtime(&now);
+
+ strftime(tmpbuf, MAXCOLDIGITS, "%Y%m%d", timep);
+ params[pnr++] = "date";
+ params[pnr++] = strdup(tmpbuf);
+
+ /* As the parameter is numeric, we need to ensure that the leading zero
+ * is not discarded during the transform, thus prepend time with 1 */
+
+ strftime(tmpbuf, MAXCOLDIGITS, "1%H%M", timep);
+ params[pnr++] = "time";
+ params[pnr++] = strdup(tmpbuf);
+ params[pnr++] = NULL;
}
if (try_to_xslt_open_csv(filename, &mem, csvtemplate))
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index 9ee683a43..df136c541 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -811,7 +811,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
sample->tts.seconds *= 60;
}
} else {
- char *params[37];
+ char *params[39];
int pnr = 0;
pnr = setup_csv_params(r, params, pnr);
@@ -878,7 +878,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
parse_manual_file(fileNames[i].toUtf8().data(), params, pnr - 1);
} else {
- char *params[37];
+ char *params[39];
int pnr = 0;
pnr = setup_csv_params(r, params, pnr);