summaryrefslogtreecommitdiffstats
path: root/core/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/file.c')
-rw-r--r--core/file.c87
1 files changed, 75 insertions, 12 deletions
diff --git a/core/file.c b/core/file.c
index 3ce084e03..4c0ae8fd0 100644
--- a/core/file.c
+++ b/core/file.c
@@ -912,22 +912,85 @@ 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);
+ 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)
+ return report_error(translate("gettextFromC", "Failed to read '%s'"), filename);
+
+ /* Determine NL (new line) character and the start of CSV data */
+ if ((ptr = strstr(mem.buffer, "\r\n")) != NULL) {
+ NL = "\r\n";
+ } else if ((ptr = strstr(mem.buffer, "\n")) != NULL) {
+ NL = "\n";
+ } else {
+ fprintf(stderr, "DEBUG: failed to detect NL\n");
+ return -1;
+ }
- strftime(tmpbuf, MAXCOLDIGITS, "%Y%m%d", timep);
- params[pnr++] = "date";
- params[pnr++] = strdup(tmpbuf);
+ ptr = strstr(mem.buffer, "ZDH");
+ if (ptr) {
+ iter = ptr + 1;
+ for (i = 0; i <= 4 && iter; ++i) {
+ iter = strchr(iter, '|');
+ if (iter)
+ ++iter;
+ }
- /* As the parameter is numeric, we need to ensure that the leading zero
- * is not discarded during the transform, thus prepend time with 1 */
+ /* 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);
+ }
- strftime(tmpbuf, MAXCOLDIGITS, "1%H%M", timep);
- params[pnr++] = "time";
- params[pnr++] = strdup(tmpbuf);
- params[pnr++] = NULL;
+ ptr = strstr(mem.buffer, "ZDP");
+ if (ptr)
+ ptr = strstr(ptr, NL);
+ if (ptr)
+ ptr + strlen(NL);
+
+ /* Move the CSV data to the start of mem buffer */
+ memmove(mem.buffer, ptr, mem.size - (ptr - (char*)mem.buffer));
+ ptr = strstr(mem.buffer, "ZDP");
+ if (ptr) {
+ *ptr = 0;
+ } else {
+ fprintf(stderr, "DEBUG: failed to find end ZDP\n");
+ 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;
+ }
- mem.size = 0;
if (try_to_xslt_open_csv(filename, &mem, csvtemplate))
return -1;