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 INT64_MAX (9223372036854775807LL)
00036 #define INT64_MIN (-INT64_MAX - 1)
00037 #define INT16_MAX (32767)
00038 #define INT16_MIN (-INT16_MAX - 1)
00039 #endif
00040
00041 #include <cstdio>
00042 #include <cstddef>
00043 #include <cstring>
00044 #include <cstdlib>
00045 #include <climits>
00046
00047
00048
00049 #if !defined(__APPLE__) || defined(STRGEN)
00050 #include <cassert>
00051 #else
00052 #include "os/macosx/macos.h"
00053 #endif
00054
00055 #if defined(UNIX) || defined(__MINGW32__)
00056 #include <sys/types.h>
00057 #endif
00058
00059 #if defined(__OS2__)
00060 #include <types.h>
00061 #define strcasecmp stricmp
00062 #endif
00063
00064 #if defined(PSP)
00065 #include <psptypes.h>
00066 #include <pspdebug.h>
00067 #include <pspthreadman.h>
00068 #endif
00069
00070 #if defined(__BEOS__)
00071 #include <SupportDefs.h>
00072 #endif
00073
00074 #if defined(SUNOS)
00075 #include <alloca.h>
00076 #endif
00077
00078 #if defined(__MORPHOS__)
00079
00080
00081
00082 #if defined(amigaos)
00083 #undef amigaos
00084 #endif
00085 #if defined(__amigaos__)
00086 #undef __amigaos__
00087 # endif
00088 #if defined(__AMIGA__)
00089 #undef __AMIGA__
00090 #endif
00091 #if defined(AMIGA)
00092 #undef AMIGA
00093 #endif
00094 #if defined(amiga)
00095 #undef amiga
00096 #endif
00097
00098
00099 #define CLIB_USERGROUP_PROTOS_H
00100 #endif
00101
00102 #if defined(__APPLE__)
00103 #include "os/macosx/osx_stdafx.h"
00104 #endif
00105
00106 #if defined(PSP)
00107
00108
00109
00110 #define LIMITED_FDS 8
00111 #define printf pspDebugScreenPrintf
00112 #endif
00113
00114
00115 #define VARARRAY_SIZE
00116
00117
00118 #if defined(__GNUC__)
00119 #define NORETURN __attribute__ ((noreturn))
00120 #define FORCEINLINE inline
00121 #define CDECL
00122 #define __int64 long long
00123 #define GCC_PACK __attribute__((packed))
00124
00125 #if (__GNUC__ == 2)
00126 #undef VARARRAY_SIZE
00127 #define VARARRAY_SIZE 0
00128 #endif
00129 #endif
00130
00131 #if defined(__WATCOMC__)
00132 #define NORETURN
00133 #define FORCEINLINE inline
00134 #define CDECL
00135 #define GCC_PACK
00136 #include <malloc.h>
00137 #endif
00138
00139 #if defined(__MINGW32__) || defined(__CYGWIN__)
00140 #include <malloc.h>
00141 #endif
00142
00143
00144 #if defined(_MSC_VER)
00145 #pragma once
00146
00147
00148 #define NTDDI_VERSION NTDDI_WIN2K // Windows 2000
00149 #define _WIN32_WINNT 0x0500 // Windows 2000
00150 #define _WIN32_WINDOWS 0x400 // Windows 95
00151 #if !defined(WINCE)
00152 #define WINVER 0x0400 // Windows NT 4.0 / Windows 95
00153 #endif
00154 #define _WIN32_IE_ 0x0401 // 4.01 (win98 and NT4SP5+)
00155
00156 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
00157 #pragma warning(disable: 4244) // 'conversion' conversion from 'type1' to 'type2', possible loss of data
00158 #pragma warning(disable: 4761) // integral size mismatch in argument : conversion supplied
00159 #pragma warning(disable: 4200) // nonstandard extension used : zero-sized array in struct/union
00160
00161 #if (_MSC_VER < 1400) // MSVC 2005 safety checks
00162 #error "Only MSVC 2005 or higher are supported. MSVC 2003 and earlier are not!. Upgrade your compiler."
00163 #endif
00164 #pragma warning(disable: 4996) // 'strdup' was declared deprecated
00165 #define _CRT_SECURE_NO_DEPRECATE // all deprecated 'unsafe string functions
00166 #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
00167 #pragma warning(disable: 6011) // code analyzer: Dereferencing NULL pointer 'pfGetAddrInfo': Lines: 995, 996, 998, 999, 1001
00168 #pragma warning(disable: 6326) // code analyzer: potential comparison of a constant with another constant
00169 #pragma warning(disable: 6031) // code analyzer: Return value ignored: 'ReadFile'
00170 #pragma warning(disable: 6255) // code analyzer: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead
00171 #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 ...
00172
00173 #include <malloc.h>
00174 #define NORETURN __declspec(noreturn)
00175 #define FORCEINLINE __forceinline
00176 #define inline _inline
00177
00178 #if !defined(WINCE)
00179 #define CDECL _cdecl
00180 #endif
00181
00182 int CDECL snprintf(char *str, size_t size, const char *format, ...);
00183 #if (_MSC_VER < 1400) || defined(WINCE)
00184 int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap);
00185 #endif
00186
00187 #if defined(WIN32) && !defined(_WIN64) && !defined(WIN64)
00188 #if !defined(_W64)
00189 #define _W64
00190 #endif
00191
00192 typedef _W64 int INT_PTR, *PINT_PTR;
00193 typedef _W64 unsigned int UINT_PTR, *PUINT_PTR;
00194 #endif
00195
00196 #define GCC_PACK
00197
00198
00199 #if defined(WITH_ZLIB) || defined(WITH_PNG)
00200 #if !defined(ZLIB_WINAPI)
00201 #define ZLIB_WINAPI
00202 #endif
00203 #endif
00204
00205 #if defined(WINCE)
00206 #define strcasecmp _stricmp
00207 #define strncasecmp _strnicmp
00208 #undef DEBUG
00209 #else
00210 #define strcasecmp stricmp
00211 #define strncasecmp strnicmp
00212 #endif
00213
00214 void SetExceptionString(const char* s, ...);
00215
00216 #if defined(NDEBUG) && defined(WITH_ASSERT)
00217 #undef assert
00218 #define assert(expression) if (!(expression)) { SetExceptionString("Assertion failed at %s:%d: %s", __FILE__, __LINE__, #expression); *(byte*)0 = 0; }
00219 #endif
00220 #endif
00221
00222 #if defined(WINCE)
00223 #define strdup _strdup
00224 #endif
00225
00226
00227
00228 #if !defined(STRGEN)
00229 #if defined(WIN32) || defined(WIN64)
00230 char *getcwd(char *buf, size_t size);
00231 #include <tchar.h>
00232
00233
00234 #if !defined(WINCE)
00235 #define fopen(file, mode) _tfopen(OTTD2FS(file), _T(mode))
00236 #endif
00237
00238 const char *FS2OTTD(const TCHAR *name);
00239 const TCHAR *OTTD2FS(const char *name);
00240 #else
00241 #define fopen(file, mode) fopen(OTTD2FS(file), mode)
00242 const char *FS2OTTD(const char *name);
00243 const char *OTTD2FS(const char *name);
00244 #endif
00245 #endif
00246
00247 #if defined(WIN32) || defined(WIN64) || defined(__OS2__) && !defined(__INNOTEK_LIBC__)
00248 #define PATHSEP "\\"
00249 #define PATHSEPCHAR '\\'
00250 #else
00251 #define PATHSEP "/"
00252 #define PATHSEPCHAR '/'
00253 #endif
00254
00255 typedef unsigned char byte;
00256
00257
00258 #if (!defined(UNIX) && !defined(__CYGWIN__) && !defined(__BEOS__) && !defined(__MORPHOS__)) || defined(__QNXNTO__)
00259 typedef unsigned int uint;
00260 #endif
00261
00262 #if !defined(__BEOS__) && !defined(__NDS__)
00263 typedef unsigned char uint8;
00264 typedef signed char int8;
00265 typedef unsigned short uint16;
00266 typedef signed short int16;
00267 typedef unsigned int uint32;
00268 typedef signed int int32;
00269 typedef unsigned __int64 uint64;
00270 typedef signed __int64 int64;
00271 #endif
00272
00273 #if !defined(WITH_PERSONAL_DIR)
00274 #define PERSONAL_DIR ""
00275 #endif
00276
00277
00278 #if defined(__OS2__)
00279 #define assert_compile(expr)
00280 #else
00281 #define assert_compile(expr) extern const int __ct_assert__[1 - 2 * !(expr)]
00282 #endif
00283
00284
00285 assert_compile(sizeof(uint64) == 8);
00286 assert_compile(sizeof(uint32) == 4);
00287 assert_compile(sizeof(uint16) == 2);
00288 assert_compile(sizeof(uint8) == 1);
00289
00290 #define lengthof(x) (sizeof(x)/sizeof(x[0]))
00291 #define endof(x) (&x[lengthof(x)])
00292 #define lastof(x) (&x[lengthof(x) - 1])
00293
00294 #define cpp_offsetof(s,m) (((size_t)&reinterpret_cast<const volatile char&>((((s*)(char*)8)->m))) - 8)
00295 #if !defined(offsetof)
00296 #define offsetof(s,m) cpp_offsetof(s, m)
00297 #endif
00298
00299
00300
00301 #if defined(__APPLE__)
00302 #define GetString OTTD_GetString
00303 #define DrawString OTTD_DrawString
00304 #define CloseConnection OTTD_CloseConnection
00305 #endif
00306
00307 #if !defined(STRGEN)
00308
00309 void NORETURN CDECL error(const char *str, ...);
00310 #else
00311 void CDECL error(const char *str, ...);
00312 #endif
00313
00314 #define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
00315
00316 #if defined(MORPHOS) || defined(__NDS__)
00317
00318 #define _stricmp stricmp
00319 #elif defined(OPENBSD)
00320
00321 #define _stricmp strcasecmp
00322 #endif
00323
00324 #if !defined(MORPHOS) && !defined(OPENBSD) && !defined(__NDS__)
00325
00326 #define HAS_WCHAR
00327 #endif
00328
00329 #if !defined(MAX_PATH)
00330 #define MAX_PATH 260
00331 #endif
00332
00337 #define MAX_UVALUE(type) ((type)~(type)0)
00338
00339 #endif