Updates the SDL library to the latest standard bugfix release

This commit is contained in:
JeffR 2023-07-13 15:20:29 -05:00
parent cb766f2878
commit 083d2175ea
1280 changed files with 343926 additions and 179615 deletions

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -23,18 +23,17 @@
#include "SDL_syslocale.h"
#include "SDL_hints.h"
static SDL_Locale *
build_locales_from_csv_string(char *csv)
static SDL_Locale *build_locales_from_csv_string(char *csv)
{
size_t num_locales = 1; /* at least one */
size_t num_locales = 1; /* at least one */
size_t slen;
size_t alloclen;
char *ptr;
SDL_Locale *loc;
SDL_Locale *retval;
if (!csv || !csv[0]) {
return NULL; /* nothing to report */
if (csv == NULL || !csv[0]) {
return NULL; /* nothing to report */
}
for (ptr = csv; *ptr; ptr++) {
@ -43,21 +42,24 @@ build_locales_from_csv_string(char *csv)
}
}
num_locales++; /* one more for terminator */
num_locales++; /* one more for terminator */
slen = ((size_t) (ptr - csv)) + 1; /* SDL_strlen(csv) + 1 */
alloclen = slen + (num_locales * sizeof (SDL_Locale));
slen = ((size_t)(ptr - csv)) + 1; /* SDL_strlen(csv) + 1 */
alloclen = slen + (num_locales * sizeof(SDL_Locale));
loc = retval = (SDL_Locale *) SDL_calloc(1, alloclen);
if (!retval) {
loc = retval = (SDL_Locale *)SDL_calloc(1, alloclen);
if (retval == NULL) {
SDL_OutOfMemory();
return NULL; /* oh well */
return NULL; /* oh well */
}
ptr = (char *) (retval + num_locales);
ptr = (char *)(retval + num_locales);
SDL_strlcpy(ptr, csv, slen);
while (SDL_TRUE) { /* parse out the string */
while (*ptr == ' ') ptr++; /* skip whitespace. */
while (SDL_TRUE) { /* parse out the string */
while (*ptr == ' ') {
ptr++; /* skip whitespace. */
}
if (*ptr == '\0') {
break;
}
@ -68,7 +70,7 @@ build_locales_from_csv_string(char *csv)
*(ptr++) = '\0';
loc->country = ptr;
} else if (ch == ' ') {
*(ptr++) = '\0'; /* trim ending whitespace and keep going. */
*(ptr++) = '\0'; /* trim ending whitespace and keep going. */
} else if (ch == ',') {
*(ptr++) = '\0';
loc++;
@ -77,7 +79,7 @@ build_locales_from_csv_string(char *csv)
loc++;
break;
} else {
ptr++; /* just keep going, still a valid string */
ptr++; /* just keep going, still a valid string */
}
}
}
@ -85,19 +87,17 @@ build_locales_from_csv_string(char *csv)
return retval;
}
SDL_Locale *
SDL_GetPreferredLocales(void)
SDL_Locale *SDL_GetPreferredLocales(void)
{
char locbuf[128]; /* enough for 21 "xx_YY," language strings. */
char locbuf[128]; /* enough for 21 "xx_YY," language strings. */
const char *hint = SDL_GetHint(SDL_HINT_PREFERRED_LOCALES);
if (hint) {
SDL_strlcpy(locbuf, hint, sizeof (locbuf));
SDL_strlcpy(locbuf, hint, sizeof(locbuf));
} else {
SDL_zeroa(locbuf);
SDL_SYS_GetPreferredLocales(locbuf, sizeof (locbuf));
SDL_SYS_GetPreferredLocales(locbuf, sizeof(locbuf));
}
return build_locales_from_csv_string(locbuf);
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -23,11 +23,9 @@
#include "../SDL_syslocale.h"
#include "../../core/android/SDL_android.h"
void
SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
void SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
{
Android_JNI_GetLocale(buf, buflen);
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -22,12 +22,10 @@
#include "../../SDL_internal.h"
#include "../SDL_syslocale.h"
void
SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
void SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
{
/* dummy implementation. Caller already zero'd out buffer. */
SDL_Unsupported();
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -24,9 +24,9 @@
#include "../../SDL_internal.h"
#include "../SDL_syslocale.h"
void
SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
void SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
{
/* *INDENT-OFF* */ /* clang-format off */
EM_ASM({
var buf = $0;
var buflen = $1;
@ -66,7 +66,7 @@ SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
setValue(buf + i, str.charCodeAt(i), "i8"); /* fill in C array. */
}
}, buf, buflen);
/* *INDENT-ON* */ /* clang-format on */
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -26,8 +26,7 @@
#include "../../SDL_internal.h"
#include "../SDL_syslocale.h"
void
SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
void SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
{
BLocaleRoster *roster = BLocaleRoster::Default();
roster->Refresh();

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -24,53 +24,54 @@
#import <Foundation/Foundation.h>
void
SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
{ @autoreleasepool {
NSArray *languages = NSLocale.preferredLanguages;
size_t numlangs = 0;
size_t i;
void SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
{
@autoreleasepool {
NSArray *languages = NSLocale.preferredLanguages;
size_t numlangs = 0;
size_t i;
numlangs = (size_t) [languages count];
numlangs = (size_t)[languages count];
for (i = 0; i < numlangs; i++) {
NSString *nsstr = [languages objectAtIndex:i];
size_t len;
char *ptr;
for (i = 0; i < numlangs; i++) {
NSString *nsstr = [languages objectAtIndex:i];
size_t len;
char *ptr;
if (nsstr == nil) {
break;
}
[nsstr getCString:buf maxLength:buflen encoding:NSASCIIStringEncoding];
len = SDL_strlen(buf);
// convert '-' to '_'...
// These are always full lang-COUNTRY, so we search from the back,
// so things like zh-Hant-CN find the right '-' to convert.
if ((ptr = SDL_strrchr(buf, '-')) != NULL) {
*ptr = '_';
}
if (buflen <= len) {
*buf = '\0'; // drop this one and stop, we can't fit anymore.
break;
}
buf += len;
buflen -= len;
if (i < (numlangs - 1)) {
if (buflen <= 1) {
break; // out of room, stop looking.
if (nsstr == nil) {
break;
}
[nsstr getCString:buf maxLength:buflen encoding:NSASCIIStringEncoding];
len = SDL_strlen(buf);
// convert '-' to '_'...
// These are always full lang-COUNTRY, so we search from the back,
// so things like zh-Hant-CN find the right '-' to convert.
ptr = SDL_strrchr(buf, '-');
if (ptr != NULL) {
*ptr = '_';
}
if (buflen <= len) {
*buf = '\0'; // drop this one and stop, we can't fit anymore.
break;
}
buf += len;
buflen -= len;
if (i < (numlangs - 1)) {
if (buflen <= 1) {
break; // out of room, stop looking.
}
buf[0] = ','; // add a comma between entries.
buf[1] = '\0';
buf++;
buflen--;
}
buf[0] = ','; // add a comma between entries.
buf[1] = '\0';
buf++;
buflen--;
}
}
}}
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -0,0 +1,58 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_syslocale.h"
#include "../../SDL_internal.h"
#include <3ds.h>
/* Used when the CFGU fails to work. */
#define BAD_LOCALE 255
SDL_FORCE_INLINE u8 GetLocaleIndex(void);
void SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
{
/* The 3DS only supports these 12 languages, only one can be active at a time */
static const char AVAILABLE_LOCALES[][6] = { "ja_JP", "en_US", "fr_FR", "de_DE",
"it_IT", "es_ES", "zn_CN", "ko_KR",
"nl_NL", "pt_PT", "ru_RU", "zh_TW" };
u8 current_locale = GetLocaleIndex();
if (current_locale != BAD_LOCALE) {
SDL_strlcpy(buf, AVAILABLE_LOCALES[current_locale], buflen);
}
}
SDL_FORCE_INLINE u8
GetLocaleIndex(void)
{
u8 current_locale;
if (R_FAILED(cfguInit())) {
return BAD_LOCALE;
}
if (R_FAILED(CFGU_GetSystemLanguage(&current_locale))) {
return BAD_LOCALE;
}
cfguExit();
return current_locale;
}
/* vi: set sts=4 ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -22,17 +22,16 @@
#include "../../SDL_internal.h"
#include "../SDL_syslocale.h"
static void
normalize_locale_str(char *dst, char *str, size_t buflen)
static void normalize_locale_str(char *dst, char *str, size_t buflen)
{
char *ptr;
ptr = SDL_strchr(str, '.'); /* chop off encoding if specified. */
ptr = SDL_strchr(str, '.'); /* chop off encoding if specified. */
if (ptr != NULL) {
*ptr = '\0';
}
ptr = SDL_strchr(str, '@'); /* chop off extra bits if specified. */
ptr = SDL_strchr(str, '@'); /* chop off extra bits if specified. */
if (ptr != NULL) {
*ptr = '\0';
}
@ -44,14 +43,13 @@ normalize_locale_str(char *dst, char *str, size_t buflen)
if (*str) {
if (*dst) {
SDL_strlcat(dst, ",", buflen); /* SDL has these split by commas */
SDL_strlcat(dst, ",", buflen); /* SDL has these split by commas */
}
SDL_strlcat(dst, str, buflen);
}
}
static void
normalize_locales(char *dst, char *src, size_t buflen)
static void normalize_locales(char *dst, char *src, size_t buflen)
{
char *ptr;
@ -64,8 +62,7 @@ normalize_locales(char *dst, char *src, size_t buflen)
normalize_locale_str(dst, src, buflen);
}
void
SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
void SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
{
/* !!! FIXME: should we be using setlocale()? Or some D-Bus thing? */
SDL_bool isstack;
@ -74,7 +71,7 @@ SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
SDL_assert(buflen > 0);
tmp = SDL_small_alloc(char, buflen, &isstack);
if (!tmp) {
if (tmp == NULL) {
SDL_OutOfMemory();
return;
}
@ -106,4 +103,3 @@ SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -25,8 +25,7 @@
#include <psp2/apputil.h>
#include <psp2/system_param.h>
void
SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
void SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
{
const char *vita_locales[] = {
"ja_JP",
@ -59,8 +58,9 @@ SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
sceAppUtilInit(&initParam, &bootParam);
sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_LANG, &language);
if (language < 0 || language > SCE_SYSTEM_PARAM_LANG_TURKISH)
if (language < 0 || language > SCE_SYSTEM_PARAM_LANG_TURKISH) {
language = SCE_SYSTEM_PARAM_LANG_ENGLISH_US; // default to english
}
SDL_strlcpy(buf, vita_locales[language], buflen);
@ -68,4 +68,3 @@ SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -23,7 +23,7 @@
#include "../../core/windows/SDL_windows.h"
#include "../SDL_syslocale.h"
typedef BOOL (WINAPI *pfnGetUserPreferredUILanguages)(DWORD,PULONG,WCHAR*,PULONG);
typedef BOOL(WINAPI *pfnGetUserPreferredUILanguages)(DWORD, PULONG, WCHAR *, PULONG);
#ifndef MUI_LANGUAGE_NAME
#define MUI_LANGUAGE_NAME 0x8
#endif
@ -31,33 +31,30 @@ typedef BOOL (WINAPI *pfnGetUserPreferredUILanguages)(DWORD,PULONG,WCHAR*,PULONG
static pfnGetUserPreferredUILanguages pGetUserPreferredUILanguages = NULL;
static HMODULE kernel32 = 0;
/* this is the fallback for WinXP...one language, not a list. */
static void
SDL_SYS_GetPreferredLocales_winxp(char *buf, size_t buflen)
static void SDL_SYS_GetPreferredLocales_winxp(char *buf, size_t buflen)
{
char lang[16];
char country[16];
const int langrc = GetLocaleInfoA(LOCALE_USER_DEFAULT,
LOCALE_SISO639LANGNAME,
lang, sizeof (lang));
lang, sizeof(lang));
const int ctryrc = GetLocaleInfoA(LOCALE_USER_DEFAULT,
LOCALE_SISO3166CTRYNAME,
country, sizeof (country));
const int ctryrc = GetLocaleInfoA(LOCALE_USER_DEFAULT,
LOCALE_SISO3166CTRYNAME,
country, sizeof(country));
/* Win95 systems will fail, because they don't have LOCALE_SISO*NAME ... */
if (langrc == 0) {
SDL_SetError("Couldn't obtain language info");
} else {
SDL_snprintf(buf, buflen, "%s%s%s", lang, ctryrc ? "_" : "", ctryrc ? country : "");
(void)SDL_snprintf(buf, buflen, "%s%s%s", lang, ctryrc ? "_" : "", ctryrc ? country : "");
}
}
/* this works on Windows Vista and later. */
static void
SDL_SYS_GetPreferredLocales_vista(char *buf, size_t buflen)
static void SDL_SYS_GetPreferredLocales_vista(char *buf, size_t buflen)
{
ULONG numlangs = 0;
WCHAR *wbuf = NULL;
@ -68,50 +65,48 @@ SDL_SYS_GetPreferredLocales_vista(char *buf, size_t buflen)
pGetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numlangs, NULL, &wbuflen);
wbuf = SDL_small_alloc(WCHAR, wbuflen, &isstack);
if (!wbuf) {
if (wbuf == NULL) {
SDL_OutOfMemory();
return;
}
if (!pGetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numlangs, wbuf, &wbuflen)) {
SDL_SYS_GetPreferredLocales_winxp(buf, buflen); /* oh well, try the fallback. */
SDL_SYS_GetPreferredLocales_winxp(buf, buflen); /* oh well, try the fallback. */
} else {
const ULONG endidx = (ULONG) SDL_min(buflen, wbuflen - 1);
const ULONG endidx = (ULONG)SDL_min(buflen, wbuflen - 1);
ULONG str_start = 0;
ULONG i;
for (i = 0; i < endidx; i++) {
const char ch = (char) wbuf[i]; /* these should all be low-ASCII, safe to cast */
const char ch = (char)wbuf[i]; /* these should all be low-ASCII, safe to cast */
if (ch == '\0') {
buf[i] = ','; /* change null separators to commas */
buf[i] = ','; /* change null separators to commas */
str_start = i;
} else if (ch == '-') {
buf[i] = '_'; /* change '-' to '_' */
buf[i] = '_'; /* change '-' to '_' */
} else {
buf[i] = ch; /* copy through as-is. */
buf[i] = ch; /* copy through as-is. */
}
}
buf[str_start] = '\0'; /* terminate string, chop off final ',' */
buf[str_start] = '\0'; /* terminate string, chop off final ',' */
}
SDL_small_free(wbuf, isstack);
}
void
SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
void SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
{
if (!kernel32) {
kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
if (kernel32) {
pGetUserPreferredUILanguages = (pfnGetUserPreferredUILanguages) GetProcAddress(kernel32, "GetUserPreferredUILanguages");
pGetUserPreferredUILanguages = (pfnGetUserPreferredUILanguages)GetProcAddress(kernel32, "GetUserPreferredUILanguages");
}
}
if (pGetUserPreferredUILanguages == NULL) {
SDL_SYS_GetPreferredLocales_winxp(buf, buflen); /* this is always available */
SDL_SYS_GetPreferredLocales_winxp(buf, buflen); /* this is always available */
} else {
SDL_SYS_GetPreferredLocales_vista(buf, buflen); /* available on Vista and later. */
SDL_SYS_GetPreferredLocales_vista(buf, buflen); /* available on Vista and later. */
}
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 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
@ -27,32 +27,29 @@
/*using namespace Windows::Graphics::Display;*/
#include <wchar.h>
void
SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
void SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
{
WCHAR wbuffer[128] = L"";
int ret = 0;
/* !!! FIXME: do we not have GetUserPreferredUILanguages on WinPhone or UWP? */
# if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
ret = GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_SNAME, wbuffer, SDL_arraysize(wbuffer));
# else
#else
ret = GetSystemDefaultLocaleName(wbuffer, SDL_arraysize(wbuffer));
# endif
#endif
if (ret > 0)
{
if (ret > 0) {
/* Need to convert LPWSTR to LPSTR, that is wide char to char. */
int i;
if ( ((size_t) ret) >= (buflen - 1) ) {
ret = (int) (buflen - 1);
if (((size_t)ret) >= (buflen - 1)) {
ret = (int)(buflen - 1);
}
for (i = 0; i < ret; i++) {
buf[i] = (char) wbuffer[i]; /* assume this was ASCII anyhow. */
buf[i] = (char)wbuffer[i]; /* assume this was ASCII anyhow. */
}
}
}
/* vi: set ts=4 sw=4 expandtab: */