diff options
Diffstat (limited to 'Source/cmExecuteProcessCommand.cxx')
-rw-r--r-- | Source/cmExecuteProcessCommand.cxx | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index 835144f..767690f 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -19,7 +19,15 @@ #include <cmsys/Process.h> -void cmExecuteProcessCommandFixText(std::vector<char>& output); +#include <ctype.h> /* isspace */ + +static bool cmExecuteProcessCommandIsWhitespace(char c) +{ + return (isspace((int)c) || c == '\n' || c == '\r'); +} + +void cmExecuteProcessCommandFixText(std::vector<char>& output, + bool strip_trailing_whitespace); // cmExecuteProcessCommand bool cmExecuteProcessCommand @@ -36,6 +44,8 @@ bool cmExecuteProcessCommand size_t command_index = 0; bool output_quiet = false; bool error_quiet = false; + bool output_strip_trailing_whitespace = false; + bool error_strip_trailing_whitespace = false; std::string timeout_string; std::string input_file; std::string output_file; @@ -166,10 +176,27 @@ bool cmExecuteProcessCommand doing_command = false; error_quiet = true; } + else if(args[i] == "OUTPUT_STRIP_TRAILING_WHITESPACE") + { + doing_command = false; + output_strip_trailing_whitespace = true; + } + else if(args[i] == "ERROR_STRIP_TRAILING_WHITESPACE") + { + doing_command = false; + error_strip_trailing_whitespace = true; + } else if(doing_command) { cmds[command_index].push_back(args[i].c_str()); } + else + { + cmOStringStream e; + e << " given unknown argument \"" << args[i] << "\"."; + this->SetError(e.str().c_str()); + return false; + } } if ( !this->Makefile->CanIWriteThisFile(output_file.c_str()) ) @@ -294,8 +321,10 @@ bool cmExecuteProcessCommand cmsysProcess_WaitForExit(cp, 0); // Fix the text in the output strings. - cmExecuteProcessCommandFixText(tempOutput); - cmExecuteProcessCommandFixText(tempError); + cmExecuteProcessCommandFixText(tempOutput, + output_strip_trailing_whitespace); + cmExecuteProcessCommandFixText(tempError, + error_strip_trailing_whitespace); // Store the output obtained. if(!output_variable.empty() && tempOutput.size()) @@ -344,7 +373,8 @@ bool cmExecuteProcessCommand } //---------------------------------------------------------------------------- -void cmExecuteProcessCommandFixText(std::vector<char>& output) +void cmExecuteProcessCommandFixText(std::vector<char>& output, + bool strip_trailing_whitespace) { // Remove \0 characters and the \r part of \r\n pairs. unsigned int in_index = 0; @@ -358,6 +388,18 @@ void cmExecuteProcessCommandFixText(std::vector<char>& output) output[out_index++] = c; } } + + // Remove trailing whitespace if requested. + if(strip_trailing_whitespace) + { + while(out_index > 0 && + cmExecuteProcessCommandIsWhitespace(output[out_index-1])) + { + --out_index; + } + } + + // Shrink the vector to the size needed. output.resize(out_index); // Put a terminator on the text string. |