summaryrefslogtreecommitdiffstats
path: root/parse-xml.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2014-03-14 11:26:07 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-03-14 12:36:06 -0700
commit609715ab698489588b32aa69d98fa2c5b233ef8f (patch)
treed9bfef1748deea912ce894e22c53f7920a62afec /parse-xml.c
parentec33a95ad04099d428275de2c6b36e7098cc943e (diff)
downloadsubsurface-609715ab698489588b32aa69d98fa2c5b233ef8f.tar.gz
Convert other users of showError() to the new world order
The "report_error()" interface is a lot simpler, although some of the C++ code uses QStrings which make them a bit annoying, especially for the varargs model. Still, even with the explicit conversion to UTF8 and "char *", the report_error() model is much nicer. This also just makes refreshDisplay() do the error reporting in the UI automatically, so a number of error paths don't even have to worry. And the multi-line model of error reporting means that it all automatically does the right thing, and reports errors for each file rather than just for the last file that failed to open. So this removes closer to a hundred lines of cruft, while being a simpler interface and doing better error reporting. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'parse-xml.c')
-rw-r--r--parse-xml.c40
1 files changed, 8 insertions, 32 deletions
diff --git a/parse-xml.c b/parse-xml.c
index d3ff03d2c..483187a51 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -20,36 +20,13 @@
int verbose, quit;
int metric = 1;
-static xmlDoc *test_xslt_transforms(xmlDoc *doc, const char **params, char **error);
+static xmlDoc *test_xslt_transforms(xmlDoc *doc, const char **params);
/* the dive table holds the overall dive list; target table points at
* the table we are currently filling */
struct dive_table dive_table;
struct dive_table *target_table = NULL;
-static void parser_error(char **error, const char *fmt, ...)
-{
- va_list args;
- char *tmp;
-
- if (!error)
- return;
-
- tmp = malloc(1024);
- va_start(args, fmt);
- vsnprintf(tmp, 1024, fmt, args);
- va_end(args);
-
- if (*error) {
- int len = strlen(*error) + strlen(tmp) + 1;
- *error = realloc(*error, len);
- strncat(*error, tmp, strlen(tmp));
- free(tmp);
- } else {
- *error = tmp;
- }
-}
-
/*
* Add a dive into the dive_table array
*/
@@ -1611,7 +1588,7 @@ const char *preprocess_divelog_de(const char *buffer)
}
void parse_xml_buffer(const char *url, const char *buffer, int size,
- struct dive_table *table, const char **params, char **error)
+ struct dive_table *table, const char **params)
{
xmlDoc *doc;
const char *res = preprocess_divelog_de(buffer);
@@ -1622,13 +1599,12 @@ void parse_xml_buffer(const char *url, const char *buffer, int size,
free((char *)res);
if (!doc) {
- fprintf(stderr, translate("gettextFromC", "Failed to parse '%s'.\n"), url);
- parser_error(error, translate("gettextFromC", "Failed to parse '%s'"), url);
+ report_error(translate("gettextFromC", "Failed to parse '%s'"), url);
return;
}
reset_all();
dive_start();
- doc = test_xslt_transforms(doc, params, error);
+ doc = test_xslt_transforms(doc, params);
traverse(xmlDocGetRootElement(doc));
dive_end();
xmlFreeDoc(doc);
@@ -1870,7 +1846,7 @@ extern int dm4_dive(void *param, int columns, char **data, char **column)
}
int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
- struct dive_table *table, char **error)
+ struct dive_table *table)
{
int retval;
char *err = NULL;
@@ -2019,7 +1995,7 @@ extern int shearwater_dive(void *param, int columns, char **data, char **column)
int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
- struct dive_table *table, char **error)
+ struct dive_table *table)
{
int retval;
char *err = NULL;
@@ -2068,7 +2044,7 @@ static struct xslt_files {
{ NULL, }
};
-static xmlDoc *test_xslt_transforms(xmlDoc *doc, const char **params, char **error)
+static xmlDoc *test_xslt_transforms(xmlDoc *doc, const char **params)
{
struct xslt_files *info = xslt_files;
xmlDoc *transformed;
@@ -2099,7 +2075,7 @@ static xmlDoc *test_xslt_transforms(xmlDoc *doc, const char **params, char **err
xmlSubstituteEntitiesDefault(1);
xslt = get_stylesheet(info->file);
if (xslt == NULL) {
- parser_error(error, translate("gettextFromC", "Can't open stylesheet %s"), info->file);
+ report_error(translate("gettextFromC", "Can't open stylesheet %s"), info->file);
return doc;
}
transformed = xsltApplyStylesheet(xslt, doc, params);