summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/file.c58
-rw-r--r--desktop-widgets/divelogimportdialog.cpp4
2 files changed, 44 insertions, 18 deletions
diff --git a/core/file.c b/core/file.c
index b00e0e8a9..82eb684b0 100644
--- a/core/file.c
+++ b/core/file.c
@@ -912,26 +912,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)
@@ -947,6 +933,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);
@@ -963,6 +974,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/desktop-widgets/divelogimportdialog.cpp b/desktop-widgets/divelogimportdialog.cpp
index 0fd911fe1..fb2e1d65b 100644
--- a/desktop-widgets/divelogimportdialog.cpp
+++ b/desktop-widgets/divelogimportdialog.cpp
@@ -819,7 +819,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);
@@ -886,7 +886,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);