00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00027 #ifndef _SDL_stdinc_h
00028 #define _SDL_stdinc_h
00029
00030 #include "SDL_config.h"
00031
00032
00033 #ifdef HAVE_SYS_TYPES_H
00034 #include <sys/types.h>
00035 #endif
00036 #ifdef HAVE_STDIO_H
00037 #include <stdio.h>
00038 #endif
00039 #if defined(STDC_HEADERS)
00040 # include <stdlib.h>
00041 # include <stddef.h>
00042 # include <stdarg.h>
00043 #else
00044 # if defined(HAVE_STDLIB_H)
00045 # include <stdlib.h>
00046 # elif defined(HAVE_MALLOC_H)
00047 # include <malloc.h>
00048 # endif
00049 # if defined(HAVE_STDDEF_H)
00050 # include <stddef.h>
00051 # endif
00052 # if defined(HAVE_STDARG_H)
00053 # include <stdarg.h>
00054 # endif
00055 #endif
00056 #ifdef HAVE_STRING_H
00057 # if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
00058 # include <memory.h>
00059 # endif
00060 # include <string.h>
00061 #endif
00062 #ifdef HAVE_STRINGS_H
00063 # include <strings.h>
00064 #endif
00065 #if defined(HAVE_INTTYPES_H)
00066 # include <inttypes.h>
00067 #elif defined(HAVE_STDINT_H)
00068 # include <stdint.h>
00069 #endif
00070 #ifdef HAVE_CTYPE_H
00071 # include <ctype.h>
00072 #endif
00073 #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
00074 # include <iconv.h>
00075 #endif
00076
00078 #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
00079 #define SDL_TABLESIZE(table) SDL_arraysize(table)
00080
00081
00082
00083 #ifdef __cplusplus
00084 #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
00085 #define SDL_static_cast(type, expression) static_cast<type>(expression)
00086 #else
00087 #define SDL_reinterpret_cast(type, expression) ((type)(expression))
00088 #define SDL_static_cast(type, expression) ((type)(expression))
00089 #endif
00090
00093 typedef enum SDL_bool {
00094 SDL_FALSE = 0,
00095 SDL_TRUE = 1
00096 } SDL_bool;
00097
00098 typedef int8_t Sint8;
00099 typedef uint8_t Uint8;
00100 typedef int16_t Sint16;
00101 typedef uint16_t Uint16;
00102 typedef int32_t Sint32;
00103 typedef uint32_t Uint32;
00104
00105 #ifdef SDL_HAS_64BIT_TYPE
00106 typedef int64_t Sint64;
00107 #ifndef SYMBIAN32_GCCE
00108 typedef uint64_t Uint64;
00109 #endif
00110 #else
00111
00112 typedef struct {
00113 Uint32 hi;
00114 Uint32 lo;
00115 } Uint64, Sint64;
00116 #endif
00117
00122 #define SDL_COMPILE_TIME_ASSERT(name, x) \
00123 typedef int SDL_dummy_ ## name[(x) * 2 - 1]
00124
00125 SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
00126 SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
00127 SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
00128 SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
00129 SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
00130 SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
00131 SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
00132 SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
00141
00142 #ifdef __MWERKS__
00143 #pragma enumsalwaysint on
00144 #endif
00145
00146 typedef enum {
00147 DUMMY_ENUM_VALUE
00148 } SDL_DUMMY_ENUM;
00149
00150 #ifndef __NDS__
00151 SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
00152 #endif
00153
00155 #include "begin_code.h"
00156
00157 #ifdef __cplusplus
00158 extern "C" {
00159 #endif
00160
00161 #ifdef HAVE_MALLOC
00162 #define SDL_malloc malloc
00163 #else
00164 extern DECLSPEC void * SDLCALL SDL_malloc(size_t size);
00165 #endif
00166
00167 #ifdef HAVE_CALLOC
00168 #define SDL_calloc calloc
00169 #else
00170 extern DECLSPEC void * SDLCALL SDL_calloc(size_t nmemb, size_t size);
00171 #endif
00172
00173 #ifdef HAVE_REALLOC
00174 #define SDL_realloc realloc
00175 #else
00176 extern DECLSPEC void * SDLCALL SDL_realloc(void *mem, size_t size);
00177 #endif
00178
00179 #ifdef HAVE_FREE
00180 #define SDL_free free
00181 #else
00182 extern DECLSPEC void SDLCALL SDL_free(void *mem);
00183 #endif
00184
00185 #if defined(HAVE_ALLOCA) && !defined(alloca)
00186 # if defined(HAVE_ALLOCA_H)
00187 # include <alloca.h>
00188 # elif defined(__GNUC__)
00189 # define alloca __builtin_alloca
00190 # elif defined(_MSC_VER)
00191 # include <malloc.h>
00192 # define alloca _alloca
00193 # elif defined(__WATCOMC__)
00194 # include <malloc.h>
00195 # elif defined(__BORLANDC__)
00196 # include <malloc.h>
00197 # elif defined(__DMC__)
00198 # include <stdlib.h>
00199 # elif defined(__AIX__)
00200 #pragma alloca
00201 # elif defined(__MRC__)
00202 void *alloca (unsigned);
00203 # else
00204 char *alloca ();
00205 # endif
00206 #endif
00207 #ifdef HAVE_ALLOCA
00208 #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
00209 #define SDL_stack_free(data)
00210 #else
00211 #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
00212 #define SDL_stack_free(data) SDL_free(data)
00213 #endif
00214
00215 #ifdef HAVE_GETENV
00216 #define SDL_getenv getenv
00217 #else
00218 extern DECLSPEC char * SDLCALL SDL_getenv(const char *name);
00219 #endif
00220
00221 #ifdef HAVE_PUTENV
00222 #define SDL_putenv putenv
00223 #else
00224 extern DECLSPEC int SDLCALL SDL_putenv(const char *variable);
00225 #endif
00226
00227 #ifdef HAVE_QSORT
00228 #define SDL_qsort qsort
00229 #else
00230 extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size,
00231 int (*compare)(const void *, const void *));
00232 #endif
00233
00234 #ifdef HAVE_ABS
00235 #define SDL_abs abs
00236 #else
00237 #define SDL_abs(X) ((X) < 0 ? -(X) : (X))
00238 #endif
00239
00240 #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
00241 #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
00242
00243 #ifdef HAVE_CTYPE_H
00244 #define SDL_isdigit(X) isdigit(X)
00245 #define SDL_isspace(X) isspace(X)
00246 #define SDL_toupper(X) toupper(X)
00247 #define SDL_tolower(X) tolower(X)
00248 #else
00249 #define SDL_isdigit(X) (((X) >= '0') && ((X) <= '9'))
00250 #define SDL_isspace(X) (((X) == ' ') || ((X) == '\t') || ((X) == '\r') || ((X) == '\n'))
00251 #define SDL_toupper(X) (((X) >= 'a') && ((X) <= 'z') ? ('A'+((X)-'a')) : (X))
00252 #define SDL_tolower(X) (((X) >= 'A') && ((X) <= 'Z') ? ('a'+((X)-'A')) : (X))
00253 #endif
00254
00255 #ifdef HAVE_MEMSET
00256 #define SDL_memset memset
00257 #else
00258 extern DECLSPEC void * SDLCALL SDL_memset(void *dst, int c, size_t len);
00259 #endif
00260
00261 #if defined(__GNUC__) && defined(i386)
00262 #define SDL_memset4(dst, val, len) \
00263 do { \
00264 int u0, u1, u2; \
00265 __asm__ __volatile__ ( \
00266 "cld\n\t" \
00267 "rep ; stosl\n\t" \
00268 : "=&D" (u0), "=&a" (u1), "=&c" (u2) \
00269 : "0" (dst), "1" (val), "2" ((Uint32)(len)) \
00270 : "memory" ); \
00271 } while(0)
00272 #endif
00273 #ifndef SDL_memset4
00274 #define SDL_memset4(dst, val, len) \
00275 do { \
00276 unsigned _count = (len); \
00277 unsigned _n = (_count + 3) / 4; \
00278 Uint32 *_p = (Uint32 *)(dst); \
00279 Uint32 _val = (val); \
00280 if (len == 0) break; \
00281 switch (_count % 4) { \
00282 case 0: do { *_p++ = _val; \
00283 case 3: *_p++ = _val; \
00284 case 2: *_p++ = _val; \
00285 case 1: *_p++ = _val; \
00286 } while ( --_n ); \
00287 } \
00288 } while(0)
00289 #endif
00290
00291
00292 #if defined(__MACH__) && defined(__APPLE__)
00293 #define SDL_memcpy(dst, src, len) memcpy(dst, src, len)
00294 #elif defined(__GNUC__) && defined(i386)
00295 #define SDL_memcpy(dst, src, len) \
00296 do { \
00297 int u0, u1, u2; \
00298 __asm__ __volatile__ ( \
00299 "cld\n\t" \
00300 "rep ; movsl\n\t" \
00301 "testb $2,%b4\n\t" \
00302 "je 1f\n\t" \
00303 "movsw\n" \
00304 "1:\ttestb $1,%b4\n\t" \
00305 "je 2f\n\t" \
00306 "movsb\n" \
00307 "2:" \
00308 : "=&c" (u0), "=&D" (u1), "=&S" (u2) \
00309 : "0" ((unsigned)(len)/4), "q" (len), "1" (dst),"2" (src) \
00310 : "memory" ); \
00311 } while(0)
00312 #endif
00313 #ifndef SDL_memcpy
00314 #ifdef HAVE_MEMCPY
00315 #define SDL_memcpy memcpy
00316 #elif defined(HAVE_BCOPY)
00317 #define SDL_memcpy(d, s, n) bcopy((s), (d), (n))
00318 #else
00319 extern DECLSPEC void * SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
00320 #endif
00321 #endif
00322
00323
00324 #if defined(__MACH__) && defined(__APPLE__)
00325 #define SDL_memcpy4(dst, src, len) memcpy(dst, src, (len)*4)
00326 #elif defined(__GNUC__) && defined(i386)
00327 #define SDL_memcpy4(dst, src, len) \
00328 do { \
00329 int ecx, edi, esi; \
00330 __asm__ __volatile__ ( \
00331 "cld\n\t" \
00332 "rep ; movsl" \
00333 : "=&c" (ecx), "=&D" (edi), "=&S" (esi) \
00334 : "0" ((unsigned)(len)), "1" (dst), "2" (src) \
00335 : "memory" ); \
00336 } while(0)
00337 #endif
00338 #ifndef SDL_memcpy4
00339 #define SDL_memcpy4(dst, src, len) SDL_memcpy(dst, src, (len) << 2)
00340 #endif
00341
00342 #if defined(__GNUC__) && defined(i386)
00343 #define SDL_revcpy(dst, src, len) \
00344 do { \
00345 int u0, u1, u2; \
00346 char *dstp = (char *)(dst); \
00347 char *srcp = (char *)(src); \
00348 int n = (len); \
00349 if ( n >= 4 ) { \
00350 __asm__ __volatile__ ( \
00351 "std\n\t" \
00352 "rep ; movsl\n\t" \
00353 "cld\n\t" \
00354 : "=&c" (u0), "=&D" (u1), "=&S" (u2) \
00355 : "0" (n >> 2), \
00356 "1" (dstp+(n-4)), "2" (srcp+(n-4)) \
00357 : "memory" ); \
00358 } \
00359 switch (n & 3) { \
00360 case 3: dstp[2] = srcp[2]; \
00361 case 2: dstp[1] = srcp[1]; \
00362 case 1: dstp[0] = srcp[0]; \
00363 break; \
00364 default: \
00365 break; \
00366 } \
00367 } while(0)
00368 #endif
00369 #ifndef SDL_revcpy
00370 extern DECLSPEC void * SDLCALL SDL_revcpy(void *dst, const void *src, size_t len);
00371 #endif
00372
00373 #ifdef HAVE_MEMMOVE
00374 #define SDL_memmove memmove
00375 #elif defined(HAVE_BCOPY)
00376 #define SDL_memmove(d, s, n) bcopy((s), (d), (n))
00377 #else
00378 #define SDL_memmove(dst, src, len) \
00379 do { \
00380 if ( dst < src ) { \
00381 SDL_memcpy(dst, src, len); \
00382 } else { \
00383 SDL_revcpy(dst, src, len); \
00384 } \
00385 } while(0)
00386 #endif
00387
00388 #ifdef HAVE_MEMCMP
00389 #define SDL_memcmp memcmp
00390 #else
00391 extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
00392 #endif
00393
00394 #ifdef HAVE_STRLEN
00395 #define SDL_strlen strlen
00396 #else
00397 extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string);
00398 #endif
00399
00400 #ifdef HAVE_STRLCPY
00401 #define SDL_strlcpy strlcpy
00402 #else
00403 extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
00404 #endif
00405
00406 #ifdef HAVE_STRLCAT
00407 #define SDL_strlcat strlcat
00408 #else
00409 extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
00410 #endif
00411
00412 #ifdef HAVE_STRDUP
00413 #define SDL_strdup strdup
00414 #else
00415 extern DECLSPEC char * SDLCALL SDL_strdup(const char *string);
00416 #endif
00417
00418 #ifdef HAVE__STRREV
00419 #define SDL_strrev _strrev
00420 #else
00421 extern DECLSPEC char * SDLCALL SDL_strrev(char *string);
00422 #endif
00423
00424 #ifdef HAVE__STRUPR
00425 #define SDL_strupr _strupr
00426 #else
00427 extern DECLSPEC char * SDLCALL SDL_strupr(char *string);
00428 #endif
00429
00430 #ifdef HAVE__STRLWR
00431 #define SDL_strlwr _strlwr
00432 #else
00433 extern DECLSPEC char * SDLCALL SDL_strlwr(char *string);
00434 #endif
00435
00436 #ifdef HAVE_STRCHR
00437 #define SDL_strchr strchr
00438 #elif defined(HAVE_INDEX)
00439 #define SDL_strchr index
00440 #else
00441 extern DECLSPEC char * SDLCALL SDL_strchr(const char *string, int c);
00442 #endif
00443
00444 #ifdef HAVE_STRRCHR
00445 #define SDL_strrchr strrchr
00446 #elif defined(HAVE_RINDEX)
00447 #define SDL_strrchr rindex
00448 #else
00449 extern DECLSPEC char * SDLCALL SDL_strrchr(const char *string, int c);
00450 #endif
00451
00452 #ifdef HAVE_STRSTR
00453 #define SDL_strstr strstr
00454 #else
00455 extern DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
00456 #endif
00457
00458 #ifdef HAVE_ITOA
00459 #define SDL_itoa itoa
00460 #else
00461 #define SDL_itoa(value, string, radix) SDL_ltoa((long)value, string, radix)
00462 #endif
00463
00464 #ifdef HAVE__LTOA
00465 #define SDL_ltoa _ltoa
00466 #else
00467 extern DECLSPEC char * SDLCALL SDL_ltoa(long value, char *string, int radix);
00468 #endif
00469
00470 #ifdef HAVE__UITOA
00471 #define SDL_uitoa _uitoa
00472 #else
00473 #define SDL_uitoa(value, string, radix) SDL_ultoa((long)value, string, radix)
00474 #endif
00475
00476 #ifdef HAVE__ULTOA
00477 #define SDL_ultoa _ultoa
00478 #else
00479 extern DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *string, int radix);
00480 #endif
00481
00482 #ifdef HAVE_STRTOL
00483 #define SDL_strtol strtol
00484 #else
00485 extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp, int base);
00486 #endif
00487
00488 #ifdef HAVE_STRTOUL
00489 #define SDL_strtoul strtoul
00490 #else
00491 extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string, char **endp, int base);
00492 #endif
00493
00494 #ifdef SDL_HAS_64BIT_TYPE
00495
00496 #ifdef HAVE__I64TOA
00497 #define SDL_lltoa _i64toa
00498 #else
00499 extern DECLSPEC char* SDLCALL SDL_lltoa(Sint64 value, char *string, int radix);
00500 #endif
00501
00502 #ifdef HAVE__UI64TOA
00503 #define SDL_ulltoa _ui64toa
00504 #else
00505 extern DECLSPEC char* SDLCALL SDL_ulltoa(Uint64 value, char *string, int radix);
00506 #endif
00507
00508 #ifdef HAVE_STRTOLL
00509 #define SDL_strtoll strtoll
00510 #else
00511 extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp, int base);
00512 #endif
00513
00514 #ifdef HAVE_STRTOULL
00515 #define SDL_strtoull strtoull
00516 #else
00517 extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp, int base);
00518 #endif
00519
00520 #endif
00521
00522 #ifdef HAVE_STRTOD
00523 #define SDL_strtod strtod
00524 #else
00525 extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp);
00526 #endif
00527
00528 #ifdef HAVE_ATOI
00529 #define SDL_atoi atoi
00530 #else
00531 #define SDL_atoi(X) SDL_strtol(X, NULL, 0)
00532 #endif
00533
00534 #ifdef HAVE_ATOF
00535 #define SDL_atof atof
00536 #else
00537 #define SDL_atof(X) SDL_strtod(X, NULL)
00538 #endif
00539
00540 #ifdef HAVE_STRCMP
00541 #define SDL_strcmp strcmp
00542 #else
00543 extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
00544 #endif
00545
00546 #ifdef HAVE_STRNCMP
00547 #define SDL_strncmp strncmp
00548 #else
00549 extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
00550 #endif
00551
00552 #ifdef HAVE_STRCASECMP
00553 #define SDL_strcasecmp strcasecmp
00554 #elif defined(HAVE__STRICMP)
00555 #define SDL_strcasecmp _stricmp
00556 #else
00557 extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
00558 #endif
00559
00560 #ifdef HAVE_STRNCASECMP
00561 #define SDL_strncasecmp strncasecmp
00562 #elif defined(HAVE__STRNICMP)
00563 #define SDL_strncasecmp _strnicmp
00564 #else
00565 extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
00566 #endif
00567
00568 #ifdef HAVE_SSCANF
00569 #define SDL_sscanf sscanf
00570 #else
00571 extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
00572 #endif
00573
00574 #ifdef HAVE_SNPRINTF
00575 #define SDL_snprintf snprintf
00576 #else
00577 extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
00578 #endif
00579
00580 #ifdef HAVE_VSNPRINTF
00581 #define SDL_vsnprintf vsnprintf
00582 #else
00583 extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
00584 #endif
00585
00590 #define SDL_ICONV_ERROR (size_t)-1
00591 #define SDL_ICONV_E2BIG (size_t)-2
00592 #define SDL_ICONV_EILSEQ (size_t)-3
00593 #define SDL_ICONV_EINVAL (size_t)-4
00594
00596 #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
00597 #define SDL_iconv_t iconv_t
00598 #define SDL_iconv_open iconv_open
00599 #define SDL_iconv_close iconv_close
00600 #else
00601 typedef struct _SDL_iconv_t *SDL_iconv_t;
00602 extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode, const char *fromcode);
00603 extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
00604 #endif
00605 extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
00609 extern DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft);
00610 #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
00611 #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
00612 #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
00613
00614
00615 #ifdef __cplusplus
00616 }
00617 #endif
00618 #include "close_code.h"
00619
00620 #endif