Skip to content

Commit

Permalink
Test2
Browse files Browse the repository at this point in the history
  • Loading branch information
maron2000 committed Sep 30, 2024
1 parent a8882de commit 4a6fcf8
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 84 deletions.
7 changes: 6 additions & 1 deletion src/dos/dos_keyboard_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1419,13 +1419,18 @@ Bitu DOS_ChangeKeyboardLayout(const char* layoutname, int32_t codepage) {
return kerrcode;
}
// Everything went fine, switch to new layout
delete loaded_layout;
loaded_layout = temp_layout;
return KEYB_NOERROR;
}

Bitu DOS_ChangeCodepage(int32_t codepage, const char* codepagefile) {
// try to read the layout for the specified codepage
Bitu kerrcode = loaded_layout->read_codepage_file(codepagefile, codepage);
Bitu kerrcode;
if(loaded_layout)kerrcode = loaded_layout->read_codepage_file(codepagefile, codepage);
else {
kerrcode = DOS_LoadKeyboardLayout("us", codepage, "auto");
}
if(kerrcode) {
return kerrcode;
}
Expand Down
28 changes: 6 additions & 22 deletions src/dos/dos_programs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,13 @@ std::string GetDOSBoxXPath(bool withexe=false);
FILE *testLoadLangFile(const char *fname);
bool loadlangnew = false;
extern bool loadlangcp;
Bitu DOS_SwitchKeyboardLayout(const char* new_layout, int32_t& tried_cp);
Bitu DOS_LoadKeyboardLayout(const char* layoutname, int32_t codepage, const char* codepagefile);
Bitu DOS_ChangeKeyboardLayout(const char* layoutname, int32_t codepage);
Bitu DOS_ChangeCodepage(int32_t codepage, const char* codepagefile);
const char* DOS_GetLoadedLayout(void);
void SwitchLanguage(int oldcp, int newcp, bool confirm);
bool CheckDBCSCP(int32_t codepage);
bool CheckDBCSCP(int32_t codepage), TTF_using(void);

#if defined(OS2)
#define INCL DOSFILEMGR
Expand Down Expand Up @@ -6912,12 +6916,6 @@ void runImgmount(const char *str) {
imgmount.Run();
}

Bitu DOS_SwitchKeyboardLayout(const char* new_layout, int32_t& tried_cp);
Bitu DOS_LoadKeyboardLayout(const char * layoutname, int32_t codepage, const char * codepagefile);
Bitu DOS_ChangeKeyboardLayout(const char* layoutname, int32_t codepage);
Bitu DOS_ChangeCodepage(int32_t codepage, const char* codepagefile);
const char* DOS_GetLoadedLayout(void);

class KEYB : public Program {
public:
void Run(void) override;
Expand All @@ -6939,22 +6937,8 @@ void KEYB::Run(void) {
const char* layout_name = DOS_GetLoadedLayout();
if(tocp && !IS_PC98_ARCH) {
dos.loaded_codepage = tocp;
#if defined(USE_TTF)
if(ttf.inUse) {
dos.loaded_codepage = cpbak;
if((TTF_using() && isSupportedCP(tocp)) || !TTF_using()) {
toSetCodePage(NULL, tocp, -1);
}
else
#endif
{
MSG_Init();
DOSBox_SetSysMenu();
if(isDBCSCP()) {
ShutFontHandle();
InitFontHandle();
JFONT_Init();
}
SetupDBCSTable();
runRescan("-A -Q");
#if C_OPENGL && DOSBOXMENU_TYPE == DOSBOXMENU_SDLDRAW
if(OpenGL_using() && control->opt_lang.size() && lastcp && lastcp != dos.loaded_codepage)
Expand Down
3 changes: 3 additions & 0 deletions src/gui/sdlmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ extern bool force_load_state, force_conversion;
extern bool pc98_force_ibm_layout, gbk, chinasea;
extern bool inshell, enable_config_as_shell_commands;
extern bool switchttf, ttfswitch, switch_output_from_ttf;
extern bool skip_loadmessagefile;
bool checkmenuwidth = false;
bool dos_kernel_disabled = true;
bool winrun=false, use_save_file=false;
Expand Down Expand Up @@ -9059,7 +9060,9 @@ int main(int argc, char* argv[]) SDL_MAIN_NOEXCEPT {
/* finally, the mapper */
MAPPER_Init();
AllocCallback2();
skip_loadmessagefile = true;
MSG_Init();
skip_loadmessagefile = false;

/* stop at this point, and show the configuration tool/mapper editor, if instructed */
if (control->opt_startui) {
Expand Down
62 changes: 30 additions & 32 deletions src/misc/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ 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);
void Load_Language(std::string name);
bool CheckDBCSCP(int32_t codepage);
bool CheckDBCSCP(int32_t codepage), TTF_using(void);
bool loadlangcp = false;
extern bool loadlangnew;
extern bool loadlangnew, CHCPChangecodepage;

#define LINE_IN_MAXLEN 2048

Expand Down Expand Up @@ -99,6 +99,10 @@ bool InitCodePage() {
dos.loaded_codepage = msgcodepage;
return true;
}
if(msgcodepage > 0) {
dos.loaded_codepage = msgcodepage;
return true;
}
Section_prop *section = static_cast<Section_prop *>(control->GetSection("config"));
if (section!=NULL && !control->opt_noconfig && !IS_PC98_ARCH && !IS_JEGA_ARCH && !IS_DOSV) {
char *countrystr = (char *)section->Get_string("country"), *r=strchr(countrystr, ',');
Expand All @@ -110,10 +114,6 @@ bool InitCodePage() {
}
}
}
if (msgcodepage>0) {
dos.loaded_codepage = msgcodepage;
return true;
}
}
if (!dos.loaded_codepage) {
dos.loaded_codepage = GetDefaultCP();
Expand Down Expand Up @@ -211,7 +211,7 @@ void AddMessages() {
// True if specified codepage is a DBCS codepage
bool CheckDBCSCP(int32_t codepage) {
if(codepage == 932 || codepage == 936 || codepage == 949 || codepage == 950 || codepage == 951) {
LOG_MSG("CheckDBCSCP: Codepage %d true", codepage);
//LOG_MSG("CheckDBCSCP: Codepage %d true", codepage);
return true;
}
else return false;
Expand Down Expand Up @@ -271,9 +271,12 @@ FILE *testLoadLangFile(const char *fname) {
return mfile;
}

void initcodepagefont(void);
char loaded_fname[LINE_IN_MAXLEN + 1024];
bool skip_loadmessagefile = false;
void LoadMessageFile(const char * fname) {
if (!fname) return;
if(skip_loadmessagefile) return;
if (!fname) return;
if(*fname=='\0') return; //empty string=no languagefile
if(!loadlangnew) return; //load languagefile only when asked to
if (!strcmp(fname, loaded_fname)){
Expand All @@ -285,7 +288,7 @@ void LoadMessageFile(const char * fname) {

FILE * mfile=testLoadLangFile(fname);
/* This should never happen and since other modules depend on this use a normal printf */
if (!mfile) {
if (mfile == NULL) {
std::string message="Could not load language message file '"+std::string(fname)+"'. The default language will be used.";
systemmessagebox("Warning", message.c_str(), "ok","warning", 1);
SetVal("dosbox", "language", "");
Expand All @@ -305,7 +308,7 @@ void LoadMessageFile(const char * fname) {
int cp=dos.loaded_codepage;
if (!dos.loaded_codepage) res=InitCodePage();
while(fgets(linein, LINE_IN_MAXLEN+1024, mfile)) {
/* Parse the read line */
/* Parse the read line */
/* First remove characters 10 and 13 from the line */
char * parser=linein;
char * writer=linein;
Expand Down Expand Up @@ -337,12 +340,15 @@ void LoadMessageFile(const char * fname) {
return;
}
else {
if(TTF_using() && !isSupportedCP(c)) {
LOG_MSG("Codepage %d not supported in TTF mode", c);
return;
}
std::string msg = "The specified language file uses code page " + std::to_string(c) + ". Do you want to change to this code page accordingly?";
if(control->opt_langcp || uselangcp || !loadlang || (loadlang && systemmessagebox("DOSBox-X language file", msg.c_str(), "yesno", "question", 1))){
if(control->opt_langcp || uselangcp || CHCPChangecodepage || !loadlang || (loadlang && systemmessagebox("DOSBox-X language file", msg.c_str(), "yesno", "question", 1))){
loadlangcp = true;
msgcodepage = c;
if(CheckDBCSCP(c)) int missing = toSetCodePage(NULL, c, 0);
else Bitu keyb_error = DOS_ChangeCodepage(c, "auto");
if((TTF_using() && isSupportedCP(c))|| !TTF_using()) int missing = toSetCodePage(NULL, c, (loadlangnew && dos.loaded_codepage != msgcodepage)?-1:0);
if (c == 950 && !chinasea) makestdcp950table();
if (c == 951 && chinasea) makeseacp951table();
lastmsgcp = c;
Expand Down Expand Up @@ -400,27 +406,16 @@ void LoadMessageFile(const char * fname) {
menu_update_dynamic();
menu_update_autocycle();
update_bindbutton_text();
dos.loaded_codepage=cp;
if (loadlangcp && msgcodepage>0 && isSupportedCP(msgcodepage)) {
if (loadlangcp && msgcodepage>0) {
if (!IS_DOSV && !IS_JEGA_ARCH) {
if(CheckDBCSCP(msgcodepage)) {
toSetCodePage(NULL, msgcodepage, -2);
dos.loaded_codepage = msgcodepage;
ShutFontHandle();
InitFontHandle();
JFONT_Init();
SetupDBCSTable();
if(!TTF_using() || (TTF_using() && isSupportedCP(msgcodepage))) {
toSetCodePage(NULL, msgcodepage, (loadlangnew && msgcodepage != dos.loaded_codepage)?-1:-2);
}
else {
Bitu keyb_error = DOS_ChangeCodepage(msgcodepage, "auto");
if(keyb_error == KEYB_NOERROR) dos.loaded_codepage = msgcodepage;
DOSBox_SetSysMenu();
DOSBox_SetSysMenu();
#if C_OPENGL && DOSBOXMENU_TYPE == DOSBOXMENU_SDLDRAW
if (OpenGL_using() && control->opt_lang.size() && lastcp && lastcp != dos.loaded_codepage)
UpdateSDLDrawTexture();
if (OpenGL_using() && control->opt_lang.size() && lastcp && lastcp != dos.loaded_codepage)
UpdateSDLDrawTexture();
#endif
}
SetKEYBCP();
}
}
refreshExtChar();
Expand Down Expand Up @@ -511,7 +506,7 @@ void MSG_Init() {
if (control->opt_lang != "") {
LoadMessageFile(control->opt_lang.c_str());
//SetVal("dosbox", "language", control->opt_lang.c_str());
if (control->opt_langcp && msgcodepage>0 && isSupportedCP(msgcodepage)) {
if (control->opt_langcp && msgcodepage>0) {
Section_prop *sec = static_cast<Section_prop *>(control->GetSection("config"));
char cstr[20];
cstr[0] = 0;
Expand Down Expand Up @@ -543,11 +538,14 @@ void MSG_Init() {
loadlangnew = true;
std::string path = pathprop->realpath;
ResolvePath(path);
if(testLoadLangFile(path.c_str()))
if(testLoadLangFile(path.c_str())) {
loadlangnew = true;
LoadMessageFile(path.c_str());
}
else {
std::string lang = section->Get_string("language");
if(lang.size()) {
loadlangnew = true;
LoadMessageFile(lang.c_str());
}
}
Expand Down
1 change: 0 additions & 1 deletion src/shell/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ Bitu call_int23 = 0;

std::string GetDOSBoxXPath(bool withexe=false);
const char* DOS_GetLoadedLayout(void);
Bitu DOS_ChangeCodepage(int32_t codepage, const char* codepagefile);
int Reflect_Menu(void);
void SetIMPosition(void);
void SetKEYBCP();
Expand Down
45 changes: 17 additions & 28 deletions src/shell/shell_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ extern void MAPPER_AutoType(std::vector<std::string> &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);
const char* DOS_GetLoadedLayout(void);
Bitu DOS_ChangeCodepage(int32_t codepage, const char* codepagefile);
Bitu DOS_ChangeKeyboardLayout(const char* layoutname, int32_t codepage);
bool CheckDBCSCP(int32_t codepage);
bool CHCPChangecodepage = false; // Codepage to be changed by CHCP command

Expand Down Expand Up @@ -4528,14 +4531,16 @@ extern bool jfont_init, isDBCSCP();
extern Bitu DOS_LoadKeyboardLayout(const char * layoutname, int32_t codepage, const char * codepagefile);
void runRescan(const char *str), MSG_Init(), JFONT_Init(), InitFontHandle(), ShutFontHandle(), initcodepagefont(), DOSBox_SetSysMenu();
int toSetCodePage(DOS_Shell *shell, int newCP, int opt) {
if (isSupportedCP(newCP)) {
dos.loaded_codepage = newCP;
if ((TTF_using() && isSupportedCP(newCP))|| !TTF_using()){
if(!CheckDBCSCP(newCP)) DOS_ChangeCodepage(newCP, "auto");
int32_t oldcp = dos.loaded_codepage;
dos.loaded_codepage = newCP;
int missing = 0;
#if defined(USE_TTF)
missing = TTF_using() ? setTTFCodePage() : 0;
#endif
if (!TTF_using()) initcodepagefont();
if (dos.loaded_codepage==437 && DOS_GetLoadedLayout() == NULL) DOS_LoadKeyboardLayout("us", 437, "auto");
//if (dos.loaded_codepage==437 && DOS_GetLoadedLayout() == NULL) DOS_LoadKeyboardLayout("us", 437, "auto");
if (opt==-1) {
MSG_Init();
#if DOSBOXMENU_TYPE == DOSBOXMENU_HMENU
Expand All @@ -4551,8 +4556,8 @@ int toSetCodePage(DOS_Shell *shell, int newCP, int opt) {
ShutFontHandle();
InitFontHandle();
JFONT_Init();
SetupDBCSTable();
}
SetupDBCSTable();
runRescan("-A -Q");
#if defined(USE_TTF)
if ((opt==-1||opt==-2)&&TTF_using()) {
Expand All @@ -4573,10 +4578,6 @@ int toSetCodePage(DOS_Shell *shell, int newCP, int opt) {
return -1;
}

const char* DOS_GetLoadedLayout(void);
Bitu DOS_ChangeCodepage(int32_t codepage, const char* codepagefile);
Bitu DOS_ChangeKeyboardLayout(const char* layoutname, int32_t codepage);

void DOS_Shell::CMD_CHCP(char * args) {
HELP("CHCP");
args = trim(args);
Expand All @@ -4601,15 +4602,11 @@ void DOS_Shell::CMD_CHCP(char * args) {
int32_t cp = dos.loaded_codepage;
Bitu keyb_error;
if(n == 1) {
if(CheckDBCSCP(newCP)
#if defined(USE_TTF)
|| (ttf.inUse && isSupportedCP(newCP))
#endif
) {
if(!TTF_using()|| (TTF_using() && isSupportedCP(newCP))){
CHCPChangecodepage = true;
SwitchLanguage(cp, newCP, true);
missing = toSetCodePage(this, newCP, loadlangnew?-1:0);
if(missing > 0) WriteOut(MSG_Get("SHELL_CMD_CHCP_MISSING"), missing);
missing = toSetCodePage(this, newCP, loadlangnew ? -1 : 0);
if (missing > 0) WriteOut(MSG_Get("SHELL_CMD_CHCP_MISSING"), missing);
}
else {
#if defined(USE_TTF)
Expand All @@ -4618,18 +4615,9 @@ void DOS_Shell::CMD_CHCP(char * args) {
LOG_MSG("CHCP: Codepage %d not supported for TTF output", newCP);
return;
}
else
#endif
keyb_error = DOS_ChangeCodepage(newCP, "auto");
if(keyb_error == KEYB_NOERROR) {
CHCPChangecodepage = true;
SwitchLanguage(cp, newCP, true);
/**
if(layout_name != NULL) {
keyb_error = DOS_ChangeKeyboardLayout(layout_name, cp);
}
*/
}
else {
{
WriteOut(MSG_Get("SHELL_CMD_CHCP_INVALID"), StripArg(args));
return;
}
Expand All @@ -4642,10 +4630,11 @@ void DOS_Shell::CMD_CHCP(char * args) {
if(*buff == ':' && strchr(StripArg(args), ':')) {
std::string name = buff + 1;
if(name.empty() && iter != langcp_map.end()) name = iter->second;
if(CheckDBCSCP(newCP)) {
if(!TTF_using() || (TTF_using() && isSupportedCP(newCP))) {
CHCPChangecodepage = true;
missing = toSetCodePage(this, newCP, -1);
if(missing > -1) SwitchLanguage(cp, newCP, true);
loadlangnew = true;
Load_Language(name);
if(missing > 0) WriteOut(MSG_Get("SHELL_CMD_CHCP_MISSING"), missing);
}
#if defined(USE_TTF)
Expand Down

0 comments on commit 4a6fcf8

Please sign in to comment.