Update for SDL3 coding style (#6717)

I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.

In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.

The script I ran for the src directory is added as build-scripts/clang-format-src.sh

This fixes:
#6592
#6593
#6594
This commit is contained in:
Sam Lantinga
2022-11-30 12:51:59 -08:00
committed by GitHub
parent 14b902faca
commit 5750bcb174
781 changed files with 51659 additions and 55763 deletions

View File

@@ -20,8 +20,6 @@
*/
#include "SDL_internal.h"
/* Public domain CRC implementation adapted from:
http://home.thep.lu.se/~bjorn/crc/crc32_simple.c
@@ -37,7 +35,7 @@ static Uint16 crc16_for_byte(Uint8 r)
Uint16 crc = 0;
int i;
for (i = 0; i < 8; ++i) {
crc = ((crc ^ r) & 1? 0xA001 : 0) ^ crc >> 1;
crc = ((crc ^ r) & 1 ? 0xA001 : 0) ^ crc >> 1;
r >>= 1;
}
return crc;
@@ -48,7 +46,7 @@ Uint16 SDL_crc16(Uint16 crc, const void *data, size_t len)
/* As an optimization we can precalculate a 256 entry table for each byte */
size_t i;
for (i = 0; i < len; ++i) {
crc = crc16_for_byte((Uint8)crc ^ ((const Uint8*)data)[i]) ^ crc >> 8;
crc = crc16_for_byte((Uint8)crc ^ ((const Uint8 *)data)[i]) ^ crc >> 8;
}
return crc;
}

View File

@@ -20,8 +20,6 @@
*/
#include "SDL_internal.h"
/* Public domain CRC implementation adapted from:
http://home.thep.lu.se/~bjorn/crc/crc32_simple.c
@@ -36,7 +34,7 @@ static Uint32 crc32_for_byte(Uint32 r)
{
int i;
for (i = 0; i < 8; ++i) {
r = (r & 1? 0: (Uint32)0xEDB88320L) ^ r >> 1;
r = (r & 1 ? 0 : (Uint32)0xEDB88320L) ^ r >> 1;
}
return r ^ (Uint32)0xFF000000L;
}
@@ -46,7 +44,7 @@ Uint32 SDL_crc32(Uint32 crc, const void *data, size_t len)
/* As an optimization we can precalculate a 256 entry table for each byte */
size_t i;
for (i = 0; i < len; ++i) {
crc = crc32_for_byte((Uint8)crc ^ ((const Uint8*)data)[i]) ^ crc >> 8;
crc = crc32_for_byte((Uint8)crc ^ ((const Uint8 *)data)[i]) ^ crc >> 8;
}
return crc;
}

View File

