mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 13:10:19 +00:00
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>
This commit is contained in:
parent
0b8ac416bf
commit
f4ddc07883
1 changed files with 37 additions and 0 deletions
37
core/file.c
37
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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue