summaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-12-08 11:26:03 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-12-08 11:28:23 -0800
commitd9be07670c2a7e3d54b6defb5ce5334b41ae1d90 (patch)
treef44c45c7c2f0ca61427a74d488f098b23e7fbaf0 /file.c
parent77664e715026c8c587b6a9c60b774ea31d5e75d5 (diff)
downloadsubsurface-d9be07670c2a7e3d54b6defb5ce5334b41ae1d90.tar.gz
Don't ignore when we can't parse a file
We are quite inconsistent when it comes to reporting back errors. One case where this caused somewhat unexpected behavior was when the user would try to open a .csv file by passing it as command line argument. The file was silently ignored, but treated as if it had been opened successfully. Now we issue a somewhat reasonable error message. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'file.c')
-rw-r--r--file.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/file.c b/file.c
index d85661080..358397675 100644
--- a/file.c
+++ b/file.c
@@ -76,7 +76,7 @@ static void zip_read(struct zip_file *file, const char *filename)
mem = realloc(mem, size);
}
mem[read] = 0;
- parse_xml_buffer(filename, mem, read, &dive_table, NULL);
+ (void) parse_xml_buffer(filename, mem, read, &dive_table, NULL);
free(mem);
}
@@ -370,7 +370,7 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo
/* CSV files */
if (!strcasecmp(fmt, "CSV"))
- return 1;
+ return report_error("Cannot open CSV file %s; please use Import log file dialog", filename);
/* Truly nasty intentionally obfuscated Cochran Anal software */
if (!strcasecmp(fmt, "CAN"))
return try_to_open_cochran(filename, mem);
@@ -387,16 +387,17 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo
return 0;
}
-static void parse_file_buffer(const char *filename, struct memblock *mem)
+static int parse_file_buffer(const char *filename, struct memblock *mem)
{
+ int ret;
char *fmt = strrchr(filename, '.');
- if (fmt && open_by_filename(filename, fmt + 1, mem))
- return;
+ if (fmt && (ret = open_by_filename(filename, fmt + 1, mem)) != 0)
+ return ret;
if (!mem->size || !mem->buffer)
- return;
+ return report_error("Out of memory parsing file %s\n", filename);
- parse_xml_buffer(filename, mem->buffer, mem->size, &dive_table, NULL);
+ return parse_xml_buffer(filename, mem->buffer, mem->size, &dive_table, NULL);
}
int parse_file(const char *filename)
@@ -405,6 +406,7 @@ int parse_file(const char *filename)
const char *branch;
struct memblock mem;
char *fmt;
+ int ret;
git = is_git_repository(filename, &branch);
if (git && !git_load_dives(git, branch))
@@ -426,9 +428,9 @@ int parse_file(const char *filename)
}
}
- parse_file_buffer(filename, &mem);
+ ret = parse_file_buffer(filename, &mem);
free(mem.buffer);
- return 0;
+ return ret;
}
#define MATCH(buffer, pattern) \
@@ -822,6 +824,7 @@ void init_csv_file_parsing(char **params, char *timebuf, char *depthbuf, char *t
int parse_csv_file(const char *filename, int timef, int depthf, int tempf, int po2f, int cnsf, int ndlf, int ttsf, int stopdepthf, int pressuref, int sepidx, const char *csvtemplate, int unitidx)
{
+ int ret;
struct memblock mem;
char *params[27];
char timebuf[MAXCOLDIGITS];
@@ -852,13 +855,14 @@ int parse_csv_file(const char *filename, int timef, int depthf, int tempf, int p
if (try_to_xslt_open_csv(filename, &mem, csvtemplate))
return -1;
- parse_xml_buffer(filename, mem.buffer, mem.size, &dive_table, (const char **)params);
+ ret = parse_xml_buffer(filename, mem.buffer, mem.size, &dive_table, (const char **)params);
free(mem.buffer);
- return 0;
+ return ret;
}
int parse_seabear_csv_file(const char *filename, int timef, int depthf, int tempf, int po2f, int cnsf, int ndlf, int ttsf, int stopdepthf, int pressuref, int sepidx, const char *csvtemplate, int unitidx)
{
+ int ret;
struct memblock mem;
char *params[27];
char timebuf[MAXCOLDIGITS];
@@ -938,9 +942,9 @@ int parse_seabear_csv_file(const char *filename, int timef, int depthf, int temp
if (try_to_xslt_open_csv(filename, &mem, csvtemplate))
return -1;
- parse_xml_buffer(filename, mem.buffer, mem.size, &dive_table, (const char **)params);
+ ret = parse_xml_buffer(filename, mem.buffer, mem.size, &dive_table, (const char **)params);
free(mem.buffer);
- return 0;
+ return ret;
}
int parse_manual_file(const char *filename, int sepidx, int units, int dateformat, int numberf, int datef, int timef, int durationf, int locationf, int gpsf, int maxdepthf, int meandepthf, int buddyf, int notesf, int weightf, int tagsf)
@@ -967,6 +971,7 @@ int parse_manual_file(const char *filename, int sepidx, int units, int dateforma
struct tm *timep;
char curdate[9];
char curtime[6];
+ int ret;
if (numberf >= MAXCOLS || datef >= MAXCOLS || timef >= MAXCOLS || durationf >= MAXCOLS || locationf >= MAXCOLS || gpsf >= MAXCOLS || maxdepthf >= MAXCOLS || meandepthf >= MAXCOLS || buddyf >= MAXCOLS || notesf >= MAXCOLS || weightf >= MAXCOLS || tagsf >= MAXCOLS)
return report_error(translate("gettextFromC", "Maximum number of supported columns on CSV import is %d"), MAXCOLS);
@@ -1037,7 +1042,7 @@ int parse_manual_file(const char *filename, int sepidx, int units, int dateforma
if (try_to_xslt_open_csv(filename, &mem, "manualCSV"))
return -1;
- parse_xml_buffer(filename, mem.buffer, mem.size, &dive_table, (const char **)params);
+ ret = parse_xml_buffer(filename, mem.buffer, mem.size, &dive_table, (const char **)params);
free(mem.buffer);
- return 0;
+ return ret;
}