ENH: added LIMIT on file read
This commit is contained in:
parent
508ddaf929
commit
f8c982cf78
|
@ -190,9 +190,10 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
bool cmFileCommand::HandleReadCommand(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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,11 +215,32 @@ bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args)
|
||||||
return false;
|
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 output;
|
||||||
std::string line;
|
std::string line;
|
||||||
bool has_newline = false;
|
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;
|
output += line;
|
||||||
if ( has_newline )
|
if ( has_newline )
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,7 +66,7 @@ public:
|
||||||
return
|
return
|
||||||
" FILE(WRITE filename \"message to write\"... )\n"
|
" FILE(WRITE filename \"message to write\"... )\n"
|
||||||
" FILE(APPEND 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 variable [RELATIVE path] [globbing expressions]...)\n"
|
||||||
" FILE(GLOB_RECURSE variable [RELATIVE path] \n"
|
" FILE(GLOB_RECURSE variable [RELATIVE path] \n"
|
||||||
" [globbing expressions]...)\n"
|
" [globbing expressions]...)\n"
|
||||||
|
|
Loading…
Reference in New Issue