summaryrefslogtreecommitdiff
path: root/Source/cmExecuteProcessCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2006-10-16 11:32:28 -0400
committerBrad King <brad.king@kitware.com>2006-10-16 11:32:28 -0400
commite593fbf6eee74e33f721742ac0d632a3b7f72084 (patch)
treee2c76e08de8f35796a37f40b0c8077eb664447a7 /Source/cmExecuteProcessCommand.cxx
parent641a0ad878e97485dbc02b9344aa72edd2a4f24a (diff)
downloadcmake-e593fbf6eee74e33f721742ac0d632a3b7f72084.tar.gz
ENH: Added OUTPUT_STRIP_TRAILING_WHITESPACE and ERROR_STRIP_TRAILING_WHITESPACE options to EXECUTE_PROCESS command. These allow it to behave more like the old EXEC_PROGRAM command that it is supposed to replace.
Diffstat (limited to 'Source/cmExecuteProcessCommand.cxx')
-rw-r--r--Source/cmExecuteProcessCommand.cxx50
1 files changed, 46 insertions, 4 deletions
diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx
index 835144fbd6..767690fcd1 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.