From 4646929df42808b1ddca449117978b07ca7df2a7 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 10 Feb 2006 11:46:34 -0500 Subject: [PATCH] ENH: Remove extra windows newline characters from process output. Centralized text fix processing. --- Source/cmExecuteProcessCommand.cxx | 38 +++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index 64835fe86..54cd7eda7 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -19,6 +19,8 @@ #include +void cmExecuteProcessCommandFixText(std::vector& output); + // cmExecuteProcessCommand bool cmExecuteProcessCommand::InitialPass(std::vector const& args) { @@ -254,15 +256,6 @@ bool cmExecuteProcessCommand::InitialPass(std::vector 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 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 const& args) return true; } + +//---------------------------------------------------------------------------- +void cmExecuteProcessCommandFixText(std::vector& 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'); +}