Skip to content

Commit

Permalink
Fix build error on Visual Studio
Browse files Browse the repository at this point in the history
  • Loading branch information
maron2000 committed Sep 18, 2024
1 parent 36e5afe commit fad8273
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
39 changes: 34 additions & 5 deletions src/dos/dos_keyboard_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ Bitu DOS_ChangeCodepage(int32_t codepage, const char* codepagefile);
void MSG_Init(), JFONT_Init(), runRescan(const char *str);
extern int tryconvertcp, toSetCodePage(DOS_Shell *shell, int newCP, int opt);
extern bool jfont_init;
extern int msgcodepage;
extern uint16_t msgcodepage;
bool CheckDBCSCP(uint16_t codepage);
extern bool loadlangcp;
void DisplayKerrcode(Bitu kerrcode);

static FILE* OpenDosboxFile(const char* name) {
uint8_t drive;
Expand Down Expand Up @@ -1398,7 +1399,8 @@ Bitu DOS_LoadKeyboardLayout(const char * layoutname, int32_t codepage, const cha
return kerrcode;
}
// Everything went fine, switch to new layout
loaded_layout=temp_layout;
delete loaded_layout;
loaded_layout=temp_layout;
return KEYB_NOERROR;
}

Expand All @@ -1411,7 +1413,7 @@ Bitu DOS_SwitchKeyboardLayout(const char* new_layout, int32_t& tried_cp) {
delete loaded_layout;
loaded_layout=changed_layout;
}
return ret_code;
return ret_code;
} else return 0xff;
}

Expand All @@ -1422,9 +1424,11 @@ Bitu DOS_ChangeKeyboardLayout(const char* layoutname, int32_t codepage) {
Bitu kerrcode = temp_layout->read_keyboard_file(layoutname, codepage);
if(kerrcode) {
delete temp_layout;
DisplayKerrcode(kerrcode);
return kerrcode;
}
// Everything went fine, switch to new layout
delete loaded_layout;
loaded_layout = temp_layout;
return KEYB_NOERROR;
}
Expand All @@ -1447,9 +1451,32 @@ const char* DOS_GetLoadedLayout(void) {
return NULL;
}

void DisplayKerrcode(Bitu kerrcode){
switch(kerrcode){
case KEYB_NOERROR:
return;
case KEYB_FILENOTFOUND:
LOG_MSG("KEYB_CHCP Error: File not found.\n");
return;
case KEYB_INVALIDFILE:
LOG_MSG("KEYB_CHCP Error: Invalid File.\n");
return;
case KEYB_LAYOUTNOTFOUND:
LOG_MSG("KEYB_CHCP Error: Layout not found.\n");
return;
case KEYB_INVALIDCPFILE:
LOG_MSG("KEYB_CHCP Error: Invalid codepage file.\n");
return;
default:
LOG_MSG("KEYB_CHCP Error: Check entered command.\n");
break;
}
}

