summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmExecuteProcessCommand.cxx50
-rw-r--r--Source/cmExecuteProcessCommand.h4
2 files changed, 49 insertions, 5 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.
diff --git a/Source/cmExecuteProcessCommand.h b/Source/cmExecuteProcessCommand.h
index f69c414..a9286a7 100644
--- a/Source/cmExecuteProcessCommand.h
+++ b/Source/cmExecuteProcessCommand.h
@@ -78,7 +78,9 @@ public:
" [OUTPUT_FILE <file>]\n"
" [ERROR_FILE <file>]\n"
" [OUTPUT_QUIET]\n"
- " [ERROR_QUIET])\n"
+ " [ERROR_QUIET]\n"
+ " [OUTPUT_STRIP_TRAILING_WHITESPACE]\n"
+ " [ERROR_STRIP_TRAILING_WHITESPACE])\n"
"Runs the given sequence of one or more commands with the standard "
"output of each process piped to the standard input of the next. "
"A single standard error pipe is used for all processes. "