diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index e2555ac5a24a706f94ccdeb15f4151c12893b45d..b2aa694c4347f221e3327db112b61cb69697facf 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -33,6 +33,7 @@ License #include "dictionaryEntry.H" #include "regExp.H" #include "OSHA1stream.H" +#include "OSstream.H" #include "argList.H" #include "registerSwitch.H" @@ -43,6 +44,8 @@ namespace Foam defineTypeNameAndDebug(dictionary, 0); } +Foam::refPtr<Foam::OSstream> Foam::dictionary::reportingOutput(nullptr); + const Foam::dictionary Foam::dictionary::null; int Foam::dictionary::writeOptionalEntries @@ -59,6 +62,14 @@ registerInfoSwitch ); +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::word Foam::dictionary::executableName() +{ + return argList::envExecutable(); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::dictionary::dictionary() diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index 4fff7b0e7cf50aa63f8d2bd3b254aeb1fc21620e..d51673c8146d7c8e6a86b12338828152c64a68ed 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -97,6 +97,7 @@ SeeAlso #include "HashTable.H" #include "wordList.H" #include "className.H" +#include "refPtr.H" // Some common data types #include "label.H" @@ -110,6 +111,7 @@ namespace Foam // Forward Declarations class dictionary; +class OSstream; class SHA1Digest; Istream& operator>>(Istream& is, dictionary& dict); @@ -360,7 +362,11 @@ private: //- Emit IOError about bad input for the entry void raiseBadInput(const ITstream& is, const word& keyword) const; - //- Report (stderr) that the keyword default value was used. + //- The currently known executable name, + //- obtained from argList envExecutable + static word executableName(); + + //- Report (usually stderr) that the keyword default value was used, //- or FatalIOError when writeOptionalEntries greater than 1 template<class T> void reportDefault @@ -386,6 +392,9 @@ public: //- An empty dictionary, which is also the parent for all dictionaries static const dictionary null; + //- Output location when reporting default values + static refPtr<OSstream> reportingOutput; + // Static Member Functions diff --git a/src/OpenFOAM/db/dictionary/dictionaryTemplates.C b/src/OpenFOAM/db/dictionary/dictionaryTemplates.C index 2c05308c388ed73fddb26e99b94ccecc03483269..454100e2aa69c90b79fccff58ed44baf93009c84 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryTemplates.C +++ b/src/OpenFOAM/db/dictionary/dictionaryTemplates.C @@ -41,23 +41,41 @@ void Foam::dictionary::reportDefault { if (writeOptionalEntries > 1) { - FatalIOErrorInFunction(*this) + FatalIOError(dictionary::executableName(), *this) << "No optional entry: " << keyword << " Default: " << deflt << nl << exit(FatalIOError); } - InfoErr - << "Dictionary: " << this->relativeName().c_str() - << " Entry: " << keyword; + OSstream& os = InfoErr.stream(reportingOutput.get()); + + // Tag with "-- " prefix to make the message stand out + os << "-- Executable: " + << dictionary::executableName() + << " Dictionary: "; + + // Double-quote dictionary and entry for more reliably parsing, + // especially if the keyword contains regular expressions. + + if (this->isNullDict()) + { + // Output as "", but could have "(null)" etc + os << token::DQUOTE << token::DQUOTE; + } + else + { + os.writeQuoted(this->relativeName(), true); + } + + os << " Entry: "; + os.writeQuoted(keyword, true); + os << " Default: " << deflt; if (added) { - InfoErr - << " Added"; + os << " Added: true"; } - InfoErr - << " Default: " << deflt << nl; + os << nl; } @@ -195,14 +213,15 @@ T Foam::dictionary::getCheckOrDefault enum keyType::option matchOpt ) const { + #ifdef FULLDEBUG if (!pred(deflt)) { - // Could be as FULLDEBUG instead? FatalIOErrorInFunction(*this) << "Entry '" << keyword << "' with invalid default in dictionary " << name() << exit(FatalIOError); } + #endif const const_searcher finder(csearch(keyword, matchOpt)); @@ -240,14 +259,15 @@ T Foam::dictionary::getCheckOrAdd enum keyType::option matchOpt ) { + #ifdef FULLDEBUG if (!pred(deflt)) { - // Could be as FULLDEBUG instead? FatalIOErrorInFunction(*this) << "Entry '" << keyword << "' with invalid default in dictionary " << name() << exit(FatalIOError); } + #endif const const_searcher finder(csearch(keyword, matchOpt));