aboutsummaryrefslogtreecommitdiffstats
path: root/core/import-csv.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-11-27 00:25:15 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-01-09 20:58:04 -0800
commit7e33369dc8b27b20385ab055b662e06bbf369784 (patch)
treeaf674ccdd1ccb67d4de84d68cb585b481d020fb3 /core/import-csv.c
parentec37c71f5eeb7d4b0c4b8719b52583fadb0b8f4c (diff)
downloadsubsurface-7e33369dc8b27b20385ab055b662e06bbf369784.tar.gz
Parser: add trip_table parameter to parsing functions
To allow parsing into arbitrary trip_tables, add the corresponding parameter to the parsing functions and the parser state. Currently, all callers pass the global trip_table so there should be no change in functionality. These arguments will be replaced in subsequent commits. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/import-csv.c')
-rw-r--r--core/import-csv.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/core/import-csv.c b/core/import-csv.c
index c196d9283..341375851 100644
--- a/core/import-csv.c
+++ b/core/import-csv.c
@@ -101,7 +101,7 @@ static char *parse_dan_new_line(char *buf, const char *NL)
}
static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, const char *tag);
-static int parse_dan_format(const char *filename, char **params, int pnr, struct dive_table *table)
+static int parse_dan_format(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips)
{
int ret = 0, i;
size_t end_ptr = 0;
@@ -211,7 +211,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
}
}
params[pnr_local] = NULL;
- ret |= parse_xml_buffer(filename, "<csv></csv>", 11, table, (const char **)params);
+ ret |= parse_xml_buffer(filename, "<csv></csv>", 11, table, trips, (const char **)params);
continue;
}
@@ -268,7 +268,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
if (try_to_xslt_open_csv(filename, &mem_csv, "csv"))
return -1;
- ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, table, (const char **)params);
+ ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, table, trips, (const char **)params);
end_ptr += ptr - (char *)mem_csv.buffer;
free(mem_csv.buffer);
}
@@ -280,7 +280,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
return ret;
}
-int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, struct dive_table *table)
+int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, struct dive_table *table, struct trip_table *trips)
{
int ret, i;
struct memblock mem;
@@ -300,7 +300,7 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv
mem.size = 0;
if (!strcmp("DL7", csvtemplate)) {
- return parse_dan_format(filename, params, pnr, table);
+ return parse_dan_format(filename, params, pnr, table, trips);
} else if (strcmp(params[0], "date")) {
time(&now);
timep = localtime(&now);
@@ -335,7 +335,7 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv
fprintf(stderr, "%s/xslt/csv2xml.xslt -\n", SUBSURFACE_SOURCE);
}
#endif
- ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, (const char **)params);
+ ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, (const char **)params);
free(mem.buffer);
for (i = 0; params[i]; i += 2)
@@ -394,7 +394,7 @@ static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, cons
return 0;
}
-int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_table *table)
+int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_table *table, struct trip_table *trips)
{
char *p = mem->buffer;
char *header[8];
@@ -486,7 +486,7 @@ static char *next_mkvi_key(const char *haystack)
return ret;
}
-int parse_txt_file(const char *filename, const char *csv, struct dive_table *table)
+int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips)
{
struct memblock memtxt, memcsv;
@@ -778,15 +778,16 @@ int parse_txt_file(const char *filename, const char *csv, struct dive_table *tab
#define TIMESTR 6
#define SBPARAMS 40
-static int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, struct dive_table *table);
-int parse_seabear_log(const char *filename, struct dive_table *table)
+static int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate,
+ struct dive_table *table, struct trip_table *trips);
+int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips)
{
char *params[SBPARAMS];
int pnr = 0;
pnr = parse_seabear_header(filename, params, pnr);
- if (parse_seabear_csv_file(filename, params, pnr, "csv", table) < 0) {
+ if (parse_seabear_csv_file(filename, params, pnr, "csv", table, trips) < 0) {
return -1;
}
@@ -794,7 +795,8 @@ int parse_seabear_log(const char *filename, struct dive_table *table)
}
-static int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, struct dive_table *table)
+static int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate,
+ struct dive_table *table, struct trip_table *trips)
{
int ret, i;
struct memblock mem;
@@ -913,7 +915,7 @@ static int parse_seabear_csv_file(const char *filename, char **params, int pnr,
fprintf(stderr, "xslt/csv2xml.xslt\n");
}
- ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, (const char **)params);
+ ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, (const char **)params);
free(mem.buffer);
for (i = 0; params[i]; i += 2)
free(params[i + 1]);
@@ -921,7 +923,7 @@ static int parse_seabear_csv_file(const char *filename, char **params, int pnr,
return ret;
}
-int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table)
+int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips)
{
struct memblock mem;
time_t now;
@@ -939,7 +941,6 @@ int parse_manual_file(const char *filename, char **params, int pnr, struct dive_
* is not discarded during the transform, thus prepend time with 1 */
strftime(curtime, TIMESTR, "1%H%M", timep);
-
params[pnr++] = strdup("date");
params[pnr++] = strdup(curdate);
params[pnr++] = strdup("time");
@@ -961,7 +962,7 @@ int parse_manual_file(const char *filename, char **params, int pnr, struct dive_
fprintf(stderr, "%s/xslt/manualcsv2xml.xslt -\n", SUBSURFACE_SOURCE);
}
#endif
- ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, (const char **)params);
+ ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, (const char **)params);
free(mem.buffer);
for (i = 0; i < pnr - 2; ++i)