SDL  2.0
SDL_syslocale.cc File Reference
#include <AppKit.h>
#include <LocaleRoster.h>
#include <TypeConstants.h>
#include "../../SDL_internal.h"
#include "../SDL_syslocale.h"
+ Include dependency graph for SDL_syslocale.cc:

Go to the source code of this file.

Functions

void SDL_SYS_GetPreferredLocales (char *buf, size_t buflen)
 

Function Documentation

◆ SDL_SYS_GetPreferredLocales()

void SDL_SYS_GetPreferredLocales ( char *  buf,
size_t  buflen 
)

Definition at line 30 of file SDL_syslocale.cc.

31 {
32  BLocaleRoster *roster = BLocaleRoster::Default();
33  roster->Refresh();
34 
35  BMessage msg;
36  if (roster->GetPreferredLanguages(&msg) != B_OK) {
37  SDL_SetError("BLocaleRoster couldn't get preferred languages");
38  return;
39  }
40 
41  const char *key = "language";
42  type_code typ = B_ANY_TYPE;
43  int32 numlangs = 0;
44  if ((msg.GetInfo(key, &typ, &numlangs) != B_OK) || (typ != B_STRING_TYPE)) {
45  SDL_SetError("BLocaleRoster message was wrong");
46  return;
47  }
48 
49  for (int32 i = 0; i < numlangs; i++) {
50  const char *str = NULL;
51  if (msg.FindString(key, i, &str) != B_OK) {
52  continue;
53  }
54 
55  const size_t len = SDL_strlen(str);
56  if (buflen <= len) {
57  break; // can't fit it, we're done.
58  }
59 
60  SDL_strlcpy(buf, str, buflen);
61  buf += len;
62  buflen -= len;
63 
64  if (i < (numlangs - 1)) {
65  if (buflen <= 1) {
66  break; // out of room, stop looking.
67  }
68  buf[0] = ','; // add a comma between entries.
69  buf[1] = '\0';
70  buf++;
71  buflen--;
72  }
73  }
74 }
#define SDL_SetError
#define SDL_strlen
#define SDL_strlcpy
GLenum GLsizei len
GLenum GLuint GLenum GLsizei const GLchar * buf
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 NULL
Definition: begin_code.h:163
GLuint64 key
Definition: gl2ext.h:2192

References i, NULL, SDL_SetError, SDL_strlcpy, and SDL_strlen.