tron@2186: /* $Id$ */ tron@2186: belugas@6977: /** @file stdafx.h */ belugas@6916: Darkvater@2436: #ifndef STDAFX_H Darkvater@2436: #define STDAFX_H truelight@0: rubidium@8869: #if defined(__NDS__) rubidium@8869: #include rubidium@8869: /* NDS' types for uint32/int32 are based on longs, which causes rubidium@8869: * trouble all over the place in OpenTTD. */ rubidium@8869: #define uint32 uint32_ugly_hack rubidium@8869: #define int32 int32_ugly_hack rubidium@8869: typedef unsigned int uint32_ugly_hack; rubidium@8869: typedef signed int int32_ugly_hack; rubidium@8869: #endif /* __NDS__ */ rubidium@8869: bjarni@6071: /* It seems that we need to include stdint.h before anything else bjarni@6071: * We need INT64_MAX, which for most systems comes from stdint.h. However, MSVC bjarni@6071: * does not have stdint.h and apparently neither does MorphOS, so define bjarni@8271: * INT64_MAX for them ourselves. bjarni@8271: * Sometimes OSX headers manages to include stdint.h before this but without bjarni@8271: * __STDC_LIMIT_MACROS so it will be without INT64_*. We need to define those bjarni@8271: * too if this is the case. */ bjarni@8271: #if !defined(_MSC_VER) && !defined( __MORPHOS__) && !defined(_STDINT_H_) skidd13@8500: #if defined(SUNOS) skidd13@8500: /* SunOS/Solaris does not have stdint.h, but inttypes.h defines everything skidd13@8500: * stdint.h defines and we need. */ skidd13@8500: #include skidd13@8500: # else skidd13@8500: #define __STDC_LIMIT_MACROS skidd13@8500: #include skidd13@8500: #endif bjarni@6071: #else skidd13@8500: #define INT64_MAX 9223372036854775807LL skidd13@8500: #define INT64_MIN (-INT64_MAX - 1) bjarni@6071: #endif bjarni@6071: rubidium@6184: #include rubidium@6184: #include rubidium@6184: #include rubidium@6184: #include rubidium@6184: #include truelight@0: rubidium@6185: /* MacOS X will use an NSAlert to display failed assertaions since they're lost unless running from a terminal rubidium@6185: * strgen always runs from terminal and don't need a window for asserts */ bjarni@2731: #if !defined(__APPLE__) || defined(STRGEN) skidd13@8500: #include bjarni@2223: #else skidd13@8500: #include "os/macosx/macos.h" bjarni@2223: #endif bjarni@2223: darkvater@858: #if defined(UNIX) || defined(__MINGW32__) skidd13@8500: #include truelight@0: #endif truelight@0: truelight@781: #if defined(__OS2__) skidd13@8500: #include skidd13@8500: #define strcasecmp stricmp truelight@781: #endif truelight@781: truelight@6227: #if defined(PSP) skidd13@8500: #include skidd13@8500: #include skidd13@8500: #include tron@446: #endif tron@446: skidd13@8500: #if defined(__BEOS__) skidd13@8500: #include skidd13@8500: #endif skidd13@8500: skidd13@8500: #if defined(SUNOS) skidd13@8500: #include skidd13@8500: #endif skidd13@8500: skidd13@8500: #if defined(__MORPHOS__) skidd13@8500: /* MorphOS defines certain Amiga defines per default, we undefine them skidd13@8500: * here to make the rest of source less messy and more clear what is skidd13@8500: * required for morphos and what for AmigaOS */ skidd13@8500: #if defined(amigaos) skidd13@8500: #undef amigaos skidd13@8500: #endif skidd13@8500: #if defined(__amigaos__) skidd13@8500: #undef __amigaos__ skidd13@8500: # endif skidd13@8500: #if defined(__AMIGA__) skidd13@8500: #undef __AMIGA__ skidd13@8500: #endif skidd13@8500: #if defined(AMIGA) skidd13@8500: #undef AMIGA skidd13@8500: #endif skidd13@8500: #if defined(amiga) skidd13@8500: #undef amiga skidd13@8500: #endif skidd13@8500: /* Act like we already included this file, as it somehow gives linkage problems skidd13@8500: * (mismatch linkage of C++ and C between this include and unistd.h). */ skidd13@8500: #define CLIB_USERGROUP_PROTOS_H bjarni@770: #endif /* __MORPHOS__ */ bjarni@770: skidd13@8500: #if defined(__APPLE__) skidd13@8500: #include "os/macosx/osx_stdafx.h" Darkvater@3289: #endif /* __APPLE__ */ truelight@0: truelight@6218: #if defined(PSP) skidd13@8500: /* PSP can only have 10 file-descriptors open at any given time, but this skidd13@8500: * switch only limits reads via the Fio system. So keep 2 fds free for things skidd13@8500: * like saving a game. */ skidd13@8500: #define LIMITED_FDS 8 skidd13@8500: #define printf pspDebugScreenPrintf truelight@6218: #endif /* PSP */ truelight@6218: rubidium@6185: /* by default we use [] var arrays */ truelight@0: #define VARARRAY_SIZE truelight@0: rubidium@6185: /* Stuff for GCC */ truelight@0: #if defined(__GNUC__) skidd13@8500: #define NORETURN __attribute__ ((noreturn)) skidd13@8500: #define FORCEINLINE inline skidd13@8500: #define CDECL skidd13@8500: #define __int64 long long skidd13@8500: #define GCC_PACK __attribute__((packed)) truelight@0: skidd13@8500: #if (__GNUC__ == 2) skidd13@8500: #undef VARARRAY_SIZE skidd13@8500: #define VARARRAY_SIZE 0 skidd13@8500: #endif Darkvater@2485: #endif /* __GNUC__ */ truelight@0: truelight@781: #if defined(__WATCOMC__) skidd13@8500: #define NORETURN skidd13@8500: #define FORCEINLINE inline skidd13@8500: #define CDECL skidd13@8500: #define GCC_PACK skidd13@8500: #include Darkvater@2485: #endif /* __WATCOMC__ */ truelight@781: darkvater@796: #if defined(__MINGW32__) || defined(__CYGWIN__) skidd13@8500: #include // alloca() darkvater@796: #endif darkvater@796: rubidium@6185: /* Stuff for MSVC */ truelight@0: #if defined(_MSC_VER) skidd13@8500: #pragma once skidd13@8500: /* Define a win32 target platform, to override defaults of the SDK skidd13@8500: * We need to define NTDDI version for Vista SDK, but win2k is minimum */ skidd13@8500: #define NTDDI_VERSION NTDDI_WIN2K // Windows 2000 skidd13@8500: #define _WIN32_WINNT 0x0500 // Windows 2000 skidd13@8500: #define _WIN32_WINDOWS 0x400 // Windows 95 skidd13@8500: #if !defined(WINCE) skidd13@8500: #define WINVER 0x0400 // Windows NT 4.0 / Windows 95 skidd13@8500: #endif skidd13@8500: #define _WIN32_IE_ 0x0401 // 4.01 (win98 and NT4SP5+) Darkvater@2695: skidd13@8500: #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers skidd13@8500: #pragma warning(disable: 4244) // 'conversion' conversion from 'type1' to 'type2', possible loss of data skidd13@8500: #pragma warning(disable: 4761) // integral size mismatch in argument : conversion supplied skidd13@8500: #pragma warning(disable: 4200) // nonstandard extension used : zero-sized array in struct/union Darkvater@2485: rubidium@8905: #if (_MSC_VER < 1400) // MSVC 2005 safety checks rubidium@8905: #error "Only MSVC 2005 or higher are supported. MSVC 2003 and earlier are not!. Upgrade your compiler." rubidium@8905: #endif /* (_MSC_VER < 1400) */ rubidium@8905: #pragma warning(disable: 4996) // 'strdup' was declared deprecated rubidium@8905: #define _CRT_SECURE_NO_DEPRECATE // all deprecated 'unsafe string functions rubidium@8905: #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 rubidium@8905: #pragma warning(disable: 6011) // code analyzer: Dereferencing NULL pointer 'pfGetAddrInfo': Lines: 995, 996, 998, 999, 1001 rubidium@8905: #pragma warning(disable: 6326) // code analyzer: potential comparison of a constant with another constant rubidium@8905: #pragma warning(disable: 6031) // code analyzer: Return value ignored: 'ReadFile' rubidium@8905: #pragma warning(disable: 6255) // code analyzer: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead rubidium@8905: #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 ... Darkvater@2694: skidd13@8500: #include // alloca() skidd13@8500: #define NORETURN __declspec(noreturn) skidd13@8500: #define FORCEINLINE __forceinline skidd13@8500: #define inline _inline Darkvater@2694: skidd13@8500: #if !defined(WINCE) skidd13@8500: #define CDECL _cdecl skidd13@8500: #endif skidd13@8500: skidd13@8500: int CDECL snprintf(char *str, size_t size, const char *format, ...); skidd13@8500: #if (_MSC_VER < 1400) || defined(WINCE) skidd13@8500: int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap); skidd13@8500: #endif skidd13@8500: skidd13@8500: #if defined(WIN32) && !defined(_WIN64) && !defined(WIN64) skidd13@8500: #if !defined(_W64) skidd13@8500: #define _W64 skidd13@8500: #endif skidd13@8500: skidd13@8500: typedef _W64 int INT_PTR, *PINT_PTR; skidd13@8500: typedef _W64 unsigned int UINT_PTR, *PUINT_PTR; skidd13@8500: #endif /* WIN32 && !_WIN64 && !WIN64 */ skidd13@8500: skidd13@8500: #define GCC_PACK skidd13@8500: skidd13@8500: /* This is needed to zlib uses the stdcall calling convention on visual studio */ skidd13@8500: #if defined(WITH_ZLIB) || defined(WITH_PNG) skidd13@8500: #if !defined(ZLIB_WINAPI) skidd13@8500: #define ZLIB_WINAPI skidd13@8500: #endif skidd13@8500: #endif skidd13@8500: skidd13@8500: #if defined(WINCE) skidd13@8500: #define strcasecmp _stricmp skidd13@8500: #define strncasecmp _strnicmp skidd13@8500: #undef DEBUG skidd13@8500: #else skidd13@8500: #define strcasecmp stricmp skidd13@8500: #define strncasecmp strnicmp skidd13@8500: #endif glx@8547: glx@8547: void SetExceptionString(const char* s, ...); glx@8547: glx@8547: #if defined(NDEBUG) && defined(WITH_ASSERT) glx@8547: #undef assert glx@8547: #define assert(expression) if (!(expression)) { SetExceptionString("Assertion failed at %s:%d: %s", __FILE__, __LINE__, #expression); *(byte*)0 = 0; } glx@8547: #endif Darkvater@2485: #endif /* defined(_MSC_VER) */ Darkvater@2483: truelight@6006: #if defined(WINCE) skidd13@8500: #define strdup _strdup truelight@6006: #endif /* WINCE */ truelight@6006: Darkvater@5167: /* NOTE: the string returned by these functions is only valid until the next Darkvater@5167: * call to the same function and is not thread- or reentrancy-safe */ Darkvater@5167: #if !defined(STRGEN) skidd13@8500: #if defined(WIN32) || defined(WIN64) skidd13@8500: char *getcwd(char *buf, size_t size); skidd13@8500: #include Darkvater@6577: skidd13@8500: /* XXX - WinCE without MSVCRT doesn't support wfopen, so it seems */ skidd13@8500: #if !defined(WINCE) skidd13@8500: #define fopen(file, mode) _tfopen(OTTD2FS(file), _T(mode)) skidd13@8500: #endif /* WINCE */ Darkvater@6577: skidd13@8500: const char *FS2OTTD(const TCHAR *name); skidd13@8500: const TCHAR *OTTD2FS(const char *name); skidd13@8500: #else skidd13@8500: #define fopen(file, mode) fopen(OTTD2FS(file), mode) skidd13@8500: const char *FS2OTTD(const char *name); skidd13@8500: const char *OTTD2FS(const char *name); skidd13@8500: #endif /* WIN32 */ Darkvater@5167: #endif /* STRGEN */ Darkvater@2482: orudge@5842: #if defined(WIN32) || defined(WIN64) || defined(__OS2__) && !defined(__INNOTEK_LIBC__) skidd13@8500: #define PATHSEP "\\" skidd13@8500: #define PATHSEPCHAR '\\' truelight@4379: #else skidd13@8500: #define PATHSEP "/" skidd13@8500: #define PATHSEPCHAR '/' truelight@0: #endif truelight@0: truelight@0: typedef unsigned char byte; skidd13@8500: skidd13@8500: /* This is already defined in unix, but not in QNX Neutrino (6.x)*/ skidd13@8500: #if (!defined(UNIX) && !defined(__CYGWIN__) && !defined(__BEOS__) && !defined(__MORPHOS__)) || defined(__QNXNTO__) skidd13@8500: typedef unsigned int uint; truelight@0: #endif truelight@0: rubidium@8869: #if !defined(__BEOS__) && !defined(__NDS__) /* Already defined on BEOS and NDS */ skidd13@8500: typedef unsigned char uint8; skidd13@8500: typedef signed char int8; skidd13@8500: typedef unsigned short uint16; skidd13@8500: typedef signed short int16; skidd13@8500: typedef unsigned int uint32; skidd13@8500: typedef signed int int32; skidd13@8500: typedef unsigned __int64 uint64; skidd13@8500: typedef signed __int64 int64; rubidium@8869: #endif /* !__BEOS__ && !__NDS__ */ truelight@0: rubidium@7425: #if !defined(WITH_PERSONAL_DIR) skidd13@8500: #define PERSONAL_DIR "" truelight@0: #endif truelight@0: rubidium@6185: /* Compile time assertions */ skidd13@8500: #if defined(__OS2__) skidd13@8500: #define assert_compile(expr) truelight@781: #else skidd13@8500: #define assert_compile(expr) extern "C" void __ct_assert__(int a[1 - 2 * !(expr)]) KUDr@3900: #endif /* __OS2__ */ truelight@0: truelight@0: assert_compile(sizeof(uint32) == 4); truelight@0: assert_compile(sizeof(uint16) == 2); tron@2639: assert_compile(sizeof(uint8) == 1); truelight@0: truelight@0: #define lengthof(x) (sizeof(x)/sizeof(x[0])) truelight@0: #define endof(x) (&x[lengthof(x)]) tron@1317: #define lastof(x) (&x[lengthof(x) - 1]) KUDr@5922: rubidium@6409: #define cpp_offsetof(s,m) (((size_t)&reinterpret_cast((((s*)(char*)8)->m))) - 8) skidd13@8500: #if !defined(offsetof) skidd13@8500: #define offsetof(s,m) cpp_offsetof(s, m) rubidium@6409: #endif /* offsetof */ truelight@0: truelight@0: rubidium@6185: /* take care of some name clashes on MacOS */ truelight@0: #if defined(__APPLE__) skidd13@8500: #define GetString OTTD_GetString skidd13@8500: #define DrawString OTTD_DrawString skidd13@8500: #define CloseConnection OTTD_CloseConnection skidd13@8622: #endif /* __APPLE__ */ bjarni@569: skidd13@8500: #if !defined(STRGEN) skidd13@8500: /* In strgen error is not fatal and returns */ skidd13@8500: void NORETURN CDECL error(const char *str, ...); skidd13@8500: #else skidd13@8500: void CDECL error(const char *str, ...); skidd13@8500: #endif skidd13@8500: rubidium@7118: #define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__) rubidium@7118: rubidium@8869: #if defined(MORPHOS) || defined(__NDS__) rubidium@8869: /* MorphOS and NDS don't have C++ conformant _stricmp... */ skidd13@8500: #define _stricmp stricmp rubidium@7771: #elif defined(OPENBSD) skidd13@8500: /* OpenBSD uses strcasecmp(3) */ skidd13@8500: #define _stricmp strcasecmp rubidium@7771: #endif rubidium@7771: rubidium@8869: #if !defined(MORPHOS) && !defined(OPENBSD) && !defined(__NDS__) rubidium@8869: /* NDS, MorphOS & OpenBSD don't know wchars, the rest does :( */ skidd13@8500: #define HAS_WCHAR rubidium@8869: #endif /* !defined(MORPHOS) && !defined(OPENBSD) && !defined(__NDS__) */ rubidium@7751: rubidium@7762: #if !defined(MAX_PATH) skidd13@8500: #define MAX_PATH 260 rubidium@7762: #endif rubidium@7762: rubidium@8619: /** rubidium@8619: * The largest value that can be entered in a variable rubidium@8619: * @param type the type of the variable rubidium@8619: */ rubidium@8619: #define MAX_UVALUE(type) ((type)~(type)0) rubidium@8619: Darkvater@2436: #endif /* STDAFX_H */