4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "mainerror.inc"
29 #include "mwindow.inc"
31 // This is needed for errors which are too verbose to fit in the
34 // Once created, it accumulates errors in a listbox until it's closed.
36 // Macro to enable the simplest possible error output
37 //#define eprintf(format, ...) {char error_string[1024]; sprintf(sprintf(error_string, "%s: " format, __PRETTY_FUNCTION__, ## __VA_ARGS__); MainError::show_error(error_string); }
38 // We have to use longer version if we want to gettext error messages
40 #define eprintf(...) do { \
41 char err_msg[1024], *ep = err_msg; \
42 ep += sprintf(ep, "%s:\n", __PRETTY_FUNCTION__); \
43 sprintf(ep, __VA_ARGS__); (volatile void)MainError::show_error(err_msg); \
47 class MainErrorGUI : public BC_Window
50 MainErrorGUI(MWindow *mwindow, MainError *thread, int x, int y);
53 void create_objects();
54 int resize_event(int w, int h);
63 class MainError : public BC_DialogThread
66 MainError(MWindow *mwindow);
69 friend class MainErrorGUI;
74 // Display error message to command line or GUI, depending on what exists.
75 static void show_error(const char *string);
76 static void finit_error() {
77 if( !main_error ) return;
78 delete main_error; main_error = 0;
80 static void init_error(MWindow *mwindow) {
82 main_error = new MainError(mwindow);
86 void show_error_local(const char *string);
88 // Split errors into multiple lines based on carriage returns.
89 void append_error(const char *string);
93 ArrayList<BC_ListBoxItem*> errors;
96 // Main error dialog. Won't exist if no GUI.
97 static MainError *main_error;