diff options
author | Brad King <brad.king@kitware.com> | 2006-02-10 16:46:34 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2006-02-10 16:46:34 (GMT) |
commit | 4646929df42808b1ddca449117978b07ca7df2a7 (patch) | |
tree | 3796fb10c7016e8b7aab89df00204e3f5a3f9eaa /Source/cmExecuteProcessCommand.cxx | |
parent | 976ab27ffd2bf71d252189724c412ecb44c49050 (diff) | |
download | CMake-4646929df42808b1ddca449117978b07ca7df2a7.zip CMake-4646929df42808b1ddca449117978b07ca7df2a7.tar.gz CMake-4646929df42808b1ddca449117978b07ca7df2a7.tar.bz2 |
ENH: Remove extra windows newline characters from process output. Centralized text fix processing.
Diffstat (limited to 'Source/cmExecuteProcessCommand.cxx')
-rw-r--r-- | Source/cmExecuteProcessCommand.cxx | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index 64835fe..54cd7ed 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -19,6 +19,8 @@ #include <cmsys/Process.h> +void cmExecuteProcessCommandFixText(std::vector<char>& output); + // cmExecuteProcessCommand bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args) { @@ -254,15 +256,6 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args) int p; while((p = cmsysProcess_WaitForData(cp, &data, &length, 0), p)) { - // Translate NULL characters in the output into valid text. - for(int i=0; i < length; ++i) - { - if(data[i] == '\0') - { - data[i] = ' '; - } - } - // Put the output in the right place. if(p == cmsysProcess_Pipe_STDOUT && !output_quiet || p == cmsysProcess_Pipe_STDERR && !error_quiet && merge_output) @@ -288,15 +281,17 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args) // All output has been read. Wait for the process to exit. cmsysProcess_WaitForExit(cp, 0); + // Fix the text in the output strings. + cmExecuteProcessCommandFixText(tempOutput); + cmExecuteProcessCommandFixText(tempError); + // Store the output obtained. if(!output_variable.empty()) { - tempOutput.push_back('\0'); m_Makefile->AddDefinition(output_variable.c_str(), &*tempOutput.begin()); } if(!merge_output && !error_variable.empty()) { - tempError.push_back('\0'); m_Makefile->AddDefinition(error_variable.c_str(), &*tempError.begin()); } @@ -333,3 +328,24 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args) return true; } + +//---------------------------------------------------------------------------- +void cmExecuteProcessCommandFixText(std::vector<char>& output) +{ + // Remove \0 characters and the \r part of \r\n pairs. + unsigned int in_index = 0; + unsigned int out_index = 0; + while(in_index < output.size()) + { + char c = output[in_index++]; + if((c != '\r' || !(in_index < output.size() && output[in_index] == '\n')) + && c != '\0') + { + output[out_index++] = c; + } + } + output.resize(out_index); + + // Put a terminator on the text string. + output.push_back('\0'); +} |