SDL  2.0
SDL_syslocale.c File Reference
+ Include dependency graph for SDL_syslocale.c:

Go to the source code of this file.

Macros

#define MUI_LANGUAGE_NAME   0x8
 

Typedefs

typedef BOOL(WINAPI * pfnGetUserPreferredUILanguages) (DWORD, PULONG, WCHAR *, PULONG)
 

Functions

static void SDL_SYS_GetPreferredLocales_winxp (char *buf, size_t buflen)
 
static void SDL_SYS_GetPreferredLocales_vista (char *buf, size_t buflen)
 
void SDL_SYS_GetPreferredLocales (char *buf, size_t buflen)
 

Variables

static pfnGetUserPreferredUILanguages pGetUserPreferredUILanguages = NULL
 
static HMODULE kernel32 = 0
 

Macro Definition Documentation

◆ MUI_LANGUAGE_NAME

#define MUI_LANGUAGE_NAME   0x8

Definition at line 28 of file SDL_syslocale.c.

Typedef Documentation

◆ pfnGetUserPreferredUILanguages

typedef BOOL(WINAPI * pfnGetUserPreferredUILanguages) (DWORD, PULONG, WCHAR *, PULONG)

Definition at line 26 of file SDL_syslocale.c.

Function Documentation

◆ SDL_SYS_GetPreferredLocales()

void SDL_SYS_GetPreferredLocales ( char *  buf,
size_t  buflen 
)

Definition at line 100 of file SDL_syslocale.c.

101 {
102  if (!kernel32) {
103  kernel32 = LoadLibraryW(L"kernel32.dll");
104  if (kernel32) {
105  pGetUserPreferredUILanguages = (pfnGetUserPreferredUILanguages) GetProcAddress(kernel32, "GetUserPreferredUILanguages");
106  }
107  }
108 
110  SDL_SYS_GetPreferredLocales_winxp(buf, buflen); /* this is always available */
111  } else {
112  SDL_SYS_GetPreferredLocales_vista(buf, buflen); /* available on Vista and later. */
113  }
114 }
GLenum GLuint GLenum GLsizei const GLchar * buf
#define NULL
Definition: begin_code.h:163
static HMODULE kernel32
Definition: SDL_syslocale.c:32
static pfnGetUserPreferredUILanguages pGetUserPreferredUILanguages
Definition: SDL_syslocale.c:31
static void SDL_SYS_GetPreferredLocales_vista(char *buf, size_t buflen)
Definition: SDL_syslocale.c:60
static void SDL_SYS_GetPreferredLocales_winxp(char *buf, size_t buflen)
Definition: SDL_syslocale.c:37
BOOL(WINAPI * pfnGetUserPreferredUILanguages)(DWORD, PULONG, WCHAR *, PULONG)
Definition: SDL_syslocale.c:26

References kernel32, NULL, pGetUserPreferredUILanguages, SDL_SYS_GetPreferredLocales_vista(), and SDL_SYS_GetPreferredLocales_winxp().

◆ SDL_SYS_GetPreferredLocales_vista()

static void SDL_SYS_GetPreferredLocales_vista ( char *  buf,
size_t  buflen 
)
static

Definition at line 60 of file SDL_syslocale.c.

61 {
62  ULONG numlangs = 0;
63  WCHAR *wbuf = NULL;
64  ULONG wbuflen = 0;
65  SDL_bool isstack;
66 
69 
70  wbuf = SDL_small_alloc(WCHAR, wbuflen, &isstack);
71  if (!wbuf) {
73  return;
74  }
75 
76  if (!pGetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numlangs, wbuf, &wbuflen)) {
77  SDL_SYS_GetPreferredLocales_winxp(buf, buflen); /* oh well, try the fallback. */
78  } else {
79  const ULONG endidx = (ULONG) SDL_min(buflen, wbuflen - 1);
80  ULONG str_start = 0;
81  ULONG i;
82  for (i = 0; i < endidx; i++) {
83  const char ch = (char) wbuf[i]; /* these should all be low-ASCII, safe to cast */
84  if (ch == '\0') {
85  buf[i] = ','; /* change null separators to commas */
86  str_start = i;
87  } else if (ch == '-') {
88  buf[i] = '_'; /* change '-' to '_' */
89  } else {
90  buf[i] = ch; /* copy through as-is. */
91  }
92  }
93  buf[str_start] = '\0'; /* terminate string, chop off final ',' */
94  }
95 
96  SDL_small_free(wbuf, isstack);
97 }
#define SDL_assert(condition)
Definition: SDL_assert.h:171
#define SDL_OutOfMemory()
Definition: SDL_error.h:88
#define SDL_small_alloc(type, count, pisstack)
Definition: SDL_internal.h:39
#define SDL_small_free(ptr, isstack)
Definition: SDL_internal.h:40
SDL_bool
Definition: SDL_stdinc.h:168
#define SDL_min(x, y)
Definition: SDL_stdinc.h:412
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define MUI_LANGUAGE_NAME
Definition: SDL_syslocale.c:28

References i, MUI_LANGUAGE_NAME, NULL, pGetUserPreferredUILanguages, SDL_assert, SDL_min, SDL_OutOfMemory, SDL_small_alloc, SDL_small_free, and SDL_SYS_GetPreferredLocales_winxp().

Referenced by SDL_SYS_GetPreferredLocales().

◆ SDL_SYS_GetPreferredLocales_winxp()

static void SDL_SYS_GetPreferredLocales_winxp ( char *  buf,
size_t  buflen 
)
static

Definition at line 37 of file SDL_syslocale.c.

38 {
39  char lang[16];
40  char country[16];
41 
42  const int langrc = GetLocaleInfoA(LOCALE_USER_DEFAULT,
43  LOCALE_SISO639LANGNAME,
44  lang, sizeof (lang));
45 
46  const int ctryrc = GetLocaleInfoA(LOCALE_USER_DEFAULT,
47  LOCALE_SISO3166CTRYNAME,
48  country, sizeof (country));
49 
50  /* Win95 systems will fail, because they don't have LOCALE_SISO*NAME ... */
51  if (langrc == 0) {
52  SDL_SetError("Couldn't obtain language info");
53  } else {
54  SDL_snprintf(buf, buflen, "%s%s%s", lang, ctryrc ? "_" : "", ctryrc ? country : "");
55  }
56 }
#define SDL_SetError
#define SDL_snprintf

References SDL_SetError, and SDL_snprintf.

Referenced by SDL_SYS_GetPreferredLocales(), and SDL_SYS_GetPreferredLocales_vista().

Variable Documentation

◆ kernel32

HMODULE kernel32 = 0
static

Definition at line 32 of file SDL_syslocale.c.

Referenced by SDL_SYS_GetPreferredLocales().

◆ pGetUserPreferredUILanguages

pfnGetUserPreferredUILanguages pGetUserPreferredUILanguages = NULL
static