From cbae0c8cc050f91189ee57cbb87d029b6e150a87 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Sat, 7 Sep 2019 20:55:23 +0100 Subject: [PATCH] foamDictionary: Improved handling of header for binary files --- .../miscellaneous/foamDictionary/foamDictionary.C | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C b/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C index 808aa61c92..46ee8c197b 100644 --- a/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C +++ b/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C @@ -171,11 +171,14 @@ IOstream::streamFormat readDict(dictionary& dict, const fileName& dictFileName) << exit(FatalError, 1); } - // Check if the first character in the file is the first character - // of "FoamFile" to avoid problems if the first entry is a variable - // or function - if (dictFile.peek() == IOobject::foamFile[0]) + // Check if the first token in the file is "FoamFile" + // to avoid problems if the first entry is a variable or function + token firstToken; + dictFile.read(firstToken); + if (firstToken.isWord() && firstToken.wordToken() == IOobject::foamFile) { + dictFile.putBack(firstToken); + // Read the first entry from the dictionary autoPtr firstEntry(entry::New(dictFile())); @@ -191,12 +194,11 @@ IOstream::streamFormat readDict(dictionary& dict, const fileName& dictFileName) ( firstEntry->dict().lookup("format") ); - dictFile().format(dictFormat); } } } - IFstream dictFile(dictFileName); + IFstream dictFile(dictFileName, dictFormat); // Read and add the rest of the dictionary entries // preserving the IOobject::foamFile header dictionary if present