diff --git a/src/dos/dos_keyboard_layout.cpp b/src/dos/dos_keyboard_layout.cpp index 2338b7d296..fe6a56a1c2 100644 --- a/src/dos/dos_keyboard_layout.cpp +++ b/src/dos/dos_keyboard_layout.cpp @@ -55,6 +55,7 @@ extern int tryconvertcp, toSetCodePage(DOS_Shell *shell, int newCP, int opt); extern bool jfont_init; extern int32_t msgcodepage; bool CheckDBCSCP(int32_t codepage); +void Load_Language(std::string name); static FILE* OpenDosboxFile(const char* name) { uint8_t drive; @@ -1747,8 +1748,14 @@ class DOS_KeyboardLayout: public Module_base { } if(isSupportedCP(msgcodepage)) { SwitchLanguage(dos.loaded_codepage, msgcodepage, false); +#if defined(USE_TTF) + if (ttf.inUse) + toSetCodePage(NULL, msgcodepage, -1); + else +#endif if(!CheckDBCSCP(msgcodepage))DOS_ChangeCodepage(msgcodepage, "auto"); - dos.loaded_codepage = msgcodepage; + Load_Language(layoutname); + dos.loaded_codepage=msgcodepage; } } diff --git a/src/dos/dos_programs.cpp b/src/dos/dos_programs.cpp index 5bf3b88c63..91cc9e26b7 100644 --- a/src/dos/dos_programs.cpp +++ b/src/dos/dos_programs.cpp @@ -209,7 +209,6 @@ void DetachFromBios(imageDisk* image) { } void SwitchLanguage(int oldcp, int newcp, bool confirm) { - (void)oldcp; //unused auto iterold = langcp_map.find(lastmsgcp), iternew = langcp_map.find(newcp); std::string langold = iterold != langcp_map.end() ? iterold->second : "", langnew = iternew != langcp_map.end() ? iternew->second : ""; if (loadlang && langnew.size() && strcasecmp(langold.c_str(), langnew.c_str())) { diff --git a/src/misc/messages.cpp b/src/misc/messages.cpp index 0c759952eb..662fe403a1 100644 --- a/src/misc/messages.cpp +++ b/src/misc/messages.cpp @@ -53,7 +53,6 @@ Bitu DOS_ChangeKeyboardLayout(const char* layoutname, int32_t codepage); Bitu DOS_ChangeCodepage(int32_t codepage, const char* codepagefile); Bitu DOS_LoadKeyboardLayout(const char* layoutname, int32_t codepage, const char* codepagefile); bool CheckDBCSCP(int32_t codepage); -void Load_Language(std::string name); #define LINE_IN_MAXLEN 2048 @@ -219,10 +218,10 @@ void SetKEYBCP() { if (IS_PC98_ARCH || IS_JEGA_ARCH || IS_DOSV || dos_kernel_disabled || !strcmp(RunningProgram, "LOADLIN")) return; Bitu return_code; if(CheckDBCSCP(msgcodepage)) { - dos.loaded_codepage = msgcodepage; ShutFontHandle(); InitFontHandle(); JFONT_Init(); + dos.loaded_codepage = msgcodepage; } if (!CheckDBCSCP(msgcodepage) && DOS_ChangeCodepage(msgcodepage, "auto") == KEYB_NOERROR){ dos.loaded_codepage = msgcodepage; diff --git a/src/misc/programs.cpp b/src/misc/programs.cpp index ee27e63ae9..d2bcd20c58 100644 --- a/src/misc/programs.cpp +++ b/src/misc/programs.cpp @@ -727,6 +727,7 @@ bool set_ver(char *s), GFX_IsFullscreen(void); void Load_Language(std::string name) { if (control->opt_lang != "") control->opt_lang = name; + dos.loaded_codepage = msgcodepage; MSG_Init(); #if DOSBOXMENU_TYPE == DOSBOXMENU_HMENU || DOSBOXMENU_TYPE == DOSBOXMENU_NSMENU mainMenu.unbuild(); @@ -738,12 +739,12 @@ void Load_Language(std::string name) { #if defined(USE_TTF) if (TTF_using()) resetFontSize(); #endif - if (!uselangcp && !incall) { - int oldmsgcp = msgcodepage; - msgcodepage = dos.loaded_codepage; + //if (!uselangcp && !incall) { + //int oldmsgcp = msgcodepage; + //dos.loaded_codepage = msgcodepage; SetKEYBCP(); - msgcodepage = oldmsgcp; - } + //msgcodepage = oldmsgcp; + //} } void ApplySetting(std::string pvar, std::string inputline, bool quiet) { diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index 8e30e14219..8fdd0edd89 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -57,7 +57,8 @@ extern bool startcmd, startwait, startquiet, internal_program; extern bool addovl, addipx, addne2k, enableime, showdbcs; extern bool halfwidthkana, force_conversion, gbk; extern const char* RunningProgram; -extern int enablelfn, msgcodepage, lastmsgcp; +extern int enablelfn; +extern int32_t msgcodepage, lastmsgcp; extern uint16_t countryNo; extern unsigned int dosbox_shell_env_size; bool outcon = true, usecon = true, pipetmpdev = true; @@ -81,6 +82,8 @@ void SwitchLanguage(int oldcp, int newcp, bool confirm); void CALLBACK_DeAllocate(Bitu in), DOSBox_ConsolePauseWait(); void GFX_SetTitle(int32_t cycles, int frameskip, Bits timing, bool paused); bool isDBCSCP(), InitCodePage(), isKanji1(uint8_t chr), shiftjis_lead_byte(int c), sdl_wait_on_error(); +void Load_Language(std::string name); +bool CheckDBCSCP(int32_t codepage); Bitu call_shellstop = 0; /* Larger scope so shell_del autoexec can use it to @@ -883,7 +886,7 @@ void DOS_Shell::Prepare(void) { else if (IS_TDOSV) newCP=950; } const char* name = DOS_GetLoadedLayout(); - if (newCP==932||newCP==936||newCP==949||newCP==950||newCP==951) { + if (CheckDBCSCP(newCP)) { dos.loaded_codepage=newCP; SetupDBCSTable(); runRescan("-A -Q"); diff --git a/src/shell/shell_cmds.cpp b/src/shell/shell_cmds.cpp index aea938a297..049224a0f8 100644 --- a/src/shell/shell_cmds.cpp +++ b/src/shell/shell_cmds.cpp @@ -140,6 +140,7 @@ extern void MAPPER_AutoType(std::vector &sequence, const uint32_t w extern void DOS_SetCountry(uint16_t countryNo), DOSV_FillScreen(void); std::string GetDOSBoxXPath(bool withexe=false); FILE *testLoadLangFile(const char *fname); +bool CheckDBCSCP(int32_t codepage); /* support functions */ static char empty_char = 0; @@ -4599,13 +4600,16 @@ void DOS_Shell::CMD_CHCP(char * args) { int32_t cp = dos.loaded_codepage; Bitu keyb_error; if(n == 1) { - if(newCP == 932 || newCP == 936 || newCP == 949 || newCP == 950 || newCP == 951 + if(CheckDBCSCP(newCP) #if defined(USE_TTF) || (ttf.inUse && (newCP >= 1250 && newCP <= 1258)) #endif ) { missing = toSetCodePage(this, newCP, -1); - if(missing > -1) SwitchLanguage(cp, newCP, true); + if(missing > -1) { + SwitchLanguage(cp, newCP, true); + missing = toSetCodePage(this, newCP, -1); + } if(missing > 0) WriteOut(MSG_Get("SHELL_CMD_CHCP_MISSING"), missing); } else { @@ -4630,13 +4634,14 @@ void DOS_Shell::CMD_CHCP(char * args) { return; } } + Load_Language(layout_name); WriteOut(MSG_Get("SHELL_CMD_CHCP_ACTIVE"), dos.loaded_codepage); } else if(n == 2 && strlen(buff)) { + std::string name = buff + 1; if(*buff == ':' && strchr(StripArg(args), ':')) { - std::string name = buff + 1; if(name.empty() && iter != langcp_map.end()) name = iter->second; - if(newCP == 932 || newCP == 936 || newCP == 949 || newCP == 950 || newCP == 951) { + if(CheckDBCSCP(newCP)) { missing = toSetCodePage(this, newCP, -1); if(missing > -1) SwitchLanguage(cp, newCP, true); if(missing > 0) WriteOut(MSG_Get("SHELL_CMD_CHCP_MISSING"), missing); @@ -4676,7 +4681,10 @@ void DOS_Shell::CMD_CHCP(char * args) { if(ttf.inUse) { if(isSupportedCP(newCP)) { missing = toSetCodePage(this, newCP, -1); - if(missing > -1) SwitchLanguage(cp, newCP, true); + if(missing > -1) { + SwitchLanguage(cp, newCP, true); + missing = toSetCodePage(this, newCP, -1); + } if(missing > 0) WriteOut(MSG_Get("SHELL_CMD_CHCP_MISSING"), missing); LOG_MSG("CHCP: Loading cpi/cpx files ignored for TTF output"); } @@ -4685,6 +4693,7 @@ void DOS_Shell::CMD_CHCP(char * args) { LOG_MSG("CHCP: Codepage %d not supported for TTF output", newCP); return; } + Load_Language(name); } else { #endif @@ -4694,7 +4703,7 @@ void DOS_Shell::CMD_CHCP(char * args) { FILE* file = fopen(cpfile.c_str(), "r"); /* should check the result */ std::string exepath = GetDOSBoxXPath(); if(!file && exepath.size()) file = fopen((exepath + CROSS_FILESPLIT + cpfile).c_str(), "r"); - if(file && newCP > 0 && newCP != 932 && newCP != 936 && newCP != 949 && newCP != 950 && newCP != 951) { + if(file && newCP > 0 && !CheckDBCSCP(newCP)) { altcp = newCP; char line[256], * l = line; while(fgets(line, sizeof(line), file)) {