foamDictionary: improved checking for FoamFile

This commit is contained in:
Henry Weller
2019-08-19 09:20:05 +01:00
parent 3fe2d3d9ad
commit 7350f07582

View File

@ -171,14 +171,21 @@ IOstream::streamFormat readDict(dictionary& dict, const fileName& dictFileName)
<< exit(FatalError, 1); << exit(FatalError, 1);
} }
// Read the first entry from the dictionary without expansion // Check if the first character in the file is the first character
entry::disableFunctionEntries = true; // of "FoamFile" to avoid problems if the first entry is a variable
// or function
if (dictFile.peek() == IOobject::foamFile[0])
{
// Read the first entry from the dictionary
autoPtr<entry> firstEntry(entry::New(dictFile())); autoPtr<entry> firstEntry(entry::New(dictFile()));
entry::disableFunctionEntries = false;
// If the first entry is the "FoamFile" header dictionary // If the first entry is the "FoamFile" header
// read and set the stream format // read and set the stream format
if (firstEntry->isDict() && firstEntry->keyword() == IOobject::foamFile) if
(
firstEntry->isDict()
&& firstEntry->keyword() == IOobject::foamFile
)
{ {
dictFormat = IOstream::formatEnum dictFormat = IOstream::formatEnum
( (
@ -187,6 +194,7 @@ IOstream::streamFormat readDict(dictionary& dict, const fileName& dictFileName)
dictFile().format(dictFormat); dictFile().format(dictFormat);
} }
} }
}
IFstream dictFile(dictFileName); IFstream dictFile(dictFileName);