1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
1 |
/* GIMP - The GNU Image Manipulation Program
|
1
by Daniel Holbach
Import upstream version 2.2.9 |
2 |
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
3 |
*
|
|
4 |
* This program is free software; you can redistribute it and/or modify
|
|
5 |
* it under the terms of the GNU General Public License as published by
|
|
6 |
* the Free Software Foundation; either version 2 of the License, or
|
|
7 |
* (at your option) any later version.
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
17 |
*/
|
|
18 |
||
19 |
#include "config.h" |
|
20 |
||
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
21 |
#define _GNU_SOURCE /* need the POSIX signal API */ |
22 |
||
1
by Daniel Holbach
Import upstream version 2.2.9 |
23 |
#include <signal.h> |
24 |
#include <stdarg.h> |
|
25 |
#include <stdlib.h> |
|
26 |
#include <sys/types.h> |
|
27 |
#ifdef HAVE_UNISTD_H
|
|
28 |
#include <unistd.h> |
|
29 |
#endif
|
|
30 |
||
31 |
#include <glib-object.h> |
|
32 |
||
33 |
#include "libgimpbase/gimpbase.h" |
|
34 |
||
35 |
#include "core/core-types.h" |
|
36 |
||
37 |
#include "core/gimp.h" |
|
38 |
||
39 |
#include "errors.h" |
|
40 |
||
41 |
#ifdef G_OS_WIN32
|
|
42 |
#include <windows.h> |
|
43 |
#endif
|
|
44 |
||
45 |
||
46 |
/* private variables */
|
|
47 |
||
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
48 |
static Gimp *the_errors_gimp = NULL; |
1
by Daniel Holbach
Import upstream version 2.2.9 |
49 |
static gboolean use_debug_handler = FALSE; |
50 |
static GimpStackTraceMode stack_trace_mode = GIMP_STACK_TRACE_QUERY; |
|
51 |
static gchar *full_prog_name = NULL; |
|
52 |
||
53 |
||
54 |
/* local function prototypes */
|
|
55 |
||
56 |
static G_GNUC_NORETURN void gimp_eek (const gchar *reason, |
|
57 |
const gchar *message, |
|
58 |
gboolean use_handler); |
|
59 |
||
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
60 |
static void gimp_message_log_func (const gchar *log_domain, |
61 |
GLogLevelFlags flags, |
|
62 |
const gchar *message, |
|
63 |
gpointer data); |
|
64 |
static void gimp_error_log_func (const gchar *domain, |
|
65 |
GLogLevelFlags flags, |
|
66 |
const gchar *message, |
|
67 |
gpointer data) G_GNUC_NORETURN; |
|
68 |
||
69 |
||
1
by Daniel Holbach
Import upstream version 2.2.9 |
70 |
|
71 |
/* public functions */
|
|
72 |
||
73 |
void
|
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
74 |
errors_init (Gimp *gimp, |
75 |
const gchar *_full_prog_name, |
|
76 |
gboolean _use_debug_handler, |
|
77 |
GimpStackTraceMode _stack_trace_mode) |
|
1
by Daniel Holbach
Import upstream version 2.2.9 |
78 |
{
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
79 |
const gchar * const log_domains[] = |
80 |
{
|
|
81 |
"Gimp", |
|
82 |
"Gimp-Actions", |
|
83 |
"Gimp-Base", |
|
84 |
"Gimp-Composite", |
|
85 |
"Gimp-Config", |
|
86 |
"Gimp-Core", |
|
87 |
"Gimp-Dialogs", |
|
88 |
"Gimp-Display", |
|
89 |
"Gimp-File", |
|
90 |
"Gimp-GUI", |
|
91 |
"Gimp-Menus", |
|
92 |
"Gimp-PDB", |
|
93 |
"Gimp-Paint", |
|
94 |
"Gimp-Paint-Funcs", |
|
95 |
"Gimp-Plug-In", |
|
96 |
"Gimp-Text", |
|
97 |
"Gimp-Tools", |
|
98 |
"Gimp-Vectors", |
|
99 |
"Gimp-Widgets", |
|
100 |
"Gimp-XCF"
|
|
101 |
};
|
|
102 |
gint i; |
|
103 |
||
104 |
g_return_if_fail (GIMP_IS_GIMP (gimp)); |
|
1
by Daniel Holbach
Import upstream version 2.2.9 |
105 |
g_return_if_fail (_full_prog_name != NULL); |
106 |
g_return_if_fail (full_prog_name == NULL); |
|
107 |
||
108 |
#ifdef GIMP_UNSTABLE
|
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
109 |
g_printerr ("This is a development version of GIMP. " |
110 |
"Debug messages may appear here.\n\n"); |
|
1
by Daniel Holbach
Import upstream version 2.2.9 |
111 |
#endif /* GIMP_UNSTABLE */ |
112 |
||
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
113 |
the_errors_gimp = gimp; |
1
by Daniel Holbach
Import upstream version 2.2.9 |
114 |
use_debug_handler = _use_debug_handler ? TRUE : FALSE; |
115 |
stack_trace_mode = _stack_trace_mode; |
|
116 |
full_prog_name = g_strdup (_full_prog_name); |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
117 |
|
118 |
for (i = 0; i < G_N_ELEMENTS (log_domains); i++) |
|
119 |
g_log_set_handler (log_domains[i], |
|
120 |
G_LOG_LEVEL_MESSAGE, |
|
121 |
gimp_message_log_func, gimp); |
|
122 |
||
123 |
g_log_set_handler (NULL, |
|
124 |
G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL, |
|
125 |
gimp_error_log_func, gimp); |
|
1
by Daniel Holbach
Import upstream version 2.2.9 |
126 |
}
|
127 |
||
128 |
void
|
|
1.1.6
by Steve Kowalik
Import upstream version 2.4.0~rc2 |
129 |
errors_exit (void) |
130 |
{
|
|
131 |
the_errors_gimp = NULL; |
|
132 |
}
|
|
133 |
||
134 |
void
|
|
1
by Daniel Holbach
Import upstream version 2.2.9 |
135 |
gimp_fatal_error (const gchar *fmt, ...) |
136 |
{
|
|
137 |
va_list args; |
|
138 |
gchar *message; |
|
139 |
||
140 |
va_start (args, fmt); |
|
141 |
message = g_strdup_vprintf (fmt, args); |
|
142 |
va_end (args); |
|
143 |
||
144 |
gimp_eek ("fatal error", message, TRUE); |
|
145 |
}
|
|
146 |
||
147 |
void
|
|
148 |
gimp_terminate (const gchar *fmt, ...) |
|
149 |
{
|
|
150 |
va_list args; |
|
151 |
gchar *message; |
|
152 |
||
153 |
va_start (args, fmt); |
|
154 |
message = g_strdup_vprintf (fmt, args); |
|
155 |
va_end (args); |
|
156 |
||
157 |
gimp_eek ("terminated", message, use_debug_handler); |
|
158 |
}
|
|
159 |
||
160 |
||
161 |
/* private functions */
|
|
162 |
||
163 |
static void |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
164 |
gimp_message_log_func (const gchar *log_domain, |
165 |
GLogLevelFlags flags, |
|
166 |
const gchar *message, |
|
167 |
gpointer data) |
|
168 |
{
|
|
169 |
Gimp *gimp = data; |
|
170 |
||
171 |
if (gimp) |
|
172 |
{
|
|
173 |
gimp_show_message (gimp, NULL, GIMP_MESSAGE_WARNING, NULL, message); |
|
174 |
}
|
|
175 |
else
|
|
176 |
{
|
|
177 |
g_printerr ("%s: %s\n\n", |
|
178 |
gimp_filename_to_utf8 (full_prog_name), message); |
|
179 |
}
|
|
180 |
}
|
|
181 |
||
182 |
static void |
|
183 |
gimp_error_log_func (const gchar *domain, |
|
184 |
GLogLevelFlags flags, |
|
185 |
const gchar *message, |
|
186 |
gpointer data) |
|
187 |
{
|
|
188 |
gimp_fatal_error (message); |
|
189 |
}
|
|
190 |
||
191 |
static void |
|
1
by Daniel Holbach
Import upstream version 2.2.9 |
192 |
gimp_eek (const gchar *reason, |
193 |
const gchar *message, |
|
194 |
gboolean use_handler) |
|
195 |
{
|
|
196 |
#ifndef G_OS_WIN32
|
|
197 |
g_printerr ("%s: %s: %s\n", gimp_filename_to_utf8 (full_prog_name), |
|
198 |
reason, message); |
|
199 |
||
200 |
if (use_handler) |
|
201 |
{
|
|
202 |
switch (stack_trace_mode) |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
203 |
{
|
204 |
case GIMP_STACK_TRACE_NEVER: |
|
205 |
break; |
|
206 |
||
207 |
case GIMP_STACK_TRACE_QUERY: |
|
208 |
{
|
|
209 |
sigset_t sigset; |
|
210 |
||
211 |
sigemptyset (&sigset); |
|
212 |
sigprocmask (SIG_SETMASK, &sigset, NULL); |
|
213 |
||
214 |
if (the_errors_gimp) |
|
215 |
gimp_gui_ungrab (the_errors_gimp); |
|
216 |
||
217 |
g_on_error_query (full_prog_name); |
|
218 |
}
|
|
219 |
break; |
|
220 |
||
221 |
case GIMP_STACK_TRACE_ALWAYS: |
|
222 |
{
|
|
223 |
sigset_t sigset; |
|
224 |
||
225 |
sigemptyset (&sigset); |
|
226 |
sigprocmask (SIG_SETMASK, &sigset, NULL); |
|
227 |
||
228 |
g_on_error_stack_trace (full_prog_name); |
|
229 |
}
|
|
230 |
break; |
|
231 |
||
232 |
default: |
|
233 |
break; |
|
234 |
}
|
|
1
by Daniel Holbach
Import upstream version 2.2.9 |
235 |
}
|
236 |
#else
|
|
237 |
||
238 |
/* g_on_error_* don't do anything reasonable on Win32. */
|
|
239 |
||
240 |
MessageBox (NULL, g_strdup_printf ("%s: %s", reason, message), |
|
241 |
full_prog_name, MB_OK|MB_ICONERROR); |
|
242 |
||
243 |
#endif /* ! G_OS_WIN32 */ |
|
244 |
||
245 |
exit (EXIT_FAILURE); |
|
246 |
}
|