tron@2186: /* $Id$ */ tron@2186: belugas@6977: /** @file stdafx.h */ belugas@6916: Darkvater@2436: #ifndef STDAFX_H Darkvater@2436: #define STDAFX_H truelight@0: 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" skidd13@8500: /* Make endian swapping use Apple's macros to increase speed (since it will use hardware swapping if available) skidd13@8500: * Even though they should return uint16 and uint32, we get warnings if we don't cast those (why?) */ skidd13@8500: #define BSWAP32(x) ((uint32)Endian32_Swap(x)) skidd13@8500: #define BSWAP16(x) ((uint16)Endian16_Swap(x)) bjarni@3016: #else skidd13@8500: #define BSWAP32(x) ((((x) >> 24) & 0xFF) | (((x) >> 8) & 0xFF00) | (((x) << 8) & 0xFF0000) | (((x) << 24) & 0xFF000000)) skidd13@8500: #define BSWAP16(x) ((x) >> 8 | (x) << 8) 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: skidd13@8500: #if (_MSC_VER >= 1400) // MSVC 2005 safety checks skidd13@8500: #pragma warning(disable: 4996) // 'strdup' was declared deprecated skidd13@8500: #define _CRT_SECURE_NO_DEPRECATE // all deprecated 'unsafe string functions skidd13@8500: #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 skidd13@8500: #pragma warning(disable: 6011) // code analyzer: Dereferencing NULL pointer 'pfGetAddrInfo': Lines: 995, 996, 998, 999, 1001 skidd13@8500: #pragma warning(disable: 6326) // code analyzer: potential comparison of a constant with another constant skidd13@8500: #pragma warning(disable: 6031) // code analyzer: Return value ignored: 'ReadFile' skidd13@8500: #pragma warning(disable: 6255) // code analyzer: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead skidd13@8500: #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 ... skidd13@8500: #else /* _MSC_VER >= 1400 ( <1400 for MSVC2003) */ skidd13@8500: #pragma warning(disable: 4288) // nonstandard extension used : 'y' : loop control variable declared in the for-loop is used outside the for-loop scope; it conflicts with the declaration in the outer scope skidd13@8500: #pragma warning(disable: 4292) // compiler limit : terminating debug information emission for enum 'StringIdEnum' with member 'STR_801D_COAL_CAR' skidd13@8500: #endif /* _MSC_VER >= 1400 */ 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 rubidium@6185: /* suppress: warning C4005: 'offsetof' : macro redefinition (VC8) */ 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: rubidium@6185: /* Windows has always LITTLE_ENDIAN */ Darkvater@2482: #if defined(WIN32) || defined(__OS2__) || defined(WIN64) skidd13@8500: #define TTD_LITTLE_ENDIAN rubidium@7434: #elif defined(TESTING) skidd13@8500: /* Do noting */ truelight@157: #else skidd13@8500: /* Else include endian[target/host].h, which has the endian-type, autodetected by the Makefile */ skidd13@8500: #if defined(STRGEN) skidd13@8500: #include "endian_host.h" skidd13@8500: #else skidd13@8500: #include "endian_target.h" skidd13@8500: #endif Darkvater@2485: #endif /* WIN32 || __OS2__ || WIN64 */ truelight@0: 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: skidd13@8500: #if !defined(__BEOS__) /* Already defined on BEOS */ 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; truelight@543: #endif truelight@0: Darkvater@2978: #if defined(ARM) || defined(__arm__) || defined(__alpha__) skidd13@8500: #define OTTD_ALIGNMENT Darkvater@2978: #endif Darkvater@2978: rubidium@6185: /* Setup alignment and conversion macros */ truelight@0: #if defined(TTD_BIG_ENDIAN) skidd13@8500: #define TO_BE32X(x) (x) skidd13@8500: #define FROM_BE32(x) (x) skidd13@8500: #define TO_BE32(x) (x) skidd13@8500: #define FROM_BE16(x) (x) skidd13@8500: #define TO_BE16(x) (x) skidd13@8500: #define TO_LE32X(x) BSWAP32(x) skidd13@8500: static inline uint32 FROM_LE32(uint32 x) { return BSWAP32(x); } skidd13@8500: static inline uint32 TO_LE32(uint32 x) { return BSWAP32(x); } skidd13@8500: static inline uint16 FROM_LE16(uint16 x) { return BSWAP16(x); } skidd13@8500: static inline uint16 TO_LE16(uint16 x) { return BSWAP16(x); } truelight@0: #else skidd13@8500: #define TO_BE32X(x) BSWAP32(x) skidd13@8500: static inline uint32 FROM_BE32(uint32 x) { return BSWAP32(x); } skidd13@8500: static inline uint32 TO_BE32(uint32 x) { return BSWAP32(x); } skidd13@8500: static inline uint16 FROM_BE16(uint16 x) { return BSWAP16(x); } skidd13@8500: static inline uint16 TO_BE16(uint16 x) { return BSWAP16(x); } skidd13@8500: #define TO_LE32X(x) (x) skidd13@8500: #define FROM_LE32(x) (x) skidd13@8500: #define TO_LE32(x) (x) skidd13@8500: #define FROM_LE16(x) (x) skidd13@8500: #define TO_LE16(x) (x) Darkvater@2485: #endif /* TTD_BIG_ENDIAN */ 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 Random OTTD_Random skidd13@8500: #define CloseConnection OTTD_CloseConnection Darkvater@2485: #endif /* __APPLE */ truelight@0: skidd13@8500: #if defined(__AMIGA__) skidd13@8500: /* it seems AmigaOS already have a Point declared */ skidd13@8500: #define Point OTTD_AMIGA_POINT bjarni@569: #endif 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@7771: #if defined(MORPHOS) skidd13@8500: /* MorphOS doesn'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: glx@7773: #if !defined(MORPHOS) && !defined(OPENBSD) skidd13@8500: /* MorphOS & OpenBSD don't know wchars, the rest does :( */ skidd13@8500: #define HAS_WCHAR glx@7773: #endif /* !defined(MORPHOS) && !defined(OPENBSD) */ rubidium@7751: rubidium@7762: #if !defined(MAX_PATH) skidd13@8500: #define MAX_PATH 260 rubidium@7762: #endif rubidium@7762: Darkvater@2436: #endif /* STDAFX_H */