summaryrefslogtreecommitdiffstats
path: root/Source/cmFileCommand.cxx
diff options
context:
space:
mode:
authorKen Martin <ken.martin@kitware.com>2007-03-01 20:53:09 (GMT)
committerKen Martin <ken.martin@kitware.com>2007-03-01 20:53:09 (GMT)
commitf8c982cf786362385048071bb35bf826fa1516c4 (patch)
tree4c2ea1a3ed7d62a7abe9ea72386dab7ec5a24568 /Source/cmFileCommand.cxx
parent508ddaf929da47e1bf54fc3d348792694fb4b1b9 (diff)
downloadCMake-f8c982cf786362385048071bb35bf826fa1516c4.zip
CMake-f8c982cf786362385048071bb35bf826fa1516c4.tar.gz
CMake-f8c982cf786362385048071bb35bf826fa1516c4.tar.bz2
ENH: added LIMIT on file read
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r--Source/cmFileCommand.cxx28
1 files changed, 25 insertions, 3 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index d5d1eb2..a97802c 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -190,9 +190,10 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
//----------------------------------------------------------------------------
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 @@ bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args)
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 )
{