Signed-off-by: Miika Turkia <[email protected]>
---
 core/file.c                             | 58 ++++++++++++++++++++++++---------
 desktop-widgets/divelogimportdialog.cpp |  4 +--
 2 files changed, 44 insertions(+), 18 deletions(-)

diff --git a/core/file.c b/core/file.c
index b00e0e8..82eb684 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 0fd911f..fb2e1d6 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);
-- 
2.5.0

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to