1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef BACKEND_SDL_SYS_H
24 #define BACKEND_SDL_SYS_H
25 
26 // The purpose of this header is to include the SDL headers in a uniform
27 // fashion, even on the Symbian port.
28 // Moreover, it contains a workaround for the fact that SDL_rwops.h uses
29 // a FILE pointer in one place, which conflicts with common/forbidden.h.
30 // The SDL 1.3 headers also include strings.h
31 
32 #include "common/scummsys.h"
33 
34 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_FILE)
35 #undef FILE
36 #endif
37 
38 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strcasecmp)
39 #undef strcasecmp
40 #define strcasecmp FAKE_strcasecmp
41 #endif
42 
43 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strncasecmp)
44 #undef strncasecmp
45 #define strncasecmp FAKE_strncasecmp
46 #endif
47 
48 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_exit)
49 #undef exit
50 #define exit FAKE_exit
51 #endif
52 
53 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_abort)
54 #undef abort
55 #define abort FAKE_abort
56 #endif
57 
58 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_system)
59 #undef system
60 #define system FAKE_system
61 #endif
62 
63 // Fix compilation with MacPorts SDL 2
64 // It needs various (usually forbidden) symbols from time.h
65 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_time_h
66 
67 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_asctime)
68 	#undef asctime
69 	#define asctime FAKE_asctime
70 	#endif
71 
72 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_clock)
73 	#undef clock
74 	#define clock FAKE_clock
75 	#endif
76 
77 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_ctime)
78 	#undef ctime
79 	#define ctime FAKE_ctime
80 	#endif
81 
82 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_difftime)
83 	#undef difftime
84 	#define difftime FAKE_difftime
85 	#endif
86 
87 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getdate)
88 	#undef getdate
89 	#define getdate FAKE_getdate
90 	#endif
91 
92 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_gmtime)
93 	#undef gmtime
94 	#define gmtime FAKE_gmtime
95 	#endif
96 
97 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_localtime)
98 	#undef localtime
99 	#define localtime FAKE_localtime
100 	#endif
101 
102 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_mktime)
103 	#undef mktime
104 	#define mktime FAKE_mktime
105 	#endif
106 
107 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_time)
108 	#undef time
109 	#define time FAKE_time
110 	#endif
111 
112 #endif // FORBIDDEN_SYMBOL_EXCEPTION_time_h
113 
114 // Fix compilation on non-x86 architectures
115 // It needs various (usually forbidden) symbols from unistd.h
116 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
117 
118 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_chdir)
119 	#undef chdir
120 	#define chdir FAKE_chdir
121 	#endif
122 
123 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getcwd)
124 	#undef getcwd
125 	#define getcwd FAKE_getcwd
126 	#endif
127 
128 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getwd)
129 	#undef getwd
130 	#define getwd FAKE_getwd
131 	#endif
132 
133 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_unlink)
134 	#undef unlink
135 	#define unlink FAKE_unlink
136 	#endif
137 
138 #endif // FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
139 
140 // HACK: SDL might include windows.h which defines its own ARRAYSIZE.
141 // However, we want to use the version from common/util.h. Thus, we make sure
142 // that we actually have this definition after including the SDL headers.
143 #if defined(ARRAYSIZE) && defined(COMMON_UTIL_H)
144 #define HACK_REDEFINE_ARRAYSIZE
145 #undef ARRAYSIZE
146 #endif
147 
148 // HACK to fix compilation with SDL 2.0 in MSVC.
149 // In SDL 2.0, intrin.h is now included in SDL_cpuinfo.h, which includes
150 // setjmp.h. SDL_cpuinfo.h is included from SDL.h and SDL_syswm.h.
151 // Thus, we remove the exceptions for setjmp and longjmp before these two
152 // includes. Unfortunately, we can't use SDL_VERSION_ATLEAST here, as SDL.h
153 // hasn't been included yet at this point.
154 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && defined(_MSC_VER)
155 // We unset any fake definitions of setjmp/longjmp here
156 
157 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_setjmp
158 #undef setjmp
159 #endif
160 
161 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_longjmp
162 #undef longjmp
163 #endif
164 
165 #endif
166 
167 #if defined(__SYMBIAN32__)
168 #include <esdl\SDL.h>
169 #else
170 #include <SDL.h>
171 #endif
172 
173 // Ignore warnings from system headers pulled by SDL
174 #pragma warning(push)
175 #pragma warning(disable:4121) // alignment of a member was sensitive to packing
176 #include <SDL_syswm.h>
177 #pragma warning(pop)
178 
179 // Restore the forbidden exceptions from the hack above
180 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && defined(_MSC_VER)
181 
182 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_setjmp
183 #undef setjmp
184 #define setjmp(a)	FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
185 #endif
186 
187 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_longjmp
188 #undef longjmp
189 #define longjmp(a,b)	FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
190 #endif
191 
192 #endif
193 
194 // SDL_syswm.h will include windows.h on Win32. We need to undefine its
195 // ARRAYSIZE definition because we supply our own.
196 #undef ARRAYSIZE
197 
198 #ifdef HACK_REDEFINE_ARRAYSIZE
199 #undef HACK_REDEFINE_ARRAYSIZE
200 #define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
201 #endif
202 
203 // In a moment of brilliance Xlib.h included by SDL_syswm.h #defines the
204 // following names. In a moment of mental breakdown, which occurred upon
205 // gazing at Xlib.h, LordHoto decided to undefine them to prevent havoc.
206 #ifdef Status
207 #undef Status
208 #endif
209 
210 #ifdef Bool
211 #undef Bool
212 #endif
213 
214 #ifdef True
215 #undef True
216 #endif
217 
218 #ifdef False
219 #undef False
220 #endif
221 
222 // Finally forbid FILE again (if it was forbidden to start with)
223 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_FILE)
224 #undef FILE
225 #define FILE	FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
226 #endif
227 
228 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strcasecmp)
229 #undef strcasecmp
230 #define strcasecmp     FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
231 #endif
232 
233 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strncasecmp)
234 #undef strncasecmp
235 #define strncasecmp    FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
236 #endif
237 
238 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_exit)
239 #undef exit
240 #define exit(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
241 #endif
242 
243 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_abort)
244 #undef abort
245 #define abort() FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
246 #endif
247 
248 #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_system)
249 #undef system
250 #define system(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
251 #endif
252 
253 // re-forbid all those time.h symbols again (if they were forbidden)
254 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_time_h
255 
256 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_asctime)
257 	#undef asctime
258 	#define asctime(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
259 	#endif
260 
261 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_clock)
262 	#undef clock
263 	#define clock() FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
264 	#endif
265 
266 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_ctime)
267 	#undef ctime
268 	#define ctime(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
269 	#endif
270 
271 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_difftime)
272 	#undef difftime
273 	#define difftime(a,b) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
274 	#endif
275 
276 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getdate)
277 	#undef getdate
278 	#define getdate(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
279 	#endif
280 
281 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_gmtime)
282 	#undef gmtime
283 	#define gmtime(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
284 	#endif
285 
286 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_localtime)
287 	#undef localtime
288 	#define localtime(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
289 	#endif
290 
291 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_mktime)
292 	#undef mktime
293 	#define mktime(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
294 	#endif
295 
296 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_time)
297 	#undef time
298 	#define time(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
299 	#endif
300 
301 #endif // FORBIDDEN_SYMBOL_EXCEPTION_time_h
302 
303 // re-forbid all those unistd.h symbols again (if they were forbidden)
304 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
305 
306 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_chdir)
307 	#undef chdir
308 	#define chdir(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
309 	#endif
310 
311 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getcwd)
312 	#undef getcwd
313 	#define getcwd(a,b) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
314 	#endif
315 
316 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_getwd)
317 	#undef getwd
318 	#define getwd(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
319 	#endif
320 
321 	#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_unlink)
322 	#undef unlink
323 	#define unlink(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
324 	#endif
325 
326 #endif // FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
327 
328 #endif
329