@@ -28,7 +28,6 @@
#include "../core/android/SDL_android.h"
#endif
#if (defined(__WIN32__) || defined(__WINGDK__)) && (!defined(HAVE_SETENV) || !defined(HAVE_GETENV))
/* Note this isn't thread-safe! */
static char *SDL_envmem = NULL; /* Ugh, memory leak */
@@ -38,28 +37,26 @@ static size_t SDL_envmemlen = 0;
/* Put a variable into the environment */
/* Note: Name may not contain a '=' character. (Reference: http://www.unix.com/man-page/Linux/3/setenv/) */
#if defined(HAVE_SETENV)
int
SDL_setenv(const char *name, const char *value, int overwrite)
int SDL_setenv(const char *name, const char *value, int overwrite)
{
/* Input validation */
if (name == NULL || *name == '\0' || SDL_strchr(name, '=') != NULL || value == NULL) {
return -1;
}
return setenv(name, value, overwrite);
}
#elif defined(__WIN32__) || defined(__WINGDK__)
int
SDL_setenv(const char *name, const char *value, int overwrite)
int SDL_setenv(const char *name, const char *value, int overwrite)
{
/* Input validation */
if (name == NULL || *name == '\0' || SDL_strchr(name, '=') != NULL || value == NULL) {
return -1;
}
if (!overwrite) {
if (GetEnvironmentVariableA(name, NULL, 0) > 0) {
return 0; /* asked not to overwrite existing value. */
return 0; /* asked not to overwrite existing value. */
}
}
if (!SetEnvironmentVariableA(name, *value ? value : NULL)) {
@@ -69,8 +66,7 @@ SDL_setenv(const char *name, const char *value, int overwrite)
}
/* We have a real environment table, but no real setenv? Fake it w/ putenv. */
#elif (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV))
int
SDL_setenv(const char *name, const char *value, int overwrite)
int SDL_setenv(const char *name, const char *value, int overwrite)
{
size_t len;
char *new_variable;
@@ -79,18 +75,18 @@ SDL_setenv(const char *name, const char *value, int overwrite)
if (name == NULL || *name == '\0' || SDL_strchr(name, '=') != NULL || value == NULL) {
return -1;
}
if (getenv(name) != NULL) {
if (overwrite) {
unsetenv(name);
} else {
return 0; /* leave the existing one there. */
return 0; /* leave the existing one there. */
}
}
/* This leaks. Sorry. Get a better OS so we don't have to do this. */
len = SDL_strlen(name) + SDL_strlen(value) + 2;
new_variable = (char *) SDL_malloc(len);
new_variable = (char *)SDL_malloc(len);
if (new_variable == NULL) {
return -1;
}
@@ -99,9 +95,8 @@ SDL_setenv(const char *name, const char *value, int overwrite)
return putenv(new_variable);
}
#else /* roll our own */
static char **SDL_env = (char **) 0;
int
SDL_setenv(const char *name, const char *value, int overwrite)
static char **SDL_env = (char **)0;
int SDL_setenv(const char *name, const char *value, int overwrite)
{
int added;
size_t len, i;
@@ -120,7 +115,7 @@ SDL_setenv(const char *name, const char *value, int overwrite)
/* Allocate memory for the variable */
len = SDL_strlen(name) + SDL_strlen(value) + 2;
new_variable = (char *) SDL_malloc(len);
new_variable = (char *)SDL_malloc(len);
if (new_variable == NULL) {
return -1;
}
@@ -154,7 +149,7 @@ SDL_setenv(const char *name, const char *value, int overwrite)
if (new_env) {
SDL_env = new_env;
SDL_env[i++] = new_variable;
SDL_env[i++] = (char *) 0;
SDL_env[i++] = (char *)0;
added = 1;
} else {
SDL_free(new_variable);
@@ -191,20 +186,20 @@ SDL_getenv(const char *name)
if (name == NULL || *name == '\0') {
return NULL;
}
bufferlen =
GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
GetEnvironmentVariableA(name, SDL_envmem, (DWORD)SDL_envmemlen);
if (bufferlen == 0) {
return NULL;
}
if (bufferlen > SDL_envmemlen) {
char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen);
char *newmem = (char *)SDL_realloc(SDL_envmem, bufferlen);
if (newmem == NULL) {
return NULL;
}
SDL_envmem = newmem;
SDL_envmemlen = bufferlen;
GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
GetEnvironmentVariableA(name, SDL_envmem, (DWORD)SDL_envmemlen);
}
return SDL_envmem;
}
@@ -219,8 +214,8 @@ SDL_getenv(const char *name)
if (name == NULL || *name == '\0') {
return NULL;
}
value = (char *) 0;
value = (char *)0;
if (SDL_env) {
len = SDL_strlen(name);
for (i = 0; SDL_env[i] && value == NULL; ++i) {
@@ -234,12 +229,10 @@ SDL_getenv(const char *name)
}
#endif
#ifdef TEST_MAIN
#include <stdio.h>
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
char *value;

File diff suppressed because it is too large Load Diff

View File

@@ -36,26 +36,24 @@ __declspec(selectany) int _fltused = 1;
/* The optimizer on Visual Studio 2005 and later generates memcpy() and memset() calls.
Always provide it for the SDL3 DLL, but skip it when building static lib w/ static runtime. */
#if (_MSC_VER >= 1400) && (!defined(_MT) || defined(DLL_EXPORT))
extern void *memcpy(void* dst, const void* src, size_t len);
extern void *memcpy(void *dst, const void *src, size_t len);
#pragma intrinsic(memcpy)
#if !defined(__clang__)
#pragma function(memcpy)
#endif
void *
memcpy(void *dst, const void *src, size_t len)
void *memcpy(void *dst, const void *src, size_t len)
{
return SDL_memcpy(dst, src, len);
}
extern void *memset(void* dst, int c, size_t len);
extern void *memset(void *dst, int c, size_t len);
#pragma intrinsic(memset)
#if !defined(__clang__)
#pragma function(memset)
#endif
void *
memset(void *dst, int c, size_t len)
void *memset(void *dst, int c, size_t len)
{
return SDL_memset(dst, c, len);
}
@@ -64,9 +62,7 @@ memset(void *dst, int c, size_t len)
#ifdef _M_IX86
/* Float to long */
void
__declspec(naked)
_ftol()
void __declspec(naked) _ftol()
{
/* *INDENT-OFF* */
__asm {
@@ -115,22 +111,18 @@ localexit:
/* *INDENT-ON* */
}
void
_ftol2_sse()
void _ftol2_sse()
{
_ftol();
}
void
_ftol2()
void _ftol2()
{
_ftol();
}
/* 64-bit math operators for 32-bit systems */
void
__declspec(naked)
_allmul()
void __declspec(naked) _allmul()
{
/* *INDENT-OFF* */
__asm {
@@ -158,9 +150,7 @@ hard:
/* *INDENT-ON* */
}
void
__declspec(naked)
_alldiv()
void __declspec(naked) _alldiv()
{
/* *INDENT-OFF* */
__asm {
@@ -246,9 +236,7 @@ L8:
/* *INDENT-ON* */
}
void
__declspec(naked)
_aulldiv()
void __declspec(naked) _aulldiv()
{
/* *INDENT-OFF* */
__asm {
@@ -304,9 +292,7 @@ L2:
/* *INDENT-ON* */
}
void
__declspec(naked)
_allrem()
void __declspec(naked) _allrem()
{
/* *INDENT-OFF* */
__asm {
@@ -391,9 +377,7 @@ L8:
/* *INDENT-ON* */
}
void
__declspec(naked)
_aullrem()
void __declspec(naked) _aullrem()
{
/* *INDENT-OFF* */
__asm {
@@ -450,9 +434,7 @@ L2:
/* *INDENT-ON* */
}
void
__declspec(naked)
_alldvrm()
void __declspec(naked) _alldvrm()
{
/* *INDENT-OFF* */
__asm {
@@ -560,9 +542,7 @@ L8:
/* *INDENT-ON* */
}
void
__declspec(naked)
_aulldvrm()
void __declspec(naked) _aulldvrm()
{
/* *INDENT-OFF* */
__asm {
@@ -633,9 +613,7 @@ L2:
/* *INDENT-ON* */
}
void
__declspec(naked)
_allshl()
void __declspec(naked) _allshl()
{
/* *INDENT-OFF* */
__asm {
@@ -660,9 +638,7 @@ RETZERO:
/* *INDENT-ON* */
}
void
__declspec(naked)
_allshr()
void __declspec(naked) _allshr()
{
/* *INDENT-OFF* */
__asm {
@@ -687,9 +663,7 @@ RETSIGN:
/* *INDENT-ON* */
}
void
__declspec(naked)
_aullshr()
void __declspec(naked) _aullshr()
{
/* *INDENT-OFF* */
__asm {

View File

@@ -24,7 +24,6 @@
#include "../libm/math_libm.h"
double
SDL_atan(double x)
{
@@ -35,8 +34,7 @@ SDL_atan(double x)
#endif
}
float
SDL_atanf(float x)
float SDL_atanf(float x)
{
#if defined(HAVE_ATANF)
return atanf(x);
@@ -55,8 +53,7 @@ SDL_atan2(double y, double x)
#endif
}
float
SDL_atan2f(float y, float x)
float SDL_atan2f(float y, float x)
{
#if defined(HAVE_ATAN2F)
return atan2f(y, x);
@@ -76,8 +73,7 @@ SDL_acos(double val)
result = SDL_PI_D;
} else {
result = SDL_atan(SDL_sqrt(1.0 - val * val) / val);
if (result < 0.0)
{
if (result < 0.0) {
result += SDL_PI_D;
}
}
@@ -85,8 +81,7 @@ SDL_acos(double val)
#endif
}
float
SDL_acosf(float val)
float SDL_acosf(float val)
{
#if defined(HAVE_ACOSF)
return acosf(val);
@@ -111,8 +106,7 @@ SDL_asin(double val)
#endif
}
float
SDL_asinf(float val)
float SDL_asinf(float val)
{
#if defined(HAVE_ASINF)
return asinf(val);
@@ -136,8 +130,7 @@ SDL_ceil(double x)
#endif /* HAVE_CEIL */
}
float
SDL_ceilf(float x)
float SDL_ceilf(float x)
{
#if defined(HAVE_CEILF)
return ceilf(x);
@@ -155,8 +148,8 @@ SDL_copysign(double x, double y)
return _copysign(x, y);
#elif defined(__WATCOMC__) && defined(__386__)
/* this is nasty as hell, but it works.. */
unsigned int *xi = (unsigned int *) &x,
*yi = (unsigned int *) &y;
unsigned int *xi = (unsigned int *)&x,
*yi = (unsigned int *)&y;
xi[1] = (yi[1] & 0x80000000) | (xi[1] & 0x7fffffff);
return x;
#else
@@ -164,8 +157,7 @@ SDL_copysign(double x, double y)
#endif /* HAVE_COPYSIGN */
}
float
SDL_copysignf(float x, float y)
float SDL_copysignf(float x, float y)
{
#if defined(HAVE_COPYSIGNF)
return copysignf(x, y);
@@ -184,8 +176,7 @@ SDL_cos(double x)
#endif
}
float
SDL_cosf(float x)
float SDL_cosf(float x)
{
#if defined(HAVE_COSF)
return cosf(x);
@@ -204,8 +195,7 @@ SDL_exp(double x)
#endif
}
float
SDL_expf(float x)
float SDL_expf(float x)
{
#if defined(HAVE_EXPF)
return expf(x);
@@ -224,8 +214,7 @@ SDL_fabs(double x)
#endif
}
float
SDL_fabsf(float x)
float SDL_fabsf(float x)
{
#if defined(HAVE_FABSF)
return fabsf(x);
@@ -244,8 +233,7 @@ SDL_floor(double x)
#endif
}
float
SDL_floorf(float x)
float SDL_floorf(float x)
{
#if defined(HAVE_FLOORF)
return floorf(x);
@@ -268,8 +256,7 @@ SDL_trunc(double x)
#endif
}
float
SDL_truncf(float x)
float SDL_truncf(float x)
{
#if defined(HAVE_TRUNCF)
return truncf(x);
@@ -288,8 +275,7 @@ SDL_fmod(double x, double y)
#endif
}
float
SDL_fmodf(float x, float y)
float SDL_fmodf(float x, float y)
{
#if defined(HAVE_FMODF)
return fmodf(x, y);
@@ -308,8 +294,7 @@ SDL_log(double x)
#endif
}
float
SDL_logf(float x)
float SDL_logf(float x)
{
#if defined(HAVE_LOGF)
return logf(x);
@@ -328,8 +313,7 @@ SDL_log10(double x)
#endif
}
float
SDL_log10f(float x)
float SDL_log10f(float x)
{
#if defined(HAVE_LOG10F)
return log10f(x);
@@ -348,8 +332,7 @@ SDL_pow(double x, double y)
#endif
}
float
SDL_powf(float x, float y)
float SDL_powf(float x, float y)
{
#if defined(HAVE_POWF)
return powf(x, y);
@@ -372,8 +355,7 @@ SDL_round(double arg)
#endif
}
float
SDL_roundf(float arg)
float SDL_roundf(float arg)
{
#if defined HAVE_ROUNDF
return roundf(arg);
@@ -382,8 +364,7 @@ SDL_roundf(float arg)
#endif
}
long
SDL_lround(double arg)
long SDL_lround(double arg)
{
#if defined HAVE_LROUND
return lround(arg);
@@ -392,8 +373,7 @@ SDL_lround(double arg)
#endif
}
long
SDL_lroundf(float arg)
long SDL_lroundf(float arg)
{
#if defined HAVE_LROUNDF
return lroundf(arg);
@@ -410,16 +390,15 @@ SDL_scalbn(double x, int n)
#elif defined(HAVE__SCALB)
return _scalb(x, n);
#elif defined(HAVE_LIBC) && defined(HAVE_FLOAT_H) && (FLT_RADIX == 2)
/* from scalbn(3): If FLT_RADIX equals 2 (which is
* usual), then scalbn() is equivalent to ldexp(3). */
/* from scalbn(3): If FLT_RADIX equals 2 (which is
* usual), then scalbn() is equivalent to ldexp(3). */
return ldexp(x, n);
#else
return SDL_uclibc_scalbn(x, n);
#endif
}
float
SDL_scalbnf(float x, int n)
float SDL_scalbnf(float x, int n)
{
#if defined(HAVE_SCALBNF)
return scalbnf(x, n);
@@ -438,8 +417,7 @@ SDL_sin(double x)
#endif
}
float
SDL_sinf(float x)
float SDL_sinf(float x)
{
#if defined(HAVE_SINF)
return sinf(x);
@@ -458,8 +436,7 @@ SDL_sqrt(double x)
#endif
}
float
SDL_sqrtf(float x)
float SDL_sqrtf(float x)
{
#if defined(HAVE_SQRTF)
return sqrtf(x);
@@ -478,8 +455,7 @@ SDL_tan(double x)
#endif
}
float
SDL_tanf(float x)
float SDL_tanf(float x)
{
#if defined(HAVE_TANF)
return tanf(x);
@@ -498,7 +474,10 @@ int SDL_abs(int x)
}
#if defined(HAVE_CTYPE_H)
int SDL_isalpha(int x) { return isalpha(x); }
int SDL_isalpha(int x)
{
return isalpha(x);
}
int SDL_isalnum(int x) { return isalnum(x); }
int SDL_isdigit(int x) { return isdigit(x); }
int SDL_isxdigit(int x) { return isxdigit(x); }
@@ -512,7 +491,10 @@ int SDL_iscntrl(int x) { return iscntrl(x); }
int SDL_toupper(int x) { return toupper(x); }
int SDL_tolower(int x) { return tolower(x); }
#else
int SDL_isalpha(int x) { return (SDL_isupper(x)) || (SDL_islower(x)); }
int SDL_isalpha(int x)
{
return (SDL_isupper(x)) || (SDL_islower(x));
}
int SDL_isalnum(int x) { return (SDL_isalpha(x)) || (SDL_isdigit(x)); }
int SDL_isdigit(int x) { return ((x) >= '0') && ((x) <= '9'); }
int SDL_isxdigit(int x) { return (((x) >= 'A') && ((x) <= 'F')) || (((x) >= 'a') && ((x) <= 'f')) || (SDL_isdigit(x)); }
@@ -523,8 +505,8 @@ int SDL_islower(int x) { return ((x) >= 'a') && ((x) <= 'z'); }
int SDL_isprint(int x) { return ((x) >= ' ') && ((x) < '\x7f'); }
int SDL_isgraph(int x) { return (SDL_isprint(x)) && ((x) != ' '); }
int SDL_iscntrl(int x) { return (((x) >= '\0') && ((x) <= '\x1f')) || ((x) == '\x7f'); }
int SDL_toupper(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }
int SDL_tolower(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
int SDL_toupper(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A' + ((x) - 'a')) : (x); }
int SDL_tolower(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a' + ((x) - 'A')) : (x); }
#endif
/* This file contains a portable memcpy manipulation function for SDL */
@@ -560,15 +542,15 @@ SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src,
Uint32 *srcp4, *dstp4;
Uint8 *srcp1, *dstp1;
srcp4 = (Uint32 *) src;
dstp4 = (Uint32 *) dst;
srcp4 = (Uint32 *)src;
dstp4 = (Uint32 *)dst;
len /= 4;
while (len--) {
*dstp4++ = *srcp4++;
}
srcp1 = (Uint8 *) srcp4;
dstp1 = (Uint8 *) dstp4;
srcp1 = (Uint8 *)srcp4;
dstp1 = (Uint8 *)dstp4;
switch (left) {
case 3:
*dstp1++ = *srcp1++;
@@ -590,7 +572,7 @@ SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
#else
size_t left;
Uint32 *dstp4;
Uint8 *dstp1 = (Uint8 *) dst;
Uint8 *dstp1 = (Uint8 *)dst;
Uint8 value1;
Uint32 value4;
@@ -610,14 +592,14 @@ SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
}
value4 = ((Uint32)c | ((Uint32)c << 8) | ((Uint32)c << 16) | ((Uint32)c << 24));
dstp4 = (Uint32 *) dstp1;
dstp4 = (Uint32 *)dstp1;
left = (len % 4);
len /= 4;
while (len--) {
*dstp4++ = value4;
}
dstp1 = (Uint8 *) dstp4;
dstp1 = (Uint8 *)dstp4;
switch (left) {
case 3:
*dstp1++ = value1;
@@ -639,13 +621,12 @@ SDL_memset4(void *dst, Uint32 val, size_t dwords)
memset_pattern4(dst, &val, dwords * 4);
#elif defined(__GNUC__) && defined(__i386__)
int u0, u1, u2;
__asm__ __volatile__ (
__asm__ __volatile__(
"cld \n\t"
"rep ; stosl \n\t"
: "=&D" (u0), "=&a" (u1), "=&c" (u2)
: "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, dwords))
: "memory"
);
: "=&D"(u0), "=&a"(u1), "=&c"(u2)
: "0"(dst), "1"(val), "2"(SDL_static_cast(Uint32, dwords))
: "memory");
#else
size_t _n = (dwords + 3) / 4;
Uint32 *_p = SDL_static_cast(Uint32 *, dst);
@@ -654,20 +635,34 @@ SDL_memset4(void *dst, Uint32 val, size_t dwords)
return dst;
}
switch (dwords % 4) {
case 0: do { *_p++ = _val; SDL_FALLTHROUGH;
case 3: *_p++ = _val; SDL_FALLTHROUGH;
case 2: *_p++ = _val; SDL_FALLTHROUGH;
case 1: *_p++ = _val;
} while ( --_n );
case 0:
do {
*_p++ = _val;
SDL_FALLTHROUGH;
case 3:
*_p++ = _val;
SDL_FALLTHROUGH;
case 2:
*_p++ = _val;
SDL_FALLTHROUGH;
case 1:
*_p++ = _val;
} while (--_n);
}
#endif
return dst;
}
#if defined(HAVE_CTYPE_H) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
int SDL_isblank(int x) { return isblank(x); }
int SDL_isblank(int x)
{
return isblank(x);
}
#else
int SDL_isblank(int x) { return ((x) == ' ') || ((x) == '\t'); }
int SDL_isblank(int x)
{
return ((x) == ' ') || ((x) == '\t');
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -29,11 +29,11 @@
#endif
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD) || !defined(HAVE_STRTOLL) || !defined(HAVE_STRTOULL)
#define SDL_isupperhex(X) (((X) >= 'A') && ((X) <= 'F'))
#define SDL_islowerhex(X) (((X) >= 'a') && ((X) <= 'f'))
#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_IsLeadByte(c) ((c) >= 0xC0 && (c) <= 0xF4)
#define UTF8_IsTrailingByte(c) ((c) >= 0x80 && (c) <= 0xBF)
static unsigned UTF8_TrailingBytes(unsigned char c)
@@ -65,7 +65,7 @@ SDL_ScanLong(const char *text, int count, int radix, long *valuep)
}
for (;;) {
int v;
if (SDL_isdigit((unsigned char) *text)) {
if (SDL_isdigit((unsigned char)*text)) {
v = *text - '0';
} else if (radix == 16 && SDL_isupperhex(*text)) {
v = 10 + (*text - 'A');
@@ -109,7 +109,7 @@ SDL_ScanUnsignedLong(const char *text, int count, int radix, unsigned long *valu
}
for (;;) {
int v;
if (SDL_isdigit((unsigned char) *text)) {
if (SDL_isdigit((unsigned char)*text)) {
v = *text - '0';
} else if (radix == 16 && SDL_isupperhex(*text)) {
v = 10 + (*text - 'A');
@@ -135,7 +135,7 @@ SDL_ScanUnsignedLong(const char *text, int count, int radix, unsigned long *valu
#ifndef HAVE_VSSCANF
static size_t
SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep)
SDL_ScanUintPtrT(const char *text, int radix, uintptr_t *valuep)
{
const char *textstart = text;
uintptr_t value = 0;
@@ -145,7 +145,7 @@ SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep)
}
for (;;) {
int v;
if (SDL_isdigit((unsigned char) *text)) {
if (SDL_isdigit((unsigned char)*text)) {
v = *text - '0';
} else if (radix == 16 && SDL_isupperhex(*text)) {
v = 10 + (*text - 'A');
@@ -167,7 +167,7 @@ SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep)
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOLL) || !defined(HAVE_STRTOULL)
static size_t
SDL_ScanLongLong(const char *text, int count, int radix, Sint64 * valuep)
SDL_ScanLongLong(const char *text, int count, int radix, Sint64 *valuep)
{
const char *textstart = text;
Sint64 value = 0;
@@ -182,7 +182,7 @@ SDL_ScanLongLong(const char *text, int count, int radix, Sint64 * valuep)
}
for (;;) {
int v;
if (SDL_isdigit((unsigned char) *text)) {
if (SDL_isdigit((unsigned char)*text)) {
v = *text - '0';
} else if (radix == 16 && SDL_isupperhex(*text)) {
v = 10 + (*text - 'A');
@@ -212,7 +212,7 @@ SDL_ScanLongLong(const char *text, int count, int radix, Sint64 * valuep)
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOULL)
static size_t
SDL_ScanUnsignedLongLong(const char *text, int count, int radix, Uint64 * valuep)
SDL_ScanUnsignedLongLong(const char *text, int count, int radix, Uint64 *valuep)
{
const char *textstart = text;
Uint64 value = 0;
@@ -226,7 +226,7 @@ SDL_ScanUnsignedLongLong(const char *text, int count, int radix, Uint64 * valuep
}
for (;;) {
int v;
if (SDL_isdigit((unsigned char) *text)) {
if (SDL_isdigit((unsigned char)*text)) {
v = *text - '0';
} else if (radix == 16 && SDL_isupperhex(*text)) {
v = 10 + (*text - 'A');
@@ -268,9 +268,9 @@ SDL_ScanFloat(const char *text, double *valuep)
if (*text == '.') {
int mult = 10;
++text;
while (SDL_isdigit((unsigned char) *text)) {
while (SDL_isdigit((unsigned char)*text)) {
lvalue = *text - '0';
value += (double) lvalue / mult;
value += (double)lvalue / mult;
mult *= 10;
++text;
}
@@ -292,8 +292,8 @@ SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src,
#if defined(HAVE_MEMMOVE)
return memmove(dst, src, len);
#else
char *srcp = (char *) src;
char *dstp = (char *) dst;
char *srcp = (char *)src;
char *dstp = (char *)dst;
if (src < dst) {
srcp += len - 1;
@@ -310,8 +310,7 @@ SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src,
#endif /* HAVE_MEMMOVE */
}
int
SDL_memcmp(const void *s1, const void *s2, size_t len)
int SDL_memcmp(const void *s1, const void *s2, size_t len)
{
#if defined(__vita__)
/*
@@ -327,8 +326,8 @@ SDL_memcmp(const void *s1, const void *s2, size_t len)
#elif defined(HAVE_MEMCMP)
return memcmp(s1, s2, len);
#else
char *s1p = (char *) s1;
char *s2p = (char *) s2;
char *s1p = (char *)s1;
char *s2p = (char *)s2;
while (len--) {
if (*s1p != *s2p) {
return *s1p - *s2p;
@@ -355,7 +354,7 @@ SDL_strlen(const char *string)
}
size_t
SDL_wcslen(const wchar_t * string)
SDL_wcslen(const wchar_t *string)
{
#if defined(HAVE_WCSLEN)
return wcslen(string);
@@ -427,8 +426,7 @@ SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle)
#endif /* HAVE_WCSSTR */
}
int
SDL_wcscmp(const wchar_t *str1, const wchar_t *str2)
int SDL_wcscmp(const wchar_t *str1, const wchar_t *str2)
{
#if defined(HAVE_WCSCMP)
return wcscmp(str1, str2);
@@ -444,8 +442,7 @@ SDL_wcscmp(const wchar_t *str1, const wchar_t *str2)
#endif /* HAVE_WCSCMP */
}
int
SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
int SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
{
#if defined(HAVE_WCSNCMP)
return wcsncmp(str1, str2, maxlen);
@@ -466,8 +463,7 @@ SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
#endif /* HAVE_WCSNCMP */
}
int
SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2)
int SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2)
{
#if defined(HAVE_WCSCASECMP)
return wcscasecmp(str1, str2);
@@ -482,8 +478,8 @@ SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2)
a = *str1;
b = *str2;
} else {
a = SDL_toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2);
a = SDL_toupper((unsigned char)*str1);
b = SDL_toupper((unsigned char)*str2);
}
if (a != b) {
break;
@@ -497,15 +493,14 @@ SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2)
a = *str1;
b = *str2;
} else {
a = SDL_toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2);
a = SDL_toupper((unsigned char)*str1);
b = SDL_toupper((unsigned char)*str2);
}
return (int)((unsigned int)a - (unsigned int)b);
#endif /* HAVE__WCSICMP */
}
int
SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
int SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
{
#if defined(HAVE_WCSNCASECMP)
return wcsncasecmp(str1, str2, maxlen);
@@ -520,8 +515,8 @@ SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
a = *str1;
b = *str2;
} else {
a = SDL_toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2);
a = SDL_toupper((unsigned char)*str1);
b = SDL_toupper((unsigned char)*str2);
}
if (a != b) {
break;
@@ -539,8 +534,8 @@ SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
a = *str1;
b = *str2;
} else {
a = SDL_toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2);
a = SDL_toupper((unsigned char)*str1);
b = SDL_toupper((unsigned char)*str2);
}
return (int)((unsigned int)a - (unsigned int)b);
}
@@ -608,7 +603,7 @@ SDL_utf8strlen(const char *str)
retval++;
}
}
return retval;
}
@@ -682,7 +677,7 @@ SDL_strupr(char *string)
#else
char *bufp = string;
while (*bufp) {
*bufp = SDL_toupper((unsigned char) *bufp);
*bufp = SDL_toupper((unsigned char)*bufp);
++bufp;
}
return string;
@@ -697,7 +692,7 @@ SDL_strlwr(char *string)
#else
char *bufp = string;
while (*bufp) {
*bufp = SDL_tolower((unsigned char) *bufp);
*bufp = SDL_tolower((unsigned char)*bufp);
++bufp;
}
return string;
@@ -914,8 +909,7 @@ double SDL_atof(const char *string)
#endif /* HAVE_ATOF */
}
long
SDL_strtol(const char *string, char **endp, int base)
long SDL_strtol(const char *string, char **endp, int base)
{
#if defined(HAVE_STRTOL)
return strtol(string, endp, base);
@@ -933,7 +927,7 @@ SDL_strtol(const char *string, char **endp, int base)
len = SDL_ScanLong(string, 0, base, &value);
if (endp) {
*endp = (char *) string + len;
*endp = (char *)string + len;
}
return value;
#endif /* HAVE_STRTOL */
@@ -958,7 +952,7 @@ SDL_strtoul(const char *string, char **endp, int base)
len = SDL_ScanUnsignedLong(string, 0, base, &value);
if (endp) {
*endp = (char *) string + len;
*endp = (char *)string + len;
}
return value;
#endif /* HAVE_STRTOUL */
@@ -983,7 +977,7 @@ SDL_strtoll(const char *string, char **endp, int base)
len = SDL_ScanLongLong(string, 0, base, &value);
if (endp) {
*endp = (char *) string + len;
*endp = (char *)string + len;
}
return value;
#endif /* HAVE_STRTOLL */
@@ -1008,7 +1002,7 @@ SDL_strtoull(const char *string, char **endp, int base)
len = SDL_ScanUnsignedLongLong(string, 0, base, &value);
if (endp) {
*endp = (char *) string + len;
*endp = (char *)string + len;
}
return value;
#endif /* HAVE_STRTOULL */
@@ -1025,14 +1019,13 @@ SDL_strtod(const char *string, char **endp)
len = SDL_ScanFloat(string, &value);
if (endp) {
*endp = (char *) string + len;
*endp = (char *)string + len;
}
return value;
#endif /* HAVE_STRTOD */
}
int
SDL_strcmp(const char *str1, const char *str2)
int SDL_strcmp(const char *str1, const char *str2)
{
#if defined(HAVE_STRCMP)
return strcmp(str1, str2);
@@ -1040,8 +1033,8 @@ SDL_strcmp(const char *str1, const char *str2)
int result;
while (1) {
result = (int)((unsigned char) *str1 - (unsigned char) *str2);
if (result != 0 || (*str1 == '\0'/* && *str2 == '\0'*/)) {
result = (int)((unsigned char)*str1 - (unsigned char)*str2);
if (result != 0 || (*str1 == '\0' /* && *str2 == '\0'*/)) {
break;
}
++str1;
@@ -1051,8 +1044,7 @@ SDL_strcmp(const char *str1, const char *str2)
#endif /* HAVE_STRCMP */
}
int
SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
int SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
{
#if defined(HAVE_STRNCMP)
return strncmp(str1, str2, maxlen);
@@ -1060,8 +1052,8 @@ SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
int result;
while (maxlen) {
result = (int) (unsigned char) *str1 - (unsigned char) *str2;
if (result != 0 || *str1 == '\0'/* && *str2 == '\0'*/) {
result = (int)(unsigned char)*str1 - (unsigned char)*str2;
if (result != 0 || *str1 == '\0' /* && *str2 == '\0'*/) {
break;
}
++str1;
@@ -1075,8 +1067,7 @@ SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
#endif /* HAVE_STRNCMP */
}
int
SDL_strcasecmp(const char *str1, const char *str2)
int SDL_strcasecmp(const char *str1, const char *str2)
{
#ifdef HAVE_STRCASECMP
return strcasecmp(str1, str2);
@@ -1086,8 +1077,8 @@ SDL_strcasecmp(const char *str1, const char *str2)
int a, b, result;
while (1) {
a = SDL_toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2);
a = SDL_toupper((unsigned char)*str1);
b = SDL_toupper((unsigned char)*str2);
result = a - b;
if (result != 0 || a == 0 /*&& b == 0*/) {
break;
@@ -1099,8 +1090,7 @@ SDL_strcasecmp(const char *str1, const char *str2)
#endif /* HAVE_STRCASECMP */
}
int
SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
{
#ifdef HAVE_STRNCASECMP
return strncasecmp(str1, str2, maxlen);
@@ -1110,8 +1100,8 @@ SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
int a, b, result;
while (maxlen) {
a = SDL_tolower((unsigned char) *str1);
b = SDL_tolower((unsigned char) *str2);
a = SDL_tolower((unsigned char)*str1);
b = SDL_tolower((unsigned char)*str2);
result = a - b;
if (result != 0 || a == 0 /*&& b == 0*/) {
break;
@@ -1127,8 +1117,7 @@ SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
#endif /* HAVE_STRNCASECMP */
}
int
SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...)
int SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...)
{
int rc;
va_list ap;
@@ -1139,14 +1128,12 @@ SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...)
}
#ifdef HAVE_VSSCANF
int
SDL_vsscanf(const char *text, const char *fmt, va_list ap)
int SDL_vsscanf(const char *text, const char *fmt, va_list ap)
{
return vsscanf(text, fmt, ap);
}
#else
int
SDL_vsscanf(const char *text, const char *fmt, va_list ap)
int SDL_vsscanf(const char *text, const char *fmt, va_list ap)
{
int retval = 0;
@@ -1156,7 +1143,7 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
while (*fmt) {
if (*fmt == ' ') {
while (SDL_isspace((unsigned char) *text)) {
while (SDL_isspace((unsigned char)*text)) {
++text;
}
++fmt;
@@ -1210,7 +1197,7 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
continue;
}
while (SDL_isspace((unsigned char) *text)) {
while (SDL_isspace((unsigned char)*text)) {
++text;
}
@@ -1240,19 +1227,19 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
inttype = DO_SIZE_T;
break;
case 'i':
{
int index = 0;
if (text[index] == '-') {
++index;
}
if (text[index] == '0') {
if (SDL_tolower((unsigned char) text[index + 1]) == 'x') {
radix = 16;
} else {
radix = 8;
}
{
int index = 0;
if (text[index] == '-') {
++index;
}
if (text[index] == '0') {
if (SDL_tolower((unsigned char)text[index + 1]) == 'x') {
radix = 16;
} else {
radix = 8;
}
}
}
SDL_FALLTHROUGH;
case 'd':
if (inttype == DO_LONGLONG) {
@@ -1280,23 +1267,20 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
if (advance && !suppress) {
switch (inttype) {
case DO_SHORT:
{
short *valuep = va_arg(ap, short *);
*valuep = (short) value;
}
break;
{
short *valuep = va_arg(ap, short *);
*valuep = (short)value;
} break;
case DO_INT:
{
int *valuep = va_arg(ap, int *);
*valuep = (int) value;
}
break;
{
int *valuep = va_arg(ap, int *);
*valuep = (int)value;
} break;
case DO_LONG:
{
long *valuep = va_arg(ap, long *);
*valuep = value;
}
break;
{
long *valuep = va_arg(ap, long *);
*valuep = value;
} break;
case DO_LONGLONG:
case DO_SIZE_T:
/* Handled above */
@@ -1344,23 +1328,20 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
if (advance && !suppress) {
switch (inttype) {
case DO_SHORT:
{
short *valuep = va_arg(ap, short *);
*valuep = (short) value;
}
break;
{
short *valuep = va_arg(ap, short *);
*valuep = (short)value;
} break;
case DO_INT:
{
int *valuep = va_arg(ap, int *);
*valuep = (int) value;
}
break;
{
int *valuep = va_arg(ap, int *);
*valuep = (int)value;
} break;
case DO_LONG:
{
long *valuep = va_arg(ap, long *);
*valuep = value;
}
break;
{
long *valuep = va_arg(ap, long *);
*valuep = value;
} break;
case DO_LONGLONG:
case DO_SIZE_T:
/* Handled above */
@@ -1372,34 +1353,34 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
done = SDL_TRUE;
break;
case 'p':
{
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;
}
{
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;
}
}
done = SDL_TRUE;
break;
case 'f':
{
double value = 0.0;
advance = SDL_ScanFloat(text, &value);
text += advance;
if (advance && !suppress) {
float *valuep = va_arg(ap, float *);
*valuep = (float) value;
++retval;
}
{
double value = 0.0;
advance = SDL_ScanFloat(text, &value);
text += advance;
if (advance && !suppress) {
float *valuep = va_arg(ap, float *);
*valuep = (float)value;
++retval;
}
}
done = SDL_TRUE;
break;
case 's':
if (suppress) {
while (!SDL_isspace((unsigned char) *text)) {
while (!SDL_isspace((unsigned char)*text)) {
++text;
if (count) {
if (--count == 0) {
@@ -1409,7 +1390,7 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
}
} else {
char *valuep = va_arg(ap, char *);
while (!SDL_isspace((unsigned char) *text)) {
while (!SDL_isspace((unsigned char)*text)) {
*valuep++ = *text++;
if (count) {
if (--count == 0) {
@@ -1443,8 +1424,7 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
}
#endif /* HAVE_VSSCANF */
int
SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
int SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
int retval;
@@ -1482,9 +1462,9 @@ int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *f
return vsnprintf(text, maxlen, fmt, ap);
}
#else
#define TEXT_AND_LEN_ARGS (length < maxlen) ? &text[length] : NULL, (length < maxlen) ? (maxlen - length) : 0
#define TEXT_AND_LEN_ARGS (length < maxlen) ? &text[length] : NULL, (length < maxlen) ? (maxlen - length) : 0
/* FIXME: implement more of the format specifiers */
/* FIXME: implement more of the format specifiers */
typedef enum
{
SDL_CASE_NOCHANGE,
@@ -1496,7 +1476,7 @@ typedef struct
{
SDL_bool left_justify; /* for now: ignored. */
SDL_bool force_sign;
SDL_bool force_type; /* for now: used only by float printer, ignored otherwise. */
SDL_bool force_type; /* for now: used only by float printer, ignored otherwise. */
SDL_bool pad_zeroes;
SDL_letter_case force_case;
int width;
@@ -1553,9 +1533,8 @@ SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *str
return length;
}
static void
SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info)
{/* left-pad num with zeroes. */
static void SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info)
{ /* left-pad num with zeroes. */
size_t sz, pad, have_sign;
if (info == NULL) {
@@ -1576,12 +1555,12 @@ SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info)
SDL_memset(num, '0', pad);
}
}
info->precision = -1;/* so that SDL_PrintString() doesn't make a mess. */
info->precision = -1; /* so that SDL_PrintString() doesn't make a mess. */
if (info->pad_zeroes && info->width > 0 && (size_t)info->width > sz + have_sign) {
/* handle here: spaces are added before the sign
but zeroes must be placed _after_ the sign. */
/* sz hasn't changed: we ignore pad_zeroes if a precision is given. */
/* handle here: spaces are added before the sign
but zeroes must be placed _after_ the sign. */
/* sz hasn't changed: we ignore pad_zeroes if a precision is given. */
pad = (size_t)info->width - sz - have_sign;
if (pad + sz + 1 <= maxlen) {
SDL_memmove(num + pad, num, sz + 1);
@@ -1659,7 +1638,7 @@ SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg)
}
++length;
}
value = (unsigned long) arg;
value = (unsigned long)arg;
length += SDL_PrintUnsignedLong(TEXT_AND_LEN_ARGS, NULL, value);
arg -= value;
if (info->precision < 0) {
@@ -1672,9 +1651,9 @@ SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg)
}
++length;
while (info->precision-- > 0) {
value = (unsigned long) (arg * mult);
value = (unsigned long)(arg * mult);
length += SDL_PrintUnsignedLong(TEXT_AND_LEN_ARGS, NULL, value);
arg -= (double) value / mult;
arg -= (double)value / mult;
mult *= 10;
}
}
@@ -1694,8 +1673,7 @@ SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg)
return length;
}
int
SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
{
size_t length = 0;
@@ -1778,7 +1756,7 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
case 'c':
/* char is promoted to int when passed through (...) */
if (length < maxlen) {
text[length] = (char) va_arg(ap, int);
text[length] = (char)va_arg(ap, int);
}
++length;
done = SDL_TRUE;
@@ -1808,15 +1786,15 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
switch (inttype) {
case DO_INT:
length += SDL_PrintLong(TEXT_AND_LEN_ARGS, &info,
(long) va_arg(ap, int));
(long)va_arg(ap, int));
break;
case DO_LONG:
length += SDL_PrintLong(TEXT_AND_LEN_ARGS, &info,
va_arg(ap, long));
va_arg(ap, long));
break;
case DO_LONGLONG:
length += SDL_PrintLongLong(TEXT_AND_LEN_ARGS, &info,
va_arg(ap, Sint64));
va_arg(ap, Sint64));
break;
case DO_SIZE_T:
length += SDL_PrintLongLong(TEXT_AND_LEN_ARGS, &info,
@@ -1853,16 +1831,16 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
switch (inttype) {
case DO_INT:
length += SDL_PrintUnsignedLong(TEXT_AND_LEN_ARGS, &info,
(unsigned long)
va_arg(ap, unsigned int));
(unsigned long)
va_arg(ap, unsigned int));
break;
case DO_LONG:
length += SDL_PrintUnsignedLong(TEXT_AND_LEN_ARGS, &info,
va_arg(ap, unsigned long));
va_arg(ap, unsigned long));
break;
case DO_LONGLONG:
length += SDL_PrintUnsignedLongLong(TEXT_AND_LEN_ARGS, &info,
va_arg(ap, Uint64));
va_arg(ap, Uint64));
break;
case DO_SIZE_T:
length += SDL_PrintUnsignedLongLong(TEXT_AND_LEN_ARGS, &info,
@@ -1876,21 +1854,20 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
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 *);
if (wide_arg) {
char *arg = SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(wide_arg), (SDL_wcslen(wide_arg)+1)*sizeof(*wide_arg));
info.pad_zeroes = SDL_FALSE;
length += SDL_PrintString(TEXT_AND_LEN_ARGS, &info, arg);
SDL_free(arg);
} else {
info.pad_zeroes = SDL_FALSE;
length += SDL_PrintString(TEXT_AND_LEN_ARGS, &info, NULL);
}
done = SDL_TRUE;
{
/* In practice this is used on Windows for WCHAR strings */
wchar_t *wide_arg = va_arg(ap, wchar_t *);
if (wide_arg) {
char *arg = SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(wide_arg), (SDL_wcslen(wide_arg) + 1) * sizeof(*wide_arg));
info.pad_zeroes = SDL_FALSE;
length += SDL_PrintString(TEXT_AND_LEN_ARGS, &info, arg);
SDL_free(arg);
} else {
info.pad_zeroes = SDL_FALSE;
length += SDL_PrintString(TEXT_AND_LEN_ARGS, &info, NULL);
}
break;
done = SDL_TRUE;
} break;
case 's':
info.pad_zeroes = SDL_FALSE;
length += SDL_PrintString(TEXT_AND_LEN_ARGS, &info, va_arg(ap, char *));
@@ -1916,14 +1893,12 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
text[maxlen - 1] = '\0';
}
return (int)length;
}
#undef TEXT_AND_LEN_ARGS
#endif /* HAVE_VSNPRINTF */
int
SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
int SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
int retval;
@@ -1935,11 +1910,10 @@ SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
return retval;
}
int
SDL_vasprintf(char **strp, const char *fmt, va_list ap)
int SDL_vasprintf(char **strp, const char *fmt, va_list ap)
{
int retval;
int size = 100; /* Guess we need no more than 100 bytes */
int size = 100; /* Guess we need no more than 100 bytes */
char *p, *np;
va_list aq;
@@ -1968,7 +1942,7 @@ SDL_vasprintf(char **strp, const char *fmt, va_list ap)
}
/* Else try again with more space */
size = retval + 1; /* Precisely what is needed */
size = retval + 1; /* Precisely what is needed */
np = (char *)SDL_realloc(p, size);
if (np == NULL) {

View File

@@ -22,15 +22,15 @@
/* Do our best to make sure va_copy is working */
#if defined(__NGAGE__)
#undef va_copy
#define va_copy(dst, src) dst = src
#define va_copy(dst, src) dst = src
#elif defined(_MSC_VER) && _MSC_VER <= 1800
/* Visual Studio 2013 tries to link with _vacopy in the C runtime. Newer versions do an inline assignment */
#undef va_copy
#define va_copy(dst, src) dst = src
#define va_copy(dst, src) dst = src
#elif defined(__GNUC__) && (__GNUC__ < 3)
#define va_copy(dst, src) __va_copy(dst, src)
#define va_copy(dst, src) __va_copy(dst, src)
#endif
/* vi: set ts=4 sw=4 expandtab: */