stdafx.h
Go to the documentation of this file.00001
00002
00005 #ifndef STDAFX_H
00006 #define STDAFX_H
00007
00008 #if defined(__NDS__)
00009 #include <nds/jtypes.h>
00010
00011
00012 #define uint32 uint32_ugly_hack
00013 #define int32 int32_ugly_hack
00014 typedef unsigned int uint32_ugly_hack;
00015 typedef signed int int32_ugly_hack;
00016 #endif
00017
00018
00019
00020
00021
00022
00023
00024
00025 #if !defined(_MSC_VER) && !defined( __MORPHOS__) && !defined(_STDINT_H_)
00026 #if defined(SUNOS)
00027
00028
00029 #include <inttypes.h>
00030 # else
00031 #define __STDC_LIMIT_MACROS
00032 #include <stdint.h>
00033 #endif
00034 #else
00035 #define UINT64_MAX (18446744073709551615ULL)
00036 #define INT64_MAX (9223372036854775807LL)
00037 #define INT64_MIN (-INT64_MAX - 1)
00038 #define UINT32_MAX (4294967295U)
00039 #define INT32_MAX (2147483647)
00040 #define INT32_MIN (-INT32_MAX - 1)
00041 #define UINT16_MAX (65535U)
00042 #define INT16_MAX (32767)
00043 #define INT16_MIN (-INT16_MAX - 1)
00044 #endif
00045
00046 #include <cstdio>
00047 #include <cstddef>
00048 #include <cstring>
00049 #include <cstdlib>
00050 #include <climits>
00051
00052
00053
00054 #if !defined(__APPLE__) || defined(STRGEN)
00055 #include <cassert>
00056 #else
00057 #include "os/macosx/macos.h"
00058 #endif
00059
00060 #if defined(UNIX) || defined(__MINGW32__)
00061 #include <sys/types.h>
00062 #endif
00063
00064 #if defined(__OS2__)
00065 #include <types.h>
00066 #define strcasecmp stricmp
00067 #endif
00068
00069 #if defined(PSP)
00070 #include <psptypes.h>
00071 #include <pspdebug.h>
00072 #include <pspthreadman.h>
00073 #endif
00074
00075 #if defined(__BEOS__)
00076 #include <SupportDefs.h>
00077 #endif
00078
00079 #if defined(SUNOS) || defined(HPUX)
00080 #include <alloca.h>
00081 #endif
00082
00083 #if defined(__MORPHOS__)
00084
00085
00086
00087 #if defined(amigaos)
00088 #undef amigaos
00089 #endif
00090 #if defined(__amigaos__)
00091 #undef __amigaos__
00092 # endif
00093 #if defined(__AMIGA__)
00094 #undef __AMIGA__
00095 #endif
00096 #if defined(AMIGA)
00097 #undef AMIGA
00098 #endif
00099 #if defined(amiga)
00100 #undef amiga
00101 #endif
00102
00103
00104 #define CLIB_USERGROUP_PROTOS_H
00105 #endif
00106
00107 #if defined(__APPLE__)
00108 #include "os/macosx/osx_stdafx.h"
00109 #endif
00110
00111 #if defined(PSP)
00112
00113
00114
00115 #define LIMITED_FDS 8
00116 #define printf pspDebugScreenPrintf
00117 #endif
00118
00119
00120 #define VARARRAY_SIZE
00121
00122
00123 #if defined(__GNUC__)
00124 #define NORETURN __attribute__ ((noreturn))
00125 #define FORCEINLINE inline
00126 #define CDECL
00127 #define __int64 long long
00128 #define GCC_PACK __attribute__((packed))
00129
00130 #if (__GNUC__ == 2)
00131 #undef VARARRAY_SIZE
00132 #define VARARRAY_SIZE 0
00133 #endif
00134 #endif
00135
00136 #if defined(__WATCOMC__)
00137 #define NORETURN
00138 #define FORCEINLINE inline
00139 #define CDECL
00140 #define GCC_PACK
00141 #include <malloc.h>
00142 #endif
00143
00144 #if defined(__MINGW32__) || defined(__CYGWIN__)
00145 #include <malloc.h>
00146 #endif
00147
00148 #if defined(__MINGW32__) && defined(_GNU_SOURCE)
00149
00150 #undef _GNU_SOURCE
00151 #endif
00152
00153 #if defined(WIN32)
00154 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
00155 #endif
00156
00157
00158 #if defined(_MSC_VER)
00159 #pragma once
00160
00161
00162 #define NTDDI_VERSION NTDDI_WIN2K // Windows 2000
00163 #define _WIN32_WINNT 0x0500 // Windows 2000
00164 #define _WIN32_WINDOWS 0x400 // Windows 95
00165 #if !defined(WINCE)
00166 #define WINVER 0x0400 // Windows NT 4.0 / Windows 95
00167 #endif
00168 #define _WIN32_IE_ 0x0401 // 4.01 (win98 and NT4SP5+)
00169
00170 #pragma warning(disable: 4244) // 'conversion' conversion from 'type1' to 'type2', possible loss of data
00171 #pragma warning(disable: 4761) // integral size mismatch in argument : conversion supplied
00172 #pragma warning(disable: 4200) // nonstandard extension used : zero-sized array in struct/union
00173
00174 #if (_MSC_VER < 1400) // MSVC 2005 safety checks
00175 #error "Only MSVC 2005 or higher are supported. MSVC 2003 and earlier are not!. Upgrade your compiler."
00176 #endif
00177 #pragma warning(disable: 4996) // 'strdup' was declared deprecated
00178 #define _CRT_SECURE_NO_DEPRECATE // all deprecated 'unsafe string functions
00179 #pragma warning(disable: 6308) // code analyzer: 'realloc' might return null pointer: assigning null pointer to 't_ptr', which is passed as an argument to 'realloc', will cause the original memory block to be leaked
00180 #pragma warning(disable: 6011) // code analyzer: Dereferencing NULL pointer 'pfGetAddrInfo': Lines: 995, 996, 998, 999, 1001
00181 #pragma warning(disable: 6326) // code analyzer: potential comparison of a constant with another constant
00182 #pragma warning(disable: 6031) // code analyzer: Return value ignored: 'ReadFile'
00183 #pragma warning(disable: 6255) // code analyzer: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead
00184 #pragma warning(disable: 6246) // code analyzer: Local declaration of 'statspec' hides declaration of the same name in outer scope. For additional information, see previous declaration at ...
00185
00186 #include <malloc.h>
00187 #define NORETURN __declspec(noreturn)
00188 #define FORCEINLINE __forceinline
00189 #define inline _inline
00190
00191 #if !defined(WINCE)
00192 #define CDECL _cdecl
00193 #endif
00194
00195 int CDECL snprintf(char *str, size_t size, const char *format, ...);
00196 #if (_MSC_VER < 1400) || defined(WINCE)
00197 int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap);
00198 #endif
00199
00200 #if defined(WIN32) && !defined(_WIN64) && !defined(WIN64)
00201 #if !defined(_W64)
00202 #define _W64
00203 #endif
00204
00205 typedef _W64 int INT_PTR, *PINT_PTR;
00206 typedef _W64 unsigned int UINT_PTR, *PUINT_PTR;
00207 #endif
00208
00209 #if defined(_WIN64) || defined(WIN64)
00210 #define fseek _fseeki64
00211 #endif
00212
00213
00214 #define GCC_PACK
00215
00216
00217 #if defined(WITH_ZLIB) || defined(WITH_PNG)
00218 #if !defined(ZLIB_WINAPI)
00219 #define ZLIB_WINAPI
00220 #endif
00221 #endif
00222
00223 #if defined(WINCE)
00224 #define strcasecmp _stricmp
00225 #define strncasecmp _strnicmp
00226 #undef DEBUG
00227 #else
00228 #define strcasecmp stricmp
00229 #define strncasecmp strnicmp
00230 #endif
00231
00232 void SetExceptionString(const char* s, ...);
00233
00234 #if defined(NDEBUG) && defined(WITH_ASSERT)
00235 #undef assert
00236 #define assert(expression) if (!(expression)) { SetExceptionString("Assertion failed at %s:%d: %s", __FILE__, __LINE__, #expression); *(byte*)0 = 0; }
00237 #endif
00238
00239
00240 #define S_ISDIR(mode) (mode & S_IFDIR)
00241 #define S_ISREG(mode) (mode & S_IFREG)
00242
00243 #endif
00244
00245 #if defined(WINCE)
00246 #define strdup _strdup
00247 #endif
00248
00249
00250
00251 #if !defined(STRGEN)
00252 #if defined(WIN32) || defined(WIN64)
00253 char *getcwd(char *buf, size_t size);
00254 #include <tchar.h>
00255
00256
00257 #if !defined(WINCE)
00258 #define fopen(file, mode) _tfopen(OTTD2FS(file), _T(mode))
00259 #endif
00260
00261 const char *FS2OTTD(const TCHAR *name);
00262 const TCHAR *OTTD2FS(const char *name);
00263 #else
00264 #define fopen(file, mode) fopen(OTTD2FS(file), mode)
00265 const char *FS2OTTD(const char *name);
00266 const char *OTTD2FS(const char *name);
00267 #endif
00268 #endif
00269
00270 #if defined(WIN32) || defined(WIN64) || defined(__OS2__) && !defined(__INNOTEK_LIBC__)
00271 #define PATHSEP "\\"
00272 #define PATHSEPCHAR '\\'
00273 #else
00274 #define PATHSEP "/"
00275 #define PATHSEPCHAR '/'
00276 #endif
00277
00278 typedef unsigned char byte;
00279
00280
00281 #if (!defined(UNIX) && !defined(__CYGWIN__) && !defined(__BEOS__) && !defined(__MORPHOS__)) || defined(__QNXNTO__)
00282 typedef unsigned int uint;
00283 #endif
00284
00285 #if !defined(__BEOS__) && !defined(__NDS__)
00286 typedef unsigned char uint8;
00287 typedef signed char int8;
00288 typedef unsigned short uint16;
00289 typedef signed short int16;
00290 typedef unsigned int uint32;
00291 typedef signed int int32;
00292 typedef unsigned __int64 uint64;
00293 typedef signed __int64 int64;
00294 #endif
00295
00296 #if !defined(WITH_PERSONAL_DIR)
00297 #define PERSONAL_DIR ""
00298 #endif
00299
00300
00301 #if defined(__OS2__)
00302 #define assert_compile(expr)
00303 #else
00304 #define assert_compile(expr) extern const int __ct_assert__[1 - 2 * !(expr)]
00305 #endif
00306
00307
00308 assert_compile(sizeof(uint64) == 8);
00309 assert_compile(sizeof(uint32) == 4);
00310 assert_compile(sizeof(uint16) == 2);
00311 assert_compile(sizeof(uint8) == 1);
00312
00321 #define lengthof(x) (sizeof(x) / sizeof(x[0]))
00322
00329 #define endof(x) (&x[lengthof(x)])
00330
00337 #define lastof(x) (&x[lengthof(x) - 1])
00338
00339 #define cpp_offsetof(s, m) (((size_t)&reinterpret_cast<const volatile char&>((((s*)(char*)8)->m))) - 8)
00340 #if !defined(offsetof)
00341 #define offsetof(s, m) cpp_offsetof(s, m)
00342 #endif
00343
00344
00345
00346 #if defined(__APPLE__)
00347 #define GetString OTTD_GetString
00348 #define DrawString OTTD_DrawString
00349 #define CloseConnection OTTD_CloseConnection
00350 #endif
00351
00352 void NORETURN CDECL usererror(const char *str, ...);
00353 void NORETURN CDECL error(const char *str, ...);
00354 #define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
00355
00356 #if defined(MORPHOS) || defined(__NDS__) || defined(__DJGPP__)
00357
00358 #define _stricmp stricmp
00359 #elif defined(OPENBSD)
00360
00361 #define _stricmp strcasecmp
00362 #endif
00363
00364 #if !defined(MORPHOS) && !defined(OPENBSD) && !defined(__NDS__) && !defined(__DJGPP__)
00365
00366 #define HAS_WCHAR
00367 #endif
00368
00369 #if !defined(MAX_PATH)
00370 #define MAX_PATH 260
00371 #endif
00372
00377 #define MAX_UVALUE(type) ((type)~(type)0)
00378
00379 #endif