| 1 |
/* |
| 2 |
Copyright (C) 1997-2026 Sam Lantinga <[email protected]> |
| 3 |
|
| 4 |
This software is provided 'as-is', without any express or implied |
| 5 |
warranty. In no event will the authors be held liable for any damages |
| 6 |
arising from the use of this software. |
| 7 |
|
| 8 |
Permission is granted to anyone to use this software for any purpose, |
| 9 |
including commercial applications, and to alter it and redistribute it |
| 10 |
freely. |
| 11 |
*/ |
| 12 |
#include <stdio.h> |
| 13 |
#include "SDL.h" |
| 14 |
#include "SDL_test.h" |
| 15 |
|
| 16 |
/* !!! FIXME: move this to the test framework */ |
| 17 |
|
| 18 |
static void log_locales(void) |
| 19 |
{ |
| 20 |
SDL_Locale *locales = SDL_GetPreferredLocales(); |
| 21 |
if (!locales) { |
| 22 |
SDL_Log("Couldn't determine locales: %s", SDL_GetError()); |
| 23 |
} else { |
| 24 |
SDL_Locale *l; |
| 25 |
unsigned int total = 0; |
| 26 |
SDL_Log("Locales, in order of preference:"); |
| 27 |
for (l = locales; l->language; l++) { |
| 28 |
const char *c = l->country; |
| 29 |
SDL_Log(" - %s%s%s", l->language, c ? "_" : "", c ? c : ""); |
| 30 |
total++; |
| 31 |
} |
| 32 |
SDL_Log("%u locales seen.", total); |
| 33 |
SDL_free(locales); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
int main(int argc, char **argv) |
| 38 |
{ |
| 39 |
SDLTest_CommonState *state; |
| 40 |
SDL_bool listen = SDL_FALSE; |
| 41 |
int i = 1; |
| 42 |
|
| 43 |
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); |
| 44 |
if (!state) { |
| 45 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError()); |
| 46 |
return 1; |
| 47 |
} |
| 48 |
|
| 49 |
/* Enable standard application logging */ |
| 50 |
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); |
| 51 |
|
| 52 |
/* Parse commandline */ |
| 53 |
for (i = 1; i < argc;) { |
| 54 |
int consumed; |
| 55 |
|
| 56 |
consumed = SDLTest_CommonArg(state, i); |
| 57 |
if (!consumed) { |
| 58 |
if (SDL_strcmp("--listen", argv[i]) == 0) { |
| 59 |
listen = SDL_TRUE; |
| 60 |
consumed = 1; |
| 61 |
} |
| 62 |
} |
| 63 |
if (consumed <= 0) { |
| 64 |
static const char *options[] = { "[--listen]", NULL }; |
| 65 |
SDLTest_CommonLogUsage(state, argv[0], options); |
| 66 |
return 1; |
| 67 |
} |
| 68 |
|
| 69 |
i += consumed; |
| 70 |
} |
| 71 |
|
| 72 |
if (!SDLTest_CommonInit(state)) { |
| 73 |
return 1; |
| 74 |
} |
| 75 |
|
| 76 |
/* Print locales and languages */ |
| 77 |
log_locales(); |
| 78 |
|
| 79 |
if (listen) { |
| 80 |
SDL_bool keep_going = SDL_TRUE; |
| 81 |
while (keep_going) { |
| 82 |
SDL_Event e; |
| 83 |
while (SDL_PollEvent(&e)) { |
| 84 |
if (e.type == SDL_QUIT) { |
| 85 |
keep_going = SDL_FALSE; |
| 86 |
} else if (e.type == SDL_LOCALECHANGED) { |
| 87 |
SDL_Log("Saw SDL_LOCALECHANGED event!"); |
| 88 |
log_locales(); |
| 89 |
} |
| 90 |
} |
| 91 |
SDL_Delay(10); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
SDLTest_CommonQuit(state); |
| 96 |
|
| 97 |
return 0; |
| 98 |
} |
| 99 |
|
| 100 |
/* vi: set ts=4 sw=4 expandtab: */ |