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

Go to the source code of this file.

Functions

static void normalize_locale_str (char *dst, char *str, size_t buflen)
 
static void normalize_locales (char *dst, char *src, size_t buflen)
 
void SDL_SYS_GetPreferredLocales (char *buf, size_t buflen)
 

Function Documentation

◆ normalize_locale_str()

static void normalize_locale_str ( char *  dst,
char *  str,
size_t  buflen 
)
static

Definition at line 26 of file SDL_syslocale.c.

27 {
28  char *ptr;
29 
30  ptr = SDL_strchr(str, '.'); /* chop off encoding if specified. */
31  if (ptr != NULL) {
32  *ptr = '\0';
33  }
34 
35  ptr = SDL_strchr(str, '@'); /* chop off extra bits if specified. */
36  if (ptr != NULL) {
37  *ptr = '\0';
38  }
39 
40  /* The "C" locale isn't useful for our needs, ignore it if you see it. */
41  if ((str[0] == 'C') && (str[1] == '\0')) {
42  return;
43  }
44 
45  if (*str) {
46  if (*dst) {
47  SDL_strlcat(dst, ",", buflen); /* SDL has these split by commas */
48  }
49  SDL_strlcat(dst, str, buflen);
50  }
51 }
#define SDL_strchr
#define SDL_strlcat
GLenum GLenum dst
#define NULL
Definition: begin_code.h:163
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF ptr

References NULL, ptr, SDL_strchr, and SDL_strlcat.

Referenced by normalize_locales().

◆ normalize_locales()

static void normalize_locales ( char *  dst,
char *  src,
size_t  buflen 
)
static

Definition at line 54 of file SDL_syslocale.c.

55 {
56  char *ptr;
57 
58  /* entries are separated by colons */
59  while ((ptr = SDL_strchr(src, ':')) != NULL) {
60  *ptr = '\0';
61  normalize_locale_str(dst, src, buflen);
62  src = ptr + 1;
63  }
64  normalize_locale_str(dst, src, buflen);
65 }
GLenum src
static void normalize_locale_str(char *dst, char *str, size_t buflen)
Definition: SDL_syslocale.c:26

References normalize_locale_str(), NULL, ptr, and SDL_strchr.

Referenced by SDL_SYS_GetPreferredLocales().

◆ SDL_SYS_GetPreferredLocales()

void SDL_SYS_GetPreferredLocales ( char *  buf,
size_t  buflen 
)

Definition at line 68 of file SDL_syslocale.c.

69 {
70  /* !!! FIXME: should we be using setlocale()? Or some D-Bus thing? */
71  SDL_bool isstack;
72  const char *envr;
73  char *tmp;
74 
75  SDL_assert(buflen > 0);
76  tmp = SDL_small_alloc(char, buflen, &isstack);
77  if (!tmp) {
79  return;
80  }
81 
82  *tmp = '\0';
83 
84  /* LANG is the primary locale (maybe) */
85  envr = SDL_getenv("LANG");
86  if (envr) {
87  SDL_strlcpy(tmp, envr, buflen);
88  }
89 
90  /* fallback languages */
91  envr = SDL_getenv("LANGUAGE");
92  if (envr) {
93  if (*tmp) {
94  SDL_strlcat(tmp, ":", buflen);
95  }
96  SDL_strlcat(tmp, envr, buflen);
97  }
98 
99  if (*tmp == '\0') {
100  SDL_SetError("LANG environment variable isn't set");
101  } else {
102  normalize_locales(buf, tmp, buflen);
103  }
104 
105  SDL_small_free(tmp, isstack);
106 }
#define SDL_assert(condition)
Definition: SDL_assert.h:171
#define SDL_SetError
#define SDL_getenv
#define SDL_strlcpy
#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
GLenum GLuint GLenum GLsizei const GLchar * buf
SDL_bool
Definition: SDL_stdinc.h:168
static void normalize_locales(char *dst, char *src, size_t buflen)
Definition: SDL_syslocale.c:54

References normalize_locales(), SDL_assert, SDL_getenv, SDL_OutOfMemory, SDL_SetError, SDL_small_alloc, SDL_small_free, SDL_strlcat, and SDL_strlcpy.