mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-16 10:50:53 +00:00
sdl 2.0.8 update
This commit is contained in:
parent
7f674a59c6
commit
bfb08f9482
894 changed files with 66879 additions and 43299 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -18,24 +18,20 @@
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
|
||||
#if defined(__clang_analyzer__)
|
||||
#define SDL_DISABLE_ANALYZE_MACROS 1
|
||||
#endif
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE 1
|
||||
#endif
|
||||
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
/* This file contains portable string manipulation functions for SDL */
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
|
||||
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOLL) || !defined(HAVE_STRTOULL) || !defined(HAVE_STRTOD)
|
||||
#define SDL_isupperhex(X) (((X) >= 'A') && ((X) <= 'F'))
|
||||
#define SDL_islowerhex(X) (((X) >= 'a') && ((X) <= 'f'))
|
||||
#endif
|
||||
|
||||
#define UTF8_IsLeadByte(c) ((c) >= 0xC0 && (c) <= 0xF4)
|
||||
#define UTF8_IsTrailingByte(c) ((c) >= 0x80 && (c) <= 0xBF)
|
||||
|
|
@ -82,7 +78,7 @@ SDL_ScanLong(const char *text, int radix, long *valuep)
|
|||
value += v;
|
||||
++text;
|
||||
}
|
||||
if (valuep) {
|
||||
if (valuep && text > textstart) {
|
||||
if (negative && value) {
|
||||
*valuep = -value;
|
||||
} else {
|
||||
|
|
@ -118,7 +114,7 @@ SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)
|
|||
value += v;
|
||||
++text;
|
||||
}
|
||||
if (valuep) {
|
||||
if (valuep && text > textstart) {
|
||||
*valuep = value;
|
||||
}
|
||||
return (text - textstart);
|
||||
|
|
@ -150,7 +146,7 @@ SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep)
|
|||
value += v;
|
||||
++text;
|
||||
}
|
||||
if (valuep) {
|
||||
if (valuep && text > textstart) {
|
||||
*valuep = value;
|
||||
}
|
||||
return (text - textstart);
|
||||
|
|
@ -187,7 +183,7 @@ SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep)
|
|||
value += v;
|
||||
++text;
|
||||
}
|
||||
if (valuep) {
|
||||
if (valuep && text > textstart) {
|
||||
if (negative && value) {
|
||||
*valuep = -value;
|
||||
} else {
|
||||
|
|
@ -223,7 +219,7 @@ SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep)
|
|||
value += v;
|
||||
++text;
|
||||
}
|
||||
if (valuep) {
|
||||
if (valuep && text > textstart) {
|
||||
*valuep = value;
|
||||
}
|
||||
return (text - textstart);
|
||||
|
|
@ -255,7 +251,7 @@ SDL_ScanFloat(const char *text, double *valuep)
|
|||
++text;
|
||||
}
|
||||
}
|
||||
if (valuep) {
|
||||
if (valuep && text > textstart) {
|
||||
if (negative && value) {
|
||||
*valuep = -value;
|
||||
} else {
|
||||
|
|
@ -465,6 +461,22 @@ SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t max
|
|||
#endif /* HAVE_WCSLCAT */
|
||||
}
|
||||
|
||||
int
|
||||
SDL_wcscmp(const wchar_t *str1, const wchar_t *str2)
|
||||
{
|
||||
#if defined(HAVE_WCSCMP)
|
||||
return wcscmp(str1, str2);
|
||||
#else
|
||||
while (*str1 && *str2) {
|
||||
if (*str1 != *str2)
|
||||
break;
|
||||
++str1;
|
||||
++str2;
|
||||
}
|
||||
return (int)(*str1 - *str2);
|
||||
#endif /* HAVE_WCSCMP */
|
||||
}
|
||||
|
||||
size_t
|
||||
SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
|
||||
{
|
||||
|
|
@ -481,7 +493,8 @@ SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
|
|||
#endif /* HAVE_STRLCPY */
|
||||
}
|
||||
|
||||
size_t SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
|
||||
size_t
|
||||
SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
|
||||
{
|
||||
size_t src_bytes = SDL_strlen(src);
|
||||
size_t bytes = SDL_min(src_bytes, dst_bytes - 1);
|
||||
|
|
@ -513,6 +526,23 @@ size_t SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size
|
|||
return bytes;
|
||||
}
|
||||
|
||||
size_t
|
||||
SDL_utf8strlen(const char *str)
|
||||
{
|
||||
size_t retval = 0;
|
||||
const char *p = str;
|
||||
char ch;
|
||||
|
||||
while ((ch = *(p++))) {
|
||||
/* if top two bits are 1 and 0, it's a continuation byte. */
|
||||
if ((ch & 0xc0) != 0x80) {
|
||||
retval++;
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
size_t
|
||||
SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
|
||||
{
|
||||
|
|
@ -531,16 +561,12 @@ SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
|
|||
char *
|
||||
SDL_strdup(const char *string)
|
||||
{
|
||||
#if defined(HAVE_STRDUP)
|
||||
return strdup(string);
|
||||
#else
|
||||
size_t len = SDL_strlen(string) + 1;
|
||||
char *newstr = SDL_malloc(len);
|
||||
if (newstr) {
|
||||
SDL_strlcpy(newstr, string, len);
|
||||
SDL_memcpy(newstr, string, len);
|
||||
}
|
||||
return newstr;
|
||||
#endif /* HAVE_STRDUP */
|
||||
}
|
||||
|
||||
char *
|
||||
|
|
@ -789,7 +815,7 @@ SDL_strtol(const char *string, char **endp, int base)
|
|||
return strtol(string, endp, base);
|
||||
#else
|
||||
size_t len;
|
||||
long value;
|
||||
long value = 0;
|
||||
|
||||
if (!base) {
|
||||
if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
|
||||
|
|
@ -814,7 +840,7 @@ SDL_strtoul(const char *string, char **endp, int base)
|
|||
return strtoul(string, endp, base);
|
||||
#else
|
||||
size_t len;
|
||||
unsigned long value;
|
||||
unsigned long value = 0;
|
||||
|
||||
if (!base) {
|
||||
if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
|
||||
|
|
@ -839,7 +865,7 @@ SDL_strtoll(const char *string, char **endp, int base)
|
|||
return strtoll(string, endp, base);
|
||||
#else
|
||||
size_t len;
|
||||
Sint64 value;
|
||||
Sint64 value = 0;
|
||||
|
||||
if (!base) {
|
||||
if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
|
||||
|
|
@ -864,7 +890,7 @@ SDL_strtoull(const char *string, char **endp, int base)
|
|||
return strtoull(string, endp, base);
|
||||
#else
|
||||
size_t len;
|
||||
Uint64 value;
|
||||
Uint64 value = 0;
|
||||
|
||||
if (!base) {
|
||||
if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
|
||||
|
|
@ -889,7 +915,7 @@ SDL_strtod(const char *string, char **endp)
|
|||
return strtod(string, endp);
|
||||
#else
|
||||
size_t len;
|
||||
double value;
|
||||
double value = 0.0;
|
||||
|
||||
len = SDL_ScanFloat(string, &value);
|
||||
if (endp) {
|
||||
|
|
@ -911,7 +937,7 @@ SDL_strcmp(const char *str1, const char *str2)
|
|||
++str1;
|
||||
++str2;
|
||||
}
|
||||
return (int) ((unsigned char) *str1 - (unsigned char) *str2);
|
||||
return (int)((unsigned char) *str1 - (unsigned char) *str2);
|
||||
#endif /* HAVE_STRCMP */
|
||||
}
|
||||
|
||||
|
|
@ -1011,6 +1037,10 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
|
|||
{
|
||||
int retval = 0;
|
||||
|
||||
if (!text || !*text) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (*fmt) {
|
||||
if (*fmt == ' ') {
|
||||
while (SDL_isspace((unsigned char) *text)) {
|
||||
|
|
@ -1030,6 +1060,7 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
|
|||
DO_LONG,
|
||||
DO_LONGLONG
|
||||
} inttype = DO_INT;
|
||||
size_t advance;
|
||||
SDL_bool suppress = SDL_FALSE;
|
||||
|
||||
++fmt;
|
||||
|
|
@ -1109,16 +1140,18 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
|
|||
case 'd':
|
||||
if (inttype == DO_LONGLONG) {
|
||||
Sint64 value;
|
||||
text += SDL_ScanLongLong(text, radix, &value);
|
||||
if (!suppress) {
|
||||
advance = SDL_ScanLongLong(text, radix, &value);
|
||||
text += advance;
|
||||
if (advance && !suppress) {
|
||||
Sint64 *valuep = va_arg(ap, Sint64 *);
|
||||
*valuep = value;
|
||||
++retval;
|
||||
}
|
||||
} else {
|
||||
long value;
|
||||
text += SDL_ScanLong(text, radix, &value);
|
||||
if (!suppress) {
|
||||
advance = SDL_ScanLong(text, radix, &value);
|
||||
text += advance;
|
||||
if (advance && !suppress) {
|
||||
switch (inttype) {
|
||||
case DO_SHORT:
|
||||
{
|
||||
|
|
@ -1160,17 +1193,19 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
|
|||
/* Fall through to unsigned handling */
|
||||
case 'u':
|
||||
if (inttype == DO_LONGLONG) {
|
||||
Uint64 value;
|
||||
text += SDL_ScanUnsignedLongLong(text, radix, &value);
|
||||
if (!suppress) {
|
||||
Uint64 value = 0;
|
||||
advance = SDL_ScanUnsignedLongLong(text, radix, &value);
|
||||
text += advance;
|
||||
if (advance && !suppress) {
|
||||
Uint64 *valuep = va_arg(ap, Uint64 *);
|
||||
*valuep = value;
|
||||
++retval;
|
||||
}
|
||||
} else {
|
||||
unsigned long value;
|
||||
text += SDL_ScanUnsignedLong(text, radix, &value);
|
||||
if (!suppress) {
|
||||
unsigned long value = 0;
|
||||
advance = SDL_ScanUnsignedLong(text, radix, &value);
|
||||
text += advance;
|
||||
if (advance && !suppress) {
|
||||
switch (inttype) {
|
||||
case DO_SHORT:
|
||||
{
|
||||
|
|
@ -1201,9 +1236,10 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
|
|||
break;
|
||||
case 'p':
|
||||
{
|
||||
uintptr_t value;
|
||||
text += SDL_ScanUintPtrT(text, 16, &value);
|
||||
if (!suppress) {
|
||||
uintptr_t value = 0;
|
||||
advance = SDL_ScanUintPtrT(text, 16, &value);
|
||||
text += advance;
|
||||
if (advance && !suppress) {
|
||||
void **valuep = va_arg(ap, void **);
|
||||
*valuep = (void *) value;
|
||||
++retval;
|
||||
|
|
@ -1214,8 +1250,9 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
|
|||
case 'f':
|
||||
{
|
||||
double value;
|
||||
text += SDL_ScanFloat(text, &value);
|
||||
if (!suppress) {
|
||||
advance = SDL_ScanFloat(text, &value);
|
||||
text += advance;
|
||||
if (advance && !suppress) {
|
||||
float *valuep = va_arg(ap, float *);
|
||||
*valuep = (float) value;
|
||||
++retval;
|
||||
|
|
@ -1317,6 +1354,10 @@ SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *str
|
|||
size_t length = 0;
|
||||
size_t slen;
|
||||
|
||||
if (string == NULL) {
|
||||
string = "(null)";
|
||||
}
|
||||
|
||||
if (info && info->width && (size_t)info->width > SDL_strlen(string)) {
|
||||
char fill = info->pad_zeroes ? '0' : ' ';
|
||||
size_t width = info->width - SDL_strlen(string);
|
||||
|
|
@ -1488,7 +1529,7 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
|
|||
if (!fmt) {
|
||||
fmt = "";
|
||||
}
|
||||
while (*fmt) {
|
||||
while (*fmt && left > 1) {
|
||||
if (*fmt == '%') {
|
||||
SDL_bool done = SDL_FALSE;
|
||||
size_t len = 0;
|
||||
|
|
@ -1632,6 +1673,16 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
|
|||
len = SDL_PrintFloat(text, left, &info, va_arg(ap, double));
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
case 'S':
|
||||
{
|
||||
/* In practice this is used on Windows for WCHAR strings */
|
||||
wchar_t *wide_arg = va_arg(ap, wchar_t *);
|
||||
char *arg = SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(wide_arg), (SDL_wcslen(wide_arg)+1)*sizeof(*wide_arg));
|
||||
len = SDL_PrintString(text, left, &info, arg);
|
||||
SDL_free(arg);
|
||||
done = SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
len = SDL_PrintString(text, left, &info, va_arg(ap, char *));
|
||||
done = SDL_TRUE;
|
||||
|
|
@ -1650,12 +1701,8 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
|
|||
left -= len;
|
||||
}
|
||||
} else {
|
||||
if (left > 1) {
|
||||
*text = *fmt;
|
||||
--left;
|
||||
}
|
||||
++fmt;
|
||||
++text;
|
||||
*text++ = *fmt++;
|
||||
--left;
|
||||
}
|
||||
}
|
||||
if (left > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue