diff options
author | Vitaly Stakhovsky <vvs31415@gitlab.org> | 2019-05-19 14:30:00 (GMT) |
---|---|---|
committer | Vitaly Stakhovsky <vvs31415@gitlab.org> | 2019-05-19 14:33:26 (GMT) |
commit | 273257222ee6207dcb9ad290a08db5d6b7cc9db8 (patch) | |
tree | 0cc1b5bc33298f556f4438ba04dc689a9f4c09d1 /Source/cmExecProgramCommand.cxx | |
parent | 7024fe33b8ea1d1fba3bf881f8c530688107c505 (diff) | |
download | CMake-273257222ee6207dcb9ad290a08db5d6b7cc9db8.zip CMake-273257222ee6207dcb9ad290a08db5d6b7cc9db8.tar.gz CMake-273257222ee6207dcb9ad290a08db5d6b7cc9db8.tar.bz2 |
Source: change parameters to std::string
Diffstat (limited to 'Source/cmExecProgramCommand.cxx')
-rw-r--r-- | Source/cmExecProgramCommand.cxx | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/Source/cmExecProgramCommand.cxx b/Source/cmExecProgramCommand.cxx index 36651af..4b559e7 100644 --- a/Source/cmExecProgramCommand.cxx +++ b/Source/cmExecProgramCommand.cxx @@ -82,11 +82,11 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args, bool result = true; if (args.size() - count == 2) { cmSystemTools::MakeDirectory(args[1]); - result = cmExecProgramCommand::RunCommand(command.c_str(), output, retVal, + result = cmExecProgramCommand::RunCommand(command, output, retVal, args[1].c_str(), verbose); } else { - result = cmExecProgramCommand::RunCommand(command.c_str(), output, retVal, - nullptr, verbose); + result = cmExecProgramCommand::RunCommand(command, output, retVal, nullptr, + verbose); } if (!result) { retVal = -1; @@ -115,7 +115,7 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args, return true; } -bool cmExecProgramCommand::RunCommand(const char* command, std::string& output, +bool cmExecProgramCommand::RunCommand(std::string command, std::string& output, int& retVal, const char* dir, bool verbose, Encoding encoding) { @@ -128,12 +128,11 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output, // try to find the program, and if the program can not be // found use system to run the command as it must be a built in // shell command like echo or dir - int count = 0; - std::string shortCmd; - if (command[0] == '\"') { + if (!command.empty() && command[0] == '\"') { // count the number of quotes - for (const char* s = command; *s != 0; ++s) { - if (*s == '\"') { + int count = 0; + for (char c : command) { + if (c == '\"') { count++; if (count > 2) { break; @@ -147,20 +146,21 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output, if (count > 2) { cmsys::RegularExpression quoted("^\"([^\"]*)\"[ \t](.*)"); if (quoted.find(command)) { + std::string shortCmd; std::string cmd = quoted.match(1); std::string args = quoted.match(2); if (!cmSystemTools::FileExists(cmd)) { shortCmd = cmd; - } else if (!cmSystemTools::GetShortPath(cmd.c_str(), shortCmd)) { + } else if (!cmSystemTools::GetShortPath(cmd, shortCmd)) { cmSystemTools::Error("GetShortPath failed for " + cmd); return false; } shortCmd += " "; shortCmd += args; - command = shortCmd.c_str(); + command = shortCmd; } else { - cmSystemTools::Error("Could not parse command line with quotes ", + cmSystemTools::Error("Could not parse command line with quotes " + command); } } @@ -182,7 +182,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output, cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1); } cmsysProcess_SetOption(cp, cmsysProcess_Option_Verbatim, 1); - const char* cmd[] = { command, 0 }; + const char* cmd[] = { command.c_str(), nullptr }; cmsysProcess_SetCommand(cp, cmd); #else std::string commandInDir; @@ -197,7 +197,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output, # ifndef __VMS commandInDir += " 2>&1"; # endif - command = commandInDir.c_str(); + command = commandInDir; if (verbose) { cmSystemTools::Stdout("running "); cmSystemTools::Stdout(command); @@ -205,7 +205,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output, } fflush(stdout); fflush(stderr); - const char* cmd[] = { "/bin/sh", "-c", command, nullptr }; + const char* cmd[] = { "/bin/sh", "-c", command.c_str(), nullptr }; cmsysProcess_SetCommand(cp, cmd); #endif |