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 class MainErrorGUI : public BC_Window
39 MainErrorGUI(MWindow *mwindow, MainError *thread, int x, int y);
42 void create_objects();
43 int resize_event(int w, int h);
52 class MainError : public BC_DialogThread
55 MainError(MWindow *mwindow);
58 friend class MainErrorGUI;
63 // Display error message to command line or GUI, depending on what exists.
64 static void show_error(const char *string);
65 static void finit_error() {
66 if( !main_error ) return;
67 delete main_error; main_error = 0;
69 static void init_error(MWindow *mwindow) {
71 main_error = new MainError(mwindow);
75 void show_error_local(const char *string);
77 // Split errors into multiple lines based on carriage returns.
78 void append_error(const char *string);
82 ArrayList<BC_ListBoxItem*> errors;
85 // Main error dialog. Won't exist if no GUI.
86 static MainError *main_error;
90 // format text to error dialog listbox
92 static inline void eprint1(const char *func, const char *fmt, ...)
94 char err_msg[1024], *cp = err_msg, *ep = cp + sizeof(err_msg)-1;
97 cp += snprintf(cp, ep-cp, "%s:\n", func);
98 cp += vsnprintf(cp, ep-cp, fmt, va);
101 MainError::show_error(err_msg); \
104 #define eprintf(s...) eprint1(__PRETTY_FUNCTION__, s)