diff --git a/include/programs.h b/include/programs.h index 1006ac83..8815fa04 100644 --- a/include/programs.h +++ b/include/programs.h @@ -50,6 +50,7 @@ public: bool FindCommand(unsigned int which,std::string & value); bool FindStringBegin(char const * const begin,std::string & value, bool remove=false); bool FindStringRemain(char const * const name,std::string & value); + bool FindStringRemainBegin(char const * const name,std::string & value); bool GetStringRemain(std::string & value); int GetParameterFromList(const char* const params[], std::vector & output); void FillVector(std::vector & vector); diff --git a/src/misc/setup.cpp b/src/misc/setup.cpp index 655182a3..25bd5a4e 100644 --- a/src/misc/setup.cpp +++ b/src/misc/setup.cpp @@ -955,6 +955,39 @@ bool CommandLine::FindStringRemain(char const * const name,std::string & value) return true; } +/* Only used for parsing command.com /C + * Allowing /C dir and /Cdir + * Restoring quotes back into the commands so command /C mount d "/tmp/a b" works as intended + */ +bool CommandLine::FindStringRemainBegin(char const * const name,std::string & value) { + cmd_it it;value=""; + if (!FindEntry(name,it)) { + size_t len = strlen(name); + for (it=cmds.begin();it!=cmds.end();it++) { + if (strncasecmp(name,(*it).c_str(),len)==0) { + std::string temp = ((*it).c_str() + len); + //Restore quotes for correct parsing in later stages + if(temp.find(" ") != std::string::npos) + value = std::string("\"") + temp + std::string("\""); + else + value = temp; + break; + } + } + if( it == cmds.end()) return false; + } + it++; + for (;it!=cmds.end();it++) { + value += " "; + std::string temp = (*it); + if(temp.find(" ") != std::string::npos) + value += std::string("\"") + temp + std::string("\""); + else + value += temp; + } + return true; +} + bool CommandLine::GetStringRemain(std::string & value) { if(!cmds.size()) return false; diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index b4384725..a7464a19 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -285,7 +285,7 @@ void DOS_Shell::RunInternal(void) void DOS_Shell::Run(void) { char input_line[CMD_MAXLINE] = {0}; std::string line; - if (cmd->FindStringRemain("/C",line)) { + if (cmd->FindStringRemainBegin("/C",line)) { strcpy(input_line,line.c_str()); char* sep = strpbrk(input_line,"\r\n"); //GTA installer if (sep) *sep = 0;