summaryrefslogtreecommitdiffstats
path: root/core/file.c
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 09:16:32 -0700
commit24edaf4be15aad618c77a3728158202482060459 (patch)
tree8394ea6cbf7cb9974264969f136dbed7c786658f /core/file.c
parentf4ddc078838b876199a762255c632424a6f0132d (diff)
downloadsubsurface-24edaf4be15aad618c77a3728158202482060459.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>
Diffstat (limited to 'core/file.c')
-rw-r--r--core/file.c58
1 files changed, 42 insertions, 16 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))