show the error string in the GUI rather than stderr

This makes the error string just be an internal "membuffer", which the
GUI can fetch and show when errors occur.  The error string keeps
accumulating until somebody retrieves it with "get_error_string()".

This should make any write errors actually show up to the user.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2014-03-14 10:35:09 -07:00 committed by Dirk Hohndel
parent b5d0cfd557
commit ec33a95ad0
3 changed files with 33 additions and 9 deletions

View file

@ -340,16 +340,35 @@ static void create_dive_buffer(struct dive *dive, struct membuffer *b)
save_dive_temperature(b, dive);
}
static struct membuffer error_string_buffer = { 0 };
/*
* Note that the act of "getting" the error string
* buffer doesn't de-allocate the buffer, but it does
* set the buffer length to zero, so that any future
* error reports will overwrite the string rather than
* append to it.
*/
const char *get_error_string(void)
{
const char *str;
if (!error_string_buffer.len)
return "";
str = mb_cstring(&error_string_buffer);
error_string_buffer.len = 0;
return str;
}
int report_error(const char *fmt, ...)
{
struct membuffer b = { 0 };
VA_BUF(&b, fmt);
/* We should do some UI element thing describing the failure */
put_bytes(&b, "\n", 1);
flush_buffer(&b, stderr);
free_buffer(&b);
struct membuffer *buf = &error_string_buffer;
/* Previous unprinted errors? Add a newline in between */
if (buf->len)
put_bytes(buf, "\n", 1);
VA_BUF(buf, fmt);
mb_cstring(buf);
return -1;
}