const char *Sys_SetLocale (const char *localeID) { Sys_Setenv("LANG", localeID); Sys_Setenv("LANGUAGE", localeID); Sys_Setenv("LC_NUMERIC", "C"); return localeID; }
const char *Sys_SetLocale (const char *localeID) { const char *locale; # ifndef __sun unsetenv("LANGUAGE"); # endif /* __sun */ # ifdef __APPLE__ if (localeID[0] != '\0') { if (Sys_Setenv("LANGUAGE", localeID) != 0) Com_Printf("...setenv for LANGUAGE failed: %s\n", localeID); if (Sys_Setenv("LC_ALL", localeID) != 0) Com_Printf("...setenv for LC_ALL failed: %s\n", localeID); } # endif /* __APPLE__ */ Sys_Setenv("LC_NUMERIC", "C"); setlocale(LC_NUMERIC, "C"); /* set to system default */ setlocale(LC_ALL, "C"); locale = setlocale(LC_MESSAGES, localeID); if (!locale) { if (Sys_Setenv("LANGUAGE", localeID) != 0) { locale = localeID; } } if (!locale) { Com_DPrintf(DEBUG_CLIENT, "...could not set to language: %s\n", localeID); locale = setlocale(LC_MESSAGES, ""); if (!locale) { Com_DPrintf(DEBUG_CLIENT, "...could not set to system language\n"); } return NULL; } Com_Printf("...using language: %s\n", locale); return locale; }
/** * @brief Set or print some environment variables via console command * @sa Sys_Setenv */ static void CL_Env_f (void) { const int argc = Cmd_Argc(); if (argc == 3) { Sys_Setenv(Cmd_Argv(1), Cmd_Argv(2)); } else if (argc == 2) { const char* env = SDL_getenv(Cmd_Argv(1)); if (env) Com_Printf("%s=%s\n", Cmd_Argv(1), env); else Com_Printf("%s undefined\n", Cmd_Argv(1)); } }
/** * @brief Test given language by trying to set locale. * @param[in] localeID language abbreviation. * @return true if setting given language is possible. */ static bool CL_LanguageTest (const char* localeID) { #ifndef _WIN32 int i; language_t* language; localeMapping_t* mapping; #endif char languagePath[MAX_OSPATH]; assert(localeID); /* Find the proper *.mo file. */ if (fs_i18ndir->string[0] != '\0') Q_strncpyz(languagePath, fs_i18ndir->string, sizeof(languagePath)); else #ifdef LOCALEDIR Com_sprintf(languagePath, sizeof(languagePath), LOCALEDIR); #else Com_sprintf(languagePath, sizeof(languagePath), "%s/" BASEDIRNAME "/i18n/", FS_GetCwd()); #endif Com_DPrintf(DEBUG_CLIENT, "CL_LanguageTest: using mo files from '%s'\n", languagePath); Q_strcat(languagePath, sizeof(languagePath), "%s/LC_MESSAGES/ufoai.mo", localeID); /* No *.mo file -> no language. */ if (!FS_FileExists("%s", languagePath)) { Com_DPrintf(DEBUG_CLIENT, "CL_LanguageTest: locale '%s' not found.\n", localeID); return false; } #ifdef _WIN32 if (Sys_Setenv("LANGUAGE=%s", localeID) == 0) { Com_DPrintf(DEBUG_CLIENT, "CL_LanguageTest: locale '%s' found.\n", localeID); return true; } #else for (i = 0, language = languageList; i < languageCount; language = language->next, i++) { if (Q_streq(localeID, language->localeID)) break; } if (i == languageCount) { Com_DPrintf(DEBUG_CLIENT, "CL_LanguageTest: Could not find locale with id '%s'\n", localeID); return false; } mapping = language->localeMapping; if (!mapping) { Com_DPrintf(DEBUG_CLIENT, "No locale mappings for locale with id '%s'\n", localeID); return false; } /* Cycle through all mappings, but stop at first locale possible to set. */ do { /* setlocale() will return nullptr if no setting possible. */ if (setlocale(LC_MESSAGES, mapping->localeMapping)) { Com_DPrintf(DEBUG_CLIENT, "CL_LanguageTest: language '%s' with locale '%s' found.\n", localeID, mapping->localeMapping); return true; } else Com_DPrintf(DEBUG_CLIENT, "CL_LanguageTest: language '%s' with locale '%s' not found on your system.\n", localeID, mapping->localeMapping); mapping = mapping->next; } while (mapping); Com_DPrintf(DEBUG_CLIENT, "CL_LanguageTest: not possible to use language '%s'.\n", localeID); #endif return false; }
bool Rimp_Init (void) { SDL_version version; int attrValue; Com_Printf("\n------- video initialization -------\n"); OBJZERO(r_sdl_config); if (r_driver->string[0] != '\0') { Com_Printf("using driver: %s\n", r_driver->string); SDL_GL_LoadLibrary(r_driver->string); } Sys_Setenv("SDL_VIDEO_CENTERED", "1"); Sys_Setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "0"); if (SDL_WasInit(SDL_INIT_VIDEO) == 0) { if (SDL_Init(SDL_INIT_VIDEO) < 0) Com_Error(ERR_FATAL, "Video SDL_Init failed: %s", SDL_GetError()); } SDL_VERSION(&version) Com_Printf("SDL version: %i.%i.%i\n", version.major, version.minor, version.patch); #if SDL_VERSION_ATLEAST(2,0,0) int screen = 0; const int modes = SDL_GetNumDisplayModes(screen); if (modes > 0) { r_sdl_config.modes = Mem_AllocTypeN(rect_t, modes); for (int i = 0; i < modes; i++) { SDL_DisplayMode displayMode; SDL_GetDisplayMode(screen, i, &displayMode); r_sdl_config.modes[i][0] = displayMode.w; r_sdl_config.modes[i][1] = displayMode.h; } } #else const SDL_VideoInfo* info = SDL_GetVideoInfo(); if (info != nullptr) { SDL_VideoInfo videoInfo; SDL_PixelFormat pixelFormat; SDL_Rect** modes; Com_Printf("I: desktop depth: %ibpp\n", info->vfmt->BitsPerPixel); r_config.videoMemory = info->video_mem; Com_Printf("I: video memory: %i\n", r_config.videoMemory); memcpy(&pixelFormat, info->vfmt, sizeof(pixelFormat)); memcpy(&videoInfo, info, sizeof(videoInfo)); videoInfo.vfmt = &pixelFormat; modes = SDL_ListModes(videoInfo.vfmt, SDL_OPENGL | SDL_FULLSCREEN); if (modes) { if (modes == (SDL_Rect**)-1) { Com_Printf("I: Available resolutions: any resolution is supported\n"); r_sdl_config.modes = nullptr; } else { for (r_sdl_config.numModes = 0; modes[r_sdl_config.numModes]; r_sdl_config.numModes++) {} r_sdl_config.modes = Mem_AllocTypeN(rect_t, r_sdl_config.numModes); for (int i = 0; i < r_sdl_config.numModes; i++) { r_sdl_config.modes[i][0] = modes[i]->w; r_sdl_config.modes[i][1] = modes[i]->h; } } } else { Com_Printf("I: Could not get list of available resolutions\n"); } } char videoDriverName[MAX_VAR] = ""; SDL_VideoDriverName(videoDriverName, sizeof(videoDriverName)); Com_Printf("I: video driver: %s\n", videoDriverName); #endif if (r_sdl_config.numModes > 0) { char buf[4096] = ""; Q_strcat(buf, sizeof(buf), "I: Available resolutions:"); for (int i = 0; i < r_sdl_config.numModes; i++) { Q_strcat(buf, sizeof(buf), " %ix%i", r_sdl_config.modes[i][0], r_sdl_config.modes[i][1]); } Com_Printf("%s (%i)\n", buf, r_sdl_config.numModes); } if (!R_SetMode()) Com_Error(ERR_FATAL, "Video subsystem failed to initialize"); #if !SDL_VERSION_ATLEAST(2,0,0) SDL_WM_SetCaption(GAME_TITLE, GAME_TITLE_LONG); /* we need this in the renderer because if we issue an vid_restart we have * to set these values again, too */ SDL_EnableUNICODE(SDL_ENABLE); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); #endif R_SetSDLIcon(); if (!SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &attrValue)) Com_Printf("I: got %d bits of stencil\n", attrValue); if (!SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &attrValue)) Com_Printf("I: got %d bits of depth buffer\n", attrValue); if (!SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &attrValue)) Com_Printf("I: got double buffer\n"); if (!SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &attrValue)) Com_Printf("I: got %d bits for red\n", attrValue); if (!SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &attrValue)) Com_Printf("I: got %d bits for green\n", attrValue); if (!SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &attrValue)) Com_Printf("I: got %d bits for blue\n", attrValue); if (!SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &attrValue)) Com_Printf("I: got %d bits for alpha\n", attrValue); if (!SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &attrValue)) Com_Printf("I: got multisample %s\n", attrValue != 0 ? "enabled" : "disabled"); if (!SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &attrValue)) Com_Printf("I: got %d multisample buffers\n", attrValue); return true; }