mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
ec33a95ad0
commit
609715ab69
9 changed files with 96 additions and 174 deletions
40
parse-xml.c
40
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue