Atlas - testlocale.c

Home / ext / SDL / test Lines: 1 | Size: 2671 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Copyright (C) 1997-2025 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 <SDL3/SDL.h> 13#include <SDL3/SDL_main.h> 14#include <SDL3/SDL_test.h> 15 16static void log_locales(void) 17{ 18 SDL_Locale **locales = SDL_GetPreferredLocales(NULL); 19 if (!locales) { 20 SDL_Log("Couldn't determine locales: %s", SDL_GetError()); 21 } else { 22 int i; 23 unsigned int total = 0; 24 SDL_Log("Locales, in order of preference:"); 25 for (i = 0; locales[i]; ++i) { 26 const SDL_Locale *l = locales[i]; 27 const char *c = l->country; 28 SDL_Log(" - %s%s%s", l->language, c ? "_" : "", c ? c : ""); 29 total++; 30 } 31 SDL_Log("%u locales seen.", total); 32 SDL_free(locales); 33 } 34} 35 36int main(int argc, char **argv) 37{ 38 int i; 39 int listen = 0; 40 SDLTest_CommonState *state; 41 42 /* Initialize test framework */ 43 state = SDLTest_CommonCreateState(argv, 0); 44 if (!state) { 45 return 1; 46 } 47 48 /* Parse commandline */ 49 for (i = 1; i < argc;) { 50 int consumed; 51 52 consumed = SDLTest_CommonArg(state, i); 53 if (!consumed) { 54 if (SDL_strcmp(argv[1], "--listen") == 0) { 55 listen = 1; 56 consumed = 1; 57 state->flags |= SDL_INIT_VIDEO; 58 } 59 } 60 if (consumed <= 0) { 61 static const char *options[] = { "[--listen]", NULL }; 62 SDLTest_CommonLogUsage(state, argv[0], options); 63 return 1; 64 } 65 66 i += consumed; 67 } 68 69 /* Print locales and languages */ 70 if (SDLTest_CommonInit(state) == false) { 71 return 1; 72 } 73 74 log_locales(); 75 76 if (listen) { 77 int done = 0; 78 while (!done) { 79 SDL_Event e; 80 SDLTest_CommonEvent(state, &e, &done); 81 while (SDL_PollEvent(&e)) { 82 if (e.type == SDL_EVENT_QUIT) { 83 done = 1; 84 } else if (e.type == SDL_EVENT_LOCALE_CHANGED) { 85 SDL_Log("Saw SDL_EVENT_LOCALE_CHANGED event!"); 86 log_locales(); 87 } 88 } 89 90 for (i = 0; i < state->num_windows; i++) { 91 SDL_RenderPresent(state->renderers[i]); 92 } 93 94 SDL_Delay(10); 95 } 96 } 97 98 SDLTest_CommonQuit(state); 99 100 return 0; 101} 102
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.