diff options
author | Miika Turkia <miika.turkia@gmail.com> | 2016-04-24 21:11:23 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-04-25 09:08:57 -0700 |
commit | f4ddc078838b876199a762255c632424a6f0132d (patch) | |
tree | d247a71bdb239cad17310f4c135b044cbe206ceb | |
parent | 0b8ac416bf73f13ae15f5d99d6b6a914061fab53 (diff) | |
download | subsurface-f4ddc078838b876199a762255c632424a6f0132d.tar.gz |
Grab the payload of DL7 file
This allows us to parse the DL7 profile data (skipping the header and
footer)
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | core/file.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/core/file.c b/core/file.c index 52c93a719..b00e0e8a9 100644 --- a/core/file.c +++ b/core/file.c @@ -928,6 +928,43 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv params[pnr++] = NULL; mem.size = 0; + + if (!strcmp("DL7", csvtemplate)) { + char *ptr = NULL; + char *NL = 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; + } + + 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; + } + if (try_to_xslt_open_csv(filename, &mem, csvtemplate)) return -1; |