src/stdafx.h
changeset 8004 1c54bc6f4bdf
parent 7927 3a3289a049f9
child 8024 5feb155012fe
equal deleted inserted replaced
8003:c171c650d1e3 8004:1c54bc6f4bdf
    11  * INT64_MAX for them ourselves.
    11  * INT64_MAX for them ourselves.
    12  * Sometimes OSX headers manages to include stdint.h before this but without
    12  * Sometimes OSX headers manages to include stdint.h before this but without
    13  * __STDC_LIMIT_MACROS so it will be without INT64_*. We need to define those
    13  * __STDC_LIMIT_MACROS so it will be without INT64_*. We need to define those
    14  * too if this is the case. */
    14  * too if this is the case. */
    15 #if !defined(_MSC_VER) && !defined( __MORPHOS__) && !defined(_STDINT_H_)
    15 #if !defined(_MSC_VER) && !defined( __MORPHOS__) && !defined(_STDINT_H_)
    16 # if defined (SUNOS)
    16 	#if defined(SUNOS)
    17 /* SunOS/Solaris does not have stdint.h, but inttypes.h defines everything
    17 		/* SunOS/Solaris does not have stdint.h, but inttypes.h defines everything
    18  * stdint.h defines and we need. */
    18 		 * stdint.h defines and we need. */
    19 #  include <inttypes.h>
    19 		#include <inttypes.h>
    20 # else
    20 	# else
    21 #  define __STDC_LIMIT_MACROS
    21 		#define __STDC_LIMIT_MACROS
    22 #  include <stdint.h>
    22 		#include <stdint.h>
    23 # endif
    23 	#endif
    24 #else
    24 #else
    25 # define INT64_MAX 9223372036854775807LL
    25 	#define INT64_MAX 9223372036854775807LL
    26 # define INT64_MIN (-INT64_MAX - 1)
    26 	#define INT64_MIN (-INT64_MAX - 1)
    27 #endif
    27 #endif
    28 
    28 
    29 #include <cstdio>
    29 #include <cstdio>
    30 #include <cstddef>
    30 #include <cstddef>
    31 #include <cstring>
    31 #include <cstring>
    33 #include <climits>
    33 #include <climits>
    34 
    34 
    35 /* MacOS X will use an NSAlert to display failed assertaions since they're lost unless running from a terminal
    35 /* MacOS X will use an NSAlert to display failed assertaions since they're lost unless running from a terminal
    36  * strgen always runs from terminal and don't need a window for asserts */
    36  * strgen always runs from terminal and don't need a window for asserts */
    37 #if !defined(__APPLE__) || defined(STRGEN)
    37 #if !defined(__APPLE__) || defined(STRGEN)
    38 # include <cassert>
    38 	#include <cassert>
    39 #else
    39 #else
    40 # include "os/macosx/macos.h"
    40 	#include "os/macosx/macos.h"
    41 #endif
    41 #endif
    42 
    42 
    43 #if defined(UNIX) || defined(__MINGW32__)
    43 #if defined(UNIX) || defined(__MINGW32__)
    44 # include <sys/types.h>
    44 	#include <sys/types.h>
    45 #endif
    45 #endif
    46 
    46 
    47 #if defined(__OS2__)
    47 #if defined(__OS2__)
    48 # include <types.h>
    48 	#include <types.h>
    49 # define strcasecmp stricmp
    49 	#define strcasecmp stricmp
    50 #endif
    50 #endif
    51 
    51 
    52 #if defined(PSP)
    52 #if defined(PSP)
    53 # include <psptypes.h>
    53 	#include <psptypes.h>
    54 # include <pspdebug.h>
    54 	#include <pspdebug.h>
    55 # include <pspthreadman.h>
    55 	#include <pspthreadman.h>
    56 #endif /* PSP */
    56 #endif
    57 
    57 
    58 #ifdef __BEOS__
    58 #if defined(__BEOS__)
    59 # include <SupportDefs.h>
    59 	#include <SupportDefs.h>
    60 #endif
    60 #endif
    61 
    61 
    62 #ifdef SUNOS
    62 #if defined(SUNOS)
    63 # include <alloca.h>
    63 	#include <alloca.h>
    64 #endif
    64 #endif
    65 
    65 
    66 #ifdef __MORPHOS__
    66 #if defined(__MORPHOS__)
    67 /* MorphOS defines certain Amiga defines per default, we undefine them
    67 	/* MorphOS defines certain Amiga defines per default, we undefine them
    68  * here to make the rest of source less messy and more clear what is
    68 	 * here to make the rest of source less messy and more clear what is
    69  * required for morphos and what for AmigaOS */
    69 	 * required for morphos and what for AmigaOS */
    70 # ifdef amigaos
    70 	#if defined(amigaos)
    71 #  undef amigaos
    71 		#undef amigaos
    72 # endif
    72 	#endif
    73 # ifdef __amigaos__
    73 	#if defined(__amigaos__)
    74 #  undef __amigaos__
    74 		#undef __amigaos__
    75 # endif
    75 	# endif
    76 # ifdef __AMIGA__
    76 	#if defined(__AMIGA__)
    77 #  undef __AMIGA__
    77 		#undef __AMIGA__
    78 # endif
    78 	#endif
    79 # ifdef AMIGA
    79 	#if defined(AMIGA)
    80 #  undef AMIGA
    80 		#undef AMIGA
    81 # endif
    81 	#endif
    82 # ifdef amiga
    82 	#if defined(amiga)
    83 #  undef amiga
    83 		#undef amiga
    84 # endif
    84 	#endif
    85 /* Act like we already included this file, as it somehow gives linkage problems
    85 	/* Act like we already included this file, as it somehow gives linkage problems
    86  *  (mismatch linkage of C++ and C between this include and unistd.h). */
    86 	 *  (mismatch linkage of C++ and C between this include and unistd.h). */
    87 #define CLIB_USERGROUP_PROTOS_H
    87 	#define CLIB_USERGROUP_PROTOS_H
    88 #endif /* __MORPHOS__ */
    88 #endif /* __MORPHOS__ */
    89 
    89 
    90 #ifdef __APPLE__
    90 #if defined(__APPLE__)
    91 # include "os/macosx/osx_stdafx.h"
    91 	#include "os/macosx/osx_stdafx.h"
    92 /* Make endian swapping use Apple's macros to increase speed (since it will use hardware swapping if available)
    92 	/* Make endian swapping use Apple's macros to increase speed (since it will use hardware swapping if available)
    93  * Even though they should return uint16 and uint32, we get warnings if we don't cast those (why?) */
    93 	 * Even though they should return uint16 and uint32, we get warnings if we don't cast those (why?) */
    94 # define BSWAP32(x) ((uint32)Endian32_Swap(x))
    94 	#define BSWAP32(x) ((uint32)Endian32_Swap(x))
    95 # define BSWAP16(x) ((uint16)Endian16_Swap(x))
    95 	#define BSWAP16(x) ((uint16)Endian16_Swap(x))
    96 #else
    96 #else
    97 # define BSWAP32(x) ((((x) >> 24) & 0xFF) | (((x) >> 8) & 0xFF00) | (((x) << 8) & 0xFF0000) | (((x) << 24) & 0xFF000000))
    97 	#define BSWAP32(x) ((((x) >> 24) & 0xFF) | (((x) >> 8) & 0xFF00) | (((x) << 8) & 0xFF0000) | (((x) << 24) & 0xFF000000))
    98 # define BSWAP16(x) ((x) >> 8 | (x) << 8)
    98 	#define BSWAP16(x) ((x) >> 8 | (x) << 8)
    99 #endif /* __APPLE__ */
    99 #endif /* __APPLE__ */
   100 
   100 
   101 #if defined(PSP)
   101 #if defined(PSP)
   102 /* PSP can only have 10 file-descriptors open at any given time, but this
   102 	/* PSP can only have 10 file-descriptors open at any given time, but this
   103  *  switch only limits reads via the Fio system. So keep 2 fds free for things
   103 	 *  switch only limits reads via the Fio system. So keep 2 fds free for things
   104  *  like saving a game. */
   104 	 *  like saving a game. */
   105 # define LIMITED_FDS 8
   105 	#define LIMITED_FDS 8
   106 # define printf pspDebugScreenPrintf
   106 	#define printf pspDebugScreenPrintf
   107 #endif /* PSP */
   107 #endif /* PSP */
   108 
   108 
   109 /* by default we use [] var arrays */
   109 /* by default we use [] var arrays */
   110 #define VARARRAY_SIZE
   110 #define VARARRAY_SIZE
   111 
   111 
   112 
       
   113 /* Stuff for GCC */
   112 /* Stuff for GCC */
   114 #if defined(__GNUC__)
   113 #if defined(__GNUC__)
   115 # define NORETURN __attribute__ ((noreturn))
   114 	#define NORETURN __attribute__ ((noreturn))
   116 # define FORCEINLINE inline
   115 	#define FORCEINLINE inline
   117 # define CDECL
   116 	#define CDECL
   118 # define __int64 long long
   117 	#define __int64 long long
   119 # define GCC_PACK __attribute__((packed))
   118 	#define GCC_PACK __attribute__((packed))
   120 
   119 
   121 # if (__GNUC__ == 2)
   120 	#if (__GNUC__ == 2)
   122 #  undef VARARRAY_SIZE
   121 		#undef VARARRAY_SIZE
   123 #  define VARARRAY_SIZE 0
   122 		#define VARARRAY_SIZE 0
   124 # endif
   123 	#endif
   125 #endif /* __GNUC__ */
   124 #endif /* __GNUC__ */
   126 
   125 
   127 #if defined(__WATCOMC__)
   126 #if defined(__WATCOMC__)
   128 # define NORETURN
   127 	#define NORETURN
   129 # define FORCEINLINE inline
   128 	#define FORCEINLINE inline
   130 # define CDECL
   129 	#define CDECL
   131 # define GCC_PACK
   130 	#define GCC_PACK
   132 # include <malloc.h>
   131 	#include <malloc.h>
   133 #endif /* __WATCOMC__ */
   132 #endif /* __WATCOMC__ */
   134 
   133 
   135 #if defined(__MINGW32__) || defined(__CYGWIN__)
   134 #if defined(__MINGW32__) || defined(__CYGWIN__)
   136 # include <malloc.h> // alloca()
   135 	#include <malloc.h> // alloca()
   137 #endif
   136 #endif
   138 
   137 
   139 /* Stuff for MSVC */
   138 /* Stuff for MSVC */
   140 #if defined(_MSC_VER)
   139 #if defined(_MSC_VER)
   141 # pragma once
   140 	#pragma once
   142 /* Define a win32 target platform, to override defaults of the SDK
   141 	/* Define a win32 target platform, to override defaults of the SDK
   143  * We need to define NTDDI version for Vista SDK, but win2k is minimum */
   142 	 * We need to define NTDDI version for Vista SDK, but win2k is minimum */
   144 # define NTDDI_VERSION NTDDI_WIN2K // Windows 2000
   143 	#define NTDDI_VERSION NTDDI_WIN2K // Windows 2000
   145 # define _WIN32_WINNT 0x0500       // Windows 2000
   144 	#define _WIN32_WINNT 0x0500       // Windows 2000
   146 
   145 	#define _WIN32_WINDOWS 0x400      // Windows 95
   147 # define _WIN32_WINDOWS 0x400      // Windows 95
   146 	#if !defined(WINCE)
   148 #if !defined(WINCE)
   147 		#define WINVER 0x0400     // Windows NT 4.0 / Windows 95
   149 # define WINVER 0x0400             // Windows NT 4.0 / Windows 95
   148 	#endif
   150 #endif
   149 	#define _WIN32_IE_ 0x0401         // 4.01 (win98 and NT4SP5+)
   151 # define _WIN32_IE_ 0x0401         // 4.01 (win98 and NT4SP5+)
   150 
   152 
   151 	#define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers
   153 # define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers
   152 	#pragma warning(disable: 4244)  // 'conversion' conversion from 'type1' to 'type2', possible loss of data
   154 # pragma warning(disable: 4244)  // 'conversion' conversion from 'type1' to 'type2', possible loss of data
   153 	#pragma warning(disable: 4761)  // integral size mismatch in argument : conversion supplied
   155 # pragma warning(disable: 4761)  // integral size mismatch in argument : conversion supplied
   154 	#pragma warning(disable: 4200)  // nonstandard extension used : zero-sized array in struct/union
   156 # pragma warning(disable: 4200)  // nonstandard extension used : zero-sized array in struct/union
   155 
   157 
   156 	#if (_MSC_VER >= 1400)                   // MSVC 2005 safety checks
   158 # if _MSC_VER >= 1400              // MSVC 2005 safety checks
   157 		#pragma warning(disable: 4996)   // 'strdup' was declared deprecated
   159 #  pragma warning(disable: 4996)   // 'strdup' was declared deprecated
   158 		#define _CRT_SECURE_NO_DEPRECATE // all deprecated 'unsafe string functions
   160 #  define _CRT_SECURE_NO_DEPRECATE // all deprecated 'unsafe string functions
   159 		#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
   161 #  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
   160 		#pragma warning(disable: 6011)   // code analyzer: Dereferencing NULL pointer 'pfGetAddrInfo': Lines: 995, 996, 998, 999, 1001
   162 #  pragma warning(disable: 6011)   // code analyzer: Dereferencing NULL pointer 'pfGetAddrInfo': Lines: 995, 996, 998, 999, 1001
   161 		#pragma warning(disable: 6326)   // code analyzer: potential comparison of a constant with another constant
   163 #  pragma warning(disable: 6326)   // code analyzer: potential comparison of a constant with another constant
   162 		#pragma warning(disable: 6031)   // code analyzer: Return value ignored: 'ReadFile'
   164 #  pragma warning(disable: 6031)   // code analyzer: Return value ignored: 'ReadFile'
   163 		#pragma warning(disable: 6255)   // code analyzer: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead
   165 #  pragma warning(disable: 6255)   // code analyzer: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead
   164 		#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 ...
   166 #  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 ...
   165 	#else /* _MSC_VER >= 1400  ( <1400 for MSVC2003) */
   167 # else /* _MSC_VER >= 1400  ( <1400 for MSVC2003) */
   166 		#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
   168 #  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
   167 		#pragma warning(disable: 4292)   // compiler limit : terminating debug information emission for enum 'StringIdEnum' with member 'STR_801D_COAL_CAR'
   169 #  pragma warning(disable: 4292)   // compiler limit : terminating debug information emission for enum 'StringIdEnum' with member 'STR_801D_COAL_CAR'
   168 	#endif /* _MSC_VER >= 1400 */
   170 # endif /* _MSC_VER >= 1400 */
   169 
   171 
   170 	#include <malloc.h> // alloca()
   172 # include <malloc.h> // alloca()
   171 	#define NORETURN __declspec(noreturn)
   173 # define NORETURN __declspec(noreturn)
   172 	#define FORCEINLINE __forceinline
   174 # define FORCEINLINE __forceinline
   173 	#define inline _inline
   175 # define inline _inline
   174 
   176 # if !defined(WINCE)
   175 	#if !defined(WINCE)
   177 #  define CDECL _cdecl
   176 		#define CDECL _cdecl
   178 # endif
   177 	#endif
   179   int CDECL snprintf(char *str, size_t size, const char *format, ...);
   178 
   180 # if _MSC_VER < 1400 || defined(WINCE)
   179 	int CDECL snprintf(char *str, size_t size, const char *format, ...);
   181    int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap);
   180 	#if (_MSC_VER < 1400) || defined(WINCE)
   182 # endif
   181 		int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap);
   183 
   182 	#endif
   184 # if defined(WIN32) && !defined(_WIN64) && !defined(WIN64)
   183 
   185 #  ifndef _W64
   184 	#if defined(WIN32) && !defined(_WIN64) && !defined(WIN64)
   186 #   define _W64
   185 		#if !defined(_W64)
   187 #  endif
   186 			#define _W64
   188    typedef _W64 int INT_PTR, *PINT_PTR;
   187 		#endif
   189    typedef _W64 unsigned int UINT_PTR, *PUINT_PTR;
   188 
   190 # endif /* WIN32 && !_WIN64 && !WIN64 */
   189 		typedef _W64 int INT_PTR, *PINT_PTR;
   191 
   190 		typedef _W64 unsigned int UINT_PTR, *PUINT_PTR;
   192 # define GCC_PACK
   191 	#endif /* WIN32 && !_WIN64 && !WIN64 */
   193 
   192 
   194 /* This is needed to zlib uses the stdcall calling convention on visual studio */
   193 	#define GCC_PACK
   195 # if defined(WITH_ZLIB) || defined(WITH_PNG)
   194 
   196 #  ifndef ZLIB_WINAPI
   195 	/* This is needed to zlib uses the stdcall calling convention on visual studio */
   197 #   define ZLIB_WINAPI
   196 	#if defined(WITH_ZLIB) || defined(WITH_PNG)
   198 #  endif
   197 		#if !defined(ZLIB_WINAPI)
   199 # endif
   198 			#define ZLIB_WINAPI
   200 
   199 		#endif
   201 # if defined(WINCE)
   200 	#endif
   202 #  define strcasecmp _stricmp
   201 
   203 #  define strncasecmp _strnicmp
   202 	#if defined(WINCE)
   204 #  undef DEBUG
   203 		#define strcasecmp _stricmp
   205 # else
   204 		#define strncasecmp _strnicmp
   206 #  define strcasecmp stricmp
   205 		#undef DEBUG
   207 #  define strncasecmp strnicmp
   206 	#else
   208 # endif
   207 		#define strcasecmp stricmp
       
   208 		#define strncasecmp strnicmp
       
   209 	#endif
   209 /* suppress: warning C4005: 'offsetof' : macro redefinition (VC8) */
   210 /* suppress: warning C4005: 'offsetof' : macro redefinition (VC8) */
   210 #endif /* defined(_MSC_VER) */
   211 #endif /* defined(_MSC_VER) */
   211 
   212 
   212 #if defined(WINCE)
   213 #if defined(WINCE)
   213 # define strdup _strdup
   214 	#define strdup _strdup
   214 #endif /* WINCE */
   215 #endif /* WINCE */
   215 
   216 
   216 /* NOTE: the string returned by these functions is only valid until the next
   217 /* NOTE: the string returned by these functions is only valid until the next
   217  * call to the same function and is not thread- or reentrancy-safe */
   218  * call to the same function and is not thread- or reentrancy-safe */
   218 #if !defined(STRGEN)
   219 #if !defined(STRGEN)
   219 # if defined(WIN32) || defined(WIN64)
   220 	#if defined(WIN32) || defined(WIN64)
   220 char *getcwd(char *buf, size_t size);
   221 		char *getcwd(char *buf, size_t size);
   221 #  include <tchar.h>
   222 		#include <tchar.h>
   222 /* XXX - WinCE without MSVCRT doesn't support wfopen, so it seems */
   223 
   223 #  if !defined(WINCE)
   224 		/* XXX - WinCE without MSVCRT doesn't support wfopen, so it seems */
   224 #   define fopen(file, mode) _tfopen(OTTD2FS(file), _T(mode))
   225 		#if !defined(WINCE)
   225 #  endif /* WINCE */
   226 			#define fopen(file, mode) _tfopen(OTTD2FS(file), _T(mode))
   226 
   227 		#endif /* WINCE */
   227    const char *FS2OTTD(const TCHAR *name);
   228 
   228    const TCHAR *OTTD2FS(const char *name);
   229 		const char *FS2OTTD(const TCHAR *name);
   229 # else
   230 		const TCHAR *OTTD2FS(const char *name);
   230 
   231 	#else
   231 #  define fopen(file, mode) fopen(OTTD2FS(file), mode)
   232 		#define fopen(file, mode) fopen(OTTD2FS(file), mode)
   232    const char *FS2OTTD(const char *name);
   233 		const char *FS2OTTD(const char *name);
   233    const char *OTTD2FS(const char *name);
   234 		const char *OTTD2FS(const char *name);
   234 # endif /* WIN32 */
   235 	#endif /* WIN32 */
   235 #endif /* STRGEN */
   236 #endif /* STRGEN */
   236 
   237 
   237 /* Windows has always LITTLE_ENDIAN */
   238 /* Windows has always LITTLE_ENDIAN */
   238 #if defined(WIN32) || defined(__OS2__) || defined(WIN64)
   239 #if defined(WIN32) || defined(__OS2__) || defined(WIN64)
   239 # define TTD_LITTLE_ENDIAN
   240 	#define TTD_LITTLE_ENDIAN
   240 #elif defined(TESTING)
   241 #elif defined(TESTING)
   241 #else
   242 	/* Do noting  */
   242 /* Else include endian[target/host].h, which has the endian-type, autodetected by the Makefile */
   243 #else
   243 # if defined(STRGEN)
   244 	/* Else include endian[target/host].h, which has the endian-type, autodetected by the Makefile */
   244 #  include "endian_host.h"
   245 	#if defined(STRGEN)
   245 # else
   246 		#include "endian_host.h"
   246 #  include "endian_target.h"
   247 	#else
   247 # endif
   248 		#include "endian_target.h"
       
   249 	#endif
   248 #endif /* WIN32 || __OS2__ || WIN64 */
   250 #endif /* WIN32 || __OS2__ || WIN64 */
   249 
   251 
   250 #if defined(WIN32) || defined(WIN64) || defined(__OS2__) && !defined(__INNOTEK_LIBC__)
   252 #if defined(WIN32) || defined(WIN64) || defined(__OS2__) && !defined(__INNOTEK_LIBC__)
   251 # define PATHSEP "\\"
   253 	#define PATHSEP "\\"
   252 # define PATHSEPCHAR '\\'
   254 	#define PATHSEPCHAR '\\'
   253 #else
   255 #else
   254 # define PATHSEP "/"
   256 	#define PATHSEP "/"
   255 # define PATHSEPCHAR '/'
   257 	#define PATHSEPCHAR '/'
   256 #endif
   258 #endif
   257 
   259 
   258 typedef unsigned char byte;
   260 typedef unsigned char byte;
   259 #ifndef __BEOS__ /* already defined */
   261 
   260   typedef unsigned char uint8;
   262 /* This is already defined in unix, but not in QNX Neutrino (6.x)*/
   261   typedef unsigned short uint16;
   263 #if (!defined(UNIX) && !defined(__CYGWIN__) && !defined(__BEOS__) && !defined(__MORPHOS__)) || defined(__QNXNTO__)
   262   typedef unsigned int uint32;
   264 	typedef unsigned int uint;
   263 #endif
   265 #endif
   264 
   266 
   265 /* This is already defined in unix */
   267 #if !defined(__BEOS__) /* Already defined on BEOS */
   266 #if !defined(UNIX) && !defined(__CYGWIN__) && !defined(__BEOS__) && !defined(__MORPHOS__)
   268 	typedef unsigned char    uint8;
   267   typedef unsigned int uint;
   269 	typedef   signed char     int8;
   268 #endif
   270 	typedef unsigned short   uint16;
   269 /* Not defined in QNX Neutrino (6.x) */
   271 	typedef   signed short    int16;
   270 #if defined(__QNXNTO__)
   272 	typedef unsigned int     uint32;
   271   typedef unsigned int uint;
   273 	typedef   signed int      int32;
   272 #endif
       
   273 
       
   274 #ifndef __BEOS__
       
   275 	typedef signed char int8;
       
   276 	typedef signed short int16;
       
   277 	typedef signed int int32;
       
   278 	typedef signed __int64 int64;
       
   279 	typedef unsigned __int64 uint64;
   274 	typedef unsigned __int64 uint64;
   280 #endif /* !__BEOS__ */
   275 	typedef   signed __int64  int64;
       
   276 #endif
   281 
   277 
   282 #if defined(ARM) || defined(__arm__) || defined(__alpha__)
   278 #if defined(ARM) || defined(__arm__) || defined(__alpha__)
   283 # define OTTD_ALIGNMENT
   279 	#define OTTD_ALIGNMENT
   284 #endif
   280 #endif
   285 
   281 
   286 /* Setup alignment and conversion macros */
   282 /* Setup alignment and conversion macros */
   287 #if defined(TTD_BIG_ENDIAN)
   283 #if defined(TTD_BIG_ENDIAN)
   288   static inline uint32 TO_LE32(uint32 x) { return BSWAP32(x); }
   284 	#define TO_BE32X(x)  (x)
   289   static inline uint16 TO_LE16(uint16 x) { return BSWAP16(x); }
   285 	#define FROM_BE32(x) (x)
   290   static inline uint32 FROM_LE32(uint32 x) { return BSWAP32(x); }
   286 	#define TO_BE32(x)   (x)
   291   static inline uint16 FROM_LE16(uint16 x) { return BSWAP16(x); }
   287 	#define FROM_BE16(x) (x)
   292 # define TO_BE32(x)   (x)
   288 	#define TO_BE16(x)   (x)
   293 # define TO_BE16(x)   (x)
   289 	#define TO_LE32X(x)  BSWAP32(x)
   294 # define FROM_BE32(x) (x)
   290 	static inline uint32 FROM_LE32(uint32 x) { return BSWAP32(x); }
   295 # define FROM_BE16(x) (x)
   291 	static inline uint32 TO_LE32(uint32 x)   { return BSWAP32(x); }
   296 # define TO_LE32X(x)  BSWAP32(x)
   292 	static inline uint16 FROM_LE16(uint16 x) { return BSWAP16(x); }
   297 # define TO_BE32X(x)  (x)
   293 	static inline uint16 TO_LE16(uint16 x)   { return BSWAP16(x); }
   298 #else
   294 #else
   299   static inline uint32 TO_BE32(uint32 x) { return BSWAP32(x); }
   295 	#define TO_BE32X(x)  BSWAP32(x)
   300   static inline uint16 TO_BE16(uint16 x) { return BSWAP16(x); }
   296 	static inline uint32 FROM_BE32(uint32 x) { return BSWAP32(x); }
   301   static inline uint32 FROM_BE32(uint32 x) { return BSWAP32(x); }
   297 	static inline uint32 TO_BE32(uint32 x)   { return BSWAP32(x); }
   302   static inline uint16 FROM_BE16(uint16 x) { return BSWAP16(x); }
   298 	static inline uint16 FROM_BE16(uint16 x) { return BSWAP16(x); }
   303 # define TO_LE32(x)   (x)
   299 	static inline uint16 TO_BE16(uint16 x)   { return BSWAP16(x); }
   304 # define TO_LE16(x)   (x)
   300 	#define TO_LE32X(x)  (x)
   305 # define FROM_LE32(x) (x)
   301 	#define FROM_LE32(x) (x)
   306 # define FROM_LE16(x) (x)
   302 	#define TO_LE32(x)   (x)
   307 # define TO_LE32X(x)  (x)
   303 	#define FROM_LE16(x) (x)
   308 # define TO_BE32X(x)  BSWAP32(x)
   304 	#define TO_LE16(x)   (x)
   309 #endif /* TTD_BIG_ENDIAN */
   305 #endif /* TTD_BIG_ENDIAN */
   310 
   306 
   311 #if !defined(WITH_PERSONAL_DIR)
   307 #if !defined(WITH_PERSONAL_DIR)
   312 # define PERSONAL_DIR ""
   308 	#define PERSONAL_DIR ""
   313 #endif
   309 #endif
   314 
   310 
   315 /* Compile time assertions */
   311 /* Compile time assertions */
   316 #ifdef __OS2__
   312 #if defined(__OS2__)
   317 # define assert_compile(expr)
   313 	#define assert_compile(expr)
   318 #else
   314 #else
   319 # define assert_compile(expr) extern "C" void __ct_assert__(int a[1 - 2 * !(expr)])
   315 	#define assert_compile(expr) extern "C" void __ct_assert__(int a[1 - 2 * !(expr)])
   320 #endif /* __OS2__ */
   316 #endif /* __OS2__ */
   321 
   317 
   322 assert_compile(sizeof(uint32) == 4);
   318 assert_compile(sizeof(uint32) == 4);
   323 assert_compile(sizeof(uint16) == 2);
   319 assert_compile(sizeof(uint16) == 2);
   324 assert_compile(sizeof(uint8)  == 1);
   320 assert_compile(sizeof(uint8)  == 1);
   326 #define lengthof(x) (sizeof(x)/sizeof(x[0]))
   322 #define lengthof(x) (sizeof(x)/sizeof(x[0]))
   327 #define endof(x) (&x[lengthof(x)])
   323 #define endof(x) (&x[lengthof(x)])
   328 #define lastof(x) (&x[lengthof(x) - 1])
   324 #define lastof(x) (&x[lengthof(x) - 1])
   329 
   325 
   330 #define cpp_offsetof(s,m)   (((size_t)&reinterpret_cast<const volatile char&>((((s*)(char*)8)->m))) - 8)
   326 #define cpp_offsetof(s,m)   (((size_t)&reinterpret_cast<const volatile char&>((((s*)(char*)8)->m))) - 8)
   331 #ifndef offsetof
   327 #if !defined(offsetof)
   332 # define offsetof(s,m)       cpp_offsetof(s, m)
   328 	#define offsetof(s,m) cpp_offsetof(s, m)
   333 #endif /* offsetof */
   329 #endif /* offsetof */
   334 
   330 
   335 
   331 
   336 /* take care of some name clashes on MacOS */
   332 /* take care of some name clashes on MacOS */
   337 #if defined(__APPLE__)
   333 #if defined(__APPLE__)
   338 # define GetString OTTD_GetString
   334 	#define GetString OTTD_GetString
   339 # define DrawString OTTD_DrawString
   335 	#define DrawString OTTD_DrawString
   340 # define Random OTTD_Random
   336 	#define Random OTTD_Random
   341 # define CloseConnection OTTD_CloseConnection
   337 	#define CloseConnection OTTD_CloseConnection
   342 #endif /* __APPLE */
   338 #endif /* __APPLE */
   343 
   339 
   344 #ifdef __AMIGA__
   340 #if defined(__AMIGA__)
   345 /* it seems AmigaOS already have a Point declared */
   341 	/* it seems AmigaOS already have a Point declared */
   346 # define Point OTTD_AMIGA_POINT
   342 	#define Point OTTD_AMIGA_POINT
   347 #endif
   343 #endif
   348 
   344 
   349 void
   345 #if !defined(STRGEN)
   350 #ifndef STRGEN
   346 	/* In strgen error is not fatal and returns */
   351 /* In strgen error is not fatal and returns */
   347 	void NORETURN CDECL error(const char *str, ...);
   352 NORETURN
   348 #else
   353 #endif /* STRGEN */
   349 	void CDECL error(const char *str, ...);
   354 CDECL error(const char *str, ...);
   350 #endif
       
   351 
   355 #define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
   352 #define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
   356 
   353 
   357 #if defined(MORPHOS)
   354 #if defined(MORPHOS)
   358 /* MorphOS doesn't have C++ conformant _stricmp... */
   355 	/* MorphOS doesn't have C++ conformant _stricmp... */
   359 #define _stricmp stricmp
   356 	#define _stricmp stricmp
   360 #elif defined(OPENBSD)
   357 #elif defined(OPENBSD)
   361 /* OpenBSD uses strcasecmp(3) */
   358 	/* OpenBSD uses strcasecmp(3) */
   362 #define _stricmp strcasecmp
   359 	#define _stricmp strcasecmp
   363 #endif
   360 #endif
   364 
   361 
   365 #if !defined(MORPHOS) && !defined(OPENBSD)
   362 #if !defined(MORPHOS) && !defined(OPENBSD)
   366 /* MorphOS & OpenBSD don't know wchars, the rest does :( */
   363 	/* MorphOS & OpenBSD don't know wchars, the rest does :( */
   367 #define HAS_WCHAR
   364 	#define HAS_WCHAR
   368 #endif /* !defined(MORPHOS) && !defined(OPENBSD) */
   365 #endif /* !defined(MORPHOS) && !defined(OPENBSD) */
   369 
   366 
   370 #if !defined(MAX_PATH)
   367 #if !defined(MAX_PATH)
   371 # define MAX_PATH 260
   368 	#define MAX_PATH 260
   372 #endif
   369 #endif
   373 
   370 
   374 #endif /* STDAFX_H */
   371 #endif /* STDAFX_H */