diff options
author | Brad King <brad.king@kitware.com> | 2019-05-21 13:46:36 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-05-21 13:46:45 (GMT) |
commit | 0bf53483295a4b7de358e8b85ad44866d89633c5 (patch) | |
tree | 3a09081130bb415685b65aec2c15c1813b232cc6 /Source/cmExecProgramCommand.cxx | |
parent | 8538685c85f75d1904800999a50e12d3abb7484e (diff) | |
parent | 273257222ee6207dcb9ad290a08db5d6b7cc9db8 (diff) | |
download | CMake-0bf53483295a4b7de358e8b85ad44866d89633c5.zip CMake-0bf53483295a4b7de358e8b85ad44866d89633c5.tar.gz CMake-0bf53483295a4b7de358e8b85ad44866d89633c5.tar.bz2 |
Merge topic 'string-param'
273257222e Source: change parameters to std::string
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3340
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 |