[cmake-commits] king committed cmExecuteProcessCommand.cxx 1.7 1.8 cmExecuteProcessCommand.h 1.3 1.4

cmake-commits at cmake.org cmake-commits at cmake.org
Mon Oct 16 11:32:36 EDT 2006


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv15508

Modified Files:
	cmExecuteProcessCommand.cxx cmExecuteProcessCommand.h 
Log Message:
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.


Index: cmExecuteProcessCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmExecuteProcessCommand.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cmExecuteProcessCommand.h	10 May 2006 19:06:06 -0000	1.3
+++ cmExecuteProcessCommand.h	16 Oct 2006 15:32:28 -0000	1.4
@@ -78,7 +78,9 @@
       "                  [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.  "

Index: cmExecuteProcessCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmExecuteProcessCommand.cxx,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- cmExecuteProcessCommand.cxx	10 May 2006 19:06:06 -0000	1.7
+++ cmExecuteProcessCommand.cxx	16 Oct 2006 15:32:28 -0000	1.8
@@ -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 @@
   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 @@
       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 @@
   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 @@
 }
 
 //----------------------------------------------------------------------------
-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 @@
       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.



More information about the Cmake-commits mailing list