1 /*
2
3 Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4 and the "Aleph One" developers.
5
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 3 of the License, or
9 (at your option) any later version.
10
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.
15
16 This license is contained in the file "COPYING",
17 which is included with this source code; it is available online at
18 http://www.gnu.org/licenses/gpl.html
19
20 */
21
22
23 #ifndef _CSERIES_ALERTS_
24 #define _CSERIES_ALERTS_
25
26 #include "cstypes.h"
27
28 #if defined(__GNUC__)
29 #define NORETURN __attribute__((noreturn))
30 #else
31 #define NORETURN
32 #endif
33
34 enum {
35 infoError,
36 fatalError
37 };
38
39 extern void alert_user(const char *message, short severity = infoError);
40
41 extern void alert_user(
42 short severity,
43 short resid,
44 short item,
45 int error);
46 static inline void alert_user_fatal(short resid, short item, int error) NORETURN;
47 static inline void alert_out_of_memory(int error = -1) NORETURN;
48 static inline void alert_bad_extra_file(int error = -1) NORETURN;
49 static inline void alert_corrupted_map(int error = -1) NORETURN;
50
51 extern bool alert_choose_scenario(char *chosen_dir);
52
53 extern void launch_url_in_browser(const char *url);
54
55 extern void pause_debug(void);
56 extern void vpause(
57 const char *message);
58
59 extern void halt(void) NORETURN;
60 extern void vhalt(
61 const char *message) NORETURN;
62
63 extern void _alephone_assert(
64 const char *file,
65 int32 line,
66 const char *what) NORETURN;
67 extern void _alephone_warn(
68 const char *file,
69 int32 line,
70 const char *what);
71
alert_user_fatal(short resid,short item,int error)72 void alert_user_fatal(short resid, short item, int error)
73 {
74 alert_user(fatalError, resid, item, error);
75 halt();
76 }
alert_out_of_memory(int error)77 void alert_out_of_memory(int error) { alert_user_fatal(128, 14, error); }
alert_bad_extra_file(int error)78 void alert_bad_extra_file(int error) { alert_user_fatal(128, 5, error); }
alert_corrupted_map(int error)79 void alert_corrupted_map(int error) { alert_user_fatal(128, 23, error); }
80
81
82
83 #undef assert
84 #ifdef DEBUG
85 #define assert(what) ((what) ? (void)0 : _alephone_assert(__FILE__,__LINE__,"Assertion failed: " #what))
86 #define vassert(what,message) ((what) ? (void)0 : _alephone_assert(__FILE__,__LINE__,(message)))
87 #define warn(what) ((what) ? (void)0 : _alephone_warn(__FILE__,__LINE__,"Assertion failed: " #what))
88 #define vwarn(what,message) ((what) ? (void)0 : _alephone_warn(__FILE__,__LINE__,(message)))
89 #else
90 #define assert(what) ((void) 0)
91 #define vassert(what,message) ((void) 0)
92 #define warn(what) ((void) 0)
93 #define vwarn(what,message) ((void) 0)
94 #endif
95
96 // "fast code" assert: disabled by default, enabled under DEBUG_FAST_CODE
97 #ifdef DEBUG_FAST_CODE
98 #define fc_assert(what) assert(what)
99 #define fc_vassert(what,message) vassert(what,message)
100 #else
101 #define fc_assert(what) ((void) 0)
102 #define fc_vassert(what,message) ((void) 0)
103 #endif
104
105 #endif
106