diff --git a/include/shell.h b/include/shell.h index 7835e4b3..fc472856 100644 --- a/include/shell.h +++ b/include/shell.h @@ -35,11 +35,12 @@ #define CMD_MAXCMDS 20 #define CMD_OLDSIZE 4096 extern Bitu call_shellstop; +class DOS_Shell; + /* first_shell is used to add and delete stuff from the shell env * by "external" programs. (config) */ -extern Program * first_shell; +extern DOS_Shell * first_shell; -class DOS_Shell; class BatchFile { public: diff --git a/src/dos/dos_programs.cpp b/src/dos/dos_programs.cpp index 3b202c26..93b8a83c 100644 --- a/src/dos/dos_programs.cpp +++ b/src/dos/dos_programs.cpp @@ -165,12 +165,12 @@ public: /* remap drives */ Drives[i_newz] = Drives[25]; Drives[25] = 0; - DOS_Shell *fs = static_cast(first_shell); //dynamic ? + if (!first_shell) return; //Should not be possible /* Update environment */ std::string line = ""; char ppp[2] = {newz[0],0}; std::string tempenv = ppp; tempenv += ":\\"; - if (fs->GetEnvStr("PATH",line)){ + if (first_shell->GetEnvStr("PATH",line)){ std::string::size_type idx = line.find('='); std::string value = line.substr(idx +1 , std::string::npos); while ( (idx = value.find("Z:\\")) != std::string::npos || @@ -179,13 +179,13 @@ public: line = value; } if (!line.size()) line = tempenv; - fs->SetEnv("PATH",line.c_str()); + first_shell->SetEnv("PATH",line.c_str()); tempenv += "COMMAND.COM"; - fs->SetEnv("COMSPEC",tempenv.c_str()); + first_shell->SetEnv("COMSPEC",tempenv.c_str()); /* Update batch file if running from Z: (very likely: autoexec) */ - if(fs->bf) { - std::string &name = fs->bf->filename; + if(first_shell->bf) { + std::string &name = first_shell->bf->filename; if(name.length() >2 && name[0] == 'Z' && name[1] == ':') name[0] = newz[0]; } /* Change the active drive */ diff --git a/src/gui/sdl_gui.cpp b/src/gui/sdl_gui.cpp index 3318af20..9640b065 100644 --- a/src/gui/sdl_gui.cpp +++ b/src/gui/sdl_gui.cpp @@ -38,7 +38,6 @@ #include extern Bit8u int10_font_14[256 * 14]; -extern Program * first_shell; extern bool MSG_Write(const char *); extern void GFX_SetTitle(Bit32s cycles, Bits frameskip, bool paused); @@ -454,10 +453,9 @@ public: if (arg == "OK") section->data = *(std::string*)content->getText(); if (arg == "OK" || arg == "Cancel") close(); else if (arg == "Append Shell Commands") { - DOS_Shell *s = static_cast(first_shell); - std::list::reverse_iterator i = s->l_history.rbegin(); + std::list::reverse_iterator i = first_shell->l_history.rbegin(); std::string lines = *(std::string*)content->getText(); - while (i != s->l_history.rend()) { + while (i != first_shell->l_history.rend()) { lines += "\n"; lines += *i; ++i; diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index 51141cb9..aff8045e 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -31,7 +31,7 @@ Bitu call_shellstop; /* Larger scope so shell_del autoexec can use it to * remove things from the environment */ -Program * first_shell = 0; +DOS_Shell * first_shell = 0; static Bitu shellstop_handler(void) { return CBRET_STOP; @@ -40,6 +40,11 @@ static Bitu shellstop_handler(void) { static void SHELL_ProgramStart(Program * * make) { *make = new DOS_Shell; } +//Repeat it with the correct type, could do it in the function below, but this way it should be +//clear that if the above function is changed, this function might need a change as well. +static void SHELL_ProgramStart_First_shell(DOS_Shell * * make) { + *make = new DOS_Shell; +} #define AUTOEXEC_SIZE 4096 static char autoexec_data[AUTOEXEC_SIZE] = { 0 }; @@ -746,7 +751,7 @@ void SHELL_Init() { dos.psp(psp_seg); - SHELL_ProgramStart(&first_shell); + SHELL_ProgramStart_First_shell(&first_shell); first_shell->Run(); delete first_shell; first_shell = 0;//Make clear that it shouldn't be used anymore