sdl

FORK: Simple Directmedia Layer
git clone https://git.neptards.moe/neptards/sdl.git
Log | Files | Refs

testlocale.c (1977B)


      1 /*
      2   Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
      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 
     15 /* !!! FIXME: move this to the test framework */
     16 
     17 static void log_locales(void)
     18 {
     19     SDL_Locale *locales = SDL_GetPreferredLocales();
     20     if (locales == NULL) {
     21         SDL_Log("Couldn't determine locales: %s", SDL_GetError());
     22     } else {
     23         SDL_Locale *l;
     24         unsigned int total = 0;
     25         SDL_Log("Locales, in order of preference:");
     26         for (l = locales; l->language; l++) {
     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 
     36 int main(int argc, char **argv)
     37 {
     38     /* Enable standard application logging */
     39     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
     40 
     41     /* Print locales and languages */
     42     if (SDL_Init(SDL_INIT_VIDEO) != -1) {
     43         log_locales();
     44 
     45         if ((argc == 2) && (SDL_strcmp(argv[1], "--listen") == 0)) {
     46             SDL_bool keep_going = SDL_TRUE;
     47             while (keep_going) {
     48                 SDL_Event e;
     49                 while (SDL_PollEvent(&e)) {
     50                     if (e.type == SDL_QUIT) {
     51                         keep_going = SDL_FALSE;
     52                     } else if (e.type == SDL_LOCALECHANGED) {
     53                         SDL_Log("Saw SDL_LOCALECHANGED event!");
     54                         log_locales();
     55                     }
     56                 }
     57                 SDL_Delay(10);
     58             }
     59         }
     60 
     61         SDL_Quit();
     62     }
     63 
     64    return 0;
     65 }
     66 
     67 /* vi: set ts=4 sw=4 expandtab: */