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

(cherry picked from commit 5750bcb174)
This commit is contained in:
Sam Lantinga
2022-11-30 12:51:59 -08:00
parent 5c4bc807f7
commit b8d85c6939
764 changed files with 50598 additions and 54407 deletions

View File

@@ -34,11 +34,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)
@@ -70,7 +70,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');
@@ -114,7 +114,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');
@@ -140,7 +140,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;
@@ -150,7 +150,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');
@@ -172,7 +172,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;
@@ -187,7 +187,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');
@@ -217,7 +217,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;
@@ -231,7 +231,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');
@@ -273,9 +273,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;
}
@@ -297,8 +297,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;
@@ -315,8 +315,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__)
/*
@@ -332,8 +331,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;
@@ -360,7 +359,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);
@@ -432,8 +431,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);
@@ -449,8 +447,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);
@@ -471,8 +468,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);
@@ -487,8 +483,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;
@@ -502,15 +498,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);
@@ -525,8 +520,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;
@@ -544,8 +539,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);
}
@@ -613,7 +608,7 @@ SDL_utf8strlen(const char *str)
retval++;
}
}
return retval;
}
@@ -687,7 +682,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;
@@ -702,7 +697,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;
@@ -919,8 +914,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);
@@ -938,7 +932,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 */
@@ -963,7 +957,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 */
@@ -988,7 +982,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 */
@@ -1013,7 +1007,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 */
@@ -1030,14 +1024,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);
@@ -1045,8 +1038,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;
@@ -1056,8 +1049,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);
@@ -1065,8 +1057,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;
@@ -1080,8 +1072,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);
@@ -1091,8 +1082,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;
@@ -1104,8 +1095,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);
@@ -1115,8 +1105,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;
@@ -1132,8 +1122,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;
@@ -1144,14 +1133,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;
@@ -1161,7 +1148,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;
@@ -1215,7 +1202,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;
}
@@ -1245,19 +1232,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) {
@@ -1285,23 +1272,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 */
@@ -1349,23 +1333,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 */
@@ -1377,34 +1358,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) {
@@ -1414,7 +1395,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) {
@@ -1448,8 +1429,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;
@@ -1487,9 +1467,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,
@@ -1501,7 +1481,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;
@@ -1558,9 +1538,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) {
@@ -1581,12 +1560,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);
@@ -1664,7 +1643,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) {
@@ -1677,9 +1656,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;
}
}
@@ -1699,8 +1678,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;
@@ -1783,7 +1761,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;
@@ -1813,15 +1791,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,
@@ -1858,16 +1836,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,
@@ -1881,21 +1859,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 *));
@@ -1921,14 +1898,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;
@@ -1940,11 +1915,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;
@@ -1973,7 +1947,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) {