class DOS_KeyboardLayout: public Module_base {
public:
DOS_KeyboardLayout(Section* configuration):Module_base(configuration){
Bitu kerrcode;
const Section_prop* section = static_cast<Section_prop*>(configuration);
const char * layoutname=section->Get_string("keyboardlayout");
//dos.loaded_codepage = GetDefaultCP(); // default codepage already initialized
Expand Down Expand Up @@ -1747,7 +1774,7 @@ class DOS_KeyboardLayout: public Module_base {

if(msgcodepage) {
SwitchLanguage(dos.loaded_codepage, msgcodepage, false);
if(!CheckDBCSCP(msgcodepage)) DOS_ChangeCodepage(msgcodepage, "auto");
if(!CheckDBCSCP(msgcodepage)) DisplayKerrcode(DOS_ChangeCodepage(msgcodepage, "auto"));
}

}
Expand Down Expand Up @@ -1789,12 +1816,14 @@ void DOS_KeyboardLayout_Init() {
AddVMEventFunction(VM_EVENT_DOS_EXIT_BEGIN,AddVMEventFunctionFuncPair(DOS_KeyboardLayout_ShutDown));
}

static const std::set<int> supportedCodepages = // Codepages supported in TTF output mode
// Codepages supported in TTF output mode
static const std::set<int> supportedCodepages =
{
437, 737, 775, 808, 850, 852, 853, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 872, 874,
932, 936, 949, 950, 951, 1250, 1251, 1252, 1253, 1254, 1255, 1256, 1257, 1258, 3021
};

// True if specified codepage is supported in TTF output mode
bool isSupportedCP(int cp)
{
if (supportedCodepages.count(cp)) return true;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ DOSBoxMenu mainMenu;

extern const char* drive_opts[][2];
extern const char* scaler_menu_opts[][2];
extern int NonUserResizeCounter, msgcodepage;
extern int NonUserResizeCounter;
extern uint16_t msgcodepage;

extern bool force_conversion;
extern bool dos_kernel_disabled;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/menu_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ std::string savefilename = "";

extern SHELL_Cmd cmd_list[];
extern unsigned int page, hostkeyalt, sendkeymap;
extern int posx, posy, wheel_key, mbutton, enablelfn, dos_clipboard_device_access, aspect_ratio_x, aspect_ratio_y, disk_data_rate, floppy_data_rate, lastmsgcp;
extern int posx, posy, wheel_key, mbutton, enablelfn, dos_clipboard_device_access, aspect_ratio_x, aspect_ratio_y, disk_data_rate, floppy_data_rate;
extern uint16_t lastmsgcp;
extern bool addovl, clearline, pcibus_enable, winrun, window_was_maximized, wheel_guest, clipboard_dosapi, clipboard_biospaste, direct_mouse_clipboard, sync_time, manualtime, pausewithinterrupts_enable, enable_autosave, enable_config_as_shell_commands, noremark_save_state, force_load_state, use_quick_reboot, use_save_file, dpi_aware_enable, pc98_force_ibm_layout, log_int21, log_fileio, x11_on_top, macosx_on_top, rtl, gbk, chinasea, uselangcp;
extern bool mountfro[26], mountiro[26];
extern struct BuiltinFileBlob bfb_GLIDE2X_OVL;
Expand Down
3 changes: 2 additions & 1 deletion src/misc/programs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ extern char lastmount;
extern const char *modifier;
extern unsigned int sendkeymap;
extern std::string langname, configfile, dosbox_title;
extern int autofixwarn, enablelfn, fat32setver, paste_speed, wheel_key, freesizecap, wpType, wpVersion, wpBG, wpFG, lastset, blinkCursor, msgcodepage;
extern int autofixwarn, enablelfn, fat32setver, paste_speed, wheel_key, freesizecap, wpType, wpVersion, wpBG, wpFG, lastset, blinkCursor;
extern uint16_t msgcodepage;
extern bool dos_kernel_disabled, force_nocachedir, wpcolon, convertimg, lockmount, enable_config_as_shell_commands, lesssize, load, winrun, winautorun, startcmd, startwait, startquiet, starttranspath, mountwarning, wheel_guest, clipboard_dosapi, noremark_save_state, force_load_state, sync_time, manualtime, ttfswitch, loadlang, showbold, showital, showline, showsout, char512, printfont, rtl, gbk, chinasea, uao, showdbcs, dbcs_sbcs, autoboxdraw, halfwidthkana, ticksLocked, outcon, enable_dbcs_tables, show_recorded_filename, internal_program, pipetmpdev, notrysgf, uselangcp, incall;

/* This registers a file on the virtual drive and creates the correct structure for it*/
Expand Down
8 changes: 5 additions & 3 deletions src/shell/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 uint16_t msgcodepage, lastmsgcp;
extern uint16_t countryNo;
extern unsigned int dosbox_shell_env_size;
bool outcon = true, usecon = true, pipetmpdev = true;
Expand All @@ -81,6 +82,7 @@ void SwitchLanguage(uint16_t oldcp, uint16_t 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();
bool CheckDBCSCP(uint16_t msgcodepage);

Bitu call_shellstop = 0;
/* Larger scope so shell_del autoexec can use it to
Expand Down Expand Up @@ -861,7 +863,7 @@ void DOS_Shell::Prepare(void) {
else {
if (r!=NULL) *r=0;
country = atoi(trim(countrystr));
int32_t newCP = r==NULL||IS_PC98_ARCH||IS_JEGA_ARCH||IS_DOSV?dos.loaded_codepage:atoi(trim(r+1));
uint16_t newCP = r==NULL||IS_PC98_ARCH||IS_JEGA_ARCH||IS_DOSV?dos.loaded_codepage:atoi(trim(r+1));
if (control->opt_langcp && msgcodepage>0 && isSupportedCP(msgcodepage) && msgcodepage != newCP)
newCP = msgcodepage;
if (r!=NULL) *r=',';
Expand All @@ -883,7 +885,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");
Expand Down

0 comments on commit fad8273

Please sign in to comment.