mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Parse date and time in DL7 import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
f4ddc07883
commit
24edaf4be1
2 changed files with 44 additions and 18 deletions
58
core/file.c
58
core/file.c
|
@ -912,26 +912,12 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv
|
||||||
if (filename == NULL)
|
if (filename == NULL)
|
||||||
return report_error("No CSV filename");
|
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;
|
mem.size = 0;
|
||||||
|
|
||||||
if (!strcmp("DL7", csvtemplate)) {
|
if (!strcmp("DL7", csvtemplate)) {
|
||||||
char *ptr = NULL;
|
char *ptr = NULL;
|
||||||
char *NL = NULL;
|
char *NL = NULL;
|
||||||
|
char *iter = NULL;
|
||||||
|
char *tmp = NULL;
|
||||||
|
|
||||||
csvtemplate = "csv";
|
csvtemplate = "csv";
|
||||||
if (readfile(filename, &mem) < 0)
|
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;
|
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");
|
ptr = strstr(mem.buffer, "ZDP");
|
||||||
if (ptr)
|
if (ptr)
|
||||||
ptr = strstr(ptr, NL);
|
ptr = strstr(ptr, NL);
|
||||||
|
@ -963,6 +974,21 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
mem.size = ptr - (char*)mem.buffer;
|
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))
|
if (try_to_xslt_open_csv(filename, &mem, csvtemplate))
|
||||||
|
|
|
@ -819,7 +819,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
|
||||||
sample->tts.seconds *= 60;
|
sample->tts.seconds *= 60;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
char *params[37];
|
char *params[39];
|
||||||
int pnr = 0;
|
int pnr = 0;
|
||||||
|
|
||||||
pnr = setup_csv_params(r, params, pnr);
|
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);
|
parse_manual_file(fileNames[i].toUtf8().data(), params, pnr - 1);
|
||||||
} else {
|
} else {
|
||||||
char *params[37];
|
char *params[39];
|
||||||
int pnr = 0;
|
int pnr = 0;
|
||||||
|
|
||||||
pnr = setup_csv_params(r, params, pnr);
|
pnr = setup_csv_params(r, params, pnr);
|
||||||
|
|
Loading…
Add table
Reference in a new issue