summaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2013-10-16 22:05:19 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-10-16 12:44:07 -0700
commit4c49670cdba403090067d8b92940b577d16ba550 (patch)
treec6d331e238d934e95e54a05e4967a7eec564784c /file.c
parent80bced4f560047874515536979e3cba1e519e147 (diff)
downloadsubsurface-4c49670cdba403090067d8b92940b577d16ba550.tar.gz
GUI for CSV import
This patch implements GUI for importing CSV log files. One is able to configure what columns contain time, depth and temperature fields. Pre-configured log applications currently included are ADP log viewer and XP5. (Both of these use actually tab as separator, so the field separator currently hard-coded.) [Dirk Hohndel: minor fixes] Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'file.c')
-rw-r--r--file.c53
1 files changed, 51 insertions, 2 deletions
diff --git a/file.c b/file.c
index a4b90129a..acabd1b6b 100644
--- a/file.c
+++ b/file.c
@@ -72,7 +72,7 @@ static void zip_read(struct zip_file *file, char **error, const char *filename)
mem = realloc(mem, size);
}
mem[read] = 0;
- parse_xml_buffer(filename, mem, read, &dive_table, error);
+ parse_xml_buffer(filename, mem, read, &dive_table, NULL, error);
free(mem);
}
@@ -286,7 +286,7 @@ static void parse_file_buffer(const char *filename, struct memblock *mem, char *
if (fmt && open_by_filename(filename, fmt+1, mem, error))
return;
- parse_xml_buffer(filename, mem->buffer, mem->size, &dive_table, error);
+ parse_xml_buffer(filename, mem->buffer, mem->size, &dive_table, NULL, error);
}
void parse_file(const char *filename, char **error)
@@ -319,3 +319,52 @@ void parse_file(const char *filename, char **error)
parse_file_buffer(filename, &mem, error);
free(mem.buffer);
}
+
+#define MAXCOLDIGITS 3
+#define MAXCOLS 100
+void parse_csv_file(const char *filename, int time, int depth, int temp, char **error)
+{
+ struct memblock mem;
+ char *params[7];
+ char timebuf[MAXCOLDIGITS];
+ char depthbuf[MAXCOLDIGITS];
+ char tempbuf[MAXCOLDIGITS];
+
+ if (time >= MAXCOLS || depth >= MAXCOLS || temp >= MAXCOLS) {
+ int len = strlen(translate("gettextFromC", "Maximum number of supported columns on CSV import is %d")) + MAXCOLDIGITS;
+ *error = malloc(len);
+ snprintf(*error, len, translate("gettextFromC", "Maximum number of supported columns on CSV import is %d"), MAXCOLS);
+
+ return;
+ }
+ snprintf(timebuf, MAXCOLDIGITS, "%d", time);
+ snprintf(depthbuf, MAXCOLDIGITS, "%d", depth);
+ snprintf(tempbuf, MAXCOLDIGITS, "%d", temp);
+
+ params[0] = "timeField";
+ params[1] = timebuf;
+ params[2] = "depthField";
+ params[3] = depthbuf;
+ params[4] = "tempField";
+ params[5] = tempbuf;
+ params[6] = NULL;
+
+ if (filename == NULL)
+ return;
+
+ if (readfile(filename, &mem) < 0) {
+ if (error) {
+ int len = strlen(translate("gettextFromC","Failed to read '%s'")) + strlen(filename);
+ *error = malloc(len);
+ snprintf(*error, len, translate("gettextFromC","Failed to read '%s'"), filename);
+ }
+
+ return;
+ }
+
+ if (try_to_xslt_open_csv(filename, &mem, error))
+ return;
+
+ parse_xml_buffer(filename, mem.buffer, mem.size, &dive_table, (const char **)params, error);
+ free(mem.buffer);
+}