Seabear import: remove excessive amount of parameters

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Miika Turkia 2015-08-23 20:56:20 +03:00 committed by Dirk Hohndel
parent ad75b09581
commit bde2e93f8f
3 changed files with 58 additions and 33 deletions

2
dive.h
View file

@ -669,7 +669,7 @@ extern int parse_dlf_buffer(unsigned char *buffer, size_t size);
extern int parse_file(const char *filename);
extern int parse_csv_file(const char *filename, int timef, int depthf, int tempf, int po2f, int o2Sensor1f, int o2Sensor2f, int o2Sensor3f, int cnsf, int ndlf, int ttsf, int stopdepthf, int pressuref, int setpointf, int sepidx, const char *csvtemplate, int unitidx, const char *hw);
extern int parse_seabear_csv_file(const char *filename, int timef, int depthf, int tempf, int po2f, int o2Sensor1f, int o2Sensor2f, int o2Sensor3f, int cnsf, int ndlf, int ttsf, int stopdepthf, int pressuref, int sepidx, const char *csvtemplate, int unitidx, const char *delta, const char *hw);
extern int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate);
extern int parse_txt_file(const char *filename, const char *csv);
extern int parse_manual_file(const char *filename, char **params, int pnr);
extern int save_dives(const char *filename);

29
file.c
View file

@ -980,16 +980,15 @@ int parse_csv_file(const char *filename, int timef, int depthf, int tempf, int p
}
#define SBPARAMS 40
int parse_seabear_csv_file(const char *filename, int timef, int depthf, int tempf, int po2f, int o2sensor1f, int o2sensor2f, int o2sensor3f, int cnsf, int ndlf, int ttsf, int stopdepthf, int pressuref, int sepidx, const char *csvtemplate, int unitidx, const char *delta, const char *hw)
int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate)
{
int ret, i, pnr;
int ret, i;
struct memblock mem;
char *params[SBPARAMS];
char deltabuf[MAXCOLDIGITS];
time_t now;
struct tm *timep = NULL;
char *ptr, *ptr_old = NULL;
char *NL = NULL;
char tmpbuf[MAXCOLDIGITS];
/* Increase the limits for recursion and variables on XSLT
* parsing */
@ -998,10 +997,19 @@ int parse_seabear_csv_file(const char *filename, int timef, int depthf, int temp
xsltMaxVars = 150000;
#endif
if (timef >= MAXCOLS || depthf >= MAXCOLS || tempf >= MAXCOLS || po2f >= MAXCOLS || o2sensor1f >= MAXCOLS || o2sensor2f >= MAXCOLS || o2sensor3f >= MAXCOLS || cnsf >= MAXCOLS || ndlf >= MAXCOLS || cnsf >= MAXCOLS || stopdepthf >= MAXCOLS || pressuref >= MAXCOLS)
return report_error(translate("gettextFromC", "Maximum number of supported columns on CSV import is %d"), MAXCOLS);
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);
pnr = init_csv_file_parsing(params, &now, timep, timef, depthf, tempf, po2f, o2sensor1f, o2sensor2f, o2sensor3f, cnsf, ndlf, ttsf, stopdepthf, pressuref, -1, sepidx, csvtemplate, unitidx);
if (filename == NULL)
return report_error("No CSV filename");
@ -1069,13 +1077,6 @@ int parse_seabear_csv_file(const char *filename, int timef, int depthf, int temp
params[pnr - 1][5] = 0;
}
snprintf(deltabuf, MAXCOLDIGITS, "%s", delta);
params[pnr++] = "delta";
params[pnr++] = strdup(deltabuf);
if (strlen(hw)) {
params[pnr++] = "hw";
params[pnr++] = strdup(hw);
}
params[pnr++] = NULL;
/* Move the CSV data to the start of mem buffer */

View file

@ -629,25 +629,49 @@ void DiveLogImportDialog::on_buttonBox_accepted()
if (ui->knownImports->currentText() != "Manual import") {
for (int i = 0; i < fileNames.size(); ++i) {
if (ui->knownImports->currentText() == "Seabear CSV") {
char *params[40];
int pnr = 0;
params[pnr++] = strdup("timeField");
params[pnr++] = intdup(r.indexOf(tr("Sample time")));
params[pnr++] = strdup("depthField");
params[pnr++] = intdup(r.indexOf(tr("Sample depth")));
params[pnr++] = strdup("tempField");
params[pnr++] = intdup(r.indexOf(tr("Sample temperature")));
params[pnr++] = strdup("po2Field");
params[pnr++] = intdup(r.indexOf(tr("Sample pO₂")));
params[pnr++] = strdup("o2sensor1Field");
params[pnr++] = intdup(r.indexOf(tr("Sample sensor1 pO₂")));
params[pnr++] = strdup("o2sensor2Field");
params[pnr++] = intdup(r.indexOf(tr("Sample sensor2 pO₂")));
params[pnr++] = strdup("o2sensor3Field");
params[pnr++] = intdup(r.indexOf(tr("Sample sensor3 pO₂")));
params[pnr++] = strdup("cnsField");
params[pnr++] = intdup(r.indexOf(tr("Sample CNS")));
params[pnr++] = strdup("ndlField");
params[pnr++] = intdup(r.indexOf(tr("Sample NDL")));
params[pnr++] = strdup("ttsField");
params[pnr++] = intdup(r.indexOf(tr("Sample TTS")));
params[pnr++] = strdup("stopdepthField");
params[pnr++] = intdup(r.indexOf(tr("Sample stopdepth")));
params[pnr++] = strdup("pressureField");
params[pnr++] = intdup(r.indexOf(tr("Sample pressure")));
params[pnr++] = strdup("setpointFiend");
params[pnr++] = intdup(-1);
params[pnr++] = strdup("separatorIndex");
params[pnr++] = intdup(ui->CSVSeparator->currentIndex());
params[pnr++] = strdup("units");
params[pnr++] = intdup(ui->CSVUnits->currentIndex());
params[pnr++] = strdup("delta");
params[pnr++] = strdup(delta.toUtf8().data());
if (hw.length()) {
params[pnr++] = strdup("hw");
params[pnr++] = strdup(hw.toUtf8().data());
}
params[pnr++] = NULL;
if (parse_seabear_csv_file(fileNames[i].toUtf8().data(),
r.indexOf(tr("Sample time")),
r.indexOf(tr("Sample depth")),
r.indexOf(tr("Sample temperature")),
r.indexOf(tr("Sample pO₂")),
r.indexOf(tr("Sample sensor1 pO₂")),
r.indexOf(tr("Sample sensor2 pO₂")),
r.indexOf(tr("Sample sensor3 pO₂")),
r.indexOf(tr("Sample CNS")),
r.indexOf(tr("Sample NDL")),
r.indexOf(tr("Sample TTS")),
r.indexOf(tr("Sample stopdepth")),
r.indexOf(tr("Sample pressure")),
ui->CSVSeparator->currentIndex(),
"csv",
ui->CSVUnits->currentIndex(),
delta.toUtf8().data(),
hw.toUtf8().data()
) < 0) {
params, pnr - 1, "csv") < 0) {
return;
}
// Seabear CSV stores NDL and TTS in Minutes, not seconds