[cmake-commits] martink committed cmFileCommand.h 1.19 1.20 cmFileCommand.cxx 1.71 1.72

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Mar 1 15:53:11 EST 2007


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

Modified Files:
	cmFileCommand.h cmFileCommand.cxx 
Log Message:
ENH: added LIMIT on file read


Index: cmFileCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFileCommand.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- cmFileCommand.h	20 Feb 2007 20:09:09 -0000	1.19
+++ cmFileCommand.h	1 Mar 2007 20:53:09 -0000	1.20
@@ -66,7 +66,7 @@
     return
       "  FILE(WRITE filename \"message to write\"... )\n"
       "  FILE(APPEND filename \"message to write\"... )\n"
-      "  FILE(READ filename variable)\n"
+      "  FILE(READ filename variable [LIMIT numBytes])\n"
       "  FILE(GLOB variable [RELATIVE path] [globbing expressions]...)\n"
       "  FILE(GLOB_RECURSE variable [RELATIVE path] \n"
       "       [globbing expressions]...)\n"

Index: cmFileCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFileCommand.cxx,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- cmFileCommand.cxx	29 Aug 2006 19:04:29 -0000	1.71
+++ cmFileCommand.cxx	1 Mar 2007 20:53:09 -0000	1.72
@@ -190,9 +190,10 @@
 //----------------------------------------------------------------------------
 bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args)
 {
-  if ( args.size() != 3 )
+  if ( args.size() < 3 )
     {
-    this->SetError("READ must be called with two additional arguments");
+    this->SetError("READ must be called with at least two additional "
+                   "arguments");
     return false;
     }
 
@@ -214,11 +215,32 @@
     return false;
     }
 
+  // if there a limit?
+  long sizeLimit = -1;
+  if (args.size() >= 5 && args[3] == "LIMIT")
+    {
+    sizeLimit = atof(args[4].c_str());
+    }
+
   std::string output;
   std::string line;
   bool has_newline = false;
-  while ( cmSystemTools::GetLineFromStream(file, line, &has_newline) )
+  while (sizeLimit != 0 &&
+         cmSystemTools::GetLineFromStream(file, line, &has_newline, 
+                                          sizeLimit) )
     {
+    if (sizeLimit > 0)
+      {
+      sizeLimit -= line.size();
+      if (has_newline)
+        {
+        sizeLimit--;
+        }
+      if (sizeLimit < 0)
+        {
+        sizeLimit = 0;
+        }
+      }
     output += line;
     if ( has_newline )
       {



More information about the Cmake-commits mailing list